Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript-estree): check for illegal decorators on function declarations #6590

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,3 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function TSESTree - Error 1`] = `"NO ERROR"`;
exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function TSESTree - Error 1`] = `
"TSError
1 | // TODO: This fixture might be too large, and if so should be split up.
2 |
> 3 | @dec
| ^^^^ Decorators are not valid here.
4 | function b(){}
5 |"
`;
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function Error Alignment 1`] = `"Babel errored but TSESTree didn't"`;
exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function Error Alignment 1`] = `"Both errored"`;
Expand Up @@ -38,7 +38,6 @@ Object {
"legacy-fixtures/basics/fixtures/_error_/interface-with-construct-signature-with-parameter-accessibility/fixture.ts",
"legacy-fixtures/basics/fixtures/_error_/new-target-in-arrow-function-body/fixture.ts",
"legacy-fixtures/basics/fixtures/_error_/var-with-definite-assignment/fixture.ts",
"legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/fixture.ts",
"legacy-fixtures/errorRecovery/fixtures/_error_/empty-type-arguments-in-call-expression/fixture.ts",
"legacy-fixtures/errorRecovery/fixtures/_error_/empty-type-arguments-in-new-expression/fixture.ts",
"legacy-fixtures/errorRecovery/fixtures/_error_/empty-type-arguments/fixture.ts",
Expand Down
7 changes: 0 additions & 7 deletions packages/eslint-plugin/src/rules/no-empty-function.ts
Expand Up @@ -166,13 +166,6 @@ export default util.createRule<Options, MessageIds>({

rules.FunctionExpression(node);
},
FunctionDeclaration(node): void {
if (isAllowedEmptyDecoratedFunctions(node)) {
return;
}

rules.FunctionDeclaration(node);
},
};
},
});
18 changes: 1 addition & 17 deletions packages/eslint-plugin/tests/rules/no-empty-function.test.ts
@@ -1,5 +1,5 @@
import rule from '../../src/rules/no-empty-function';
import { noFormat, RuleTester } from '../RuleTester';
import { RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -169,22 +169,6 @@ function foo() {}
},
],
},
{
code: noFormat`
@decorator()
function foo() {}
`,
errors: [
{
messageId: 'unexpected',
data: {
name: "function 'foo'",
},
line: 3,
column: 16,
},
],
},
{
code: `
class Foo {
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -907,6 +907,8 @@ export class Converter {
// Declarations

case SyntaxKind.FunctionDeclaration: {
this.#checkIllegalDecorators(node);

const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node);

const result = this.createNode<
Expand Down