This commit is contained in:
Ms2ger 2022-12-02 16:35:14 +01:00
parent 8f68a50314
commit 745956f1ac
2 changed files with 46 additions and 0 deletions

View File

@ -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

View File

@ -33,6 +33,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
@ -58,6 +59,7 @@ parser.add_argument('path',
checks = [
CheckEsid(),
CheckEsidValid("node_modules/@tc39/ecma262-biblio/biblio.json"),
CheckFileName(),
CheckFrontmatter(),
CheckFeatures('features.txt'),