Skip to content

Commit 97d4ab1

Browse files
authored
Add travis check for filename spaces (#2821)
* Proposed improvements to space checking (#2824)
1 parent 58205aa commit 97d4ab1

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

scripts/check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ fi
212212

213213
# Check lint errors.
214214
"${top_dir}/scripts/check_whitespace.sh"
215+
"${top_dir}/scripts/check_filename_spaces.sh"
215216
"${top_dir}/scripts/check_copyright.sh"
216217
"${top_dir}/scripts/check_no_module_imports.sh"
217218
"${top_dir}/scripts/check_test_inclusion.py"

scripts/check_filename_spaces.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 Google
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Fail on spaces in file names, excluding the patterns listed below.
18+
19+
# A sed program that removes filename patterns that are allowed to have spaces
20+
# in them.
21+
function remove_valid_names() {
22+
sed '
23+
# Xcode-generated asset files
24+
/Assets.xcassets/ d
25+
26+
# Files without spaces
27+
/^[^ ]*$/ d
28+
'
29+
}
30+
31+
count=$(git ls-files | remove_valid_names | wc -l | xargs)
32+
33+
if [[ ${count} != 0 ]]; then
34+
echo 'ERROR: Spaces in filenames are not permitted in this repo. Please fix.'
35+
echo ''
36+
37+
git ls-files | remove_valid_names
38+
exit 1
39+
fi

0 commit comments

Comments
 (0)