Skip to content

Commit

Permalink
fix(check-indentation): ensure decorators in fenced code blocks do …
Browse files Browse the repository at this point in the history
…not terminate ignoring of indentation in code blocks; fixes #789

Prevent decorators from being interpreted as tags which may force end code block masking
  • Loading branch information
brettz9 committed Oct 9, 2021
1 parent cb12d33 commit 0f4d8e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -1932,6 +1932,20 @@ function quux () {
* ```
*/
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]

/**
* @example
* ```
* @MyDecorator({
* myOptions: 42
* })
* export class MyClass {}
* ```
*/
function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":["example","MyDecorator"]}]
````


Expand Down
2 changes: 1 addition & 1 deletion src/rules/checkIndentation.js
Expand Up @@ -9,7 +9,7 @@ const maskExcludedContent = (str, excludeTags) => {
};

const maskCodeBlocks = (str) => {
const regContent = /([ \t]+\*)[ \t]```[^\n]*?([\w|\W]*?\n)(?=[ \t]*\*(?:[ \t]*(?:```|@)|\/))/gu;
const regContent = /([ \t]+\*)[ \t]```[^\n]*?([\w|\W]*?\n)(?=[ \t]*\*(?:[ \t]*(?:```|@\w+\s)|\/))/gu;

return str.replace(regContent, (_match, margin, code) => {
return new Array(code.match(/\n/gu).length + 1).join(margin + '\n');
Expand Down
22 changes: 22 additions & 0 deletions test/rules/assertions/checkIndentation.js
Expand Up @@ -289,5 +289,27 @@ export default {
excludeTags: [],
}],
},
{
code: `
/**
* @example
* \`\`\`
* @MyDecorator({
* myOptions: 42
* })
* export class MyClass {}
* \`\`\`
*/
function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
`,
options: [
{
excludeTags: ['example', 'MyDecorator'],
},
],
parser: require.resolve('@typescript-eslint/parser'),
},
],
};

0 comments on commit 0f4d8e0

Please sign in to comment.