-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[consistent-type-imports] ignore imports marked as used #450 8000 8
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
Comments
I don't think that operating based on Ideally the vue parser should augment the scope with the additional information about the usages, rather than just marking the variable as used. As an example - our scope analyser adds usages for |
@ota-meshi Maybe |
I'll explain why later, but the conclusion is that it's very difficult to use ScopeManager in vue-eslint-parser to mark template variables. |
You already get the variables to mark them as used - couldn't you just synthesise and add references to the imports instead? |
vue-eslint-parser parses The ScopeManager only has the scope of |
I don't think it's a good idea as you say. However, I think it might be a good solution for Vue users as a compromise. |
I don't think we should subject all TS users to a hack just for Vue.
FWIW - as mentioned, we already do some "weird" stuff in our scope manager for references to import React from 'react';
// ^^^^^ Variable.references = [ Reference<Identifier, 'React', {line:1, column: 8}> ]
const x = <div />; Relevant code that does this: typescript-eslint/packages/scope-manager/src/referencer/Referencer.ts Lines 122 to 141 in 5ab1d57
typescript-eslint/packages/scope-manager/src/referencer/Referencer.ts Lines 103 to 120 in 5ab1d57
This code has been in place for 17 months without issue (#2498). |
Oh. I didn't understand your first comment. Thank you for explaining in detail. I didn't have the idea to add a reference in the same place. I think it's worth trying.
Thank you for your opinion. If the method 8000 of using ScopeManager doesn't work, I will consider creating an extension rule in eslint-plugin-vue. |
I'll close this here, as you have a tracking issue in your repo. |
Description
Vue.js 3 has a syntax (
<script setup>
) that allows importing stuff in the JavaScript/TypeScript section, and using it in the HTML/template section:Here,
@typescript-eslint/consistent-type-imports
would report theMyComponent
import, as it thinks it's only being used as a type. However, it is actually also used as a value in the template. So applying the autofix breaks the Vue build.Vue + typescript-eslint users are likely to also have the eslint-plugin-vue installed. There, we have rules that mark variables and imports from the
<script setup>
section with ESLint'smarkVariableAsUsed
function when they are used somewhere in the<template>
section.Would it be possible to ignore imports that have been marked with this function in
@typescript-eslint/consistent-type-imports
?For reference, this problem has been reported in the
eslint-plugin-vue
repo first: vuejs/eslint-plugin-vue#1784Fail
Pass
The text was updated successfully, but these errors were encountered: