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

Improve the time complexity of the sanity check for mapped rules #4351

Merged
merged 1 commit into from
Nov 2, 2023
Merged
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
8 changes: 2 additions & 6 deletions packages/jsts/tests/rules/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ import path from 'path';

describe('index', () => {
it('should map keys to rules definitions', () => {
// FIXME: This test runs with a time complexity of O(n^2) where n is the number of rules.
// This is because it iterates over all rules and checks if they are mapped. Once
// we use Sonar rule keys as ESLint rule keys, we can make this test O(n) just by
// checking if the rule key is in the mapping.
const ruleFolder = path.join(__dirname, '../../src/rules');
const sonarKeys = fs.readdirSync(ruleFolder).filter(name => /^S\d+/.test(name));
const mappedRules = Object.values(mapping);
const mappedRules = new Map(Object.values(mapping).map(rule => [rule, true]));
const missing = [];
for (const sonarKey of sonarKeys) {
const { rule } = require(path.join(ruleFolder, sonarKey));
if (!mappedRules.some(mapped => mapped === rule)) {
if (!mappedRules.has(rule)) {
missing.push(sonarKey);
}
}
Expand Down