Skip to content
Snippets Groups Projects
Commit 65424be3 authored by Rick Waldron's avatar Rick Waldron
Browse files

Lint: harness features flag enforcement via linter

parent f83adad4
No related branches found
No related tags found
No related merge requests found
propertyHelper.js: [template]
typeCoercion.js: [Symbol.toPrimitive,BigInt]
testTypedArray.js: [TypedArray]
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):
......
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 ...@@ -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', ...@@ -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()
] ]
......
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
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
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
^ 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
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