1717import { Linter , SourceCode } from 'eslint' ;
1818import { transformFixes } from '../quickfixes/transform.js' ;
1919import { Issue } from './issue.js' ;
20+ import * as ruleMetas from '../../rules/metas.js' ;
21+
22+ function getESLintKeys ( sonarKey : string ) {
23+ const ruleMeta = ruleMetas [ sonarKey as keyof typeof ruleMetas ] ;
24+ if ( ! ruleMeta ?. eslintId ) {
25+ return [ ] ;
26+ }
27+ const keys = new Set < string > ( ) ;
28+ keys . add ( ruleMeta . eslintId ) ;
29+ if ( ruleMeta . implementation === 'decorated' ) {
30+ ruleMeta . externalRules . forEach ( externalRule => {
31+ keys . add ( externalRule . externalRule ) ;
32+ } ) ;
33+ }
34+ return Array . from ( keys ) ;
35+ }
2036
2137/**
2238 * Converts an ESLint message into a SonarQube issue
@@ -29,9 +45,14 @@ import { Issue } from './issue.js';
2945 *
3046 * @param source the source code
3147 * @param message the ESLint message to convert
48+ * @param filePath the path to the file where the issue was found
3249 * @returns the converted SonarQube issue
3350 */
34- export function convertMessage ( source : SourceCode , message : Linter . LintMessage ) : Issue | null {
51+ export function convertMessage (
52+ source : SourceCode ,
53+ message : Linter . LintMessage ,
54+ filePath : string ,
55+ ) : Issue | null {
3556 /**
3657 * The property `ruleId` equals `null` on parsing errors and not applied directives.
3758 * The first should not happen because we lint ready SourceCode instances and not file contents.
@@ -40,14 +61,17 @@ export function convertMessage(source: SourceCode, message: Linter.LintMessage):
4061 if ( ! message . ruleId ?. startsWith ( 'sonarjs/' ) ) {
4162 return null ;
4263 }
64+ const ruleId = message . ruleId . slice ( 8 ) ; // remove "sonarjs/" prefix
4365 return {
44- ruleId : message . ruleId . slice ( 8 ) , // remove "sonarjs/" prefix
66+ ruleId,
4567 line : message . line ,
4668 column : message . column ,
4769 endLine : message . endLine ,
4870 endColumn : message . endColumn ,
4971 message : message . message ,
5072 quickFixes : transformFixes ( source , message ) ,
5173 secondaryLocations : [ ] ,
74+ ruleESLintKeys : getESLintKeys ( ruleId ) ,
75+ filePath,
5276 } ;
5377}
0 commit comments