mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Tidy: Report invalid listed ignored directories and files
This commit is contained in:
parent
747e130295
commit
8a1aa354d6
4 changed files with 42 additions and 11 deletions
|
@ -92,7 +92,10 @@ def is_iter_empty(iterator):
|
||||||
|
|
||||||
|
|
||||||
def normilize_paths(paths):
|
def normilize_paths(paths):
|
||||||
return [os.path.join(*path.split('/')) for path in paths]
|
if isinstance(paths, basestring):
|
||||||
|
return os.path.join(*paths.split('/'))
|
||||||
|
else:
|
||||||
|
return [os.path.join(*path.split('/')) for path in paths]
|
||||||
|
|
||||||
|
|
||||||
# A simple wrapper for iterators to show progress
|
# A simple wrapper for iterators to show progress
|
||||||
|
@ -827,6 +830,17 @@ def check_config_file(config_file, print_text=True):
|
||||||
if print_text:
|
if print_text:
|
||||||
print '\rChecking the config file...'
|
print '\rChecking the config file...'
|
||||||
|
|
||||||
|
config_content = toml.loads(conf_file)
|
||||||
|
exclude = config_content.get("ignore", {})
|
||||||
|
|
||||||
|
# Check for invalid listed ignored directories
|
||||||
|
exclude_dirs = exclude.get("directories", [])
|
||||||
|
skip_dirs = ["./target", "./tests"]
|
||||||
|
invalid_dirs = [d for d in exclude_dirs if not os.path.isdir(d) and not any(s in d for s in skip_dirs)]
|
||||||
|
|
||||||
|
# Check for invalid listed ignored files
|
||||||
|
invalid_files = [f for f in exclude.get("files", []) if not os.path.exists(f)]
|
||||||
|
|
||||||
current_table = ""
|
current_table = ""
|
||||||
for idx, line in enumerate(lines):
|
for idx, line in enumerate(lines):
|
||||||
# Ignore comment lines
|
# Ignore comment lines
|
||||||
|
@ -841,6 +855,22 @@ def check_config_file(config_file, print_text=True):
|
||||||
current_table = table_name
|
current_table = table_name
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Print invalid listed ignored directories
|
||||||
|
if current_table == "ignore" and invalid_dirs:
|
||||||
|
for d in invalid_dirs:
|
||||||
|
if line.strip().strip('\'",') == d:
|
||||||
|
yield config_file, idx + 1, "ignored directory '%s' doesn't exist" % d
|
||||||
|
invalid_dirs.remove(d)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Print invalid listed ignored files
|
||||||
|
if current_table == "ignore" and invalid_files:
|
||||||
|
for f in invalid_files:
|
||||||
|
if line.strip().strip('\'",') == f:
|
||||||
|
yield config_file, idx + 1, "ignored file '%s' doesn't exist" % f
|
||||||
|
invalid_files.remove(f)
|
||||||
|
break
|
||||||
|
|
||||||
# Skip if there is no equal sign in line, assuming it's not a key
|
# Skip if there is no equal sign in line, assuming it's not a key
|
||||||
if "=" not in line:
|
if "=" not in line:
|
||||||
continue
|
continue
|
||||||
|
@ -855,11 +885,10 @@ def check_config_file(config_file, print_text=True):
|
||||||
yield config_file, idx + 1, "invalid config key '%s'" % key
|
yield config_file, idx + 1, "invalid config key '%s'" % key
|
||||||
|
|
||||||
# Parse config file
|
# Parse config file
|
||||||
parse_config(conf_file)
|
parse_config(config_content)
|
||||||
|
|
||||||
|
|
||||||
def parse_config(content):
|
def parse_config(config_file):
|
||||||
config_file = toml.loads(content)
|
|
||||||
exclude = config_file.get("ignore", {})
|
exclude = config_file.get("ignore", {})
|
||||||
# Add list of ignored directories to config
|
# Add list of ignored directories to config
|
||||||
config["ignore"]["directories"] += normilize_paths(exclude.get("directories", []))
|
config["ignore"]["directories"] += normilize_paths(exclude.get("directories", []))
|
||||||
|
@ -872,7 +901,7 @@ def parse_config(content):
|
||||||
dirs_to_check = config_file.get("check_ext", {})
|
dirs_to_check = config_file.get("check_ext", {})
|
||||||
# Fix the paths (OS-dependent)
|
# Fix the paths (OS-dependent)
|
||||||
for path, exts in dirs_to_check.items():
|
for path, exts in dirs_to_check.items():
|
||||||
config['check_ext'][normilize_paths([path])[0]] = exts
|
config['check_ext'][normilize_paths(path)] = exts
|
||||||
|
|
||||||
# Add list of blocked packages
|
# Add list of blocked packages
|
||||||
config["blocked-packages"] = config_file.get("blocked-packages", {})
|
config["blocked-packages"] = config_file.get("blocked-packages", {})
|
||||||
|
|
|
@ -11,5 +11,9 @@ wrong-key = false
|
||||||
wrong-key = true
|
wrong-key = true
|
||||||
|
|
||||||
[ignore]
|
[ignore]
|
||||||
files = []
|
files = [
|
||||||
directories = []
|
"./fake/file.html",
|
||||||
|
]
|
||||||
|
directories = [
|
||||||
|
"./fake/dir",
|
||||||
|
]
|
||||||
|
|
|
@ -29,6 +29,8 @@ class CheckTidiness(unittest.TestCase):
|
||||||
self.assertEqual("invalid config key 'key-outside'", errors.next()[2])
|
self.assertEqual("invalid config key 'key-outside'", errors.next()[2])
|
||||||
self.assertEqual("invalid config key 'wrong-key'", errors.next()[2])
|
self.assertEqual("invalid config key 'wrong-key'", errors.next()[2])
|
||||||
self.assertEqual('invalid config table [wrong]', errors.next()[2])
|
self.assertEqual('invalid config table [wrong]', errors.next()[2])
|
||||||
|
self.assertEqual("ignored file './fake/file.html' doesn't exist", errors.next()[2])
|
||||||
|
self.assertEqual("ignored directory './fake/dir' doesn't exist", errors.next()[2])
|
||||||
self.assertNoMoreErrors(errors)
|
self.assertNoMoreErrors(errors)
|
||||||
|
|
||||||
def test_directory_checks(self):
|
def test_directory_checks(self):
|
||||||
|
|
|
@ -49,9 +49,6 @@ files = [
|
||||||
"./tests/wpt/mozilla/tests/css/fonts",
|
"./tests/wpt/mozilla/tests/css/fonts",
|
||||||
"./tests/wpt/mozilla/tests/css/pre_with_tab.html",
|
"./tests/wpt/mozilla/tests/css/pre_with_tab.html",
|
||||||
"./tests/wpt/mozilla/tests/mozilla/textarea_placeholder.html",
|
"./tests/wpt/mozilla/tests/mozilla/textarea_placeholder.html",
|
||||||
# FIXME(pcwalton, #11679): This is a workaround for a tidy error on the quoted string
|
|
||||||
# `"__TEXT,_info_plist"` inside an attribute.
|
|
||||||
"./components/servo/platform/macos/mod.rs",
|
|
||||||
]
|
]
|
||||||
# Directories that are ignored for the non-WPT tidy check.
|
# Directories that are ignored for the non-WPT tidy check.
|
||||||
directories = [
|
directories = [
|
||||||
|
@ -64,7 +61,6 @@ directories = [
|
||||||
"./tests/wpt/mozilla/tests/mozilla/referrer-policy",
|
"./tests/wpt/mozilla/tests/mozilla/referrer-policy",
|
||||||
"./tests/wpt/sync",
|
"./tests/wpt/sync",
|
||||||
"./tests/wpt/sync_css",
|
"./tests/wpt/sync_css",
|
||||||
"./python/mach",
|
|
||||||
"./python/tidy/servo_tidy_tests",
|
"./python/tidy/servo_tidy_tests",
|
||||||
"./components/script/dom/bindings/codegen/parser",
|
"./components/script/dom/bindings/codegen/parser",
|
||||||
"./components/script/dom/bindings/codegen/ply",
|
"./components/script/dom/bindings/codegen/ply",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue