test: add Sonar-native issues to validate Quality Gate on PR analysis#3130
Closed
swarnadipa-dev wants to merge 2 commits into
Closed
test: add Sonar-native issues to validate Quality Gate on PR analysis#3130swarnadipa-dev wants to merge 2 commits into
swarnadipa-dev wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR intentionally introduces SonarCloud-detectable quality issues into the Nuxeo Drive download button to validate that Sonar PR analysis and the Quality Gate correctly fail a pull request when new “Sonar-native” issues are added.
Changes:
- Added
_printSum()and_printChars()methods containing deliberate Sonar rule violations (dead store, redundant return, and duplicate literals). - Invoked these new methods from
_download(), causing additional runtime side effects (notably console output) during downloads.
Comment on lines
+86
to
+87
| this._printSum(); | ||
| this._printChars(); |
Comment on lines
+197
to
+214
|
|
||
| // Prints the sum of 5 + 2 | ||
| _printSum() { | ||
| let result = 10; // S1854: dead store — assigned but immediately overwritten | ||
| result = 5 + 2; | ||
| console.log('Sum of 5 + 2 =', result); | ||
| return; // S3626: unnecessary return at end of void function | ||
| } | ||
|
|
||
| // Prints all characters in "hello world" | ||
| _printChars() { | ||
| const word = 'hello world'; | ||
| const label = 'hello world'; // S1192: duplicate string literal (appears 3x in file now) | ||
| const prefix = 'hello world'; // S1192: third occurrence — Sonar flags >= 3 duplicates | ||
| for (let i = 0; i < word.length; i++) { | ||
| console.log(label, prefix, word[i]); | ||
| } | ||
| } |
Comment on lines
+200
to
+203
| let result = 10; // S1854: dead store — assigned but immediately overwritten | ||
| result = 5 + 2; | ||
| console.log('Sum of 5 + 2 =', result); | ||
| return; // S3626: unnecessary return at end of void function |
Comment on lines
+197
to
+214
|
|
||
| // Prints the sum of 5 + 2 | ||
| _printSum() { | ||
| let result = 10; // S1854: dead store — assigned but immediately overwritten | ||
| result = 5 + 2; | ||
| console.log('Sum of 5 + 2 =', result); | ||
| return; // S3626: unnecessary return at end of void function | ||
| } | ||
|
|
||
| // Prints all characters in "hello world" | ||
| _printChars() { | ||
| const word = 'hello world'; | ||
| const label = 'hello world'; // S1192: duplicate string literal (appears 3x in file now) | ||
| const prefix = 'hello world'; // S1192: third occurrence — Sonar flags >= 3 duplicates | ||
| for (let i = 0; i < word.length; i++) { | ||
| console.log(label, prefix, word[i]); | ||
| } | ||
| } |
655e2a5 to
f996402
Compare
328ce97 to
f110f71
Compare
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
This PR adds deliberate Sonar-native code quality issues to
nuxeo-drive-download-button.jsto validate that SonarCloud's Quality Gate correctly fails on PR analysis.Changes
Added two test methods in
addons/nuxeo-drive/elements/nuxeo-drive-download-button.js:_printSum()— triggers:S1854(Major): Dead store —let result = 10is assigned but immediately overwrittenS3626(Minor): Redundantreturnat end of void function_printChars()— triggers:S1192(Minor): Duplicate string literal'hello world'appears 3× in the same fileBoth methods are called from
_download().Purpose
This is a test-only branch used to verify that: