Skip to content

Commit

Permalink
fix(no-bad-blocks): exclude ESLint directives
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Aug 11, 2024
1 parent 1cae2cb commit df55137
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
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': () => {}
}
}
},
},
],
};

0 comments on commit df55137

Please sign in to comment.