Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[semi] incorrectly requires semicolon after export default interface #123

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

Closed
nstepien opened this issue Jan 22, 2019 · 12 comments
Closed

[semi] incorrectly requires semicolon after export default interface #123

nstepien opened this issue Jan 22, 2019 · 12 comments
Labels
bug Something isn't working enhancement: new base rule extension New base rule extension required to handle a TS specific case package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@nstepien
Copy link
Contributor

What code were you trying to parse?

export default interface test {}

What did you expect to happen?
semi should ignore the interface block.
What actually happened?
semi wants a semicolon after the block, which then triggers the no-extra-semi rule.

It works fine without default:

export interface test1 {}
interface test2 {}

Versions

package version
@typescript-eslint/parser 1.0.0
TypeScript 3.2.4
ESLint 5.12.1
node 11.7.0
npm 6.5.0
@nstepien nstepien added package: parser Issues related to @typescript-eslint/parser triage Waiting for team members to take a look labels Jan 22, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Jan 22, 2019
@bradzacher
Copy link
Member

TSInterfaceDeclaration by itself doesn't trigger a semi check purely because it doesn't match the base rule's matchers.

https://github.com/eslint/eslint/blob/faf3c4eda0d27323630d0bc103a99dd0ecffe842/lib/rules/semi.js#L320-L324

The base rule has a specific case for ExportDefaultDeclaration, and only skips the semi check if it's a class or function declaration.

We might have to override the rule for this one.

Temp workaround is to define your interface separately:

interface Foo {}
export default Foo;

@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin and removed package: parser Issues related to @typescript-eslint/parser labels Jan 22, 2019
@nstepien
Copy link
Contributor Author

@bradzacher could this possibly be fixed in eslint by making the ExportDefaultDeclaration check use a whitelist instead of a blacklist?

@bradzacher
Copy link
Member

Probably would fix it, but the problem is:

  • there is a large number of nodes that would need to be whitelisted
  • it would cause false positives as new language features get supported by the base ESTree representation

We can bring this rule internally and extend its so that it works for TS nodes.

@robertmain
Copy link

I don't suppose this is related to eslint/eslint#9399 is it?

I'm seeing it in my app too.

export default interface AudioFactory{
    getSong(id: string): Promise<Song>;
};

I get missing semicolon

@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin enhancement: new base rule extension New base rule extension required to handle a TS specific case and removed enhancement: new plugin rule New rule request for eslint-plugin labels Apr 15, 2019
@JamesHenry
Copy link
Member

Fixed by #461

@mateja176
Copy link

Fixed by #461

I've tried:

  • "@typescript-eslint/semi": "error"
  • "@typescript-eslint/semi": "[2, "always"]"

Unfortunately, none of which work. Is something missing?

@bradzacher
Copy link
Member

https://github.com/typescript-eslint/typescript-eslint/releases

Hasn't been released to master yet.
Try the canary tag on npm for builds directly from master if you don't want to wait for a main release.

@bjerkins
Copy link

@bradzacher tried 1.7.1-alpha.16, marked as canary, but I still have the same problem
image

@bradzacher
Copy link
Member

@bjerkins - you still have the base semi rule turned on, which is what causes the first error.
you cannot have both the base rule and our rule turned on, as the base rule will false positive.
see the docs on semi: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md

the second one might be a bug, but it's hard to tell because you've clipped the code out.

@eyedean
Copy link

eyedean commented Jun 19, 2019

I had the same problem as @bjerkins and just confirmed adding the following from @bradzacher's link fixed it. Thanks, Brad!

  "semi": "off",
  "@typescript-eslint/semi": ["error"]

@bradzacher
Copy link
Member

why have you got both?

"semi: ["warn", "always"],
"@typescript-eslint/semi": ["warn", "always"],

This will ofc cause a problem because both rules are going to try and add a semi.

Please read the rule doc, which tells you to explicitly NOT do this.
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md

@audacioustux
Copy link

audacioustux commented Jul 18, 2019

why have you got both?

"semi: ["warn", "always"],
"@typescript-eslint/semi": ["warn", "always"],

This will ofc cause a problem because both rules are going to try and add a semi.

Please read the rule doc, which tells you to explicitly NOT do this.
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md

sorry for deleting my last comment... just figured out what I'm messing with and didn't see someone already seen and replied lol ...

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement: new base rule extension New base rule extension required to handle a TS specific case package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

8 participants