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

fix(no-bad-blocks): exclude ESLint directives #1301

Merged
merged 1 commit into from
Aug 11, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .README/rules/no-bad-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
{"gitdown": "contents", "rootId": "no-bad-blocks"}

This rule checks for multi-line-style comments which fail to meet the
criteria of a jsdoc block, namely that it should begin with two and only two
asterisks, but which appear to be intended as jsdoc blocks due to the presence
criteria of a JSDoc block, namely that it should begin with two and only two
asterisks, but which appear to be intended as JSDoc blocks due to the presence
of whitespace followed by whitespace or asterisks, and
an at-sign (`@`) and some non-whitespace (as with a jsdoc block tag).

Exceptions are made for ESLint directive comments (which may use `@` in
rule names).

## Fixer

(TODO)
Expand Down
9 changes: 7 additions & 2 deletions docs/rules/no-bad-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@


This rule checks for multi-line-style comments which fail to meet the
criteria of a jsdoc block, namely that it should begin with two and only two
asterisks, but which appear to be intended as jsdoc blocks due to the presence
criteria of a JSDoc block, namely that it should begin with two and only two
asterisks, but which appear to be intended as JSDoc blocks due to the presence
of whitespace followed by whitespace or asterisks, and
an at-sign (`@`) and some non-whitespace (as with a jsdoc block tag).

Exceptions are made for ESLint directive comments (which may use `@` in
rule names).

<a name="user-content-fixer"></a>
<a name="fixer"></a>
## Fixer
Expand Down Expand Up @@ -170,5 +173,7 @@ function quux (foo) {
}

/***/

/* eslint-disable @stylistic/max-len */
````

10 changes: 10 additions & 0 deletions src/rules/noBadBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export default iterateJsdoc(({
allComments
).filter((comment) => {
const commentText = sourceCode.getText(comment);

const initialText = commentText.replace(commentRegexp, '').trimStart();
if ([
'eslint'
].some((directive) => {
return initialText.startsWith(directive);
})) {
return false;
}

let sliceIndex = 2;
if (!commentRegexp.test(commentText)) {
const multiline = extraAsteriskCommentRegexp.exec(commentText)?.[0];
Expand Down
10 changes: 10 additions & 0 deletions test/rules/assertions/noBadBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,15 @@ export default {
{
code: '/***/',
},
{
code: '/* eslint-disable @stylistic/max-len */',
plugins: {
'@stylistic': {
rules: {
'max-len': () => {}
}
}
},
},
],
};
Loading