Some @typescript-eslint rules doesn't work in vue files
See original GitHub issueSome 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:
- Created 5 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top GitHub Comments
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?
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.