linter: Fix parsing features.txt

Previously, split() would split on whitespace, then the if-condition would
remove `#` - interpreting every word in every comment in the file as a
potential valid feature flag. We want splitlines() here.

Partial-line comments were inadvertently "supported" before, because of
this bug. Instead, support them explicitly by chopping off a `#`
character, anything after it, and any whitespace immediately preceding it.
This commit is contained in:
Philip Chimento 2023-02-13 12:40:21 -08:00 committed by Ms2ger
parent 6e1b737357
commit a58ae41ea7
2 changed files with 7 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import re
from ..check import Check
class CheckFeatures(Check):
@ -11,8 +13,9 @@ class CheckFeatures(Check):
@staticmethod
def _parse(content):
features = []
for line in content.split():
if not line or line.startswith('#'):
for line in content.splitlines():
line = re.sub(r'\s*#.*', '', line)
if not line:
continue
features.append(line)
return features

View File

@ -1,4 +1,5 @@
async-functions
# Here is a full-line comment: not-a-valid-feature
async-functions # This is a partial-line comment
object-spread
generators
BigInt