Skip to content

Commit 6bda6b4

Browse files
committed
fix: bug with false positive decorator detection (evident sans semi-colons); e.g., require-jsdoc fixer
1 parent 8b2d143 commit 6bda6b4

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9942,6 +9942,12 @@ Defaults to `true`.
99429942
The following patterns are considered problems:
99439943
99449944
````js
9945+
requestAnimationFrame(draw)
9946+
9947+
function bench() {
9948+
}
9949+
// Message: Missing JSDoc comment.
9950+
99459951
function quux (foo) {
99469952
99479953
}

src/eslint/getJSDocComment.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ const getDecorator = (token, sourceCode) => {
3232
if (tokenBefore && tokenBefore.type === 'Punctuator') {
3333
if (tokenBefore.value === tokenClose) {
3434
nested++;
35-
}
36-
if (tokenBefore.value === tokenOpen) {
35+
} else if (tokenBefore.value === tokenOpen) {
3736
if (nested) {
3837
nested--;
3938
} else {
@@ -43,18 +42,16 @@ const getDecorator = (token, sourceCode) => {
4342
}
4443
} while (tokenBefore);
4544

46-
return tokenBefore;
45+
return getDecorator(tokenBefore, sourceCode);
4746
}
48-
}
49-
50-
if (token.type === 'Identifier') {
51-
const tokenBefore = sourceCode.getTokenBefore(token, {includeComments: true});
52-
if (tokenBefore && tokenBefore.type === 'Punctuator' && tokenBefore.value === '@') {
53-
return tokenBefore;
47+
if (token.value === '@') {
48+
return token;
5449
}
5550
}
5651

57-
return false;
52+
const tokenBfr = sourceCode.getTokenBefore(token, {includeComments: true});
53+
54+
return getDecorator(tokenBfr, sourceCode);
5855
};
5956

6057
/**

test/rules/assertions/requireJsdoc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ export default {
66
invalid: [
77
{
88
code: `
9+
requestAnimationFrame(draw)
10+
11+
function bench() {
12+
}
13+
`,
14+
errors: [{
15+
message: 'Missing JSDoc comment.',
16+
}],
17+
output: `
18+
requestAnimationFrame(draw)
19+
20+
/**
21+
*
22+
*/
23+
function bench() {
24+
}
25+
`,
26+
},
27+
{
28+
code: `
929
function quux (foo) {
1030
1131
}`,

0 commit comments

Comments
 (0)