Skip to content

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

Closed
@trygveaa

Description

@trygveaa

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions