-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a sanity check for rules that should be mapped (#4350)
- Loading branch information
1 parent
0b48c18
commit 4044b82
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SonarQube JavaScript Plugin | ||
* Copyright (C) 2011-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
import { rules as mapping } from '../../src/rules'; | ||
import fs from 'fs'; | ||
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 missing = []; | ||
for (const sonarKey of sonarKeys) { | ||
const { rule } = require(path.join(ruleFolder, sonarKey)); | ||
if (!mappedRules.some(mapped => mapped === rule)) { | ||
missing.push(sonarKey); | ||
} | ||
} | ||
expect(missing).toHaveLength(0); | ||
}); | ||
}); |