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

Allow linting of <script> section only if lang="ts" #2012

Open
jez9999 opened this issue Oct 18, 2022 · 6 comments
Open

Allow linting of <script> section only if lang="ts" #2012

jez9999 opened this issue Oct 18, 2022 · 6 comments

Comments

@jez9999
Copy link

jez9999 commented Oct 18, 2022

I'd like to be able to lint my .vue file script sections only if lang="ts". At the moment ESLint is linting script sections that are just plain JS (ie. <script setup>) as well as TS ones (<script setup lang="ts">) when I run eslint . --ext .vue --ignore-path .gitignore. A good solution would perhaps be to be able to say in .eslintrc.cjs which script section languages should be linted. Another solution would be to allow to set which rules get linted based on language; obviously certain TS rules I apply do not apply to plain JS because plain JS cannot set types.

Tell us about your environment

  • ESLint version: ^8.22.0
  • eslint-plugin-vue version: ^9.3.0
  • Node version: 16.17.0
@jez9999
Copy link
Author

jez9999 commented Nov 8, 2022

Guys, you advise opening new issues like this and reaching out and yet an issue can go weeks and have absolutely no response. It's kind of frustrating. Why don't you make some effort to give some response??? I'd really like some direction on this, it's rather screwing up my linting. Quote: "If you can't find the right solution, don't hesitate to reach out in issues – we're happy to help!"

@FloEdelmann
Copy link
Member

Please watch your tone, this is an open-source repository and we all work in our spare time on triaging, commenting, reviewing and coding.

Limiting rules to only .vue files with lang="ts" seems like a good idea, but it is currently not possible. I don't know if extra support for that would maybe need to be implemented in https://github.com/vuejs/vue-eslint-parser. Also, there could already be (closed) issues in this repository suggesting the same thing, have you looked at those already? @ota-meshi Maybe you know what needs to be done to get support for this?

@yuntian001
Copy link

Please watch your tone, this is an open-source repository and we all work in our spare time on triaging, commenting, reviewing and coding.

Limiting rules to only .vue files with lang="ts" seems like a good idea, but it is currently not possible. I don't know if extra support for that would maybe need to be implemented in https://github.com/vuejs/vue-eslint-parser. Also, there could already be (closed) issues in this repository suggesting the same thing, have you looked at those already? @ota-meshi Maybe you know what needs to be done to get support for this?

这个功能是有必要的,因为如果设置规则@typescript-eslint/naming-convention 会报错 Error: Error while loading rule '@typescript-eslint/naming-convention': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. 原因是为.vue中的<script>应用了@typescript-eslint/naming-convention rules, 而现在无法为.vue中的<script><script lang="ts"> 分别设置规则

@kawazoe
Copy link

kawazoe commented Jan 5, 2023

I've hit the same issue as @yuntian001 . I have @typescript-eslint/prefer-optional-chain set and it crashes when eslint process vue files that uses plain javascript.

I'm not too sure if this is possible, but maybe there's a way to automatically skip rules that requires context.parserServices.hasFullTypeInformation to be true when parsing js code? They usually don't make sense anyway.

In the mean time, the best solution is to always set lang="ts" in vue files if you use TS in some.

@wenfangdu
Copy link
Contributor

@kawazoe Tracked here: #2211

@so1ve
Copy link
Member

so1ve commented Oct 4, 2023

I think this is currently impossible unless eslint-plugin-vue do a huge refactor to use eslint's preprocessor api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants