Skip to content

Commit

Permalink
feat(typescript-estree): check for illegal decorators on function dec…
Browse files Browse the repository at this point in the history
…larations (#6590)
  • Loading branch information
fisker committed Mar 13, 2023
1 parent 530185b commit 1b39cfd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
@@ -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

0 comments on commit 1b39cfd

Please sign in to comment.