Skip to content

Commit

Permalink
feat(check-indentation): ensure masking through decorators within t…
Browse files Browse the repository at this point in the history
…ags (fixes #789)
  • Loading branch information
brettz9 committed Dec 1, 2021
1 parent 73f5594 commit ecd1c72
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,18 @@ function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":["example","MyDecorator"]}]

/**
* @example ```
* @MyDecorator({
* myOptions: 42
* })
* export class MyClass {}
* ```
*/
function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
````


Expand Down
2 changes: 1 addition & 1 deletion src/rules/checkIndentation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import iterateJsdoc from '../iterateJsdoc';

const maskExcludedContent = (str, excludeTags) => {
const regContent = new RegExp(`([ \\t]+\\*)[ \\t]@(?:${excludeTags.join('|')})(?=[ \\n])([\\w|\\W]*?\\n)(?=[ \\t]*\\*(?:[ \\t]*@|\\/))`, 'gu');
const regContent = new RegExp(`([ \\t]+\\*)[ \\t]@(?:${excludeTags.join('|')})(?=[ \\n])([\\w|\\W]*?\\n)(?=[ \\t]*\\*(?:[ \\t]*@\\w+\\s|\\/))`, 'gu');

return str.replace(regContent, (_match, margin, code) => {
return (margin + '\n').repeat(code.match(/\n/gu).length);
Expand Down
16 changes: 16 additions & 0 deletions test/rules/assertions/checkIndentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,21 @@ export default {
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
* @example \`\`\`
* @MyDecorator({
* myOptions: 42
* })
* export class MyClass {}
* \`\`\`
*/
function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
};

0 comments on commit ecd1c72

Please sign in to comment.