Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(traverse): should correctly parse rules with fixability metadata #196

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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