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

JS-312 Improve S1607 (no-skipped-tests): Allow explanation comments adjacent to the disabled test #4804

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

yassin-kammoun-sonarsource
Copy link
Contributor

While validating S1607 on Peach, I encountered some false positives where a disabled test has an explanation comment that follows the test, such as this issue.

RSPEC's change to review

@ilia-kebets-sonarsource ilia-kebets-sonarsource changed the title Improve S1607 (no-skipped-tests): Allow explanation comments after the disabled test JS-312 Improve S1607 (no-skipped-tests): Allow explanation comments after the disabled test Sep 6, 2024
@ilia-kebets-sonarsource
Copy link
Contributor

@yassin-kammoun-sonarsource Great idea to tackle the line after, but why not handle when the explanation comment is on the same line as well?

function isAdjacent(comment: estree.Comment, node: estree.Node) {
const commentLine = comment.loc!.end.line;
const nodeLine = node.loc!.start.line;
return commentLine === nodeLine - 1 || commentLine === nodeLine + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we consider my comment here,

This could be:

Suggested change
return commentLine === nodeLine - 1 || commentLine === nodeLine + 1;
return Math.abs(commentLine - nodeLine) <= 1;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how it could be tested in the comment-based framework though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was going to, but I just don't know how to test that.
Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to use relative line increments (@+line_increment) or decrements (@-line_decrement):

// Noncompliant@+1
some.faulty.code();

another.faulty.code();
// another comment
// Noncompliant@-2

from DEV.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for remembering it!

Copy link
Contributor

@ilia-kebets-sonarsource ilia-kebets-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good job!

@yassin-kammoun-sonarsource yassin-kammoun-sonarsource changed the title JS-312 Improve S1607 (no-skipped-tests): Allow explanation comments after the disabled test JS-312 Improve S1607 (no-skipped-tests): Allow explanation comments adjacent to the disabled test Sep 6, 2024
@yassin-kammoun-sonarsource yassin-kammoun-sonarsource merged commit 86f79e9 into master Sep 6, 2024
15 of 16 checks passed
@yassin-kammoun-sonarsource yassin-kammoun-sonarsource deleted the improve-JS-312 branch September 6, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants