Skip to content

Commit

Permalink
Remove mapping between Sonar and ESLint keys (#4832)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez authored Sep 19, 2024
1 parent 7dc3241 commit f2b3bf9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 41 deletions.
1 change: 0 additions & 1 deletion packages/ruling/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
actual
eslint-to-sonar-id.json
rules.json
14 changes: 2 additions & 12 deletions packages/ruling/tests/tools/lits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ export function writeResults(
fileSet: JsTsFiles[],
actualPath: string,
) {
const eslintIdToSonarId = loadKeysMapping();
const targetProjectPath = path.join(actualPath);
try {
fs.rmSync(targetProjectPath, { recursive: true });
} catch {}
fs.mkdirSync(targetProjectPath, { recursive: true });
const litsResults = transformResults(projectPath, projectName, results, fileSet);
for (const [ruleId, { js: jsIssues, ts: tsIssues }] of Object.entries(litsResults.issues)) {
const sonarRuleId = eslintIdToSonarId[ruleId] || ruleId;
writeIssues(targetProjectPath, sonarRuleId, jsIssues);
writeIssues(targetProjectPath, sonarRuleId, tsIssues, false);
writeIssues(targetProjectPath, ruleId, jsIssues);
writeIssues(targetProjectPath, ruleId, tsIssues, false);
}
}

Expand Down Expand Up @@ -144,11 +142,3 @@ function writeIssues(projectDir: string, ruleId: string, issues: FileIssues, isJ
}
}
}

/**
* Loading this through `fs` and not import because the file is absent at compile time
*/
function loadKeysMapping() {
const pathToKeysMapping = path.join(__dirname, '..', 'data', 'eslint-to-sonar-id.json');
return JSON.parse(fs.readFileSync(pathToKeysMapping, 'utf8'));
}
16 changes: 0 additions & 16 deletions packages/ruling/tests/tools/parseRulesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const SONARLINT_METADATA_PATH = path.join(
'classes',
'sonarlint-metadata.json',
);
const ESLINT_TO_SONAR_ID_PATH = path.join(__dirname, '..', 'data', 'eslint-to-sonar-id.json');
const RULES_PATH = path.join(__dirname, '..', 'data', 'rules.json');

// Loading this through `fs` and not import because the file is absent at compile time
Expand All @@ -51,23 +50,8 @@ type RuleData = {
language: 'js' | 'ts';
};

extractKeysMapping();
extractRulesData();

function extractKeysMapping() {
const eslintToSonar: Record<string, string> = {};

for (const rule of rulesMetadata) {
eslintToSonar[rule.eslintKey] = extractSonarId(rule);
}

function extractSonarId(rule: { ruleKey: string }) {
return rule.ruleKey.split(':')[1];
}

fs.writeFileSync(ESLINT_TO_SONAR_ID_PATH, JSON.stringify(eslintToSonar, null, 2));
}

function extractRulesData() {
const rulesData: RuleData[] = [];
rulesMetadata.forEach(ruleData => {
Expand Down
12 changes: 0 additions & 12 deletions tools/prepare-ruling.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ if (fs.existsSync(LINK)) {
fs.symlinkSync(TARGET, LINK);

function findMissingData() {
const PATH_TO_MAPPING = path.join(
__dirname,
'..',
'packages',
'ruling',
'tests',
'data',
'eslint-to-sonar-id.json',
);
const PATH_TO_RULES = path.join(
__dirname,
'..',
Expand All @@ -45,9 +36,6 @@ function findMissingData() {
'rules.json',
);
const missing = [];
if (!fs.existsSync(PATH_TO_MAPPING)) {
missing.push(PATH_TO_MAPPING);
}
if (!fs.existsSync(PATH_TO_RULES)) {
missing.push(PATH_TO_RULES);
}
Expand Down

0 comments on commit f2b3bf9

Please sign in to comment.