Skip to content

Commit

Permalink
fix(traverse): should correctly parse rules with fixability metadata (#…
Browse files Browse the repository at this point in the history
…196)

Fixes #195

The configs needs to be re-generated after this change.
  • Loading branch information
haoqunjiang authored Oct 23, 2024
1 parent c61716f commit 0d71ecc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions scripts/traverse-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,21 @@ suite('readFilesRecursively', () => {
correctness
)`);

const ruleWithFixabilityModuleContent = dedent(`declare_oxc_lint!(
/// Some Block Content
/// ) extra parenthesis to make sure it doesn't catch
DefaultCaseLast,
correctness,
fix
)`);

vol.fromJSON({
'crates/src/rules/eslint/rulename-with-mod/mod.rs':
ruleNameWithModuleContent,
'crates/src/rules/typescript/rulename-without-mod.rs':
ruleNameWithoutModuleContent,
'crates/src/rules/unicorn/rule-with-fixability.rs':
ruleWithFixabilityModuleContent,
});

// Call the function
Expand All @@ -163,6 +173,11 @@ suite('readFilesRecursively', () => {
scope: 'typescript',
value: '@typescript-eslint/rulename-without-mod',
},
{
category: 'correctness',
scope: 'unicorn',
value: 'unicorn/rule-with-fixability',
},
]);

expect(skippedResultArray).toEqual([]);
Expand Down
5 changes: 3 additions & 2 deletions scripts/traverse-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ async function processFile(
// Remove comments to prevent them from affecting the regex
const cleanBlock = block.replace(/\/\/.*$|\/\*[\S\s]*?\*\//gm, '').trim();

// Extract the keyword, correctly handling optional trailing characters
// Extract the keyword, skipping the optional fixability metadata,
// and correctly handling optional trailing characters
// since trailing commas are optional in Rust and the last keyword may not have one
const keywordRegex = /,\s*(\w+)\s*,?\s*$/;
const keywordRegex = /,\s*(\w+)\s*,?\s*(?:(\w+)\s*,?\s*)?$/;
const keywordMatch = keywordRegex.exec(cleanBlock);

if (keywordMatch) {
Expand Down

0 comments on commit 0d71ecc

Please sign in to comment.