Skip to content

Commit

Permalink
Revert "optimize: ensure with new fix that we avoid checking back too…
Browse files Browse the repository at this point in the history
… far"

This reverts commit e13a03a.
  • Loading branch information
brettz9 committed Jan 24, 2021
1 parent e13a03a commit 0fc4663
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 69 deletions.
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -10565,13 +10565,6 @@ export class User {
}
// Options: [{"contexts":["ClassProperty:has(Decorator[expression.callee.name=\"Input\"])"]}]
// Message: Missing JSDoc comment.

@Input()
export class UserSettingsState {
method () {}
}
// Options: [{"require":{"MethodDefinition":true}}]
// Message: Missing JSDoc comment.
````

The following patterns are not considered problems:
Expand Down
34 changes: 1 addition & 33 deletions src/eslint/getJSDocComment.js
Expand Up @@ -16,29 +16,23 @@ const isCommentToken = (token) => {

const decoratorMetaTokens = new Map([[')', '('], ['>', '<']]);

// eslint-disable-next-line complexity
const getDecorator = (token, sourceCode) => {
if (!token) {
return false;
}

if (token.type === 'Punctuator') {
const tokenClose = token.value;
const tokenOpen = decoratorMetaTokens.get(tokenClose);
if (tokenOpen) {
let nested = 0;
let tokenBefore = token;
let exitEarlyUnlessTyped = false;
do {
tokenBefore = sourceCode.getTokenBefore(tokenBefore, {includeComments: true});
// istanbul ignore if
if (tokenBefore && tokenBefore.type === 'Punctuator') {
if (tokenBefore.value === tokenClose) {
nested++;
} else if (tokenBefore.value === tokenOpen) {
if (tokenOpen === '(') {
exitEarlyUnlessTyped = true;
}
if (nested) {
nested--;
} else {
Expand All @@ -48,33 +42,7 @@ const getDecorator = (token, sourceCode) => {
}
} while (tokenBefore);

// Because our token retrieval doesn't give us as much info as AST, and
// because decorators can be nested and fairly complex, besides finding
// any decorators, we also want to avoid checking backwards indefinitely
// in a potentially large document, so we exit early if parentheses are
// not preceded by a type where we have to keep checking backward for
// now (such as a regular call expression) or if a decorator is found.
if (exitEarlyUnlessTyped) {
// Check for `@someDecorator(`
const identifier = sourceCode.getTokenBefore(tokenBefore, {includeComments: true});
if (identifier && identifier.type === 'Identifier') {
const before = sourceCode.getTokenBefore(identifier, {includeComments: true});
if (before && before.type === 'Punctuator' && before.value === '@') {
// Decorator found
return before;
}
}

// If decorators may have `:`, we might need to check for those as with typed.
if (!identifier || identifier.type !== 'Punctuator' || identifier.value !== '>') {
// Should not be a decorator
return false;
}

// Could be a typed decorator, so keep checking for one
}

return getDecorator(tokenBefore, sourceCode, true);
return getDecorator(tokenBefore, sourceCode);
}
if (token.value === '@') {
return token;
Expand Down
29 changes: 0 additions & 29 deletions test/rules/assertions/requireJsdoc.js
Expand Up @@ -2763,35 +2763,6 @@ function quux (foo) {
`,
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
@Input()
export class UserSettingsState {
method () {}
}
`,
errors: [
{
line: 4,
message: 'Missing JSDoc comment.',
},
],
options: [{
require: {
MethodDefinition: true,
},
}],
output: `
/**
*
*/
@Input()
export class UserSettingsState {
method () {}
}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
valid: [{
code: `
Expand Down

0 comments on commit 0fc4663

Please sign in to comment.