Skip to content

Commit

Permalink
fix: bug with false positive decorator detection (evident sans semi-c…
Browse files Browse the repository at this point in the history
…olons); e.g., `require-jsdoc` fixer
  • Loading branch information
brettz9 committed Jan 24, 2021
1 parent 8b2d143 commit 6bda6b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -9942,6 +9942,12 @@ Defaults to `true`.
The following patterns are considered problems:
````js
requestAnimationFrame(draw)
function bench() {
}
// Message: Missing JSDoc comment.
function quux (foo) {
}
Expand Down
17 changes: 7 additions & 10 deletions src/eslint/getJSDocComment.js
Expand Up @@ -32,8 +32,7 @@ const getDecorator = (token, sourceCode) => {
if (tokenBefore && tokenBefore.type === 'Punctuator') {
if (tokenBefore.value === tokenClose) {
nested++;
}
if (tokenBefore.value === tokenOpen) {
} else if (tokenBefore.value === tokenOpen) {
if (nested) {
nested--;
} else {
Expand All @@ -43,18 +42,16 @@ const getDecorator = (token, sourceCode) => {
}
} while (tokenBefore);

return tokenBefore;
return getDecorator(tokenBefore, sourceCode);
}
}

if (token.type === 'Identifier') {
const tokenBefore = sourceCode.getTokenBefore(token, {includeComments: true});
if (tokenBefore && tokenBefore.type === 'Punctuator' && tokenBefore.value === '@') {
return tokenBefore;
if (token.value === '@') {
return token;
}
}

return false;
const tokenBfr = sourceCode.getTokenBefore(token, {includeComments: true});

return getDecorator(tokenBfr, sourceCode);
};

/**
Expand Down
20 changes: 20 additions & 0 deletions test/rules/assertions/requireJsdoc.js
Expand Up @@ -6,6 +6,26 @@ export default {
invalid: [
{
code: `
requestAnimationFrame(draw)
function bench() {
}
`,
errors: [{
message: 'Missing JSDoc comment.',
}],
output: `
requestAnimationFrame(draw)
/**
*
*/
function bench() {
}
`,
},
{
code: `
function quux (foo) {
}`,
Expand Down

0 comments on commit 6bda6b4

Please sign in to comment.