test262/tools/lint/lib/checks/license.py
Mike Pennisi 56ca8add7d Update project structure to support non-JS files
This change is in service of forthcoming tests for the "JSON modules"
language proposal [1]. Verifying the semantics of that proposal requires
modules whose source text is not valid ECMAScript; this change updates
the guidelines for contributing and interpreting tests so that such test
material can be handled consistently.

Differentiating JSON files with a distinct file name suffice will assist
consumers which require special handling of such files (e.g. web
browsers).

Change the pattern used to designate "fixture" files so that it may be
applied to files used for JSON modules.

Increment the project version number to alert consumers of this change
in interpreting instructions.

[1] https://github.com/tc39/proposal-json-modules
2021-05-28 20:02:59 -04:00

45 lines
1.2 KiB
Python

import re
from ..check import Check
_MIN_YEAR = 2009
_MAX_YEAR = 2030
_LICENSE_PATTERN = re.compile(
r'// Copyright( \([C]\))? (\w+) .+\. {1,2}All rights reserved\.[\r\n]{1,2}' +
r'(' +
r'// This code is governed by the( BSD)? license found in the LICENSE file\.' +
r'|' +
r'// See LICENSE for details.' +
r'|' +
r'// Use of this source code is governed by a BSD-style license that can be[\r\n]{1,2}' +
r'// found in the LICENSE file\.' +
r'|' +
r'// See LICENSE or https://github\.com/tc39/test262/blob/HEAD/LICENSE' +
r')', re.IGNORECASE)
class CheckLicense(Check):
'''Ensure tests declare valid license information.'''
ID = 'LICENSE'
def run(self, name, meta, source):
if name.endswith('.json'):
return
if meta and 'flags' in meta and 'generated' in meta['flags']:
return
match = _LICENSE_PATTERN.search(source)
if not match:
return 'Invalid Copyright header'
year_str = match.group(2)
try:
year = int(year_str)
if year < _MIN_YEAR or year > _MAX_YEAR:
raise ValueError()
except ValueError:
return 'Invalid year: %s' % year_str