Skip to content

Commit df55137

Browse files
committedAug 11, 2024·
fix(no-bad-blocks): exclude ESLint directives
1 parent 1cae2cb commit df55137

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed
 

‎.README/rules/no-bad-blocks.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
{"gitdown": "contents", "rootId": "no-bad-blocks"}
44

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

11+
Exceptions are made for ESLint directive comments (which may use `@` in
12+
rule names).
13+
1114
## Fixer
1215

1316
(TODO)

‎docs/rules/no-bad-blocks.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55

66

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

13+
Exceptions are made for ESLint directive comments (which may use `@` in
14+
rule names).
15+
1316
<a name="user-content-fixer"></a>
1417
<a name="fixer"></a>
1518
## Fixer
@@ -170,5 +173,7 @@ function quux (foo) {
170173
}
171174

172175
/***/
176+
177+
/* eslint-disable @stylistic/max-len */
173178
````
174179

‎src/rules/noBadBlocks.js

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export default iterateJsdoc(({
3131
allComments
3232
).filter((comment) => {
3333
const commentText = sourceCode.getText(comment);
34+
35+
const initialText = commentText.replace(commentRegexp, '').trimStart();
36+
if ([
37+
'eslint'
38+
].some((directive) => {
39+
return initialText.startsWith(directive);
40+
})) {
41+
return false;
42+
}
43+
3444
let sliceIndex = 2;
3545
if (!commentRegexp.test(commentText)) {
3646
const multiline = extraAsteriskCommentRegexp.exec(commentText)?.[0];

‎test/rules/assertions/noBadBlocks.js

+10
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,15 @@ export default {
250250
{
251251
code: '/***/',
252252
},
253+
{
254+
code: '/* eslint-disable @stylistic/max-len */',
255+
plugins: {
256+
'@stylistic': {
257+
rules: {
258+
'max-len': () => {}
259+
}
260+
}
261+
},
262+
},
253263
],
254264
};

0 commit comments

Comments
 (0)
Please sign in to comment.