Skip to content

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

@jez9999

Description

@jez9999

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

Activity

jez9999

jez9999 commented on Nov 8, 2022

@jez9999
Author

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

FloEdelmann commented on Nov 10, 2022

@FloEdelmann
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

yuntian001 commented on Nov 21, 2022

@yuntian001

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

kawazoe commented on Jan 5, 2023

@kawazoe

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

wenfangdu commented on Jun 10, 2023

@wenfangdu
Contributor

@kawazoe Tracked here: #2211

so1ve

so1ve commented on Oct 4, 2023

@so1ve
Member

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @FloEdelmann@kawazoe@jez9999@wenfangdu@yuntian001

        Issue actions

          Allow linting of <script> section only if lang="ts" · Issue #2012 · vuejs/eslint-plugin-vue