mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 00:14:35 +02:00
wip
This commit is contained in:
parent
823f4cfd20
commit
8496a8831c
44
tools/lint/lib/checks/esid_valid.py
Normal file
44
tools/lint/lib/checks/esid_valid.py
Normal 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
|
@ -30,6 +30,7 @@ except ImportError:
|
|||||||
|
|
||||||
from lib.collect_files import collect_files
|
from lib.collect_files import collect_files
|
||||||
from lib.checks.esid import CheckEsid
|
from lib.checks.esid import CheckEsid
|
||||||
|
from lib.checks.esid_valid import CheckEsidValid
|
||||||
from lib.checks.features import CheckFeatures
|
from lib.checks.features import CheckFeatures
|
||||||
from lib.checks.frontmatter import CheckFrontmatter
|
from lib.checks.frontmatter import CheckFrontmatter
|
||||||
from lib.checks.harnessfeatures import CheckHarnessFeatures
|
from lib.checks.harnessfeatures import CheckHarnessFeatures
|
||||||
@ -60,6 +61,7 @@ parser.add_argument('--features',
|
|||||||
def checks(features):
|
def checks(features):
|
||||||
return [
|
return [
|
||||||
CheckEsid(),
|
CheckEsid(),
|
||||||
|
CheckEsidValid("node_modules/@tc39/ecma262-biblio/biblio.json"),
|
||||||
CheckFileName(),
|
CheckFileName(),
|
||||||
CheckFrontmatter(),
|
CheckFrontmatter(),
|
||||||
CheckFeatures(features),
|
CheckFeatures(features),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user