Skip to content

Commit

Permalink
linter: Fix parsing features.txt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptomato authored and Ms2ger committed Mar 6, 2023
1 parent 6e1b737 commit a58ae41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions tools/lint/lib/checks/features.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from ..check import Check

class CheckFeatures(Check):
Expand All @@ -11,8 +13,9 @@ def __init__(self, filename):
@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
Expand Down
3 changes: 2 additions & 1 deletion tools/lint/test/fixtures/features.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a58ae41

Please sign in to comment.