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 Create rule S1607 (no-skipped-tests): Tests should not be skipped without providing a reason #4797

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

yassin-kammoun-sonarsource
Copy link
Contributor

RSPEC to review

Copy link
Contributor

@zglicz zglicz left a comment

Choose a reason for hiding this comment

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

Few small comments for you!

awwyiss2

*/
function hasExplanationComment(node: estree.Node): boolean {
const comments = context.sourceCode.getCommentsBefore(node);
return comments.some(comment => comment.loc!.end.line === node.loc!.start.line - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a single character enough? Should there be a minimal length of explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would you suggest as a minimal length?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't consider a single word to be a good enough reason. I'd say 20 characters could be fair, so that it can be a semblance of a valid sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds fair, but I wonder how that would work with comments written in Asian languages such as Chinese or Japanese, which can be quite compact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been thinking, and I remember seeing quite a few times comments that just mention a Jira ticket number or a GitHub issue number.

return jestListener();
case dependencies.has('mocha'):
return mochaListener();
case getPackageJsonsCount() > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this imply the nodejsListener?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume that a Node.js project includes at least one package.json file so that the Node-specific listener is worth triggering. Do you think this assumption is nonsense?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've only ever used jest, so I'm not sure how users normally setup the nodejs-tests. It's a foreign approximation for me.

*
* Ignoring tests with Jasmine is done by using `xit`, `xdescribe`, or `xcontext`.
*/
function jasmineListener(): Rule.RuleListener {
Copy link
Contributor

Choose a reason for hiding this comment

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

the jasmine, jest and mocha listeners follow the same convention. They only differ on the isIgnoredTest implementation. Could you merge them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have mixed feelings about this because of past experiences. While it's true that the implementation is quite similar, I also feel that merging them may not be beneficial once we receive feedback from users and need to introduce framework-specific exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, well ok. I would say that's a premature separation, but I lack the experience here. Just a small fear, that there might also be improvements that will need to land in all 3 places.

Copy link
Contributor

@zglicz zglicz left a comment

Choose a reason for hiding this comment

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

Thanks for answering the comments

}),
create(context) {
const dependencies = getDependencies(context.filename);
switch (true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh, that's also a new one for me as well. Interesting.

return jestListener();
case dependencies.has('mocha'):
return mochaListener();
case getPackageJsonsCount() > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

I've only ever used jest, so I'm not sure how users normally setup the nodejs-tests. It's a foreign approximation for me.

*
* Ignoring tests with Jasmine is done by using `xit`, `xdescribe`, or `xcontext`.
*/
function jasmineListener(): Rule.RuleListener {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, well ok. I would say that's a premature separation, but I lack the experience here. Just a small fear, that there might also be improvements that will need to land in all 3 places.

@JavaScriptRule
@TypeScriptRule
@Rule(key = "S1607")
public class NoSkippedTestsCheck extends Check {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need tests for checks of rules without parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We never did that until now. Did something change recently?

Copy link

sonarqube-next bot commented Sep 4, 2024

@yassin-kammoun-sonarsource yassin-kammoun-sonarsource changed the title JS-312 Create rule S1607: Tests should not be skipped without providing a reason JS-312 Create rule S1607 (no-skipped-tests): Tests should not be skipped without providing a reason Sep 4, 2024
@yassin-kammoun-sonarsource yassin-kammoun-sonarsource merged commit 77facd4 into master Sep 4, 2024
15 of 16 checks passed
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.

3 participants