diff --git a/tools/lint/lib/checks/esid_valid.py b/tools/lint/lib/checks/esid_valid.py new file mode 100644 index 0000000000..ea17035ff4 --- /dev/null +++ b/tools/lint/lib/checks/esid_valid.py @@ -0,0 +1,44 @@ +from ..check import Check +import re +import json + +class CheckEsidValid(Check): + '''Ensure tests specify only valid `es6id's''' + ID = 'ESID' + + @staticmethod + def _parse(f): + biblio = json.load(f) + entries = biblio["entries"] + return set(e["id"] for e in entries if "id" in e) + + def __init__(self, filename): + with open(filename, 'r') as f: + self.ids = self._parse(f) + self.numeric_id = re.compile(r"(\d+)(\.\d+)+") + + def test_valid(self, meta, key): + if key not in meta: + return + + id = str(meta[key]) + if id in self.ids: + return + + if self.numeric_id.match(id) is not None: + # Ignore for now. + return + + if id.lower() in self.ids: + return 'The `%s` tag should be in lower case: %s' % (key, id) + + return 'The `%s` tag is unknown: %s' % (key, id) + + def run(self, name, meta, source): + if not meta: + return + + for key in ['es6id', 'esid']: + result = self.test_valid(meta, key) + if result: + return result diff --git a/tools/lint/lint.py b/tools/lint/lint.py index 61ddf22d34..403852164c 100755 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -30,6 +30,7 @@ except ImportError: from lib.collect_files import collect_files from lib.checks.esid import CheckEsid +from lib.checks.esid_valid import CheckEsidValid from lib.checks.features import CheckFeatures from lib.checks.frontmatter import CheckFrontmatter from lib.checks.harnessfeatures import CheckHarnessFeatures @@ -60,6 +61,7 @@ parser.add_argument('--features', def checks(features): return [ CheckEsid(), + CheckEsidValid("node_modules/@tc39/ecma262-biblio/biblio.json"), CheckFileName(), CheckFrontmatter(), CheckFeatures(features),