mirror of https://github.com/tc39/test262.git
rename whitelist to exceptions in the linter tool (#2004)
This commit is contained in:
parent
ca9af579f4
commit
7054805941
|
@ -294,11 +294,11 @@ Some of the expectations documented here are enforced via a "linting" script. Th
|
|||
|
||||
Then invoke the following command:
|
||||
|
||||
python tools/lint/lint.py --whitelist lint.whitelist [paths to tests]
|
||||
python tools/lint/lint.py --exceptions lint.exceptions [paths to tests]
|
||||
|
||||
...where `[paths to tests]` is a list of one or more paths to test files or directories containing test files.
|
||||
|
||||
In some cases, it may be necessary for a test to intentionally violate the rules enforced by the linting tool. Such violations can be allowed by including the path of the test(s) in the `lint.whitelist` file. Each path must appear on a dedicated line in that file, and a space-separated list of rules to ignore must follow each path. Lines beginning with the pound sign (`#`) will be ignored. For example:
|
||||
In some cases, it may be necessary for a test to intentionally violate the rules enforced by the linting tool. Such violations can be allowed by including the path of the test(s) in the `lint.exceptions` file. Each path must appear on a dedicated line in that file, and a space-separated list of rules to ignore must follow each path. Lines beginning with the pound sign (`#`) will be ignored. For example:
|
||||
|
||||
# This file documents authorship information and is not itself a test
|
||||
test/built-ins/Simd/AUTHORS FRONTMATTER LICENSE
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
def parse(handle):
|
||||
'''Parse the contents of the provided file descriptor as a linting
|
||||
whitelist file. Return a dictionary whose keys are test file names and
|
||||
exceptions file. Return a dictionary whose keys are test file names and
|
||||
whose values are Python sets of "Check" ID strings.'''
|
||||
|
||||
whitelist = dict()
|
||||
exceptions = dict()
|
||||
|
||||
for line in handle:
|
||||
if line.startswith('#'):
|
||||
|
@ -13,12 +13,12 @@ def parse(handle):
|
|||
file_name = parts[0]
|
||||
check_names = set(parts[1:])
|
||||
|
||||
assert file_name not in whitelist, (
|
||||
'Whitelist should have a single entry for each file')
|
||||
assert file_name not in exceptions, (
|
||||
'exceptions should have a single entry for each file')
|
||||
|
||||
assert len(check_names) > 0, (
|
||||
'Each whitelist entry should specify at least on check')
|
||||
'Each exceptions entry should specify at least on check')
|
||||
|
||||
whitelist[file_name] = check_names
|
||||
exceptions[file_name] = check_names
|
||||
|
||||
return whitelist
|
||||
return exceptions
|
|
@ -39,10 +39,10 @@ from lib.checks.negative import CheckNegative
|
|||
from lib.checks.filename import CheckFileName
|
||||
from lib.eprint import eprint
|
||||
import lib.frontmatter
|
||||
import lib.whitelist
|
||||
import lib.exceptions
|
||||
|
||||
parser = argparse.ArgumentParser(description='Test262 linting tool')
|
||||
parser.add_argument('--whitelist',
|
||||
parser.add_argument('--exceptions',
|
||||
type=argparse.FileType('r'),
|
||||
help='file containing expected linting errors')
|
||||
parser.add_argument('path',
|
||||
|
@ -79,10 +79,10 @@ def lint(file_names):
|
|||
|
||||
if __name__ == '__main__':
|
||||
args = parser.parse_args()
|
||||
if args.whitelist:
|
||||
whitelist = lib.whitelist.parse(args.whitelist)
|
||||
if args.exceptions:
|
||||
exceptions = lib.exceptions.parse(args.exceptions)
|
||||
else:
|
||||
whitelist = dict()
|
||||
exceptions = dict()
|
||||
|
||||
files = [path for _path in args.path for path in collect_files(_path)]
|
||||
file_count = len(files)
|
||||
|
@ -92,9 +92,9 @@ if __name__ == '__main__':
|
|||
unexpected_errors = dict(all_errors)
|
||||
|
||||
for file_name, failures in all_errors.iteritems():
|
||||
if file_name not in whitelist:
|
||||
if file_name not in exceptions:
|
||||
continue
|
||||
if set(failures.keys()) == whitelist[file_name]:
|
||||
if set(failures.keys()) == exceptions[file_name]:
|
||||
del unexpected_errors[file_name]
|
||||
|
||||
error_count = len(unexpected_errors)
|
||||
|
|
|
@ -33,35 +33,35 @@ class TestLinter(unittest.TestCase):
|
|||
result = self.lint(['non-existent-file.js'])
|
||||
self.assertNotEqual(result["returncode"], 0)
|
||||
|
||||
def test_whitelist_single(self):
|
||||
def test_exceptions_single(self):
|
||||
test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' +
|
||||
'// This code is governed by the BSD license found in the LICENSE file.')
|
||||
test_file = self.fixture('input.js', test_content)
|
||||
whitelist_content = test_file + ' FRONTMATTER'
|
||||
whitelist_file = self.fixture('lint.whitelist', whitelist_content)
|
||||
exceptions_content = test_file + ' FRONTMATTER'
|
||||
exceptions_file = self.fixture('lint.exceptions', exceptions_content)
|
||||
|
||||
result = self.lint([test_file])
|
||||
|
||||
self.assertNotEqual(result['returncode'], 0)
|
||||
|
||||
result = self.lint(['--whitelist', whitelist_file, test_file])
|
||||
result = self.lint(['--exceptions', exceptions_file, test_file])
|
||||
|
||||
self.assertEqual(result['returncode'], 0)
|
||||
|
||||
def test_whitelist_comment(self):
|
||||
def test_exceptions_comment(self):
|
||||
test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' +
|
||||
'// This code is governed by the BSD license found in the LICENSE file.')
|
||||
test_file = self.fixture('input.js', test_content)
|
||||
whitelist_content = ('# One comment\n' +
|
||||
exceptions_content = ('# One comment\n' +
|
||||
'# Another comment\n' +
|
||||
test_file + ' FRONTMATTER')
|
||||
whitelist_file = self.fixture('lint.whitelist', whitelist_content)
|
||||
exceptions_file = self.fixture('lint.exceptions', exceptions_content)
|
||||
|
||||
result = self.lint([test_file])
|
||||
|
||||
self.assertNotEqual(result['returncode'], 0)
|
||||
|
||||
result = self.lint(['--whitelist', whitelist_file, test_file])
|
||||
result = self.lint(['--exceptions', exceptions_file, test_file])
|
||||
|
||||
self.assertEqual(result['returncode'], 0)
|
||||
|
||||
|
|
|
@ -15,4 +15,4 @@ else
|
|||
paths="test/"
|
||||
fi
|
||||
|
||||
./tools/lint/lint.py --whitelist lint.whitelist $paths
|
||||
./tools/lint/lint.py --exceptions lint.exceptions $paths
|
||||
|
|
Loading…
Reference in New Issue