| 1 |
from ..check import Check |
| 2 |
|
| 3 |
_REQUIRED_FIELDS = set(['description']) |
| 4 |
_OPTIONAL_FIELDS = set([ |
| 5 |
'author', 'es5id', 'es6id', 'esid', 'features', 'flags', 'includes', |
| 6 |
'info', 'negative', 'timeout' |
| 7 |
]) |
| 8 |
_VALID_FIELDS = _REQUIRED_FIELDS | _OPTIONAL_FIELDS |
| 9 |
|
| 10 |
class CheckFrontmatter(Check): |
| 11 |
'''Ensure tests have the expected YAML-formatted metadata.''' |
| 12 |
ID = 'FRONTMATTER' |
| 13 |
|
| 14 |
def run(self, name, meta, source): |
| 15 |
if name.endswith('_FIXTURE.js'): |
| 16 |
if meta is not None: |
| 17 |
return '"Fixture" files cannot specify metadata' |
| 18 |
return |
| 19 |
|
| 20 |
if meta is None: |
| 21 |
return 'No valid YAML-formatted frontmatter' |
| 22 |
|
| 23 |
fields = set(meta.keys()) |
| 24 |
|
| 25 |
missing = _REQUIRED_FIELDS - fields |
| 26 |
if len(missing) > 0: |
| 27 |
return 'Required fields missing: %s' % ', '.join(list(missing)) |
| 28 |
|
| 29 |
unrecognized = fields - _VALID_FIELDS |
| 30 |
if len(unrecognized) > 0: |
| 31 |
return 'Unrecognized fields: %s' % ', '.join(list(unrecognized)) |