| 1 |
import re |
| 2 |
|
| 3 |
from ..check import Check |
| 4 |
|
| 5 |
_MIN_YEAR = 2009 |
| 6 |
_MAX_YEAR = 2030 |
| 7 |
|
| 8 |
_LICENSE_PATTERN = re.compile( |
| 9 |
r'\/\/ Copyright( \([cC]\))? (\w+) .+\. {1,2}All rights reserved\.[\r\n]{1,2}' + |
| 10 |
r'(' + |
| 11 |
r'\/\/ (' + |
| 12 |
r'This code is governed by the( BSD)? license found in the LICENSE file\.' + |
| 13 |
r'|' + |
| 14 |
r'See LICENSE for details' + |
| 15 |
r')' + |
| 16 |
r'|' + |
| 17 |
r'\/\/ Use of this source code is governed by a BSD-style license that can be[\r\n]{1,2}' + |
| 18 |
r'\/\/ found in the LICENSE file\.' + |
| 19 |
r'|' + |
| 20 |
r'\/\/ See LICENSE or https://github\.com/tc39/test262/blob/master/LICENSE' + |
| 21 |
r')', re.IGNORECASE) |
| 22 |
|
| 23 |
class CheckLicense(Check): |
| 24 |
'''Ensure tests declare valid license information.''' |
| 25 |
ID = 'LICENSE' |
| 26 |
|
| 27 |
def run(self, name, meta, source): |
| 28 |
if meta and 'flags' in meta and 'generated' in meta['flags']: |
| 29 |
return |
| 30 |
|
| 31 |
match = _LICENSE_PATTERN.search(source) |
| 32 |
|
| 33 |
if not match: |
| 34 |
return 'No license information found.' |
| 35 |
|
| 36 |
year_str = match.group(2) |
| 37 |
try: |
| 38 |
year = int(year_str) |
| 39 |
|
| 40 |
if year < _MIN_YEAR or year > _MAX_YEAR: |
| 41 |
raise ValueError() |
| 42 |
except ValueError: |
| 43 |
return 'Invalid year: %s' % year_str |