-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…R" comments (#4910)
- Loading branch information
1 parent
1e28fce
commit 22ec546
Showing
14 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
its/ruling/src/test/expected/jsts/file-for-rules/javascript-S1291.json
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,6 @@ | ||
{ | ||
"file-for-rules:S1291.js": [ | ||
1, | ||
2 | ||
] | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
"file-for-rules:S1068.js": [ | ||
0 | ||
], | ||
"file-for-rules:S1291.js": [ | ||
0 | ||
], | ||
"file-for-rules:S1534.js": [ | ||
0 | ||
], | ||
|
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,3 @@ | ||
// NOSONAR | ||
/* NOSONAR */ | ||
// NOFOOBAR |
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
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,20 @@ | ||
/* | ||
* SonarQube JavaScript Plugin | ||
* Copyright (C) 2011-2024 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. | ||
*/ | ||
export { rule } from './rule.js'; |
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,33 @@ | ||
/* | ||
* SonarQube JavaScript Plugin | ||
* Copyright (C) 2011-2024 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. | ||
*/ | ||
|
||
// DO NOT EDIT! This file is autogenerated by "npm run generate-meta" | ||
|
||
export const meta = { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Track uses of "NOSONAR" comments', | ||
recommended: false, | ||
url: 'https://sonarsource.github.io/rspec/#/rspec/S1291/javascript', | ||
requiresTypeChecking: false, | ||
}, | ||
}; | ||
|
||
export const sonarKey = 'S1291'; |
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,58 @@ | ||
/* | ||
* SonarQube JavaScript Plugin | ||
* Copyright (C) 2011-2024 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. | ||
*/ | ||
// https://sonarsource.github.io/rspec/#/rspec/S1291 | ||
|
||
import type { Rule } from 'eslint'; | ||
import { generateMeta } from '../helpers/index.js'; | ||
import { meta } from './meta.js'; | ||
|
||
const NOSONAR = 'NOSONAR'; | ||
|
||
export const rule: Rule.RuleModule = { | ||
meta: generateMeta(meta as Rule.RuleMetaData, { | ||
messages: { | ||
noSonar: '"NOSONAR" comments should not be used.', | ||
}, | ||
}), | ||
create(context) { | ||
return { | ||
Program: () => { | ||
// Note: The detection of `NOSONAR` comments must be aligned | ||
// with the way the analyzer computes the `NOSONAR` metrics. | ||
// @see `findNoSonarLines` in `nosonar.ts` | ||
const comments = context.sourceCode.getAllComments(); | ||
for (const comment of comments) { | ||
if (!comment.loc) { | ||
continue; | ||
} | ||
const commentValue = comment.value.startsWith('*') | ||
? comment.value.substring(1).trim() | ||
: comment.value.trim(); | ||
if (commentValue.toUpperCase().startsWith(NOSONAR)) { | ||
context.report({ | ||
loc: comment.loc, | ||
messageId: 'noSonar', | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
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,77 @@ | ||
/* | ||
* SonarQube JavaScript Plugin | ||
* Copyright (C) 2011-2024 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 { NodeRuleTester } from '../../../tests/tools/testers/rule-tester.js'; | ||
import { rule } from './index.js'; | ||
|
||
const ruleTester = new NodeRuleTester({ parserOptions: { ecmaVersion: 2018 } }); | ||
ruleTester.run('"NOSONAR" comments should not be used', rule, { | ||
valid: [ | ||
{ | ||
code: '//', | ||
}, | ||
{ | ||
code: '/* */', | ||
}, | ||
{ | ||
code: '// foo', | ||
}, | ||
{ | ||
code: '/* foo */', | ||
}, | ||
{ | ||
code: '// no sonar', | ||
}, | ||
{ | ||
code: '/* no sonar */', | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: '// NOSONAR', | ||
errors: [ | ||
{ | ||
message: '"NOSONAR" comments should not be used.', | ||
line: 1, | ||
column: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: '// nosonar', | ||
errors: 1, | ||
}, | ||
{ | ||
code: '/* NOSONAR */', | ||
errors: 1, | ||
}, | ||
{ | ||
code: '/* nosonar */', | ||
errors: 1, | ||
}, | ||
{ | ||
code: '// NOSONARSOURCE', | ||
errors: 1, | ||
}, | ||
{ | ||
code: '/* NOSONARSOURCE */', | ||
errors: 1, | ||
}, | ||
], | ||
}); |
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
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
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
32 changes: 32 additions & 0 deletions
32
...gin/javascript-checks/src/main/java/org/sonar/javascript/checks/NoSonarCommentsCheck.java
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,32 @@ | ||
/* | ||
* SonarQube JavaScript Plugin | ||
* Copyright (C) 2011-2024 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. | ||
*/ | ||
package org.sonar.javascript.checks; | ||
|
||
import org.sonar.check.Rule; | ||
import org.sonar.plugins.javascript.api.Check; | ||
import org.sonar.plugins.javascript.api.JavaScriptRule; | ||
import org.sonar.plugins.javascript.api.TypeScriptRule; | ||
|
||
@JavaScriptRule | ||
@TypeScriptRule | ||
@Rule(key = "S1291") | ||
public class NoSonarCommentsCheck extends Check { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...avascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1291.html
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,5 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Any issue to quality rule can be deactivated with the <code>NOSONAR</code> marker. This marker is pretty useful to exclude false-positive results | ||
but it can also be used abusively to hide real quality flaws.</p> | ||
<p>This rule raises an issue when <code>NOSONAR</code> is used.</p> | ||
|
27 changes: 27 additions & 0 deletions
27
...avascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1291.json
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,27 @@ | ||
{ | ||
"title": "Track uses of \"NOSONAR\" comments", | ||
"type": "CODE_SMELL", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "MEDIUM" | ||
}, | ||
"attribute": "CLEAR" | ||
}, | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "1min" | ||
}, | ||
"tags": [ | ||
"bad-practice" | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-1291", | ||
"sqKey": "S1291", | ||
"scope": "All", | ||
"quickfix": "unknown", | ||
"compatibleLanguages": [ | ||
"JAVASCRIPT", | ||
"TYPESCRIPT" | ||
] | ||
} |