question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some @typescript-eslint rules doesn't work in vue files

See original GitHub issue

Some rules in @typescript-eslint check if the file name ends with .ts to determine if the rule should be run or not, because they don’t apply to .js files.

For example, if I have this code:

const test = x => x;

If I place it in a .ts file, I will get a warning from @typescript-eslint/explicit-function-return-type. However, if I place it in a <script lang="ts"> block of a .vue file, this warning does not appear. This is because @typescript-eslint checks the file ending, and since it is .vue and not .ts, the rule isn’t run.

Is there some other way @typescript-eslint could check if the code is typescript, other than by the file extension? How can it differentiate between .vue files which specify lang="ts" and those that don’t?

Here is where @typescript-eslint does this check: https://github.com/typescript-eslint/typescript-eslint/blob/7be56570de9d1983af95db5900ec730930d52712/packages/eslint-plugin/src/rules/explicit-function-return-type.ts#L83 https://github.com/typescript-eslint/typescript-eslint/blob/7be56570de9d1983af95db5900ec730930d52712/packages/eslint-plugin/src/util/misc.ts#L11-L13

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
seibert-iocommented, Apr 26, 2019

Hey @mysticatea,

thanks for looking into this. Just checking in to see if anyone had a chance to discuss this with the typescript-eslint team already?

1reaction
mysticateacommented, Feb 12, 2019

Thank you for this report.

This is a tough problem. Parsers cannot modify file names for rules, so this parser cannot solve the problem.

Hmm.

Possibly, this parser can tell the typescript parser (instead of rules) something. We need to discuss with typescript-eslint team.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some @typescript-eslint rules doesn't work in vue files #40
ts file, I will get a warning from @typescript-eslint/explicit-function-return-type . However, if I place it in a <script lang="ts"> block of a ...
Read more >
ESlint doesn't work on .vue file with typescript - Stack Overflow
In the .eslintrc.json file you did not declare eslint to read .vue files. You should run eslint with --ext flag. (eslnit . --ext...
Read more >
User Guide | eslint-plugin-vue
Because this plugin requires vue-eslint-parser to parse .vue files, this plugin doesn't work if you overwrite the parser option.
Read more >
ESLint | IntelliJ IDEA Documentation - JetBrains
IntelliJ IDEA integrates with ESLint which brings a wide range of linting rules that can also be extended with plugins.
Read more >
User Guide | eslint-plugin-vue-scoped-css
You can use /* eslint-disable */ -like CSS comments in <style> of .vue files to disable a certain rule temporarily. For example:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found