mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 20:44:43 +02:00
Lint: harness features flag enforcement via linter
This commit is contained in:
parent
f83adad4bd
commit
65424be3ef
3
harness/features.yml
Normal file
3
harness/features.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
propertyHelper.js: [template]
|
||||||
|
typeCoercion.js: [Symbol.toPrimitive,BigInt]
|
||||||
|
testTypedArray.js: [TypedArray]
|
@ -1,5 +1,5 @@
|
|||||||
class Check(object):
|
class Check(object):
|
||||||
'''Base class for defining linting checks.'''
|
'''Base class for defining linting checks.'''
|
||||||
ID = None
|
ID = None
|
||||||
|
|
||||||
def run(self, name, meta, source):
|
def run(self, name, meta, source):
|
||||||
|
59
tools/lint/lib/checks/harnessfeatures.py
Normal file
59
tools/lint/lib/checks/harnessfeatures.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import yaml
|
||||||
|
|
||||||
|
from ..check import Check
|
||||||
|
|
||||||
|
class CheckHarnessFeatures(Check):
|
||||||
|
'''Ensure tests that use harnesses with explicit features flag requirements
|
||||||
|
specify only `features` from a list of valid values.'''
|
||||||
|
ID = 'HARNESS_FEATURES'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
with open('./harness/features.yml', 'r') as f:
|
||||||
|
self.include_has_features = yaml.load(f.read())
|
||||||
|
|
||||||
|
def comparison_result_lists(self, meta):
|
||||||
|
|
||||||
|
result = {'features': set(), 'missing': set()}
|
||||||
|
meta_features = meta['features'] if 'features' in meta else []
|
||||||
|
meta_includes = meta['includes']
|
||||||
|
features = []
|
||||||
|
|
||||||
|
if not meta or 'includes' not in meta:
|
||||||
|
return result
|
||||||
|
|
||||||
|
if len(meta_includes) == 0:
|
||||||
|
return result
|
||||||
|
|
||||||
|
for meta_include in meta_includes:
|
||||||
|
if meta_include in self.include_has_features:
|
||||||
|
features = self.include_has_features[meta_include]
|
||||||
|
|
||||||
|
if len(features) == 0:
|
||||||
|
return result
|
||||||
|
|
||||||
|
if 'features' not in meta or len(meta['features']) == 0:
|
||||||
|
result['missing'].update(features)
|
||||||
|
else:
|
||||||
|
meta_features = meta['features']
|
||||||
|
|
||||||
|
for feature in features:
|
||||||
|
if feature not in meta_features:
|
||||||
|
result['missing'].add(feature)
|
||||||
|
|
||||||
|
result['features'].update(meta_features);
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def run(self, name, meta, source):
|
||||||
|
|
||||||
|
result = self.comparison_result_lists(meta)
|
||||||
|
|
||||||
|
if len(result['features']) == 0 and len(result['missing']) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(result['missing']) > 0:
|
||||||
|
if len(result['features']) == 0:
|
||||||
|
return 'Missing: `features: [%s]`' % ', '.join(list(result['missing']))
|
||||||
|
else:
|
||||||
|
return 'Missing from `features`: %s' % ', '.join(list(result['missing']))
|
@ -7,6 +7,7 @@ import sys
|
|||||||
|
|
||||||
from lib.collect_files import collect_files
|
from lib.collect_files import collect_files
|
||||||
from lib.checks.features import CheckFeatures
|
from lib.checks.features import CheckFeatures
|
||||||
|
from lib.checks.harnessfeatures import CheckHarnessFeatures
|
||||||
from lib.checks.frontmatter import CheckFrontmatter
|
from lib.checks.frontmatter import CheckFrontmatter
|
||||||
from lib.checks.license import CheckLicense
|
from lib.checks.license import CheckLicense
|
||||||
from lib.checks.negative import CheckNegative
|
from lib.checks.negative import CheckNegative
|
||||||
@ -23,7 +24,10 @@ parser.add_argument('path',
|
|||||||
help='file name or directory of files to lint')
|
help='file name or directory of files to lint')
|
||||||
|
|
||||||
checks = [
|
checks = [
|
||||||
CheckFrontmatter(), CheckFeatures('features.txt'), CheckLicense(),
|
CheckFrontmatter(),
|
||||||
|
CheckFeatures('features.txt'),
|
||||||
|
CheckHarnessFeatures(),
|
||||||
|
CheckLicense(),
|
||||||
CheckNegative()
|
CheckNegative()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
12
tools/lint/test/fixtures/harness_features_empty.js
vendored
Normal file
12
tools/lint/test/fixtures/harness_features_empty.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
HARNESS_FEATURES - Missing Frontmatter: `features: [TypedArray]`
|
||||||
|
^ expected errors | v input
|
||||||
|
// Copyright (C) 2017 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-assignment-operators-static-semantics-early-errors
|
||||||
|
description: Minimal test
|
||||||
|
features: []
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// empty
|
11
tools/lint/test/fixtures/harness_features_multiple_includes.js
vendored
Normal file
11
tools/lint/test/fixtures/harness_features_multiple_includes.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
HARNESS_FEATURES - Missing Frontmatter: `features: [TypedArray, template]
|
||||||
|
^ expected errors | v input
|
||||||
|
// Copyright (C) 2017 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-assignment-operators-static-semantics-early-errors
|
||||||
|
description: Minimal test
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// empty
|
12
tools/lint/test/fixtures/harness_features_partial.js
vendored
Normal file
12
tools/lint/test/fixtures/harness_features_partial.js
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
HARNESS_FEATURES - Missing from `features`: Symbol.toPrimitive
|
||||||
|
^ expected errors | v input
|
||||||
|
// Copyright (C) 2017 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-assignment-operators-static-semantics-early-errors
|
||||||
|
description: Minimal test
|
||||||
|
features: [BigInt]
|
||||||
|
includes: [typeCoercion.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// empty
|
11
tools/lint/test/fixtures/harness_features_valid.js
vendored
Normal file
11
tools/lint/test/fixtures/harness_features_valid.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
^ expected errors | v input
|
||||||
|
// Copyright (C) 2017 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-assignment-operators-static-semantics-early-errors
|
||||||
|
description: Minimal test
|
||||||
|
features: [TypedArray]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// empty
|
Loading…
x
Reference in New Issue
Block a user