Skip to content
Snippets Groups Projects
Unverified Commit 70548059 authored by Leo Balter's avatar Leo Balter Committed by GitHub
Browse files

rename whitelist to exceptions in the linter tool (#2004)

parent ca9af579
No related branches found
No related tags found
No related merge requests found
...@@ -294,11 +294,11 @@ Some of the expectations documented here are enforced via a "linting" script. Th ...@@ -294,11 +294,11 @@ Some of the expectations documented here are enforced via a "linting" script. Th
Then invoke the following command: 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. ...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 # This file documents authorship information and is not itself a test
test/built-ins/Simd/AUTHORS FRONTMATTER LICENSE test/built-ins/Simd/AUTHORS FRONTMATTER LICENSE
......
File moved
def parse(handle): def parse(handle):
'''Parse the contents of the provided file descriptor as a linting '''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.''' whose values are Python sets of "Check" ID strings.'''
whitelist = dict() exceptions = dict()
for line in handle: for line in handle:
if line.startswith('#'): if line.startswith('#'):
...@@ -13,12 +13,12 @@ def parse(handle): ...@@ -13,12 +13,12 @@ def parse(handle):
file_name = parts[0] file_name = parts[0]
check_names = set(parts[1:]) check_names = set(parts[1:])
assert file_name not in whitelist, ( assert file_name not in exceptions, (
'Whitelist should have a single entry for each file') 'exceptions should have a single entry for each file')
assert len(check_names) > 0, ( 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 ...@@ -39,10 +39,10 @@ from lib.checks.negative import CheckNegative
from lib.checks.filename import CheckFileName from lib.checks.filename import CheckFileName
from lib.eprint import eprint from lib.eprint import eprint
import lib.frontmatter import lib.frontmatter
import lib.whitelist import lib.exceptions
parser = argparse.ArgumentParser(description='Test262 linting tool') parser = argparse.ArgumentParser(description='Test262 linting tool')
parser.add_argument('--whitelist', parser.add_argument('--exceptions',
type=argparse.FileType('r'), type=argparse.FileType('r'),
help='file containing expected linting errors') help='file containing expected linting errors')
parser.add_argument('path', parser.add_argument('path',
...@@ -79,10 +79,10 @@ def lint(file_names): ...@@ -79,10 +79,10 @@ def lint(file_names):
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
if args.whitelist: if args.exceptions:
whitelist = lib.whitelist.parse(args.whitelist) exceptions = lib.exceptions.parse(args.exceptions)
else: else:
whitelist = dict() exceptions = dict()
files = [path for _path in args.path for path in collect_files(_path)] files = [path for _path in args.path for path in collect_files(_path)]
file_count = len(files) file_count = len(files)
...@@ -92,9 +92,9 @@ if __name__ == '__main__': ...@@ -92,9 +92,9 @@ if __name__ == '__main__':
unexpected_errors = dict(all_errors) unexpected_errors = dict(all_errors)
for file_name, failures in all_errors.iteritems(): for file_name, failures in all_errors.iteritems():
if file_name not in whitelist: if file_name not in exceptions:
continue continue
if set(failures.keys()) == whitelist[file_name]: if set(failures.keys()) == exceptions[file_name]:
del unexpected_errors[file_name] del unexpected_errors[file_name]
error_count = len(unexpected_errors) error_count = len(unexpected_errors)
......
...@@ -33,35 +33,35 @@ class TestLinter(unittest.TestCase): ...@@ -33,35 +33,35 @@ class TestLinter(unittest.TestCase):
result = self.lint(['non-existent-file.js']) result = self.lint(['non-existent-file.js'])
self.assertNotEqual(result["returncode"], 0) 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' + test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' +
'// This code is governed by the BSD license found in the LICENSE file.') '// This code is governed by the BSD license found in the LICENSE file.')
test_file = self.fixture('input.js', test_content) test_file = self.fixture('input.js', test_content)
whitelist_content = test_file + ' FRONTMATTER' exceptions_content = test_file + ' FRONTMATTER'
whitelist_file = self.fixture('lint.whitelist', whitelist_content) exceptions_file = self.fixture('lint.exceptions', exceptions_content)
result = self.lint([test_file]) result = self.lint([test_file])
self.assertNotEqual(result['returncode'], 0) 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) 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' + test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' +
'// This code is governed by the BSD license found in the LICENSE file.') '// This code is governed by the BSD license found in the LICENSE file.')
test_file = self.fixture('input.js', test_content) test_file = self.fixture('input.js', test_content)
whitelist_content = ('# One comment\n' + exceptions_content = ('# One comment\n' +
'# Another comment\n' + '# Another comment\n' +
test_file + ' FRONTMATTER') test_file + ' FRONTMATTER')
whitelist_file = self.fixture('lint.whitelist', whitelist_content) exceptions_file = self.fixture('lint.exceptions', exceptions_content)
result = self.lint([test_file]) result = self.lint([test_file])
self.assertNotEqual(result['returncode'], 0) 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) self.assertEqual(result['returncode'], 0)
......
...@@ -15,4 +15,4 @@ else ...@@ -15,4 +15,4 @@ else
paths="test/" paths="test/"
fi fi
./tools/lint/lint.py --whitelist lint.whitelist $paths ./tools/lint/lint.py --exceptions lint.exceptions $paths
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment