Skip to content
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

Make typescript-eslint rules compatible with .vue files #524

Closed
paetling opened this issue May 13, 2019 · 1 comment · Fixed by #594
Closed

Make typescript-eslint rules compatible with .vue files #524

paetling opened this issue May 13, 2019 · 1 comment · Fixed by #594
Labels
breaking change This change will require a new major version to be released enhancement New feature or request has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Milestone

Comments

@paetling
Copy link

My team and I are writing a Vue app using typescript. We have started making extensive use of vue single file components. The single file components end with a .vue file extension. Inside the components there are three possible sections:

  • <template></template>
  • <script lang="ts"></script>
  • `<style></style>

The problem we are seeing is that some of the eslint plugin rules (explicit-function-return-types and explicit-member-accessibility) use a function in utils called isTypescriptFile. This check ensures that the rules are run only on .ts or .tsx files. This means that we are not getting some of our linting rules run in our .vue files.

I can think of a couple good ways to fix this and would like some feedback on which is preferred :)

  1. change the isTypescriptFile check to not only check the .tsx? extension but also check for .vue files which include a <script lang="ts"> tag.
  2. Make the linter configurable on what files it should include as typescript files (run time variables, env variables, config file, etc). These variables would then replace the static file extension checker logic in isTypescriptFile.

Repro

  • Create a repo with a .eslintrc.js file. Which includes @typescript-eslint in its plugins and '@typescript-eslint/explicit-function-return-type': 'error'` in its rules
  • create a .vue file with <script lang="ts"></script>
  • In that script tag create a function with no return type
  • Linter will not catch the error
{
  "rules": {
    "typescript/<rule>": ["<setting>"]
  }
}
// your repro code case

Expected Result
Linting of .vue files for all typescript-eslint rules.

Actual Result
explicit-function-return-types and explicit-member-accessibility are not linting in .vue files.

Versions

package version
@typescript-eslint/eslint-plugin 1.9.0
@typescript-eslint/parser 1.9.0
TypeScript 3.3.4
ESLint 5.15.3
node 11.9.0
npm 6.9.1
@paetling paetling added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels May 13, 2019
@bradzacher
Copy link
Member

isTypescriptFile was added as a hack to help people with mixed codebases.
I think we should probably kill it because people can use overrides to disable the rules where appropriate.

@bradzacher bradzacher mentioned this issue May 13, 2019
14 tasks
@bradzacher bradzacher added enhancement New feature or request and removed triage Waiting for maintainers to take a look labels May 13, 2019
@bradzacher bradzacher added the breaking change This change will require a new major version to be released label Jun 28, 2019
@bradzacher bradzacher added this to the 2.0.0 milestone Jun 28, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label Jul 11, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change This change will require a new major version to be released enhancement New feature or request has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants