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

Resolves JS-278 #4769

Merged
merged 2 commits into from
Aug 22, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions its/eslint8-plugin-sonarjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"devDependencies": {
"cross-spawn": "7.0.3",
"eslint": "8.57.0",
"eslint-plugin-import": "2.29.1",
"typescript": "5.5.4",
"typescript-eslint": "7.16.1"
}
Expand Down
1 change: 1 addition & 0 deletions its/eslint9-plugin-sonarjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"devDependencies": {
"cross-spawn": "7.0.3",
"eslint": "8.57.0",
"eslint-plugin-import": "2.29.1",
"typescript": "5.5.4",
"typescript-eslint": "7.16.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void should_analyse_js_ts_pull_requests(String language) {
.withCachedFilesCounts(1, 1)
.isUsed()
.logsOnce(format("%s\" with linterId \"default\"", indexFile))
.logsTimes(Main.ANALYZER_REPORTED_ISSUES, "DEBUG: Saving issue for rule no-extra-semi")
.logsTimes(Main.ANALYZER_REPORTED_ISSUES, "DEBUG: Saving issue for rule S1116")
.logsOnce(format("%s\" with linterId \"default\"", helloFile))
.logsOnce(
"INFO: Hit the cache for 0 out of 2",
Expand Down Expand Up @@ -125,7 +125,7 @@ void should_analyse_js_ts_pull_requests(String language) {
.withCachedFilesCounts(1)
.isUsed()
.logsOnce(format("%s\" with linterId \"default\"", helloFile))
.logsTimes(PR.ANALYZER_REPORTED_ISSUES, "DEBUG: Saving issue for rule no-extra-semi")
.logsTimes(PR.ANALYZER_REPORTED_ISSUES, "DEBUG: Saving issue for rule S1116")
.logsOnce(
"INFO: Hit the cache for 1 out of 2",
"INFO: Miss the cache for 1 out of 2: FILE_CHANGED [1/2]"
Expand Down Expand Up @@ -198,7 +198,7 @@ void should_analyse_yaml_pull_requests() {
.withCachedFilesCounts(1)
.isUsed()
.logsOnce("file2.yaml\" with linterId \"default\"")
.logsTimes(PR.ANALYZER_REPORTED_ISSUES, "DEBUG: Saving issue for rule no-extra-semi")
.logsTimes(PR.ANALYZER_REPORTED_ISSUES, "DEBUG: Saving issue for rule S1116")
.logsOnce(
"INFO: Hit the cache for 1 out of 2",
"INFO: Miss the cache for 1 out of 2: FILE_CHANGED [1/2]"
Expand Down
36 changes: 35 additions & 1 deletion packages/jsts/src/linter/quickfixes/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,40 @@ const quickFixMessages = new Map<string, string>([
['quotes', 'Fix quotes'],
['radix', 'Add 10 as radix'],
['semi', 'Add semicolon'],

['S1537', 'Remove this trailing comma'],
['S113', 'Add a new line at the end of file'],
['S6749', 'Remove redundant fragment'],
['S6859', 'Replace with a relative path'],
['S4023', 'Replace with type alias'],
['S6637', 'Remove .bind() call'],
['S6509', 'Remove extra cast'],
['S1116', 'Remove extra semicolon'],
['S3257', 'Remove type declaration'],
['S6660', "Replace with 'else if'"],
['S2966', "Replace with optional chaining '.?'"],
['S1131', 'Remove trailing space'],
['S6645', 'Remove initialization'],
['S4157', 'Remove type argument'],
['S4325', 'Remove type assertion'],
['S6644', 'Replace with a simpler expression'],
['S6650', 'Remove alias'],
['S3504', "Replace 'var' with 'let'"],
['S3498', 'Use shorthand property'],
['S6590', "Replace with 'as const'"],
['S3353', "Replace with 'const'"],
['S6598', 'Replace with a function type'],
['S1488', 'Return value immediately'],
['S4156', "Replace with 'namespace' keyword"],
['S6653', 'Replace with Object.hasOwn()'],
['S6661', 'Replace with object spread syntax'],
['S2933', "Add 'readonly'"],
['S6565', "Replace return type with 'this'"],
['S3512', 'Replace with template string literal'],
['S1264', "Replace with 'while' loop"],
['S1441', 'Fix quotes'],
['S2427', 'Add 10 as radix'],
['S1438', 'Add semicolon'],
]);

/**
Expand All @@ -73,7 +107,7 @@ const quickFixMessages = new Map<string, string>([
export function getQuickFixMessage(ruleKey: string): string {
const message = quickFixMessages.get(ruleKey);
if (!message) {
if (ruleKey === 'no-duplicates') {
if (ruleKey === 'no-duplicates' || ruleKey === 'S3863') {
// TODO workaround for eslint-plugin-import/no-duplicates, rule doesn't provide message for fix
return 'Remove this duplicate import';
}
Expand Down
103 changes: 103 additions & 0 deletions packages/jsts/src/linter/quickfixes/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,107 @@ export const quickFixRules = new Set([
// eslint-plugin-import
'no-absolute-path',
'no-duplicates',

// eslint core
'S1537',
'S113',
'S6637',
'S6509',
'S1116',
'S4326',
'S1131',
'S6645',
'S6644',
'S3812',
'S6650',
'S3504',
'S3498',
'S3353',
'S6653',
'S6325',
'S3512',
'S1441',
'S2427',
'S1438',

// decorated eslint core
'S1186',
'S108',
'S6660',
'S6679',
'S3696',
'S1763',
'S1068',
'S6676',
'S6647',
'S6661',
'S6666',
'S2688',

// eslint-plugin-sonarjs
'S3981',
'S1940',
'S3626',
'S2757',
'S1488',
'S1126',
'S1264',

// eslint-plugin-react
'S6754',
'S6479',
'S6747',

// @typescript-eslint plugin
'S6568',
'S4023',
'S4204',
'S3257',
'S2966',
'S4157',
'S4325',
'S6569',
'S6590',
'S6598',
'S4156',
'S6606',
'S2933',
'S6565',
'S6557',

// decorated @typescript-eslint plugin
'S6572',
'S4138',

// sonarjs
'S1528',
'S3403',
'S3415',
'S2871',
'S125',
'S4621',
'S6426',
'S2990',
'S4619',
'S4043',
'S1533',
'S4781',
'S1110',
'S4623',
'S3984',
'S1172',
'S1444',
'S4634',
'S4322',
'S1534',
'S5868',
'S6759',
'S6594',
'S131',
'S6535',
'S1128',

// eslint-plugin-import
'S6859',
'S3863',
]);
Loading