sweepline / eslint-plugin-unused-imports

Package to separate no-unused-vars and no-unused-imports for eslint as well as providing an autofixer for the latter.
MIT License
504 stars 21 forks source link

React is marked wrongly as a unused import. #63

Closed andiShan11 closed 9 months ago

andiShan11 commented 9 months ago

if the .eslintrc.js is like below. "rules": { 'react/jsx-no-undef': [2, { allowGlobals: true }], 'react/jsx-uses-vars': "error", 'react/jsx-uses-react': "error", 'no-unused-vars': [ 2, { vars: 'local', args: 'after-used', varsIgnorePattern: 'React|createElement', }, ], }

then import React from 'react'; work well.

however, if the .eslintrc.js is like below. "rules": { 'react/jsx-no-undef': [2, { allowGlobals: true }], 'react/jsx-uses-vars': "error", 'react/jsx-uses-react': "error", "no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off", "unused-imports/no-unused-imports": "error", "unused-imports/no-unused-vars": [ "warn", { vars: "local", varsIgnorePattern: 'React|createElement', args: "after-used", argsIgnorePattern: "^_" } ] } then import React from 'react'; React will be marked wrongly as a unused import.

sweepline commented 9 months ago

Yes, this package splits up the no-unused-vars rule into no-unused-vars and no-unused-imports. You have put the varsIgnorePattern into the no-unused-vars rule and not the no-unused-imports rule.

Try "unused-imports/no-unused-imports": [ "error", {vars: "local", varsIgnorePattern: "React|createElement"}]