mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #13447 - gterzian:check_webidls_folder_files, r=Wafflespeanut
Have tidy ensure that the there are no extra files in the webidls folder #13427 <!-- Please describe your changes on the following line: --> Have tidy ensure that the there are no extra files in the webidls folder #13427 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #13427 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13447) <!-- Reviewable:end -->
This commit is contained in:
commit
3a5fd8b49a
9 changed files with 52 additions and 3 deletions
|
@ -9,4 +9,9 @@ Install from PyPI (coming soon) or
|
||||||
pip install -e git+https://github.com/servo/servo.git#egg=servo_tidy&subdirectory=python/tidy
|
pip install -e git+https://github.com/servo/servo.git#egg=servo_tidy&subdirectory=python/tidy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To run the tests
|
||||||
|
++++++++++++++++
|
||||||
|
|
||||||
|
```
|
||||||
|
./mach test-tidy --self-test
|
||||||
|
```
|
||||||
|
|
|
@ -35,7 +35,8 @@ config = {
|
||||||
"./.", # ignore hidden directories
|
"./.", # ignore hidden directories
|
||||||
],
|
],
|
||||||
"packages": [],
|
"packages": [],
|
||||||
}
|
},
|
||||||
|
"check_ext": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMENTS = ["// ", "# ", " *", "/* "]
|
COMMENTS = ["// ", "# ", " *", "/* "]
|
||||||
|
@ -687,7 +688,7 @@ def check_config_file(config_file, print_text=True):
|
||||||
# Check for invalid tables
|
# Check for invalid tables
|
||||||
if re.match("\[(.*?)\]", line.strip()):
|
if re.match("\[(.*?)\]", line.strip()):
|
||||||
table_name = re.findall(r"\[(.*?)\]", line)[0].strip()
|
table_name = re.findall(r"\[(.*?)\]", line)[0].strip()
|
||||||
if table_name not in ("configs", "ignore"):
|
if table_name not in ("configs", "ignore", "check_ext"):
|
||||||
yield config_file, idx + 1, "invalid config table [%s]" % table_name
|
yield config_file, idx + 1, "invalid config table [%s]" % table_name
|
||||||
current_table = table_name
|
current_table = table_name
|
||||||
continue
|
continue
|
||||||
|
@ -724,6 +725,13 @@ def parse_config(content):
|
||||||
config['ignore']['directories'] = map(lambda path: os.path.join(*path.split('/')),
|
config['ignore']['directories'] = map(lambda path: os.path.join(*path.split('/')),
|
||||||
config['ignore']['directories'])
|
config['ignore']['directories'])
|
||||||
|
|
||||||
|
# Add dict of dir, list of expected ext to config
|
||||||
|
dirs_to_check = config_file.get("check_ext", {})
|
||||||
|
# Fix the paths (OS-dependent)
|
||||||
|
for path, exts in dirs_to_check.items():
|
||||||
|
fixed_path = os.path.join(*path.split('/'))
|
||||||
|
config['check_ext'][fixed_path] = exts
|
||||||
|
|
||||||
# Override default configs
|
# Override default configs
|
||||||
user_configs = config_file.get("configs", [])
|
user_configs = config_file.get("configs", [])
|
||||||
for pref in user_configs:
|
for pref in user_configs:
|
||||||
|
@ -731,6 +739,23 @@ def parse_config(content):
|
||||||
config[pref] = user_configs[pref]
|
config[pref] = user_configs[pref]
|
||||||
|
|
||||||
|
|
||||||
|
def check_directory_files(directories, print_text=True):
|
||||||
|
if print_text:
|
||||||
|
print '\rChecking directories for correct file extensions...'
|
||||||
|
for directory, file_extensions in directories.items():
|
||||||
|
files = sorted(os.listdir(directory))
|
||||||
|
for filename in files:
|
||||||
|
if not any(filename.endswith(ext) for ext in file_extensions):
|
||||||
|
details = {
|
||||||
|
"name": os.path.basename(filename),
|
||||||
|
"ext": ", ".join(file_extensions),
|
||||||
|
"dir_name": directory
|
||||||
|
}
|
||||||
|
message = '''Unexpected extension found for {name}. \
|
||||||
|
We only expect files with {ext} extensions in {dir_name}'''.format(**details)
|
||||||
|
yield (filename, 1, message)
|
||||||
|
|
||||||
|
|
||||||
def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions, print_text=True):
|
def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions, print_text=True):
|
||||||
(has_element, files_to_check) = is_iter_empty(files_to_check)
|
(has_element, files_to_check) = is_iter_empty(files_to_check)
|
||||||
if not has_element:
|
if not has_element:
|
||||||
|
@ -831,6 +856,8 @@ def get_file_list(directory, only_changed_files=False, exclude_dirs=[]):
|
||||||
def scan(only_changed_files=False, progress=True):
|
def scan(only_changed_files=False, progress=True):
|
||||||
# check config file for errors
|
# check config file for errors
|
||||||
config_errors = check_config_file(CONFIG_FILE_PATH)
|
config_errors = check_config_file(CONFIG_FILE_PATH)
|
||||||
|
# check directories contain expected files
|
||||||
|
directory_errors = check_directory_files(config['check_ext'])
|
||||||
# standard checks
|
# standard checks
|
||||||
files_to_check = filter_files('.', only_changed_files, progress)
|
files_to_check = filter_files('.', only_changed_files, progress)
|
||||||
checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json)
|
checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json)
|
||||||
|
@ -842,7 +869,7 @@ def scan(only_changed_files=False, progress=True):
|
||||||
# wpt lint checks
|
# wpt lint checks
|
||||||
wpt_lint_errors = check_wpt_lint_errors(get_wpt_files(only_changed_files, progress))
|
wpt_lint_errors = check_wpt_lint_errors(get_wpt_files(only_changed_files, progress))
|
||||||
# chain all the iterators
|
# chain all the iterators
|
||||||
errors = itertools.chain(config_errors, file_errors, dep_license_errors, wpt_lint_errors)
|
errors = itertools.chain(config_errors, directory_errors, file_errors, dep_license_errors, wpt_lint_errors)
|
||||||
|
|
||||||
error = None
|
error = None
|
||||||
for error in errors:
|
for error in errors:
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from servo_tidy import tidy
|
from servo_tidy import tidy
|
||||||
|
|
||||||
base_path = 'servo_tidy_tests/' if os.path.exists('servo_tidy_tests/') else 'python/tidy/servo_tidy_tests/'
|
base_path = 'servo_tidy_tests/' if os.path.exists('servo_tidy_tests/') else 'python/tidy/servo_tidy_tests/'
|
||||||
|
@ -30,6 +31,17 @@ class CheckTidiness(unittest.TestCase):
|
||||||
self.assertEqual('invalid config table [wrong]', errors.next()[2])
|
self.assertEqual('invalid config table [wrong]', errors.next()[2])
|
||||||
self.assertNoMoreErrors(errors)
|
self.assertNoMoreErrors(errors)
|
||||||
|
|
||||||
|
def test_directory_checks(self):
|
||||||
|
dirs = {
|
||||||
|
os.path.join(base_path, "dir_check/webidl_plus"): ['webidl', 'test'],
|
||||||
|
os.path.join(base_path, "dir_check/only_webidl"): ['webidl']
|
||||||
|
}
|
||||||
|
errors = tidy.check_directory_files(dirs)
|
||||||
|
error_dir = os.path.join(base_path, "dir_check/webidl_plus")
|
||||||
|
self.assertEqual("Unexpected extension found for test.rs. We only expect files with webidl, test extensions in {0}".format(error_dir), errors.next()[2])
|
||||||
|
self.assertEqual("Unexpected extension found for test2.rs. We only expect files with webidl, test extensions in {0}".format(error_dir), errors.next()[2])
|
||||||
|
self.assertNoMoreErrors(errors)
|
||||||
|
|
||||||
def test_spaces_correctnes(self):
|
def test_spaces_correctnes(self):
|
||||||
errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line], print_text=False)
|
errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line], print_text=False)
|
||||||
self.assertEqual('trailing whitespace', errors.next()[2])
|
self.assertEqual('trailing whitespace', errors.next()[2])
|
||||||
|
|
|
@ -46,3 +46,8 @@ directories = [
|
||||||
"./target",
|
"./target",
|
||||||
"./ports/cef",
|
"./ports/cef",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Directories that are checked for correct file extension
|
||||||
|
[check_ext]
|
||||||
|
# directory, list of expected file extensions
|
||||||
|
"components/script/dom/webidls" = [".webidl"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue