diff --git a/.README/rules/no-bad-blocks.md b/.README/rules/no-bad-blocks.md index c4dd6e7e..ebbabaea 100644 --- a/.README/rules/no-bad-blocks.md +++ b/.README/rules/no-bad-blocks.md @@ -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) diff --git a/docs/rules/no-bad-blocks.md b/docs/rules/no-bad-blocks.md index 898c8c68..409b4249 100644 --- a/docs/rules/no-bad-blocks.md +++ b/docs/rules/no-bad-blocks.md @@ -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). + ## Fixer @@ -170,5 +173,7 @@ function quux (foo) { } /***/ + +/* eslint-disable @stylistic/max-len */ ```` diff --git a/src/rules/noBadBlocks.js b/src/rules/noBadBlocks.js index f64de221..abd5ee7e 100644 --- a/src/rules/noBadBlocks.js +++ b/src/rules/noBadBlocks.js @@ -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]; diff --git a/test/rules/assertions/noBadBlocks.js b/test/rules/assertions/noBadBlocks.js index 06ac28c7..41212ed9 100644 --- a/test/rules/assertions/noBadBlocks.js +++ b/test/rules/assertions/noBadBlocks.js @@ -250,5 +250,15 @@ export default { { code: '/***/', }, + { + code: '/* eslint-disable @stylistic/max-len */', + plugins: { + '@stylistic': { + rules: { + 'max-len': () => {} + } + } + }, + }, ], };