首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于未使用的变量或未导入的组件,ESLint不会发出警告(NextJs TypeScript)

对于未使用的变量或未导入的组件,ESLint不会发出警告(NextJs TypeScript)
EN

Stack Overflow用户
提问于 2021-04-26 21:21:24
回答 1查看 73关注 0票数 1

ESLint不会在未使用的变量上警告我,也不会在未导入的组件上发出警告。我尝试了所有的帖子,但我没有任何解决方案:/

免责声明:我知道我没有为example....Why导入导航栏ESLint没有警告我吗?谢谢!

.eslintrc.json

代码语言:javascript
复制
{
    "env": {
        "browser": true,
        "es2020": true,
        "node": true,
        "jest": true
    },
    "extends": [
        "standard",
        "eslint:recommended",
        "plugin:react/recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/eslint-recommended",
        "prettier/@typescript-eslint",
        "plugin:react-hooks/recommended",
        "prettier/standard",
        "prettier/react"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": ["react", "@typescript-eslint", "prettier", "react-hooks"],
    "rules": {
        "no-unused-vars": "error",
        "prettier/prettier": "error",
        "space-before-function-paren": "off",
        "react/prop-types": "off",
        "react-hooks/rules-of-hooks": "error",
        "react-hooks/exhaustive-deps": "warn",
        "@typescript-eslint/no-empty-function": "off",
        "react/react-in-jsx-scope": "off",
        "@typescript-eslint/no-explicit-any": "off",
        "@typescript-eslint/no-var-requires": "off",
        "@typescript-eslint/explicit-module-boundary-types": "off",
        "@typescript-eslint/no-unused-vars": ["off"]
    }
}

还有我的index.tsx

代码语言:javascript
复制
import React from 'react'
import Head from 'next/head'

const data = [
    { id: 1, name: 'artfol', url: 'http://google.com', alt: 'artfol' },
    { id: 2, name: 'FAQ', url: 'http://google.com', alt: 'FAQ' }
]

const Home: React.FC = () => {
    return (
        <div>
            <Head>
                <title>Create Next App</title>
                <link rel="icon" href="/favicon.ico" />
            </Head>
            <main>
                <Navbar />
            </main>
        </div>
    )
}

export default Home

EN

回答 1

Stack Overflow用户

发布于 2021-04-26 23:09:36

我找到了错误所在。Prettier合并了每个扩展到"prettier“中,所以我的代码看起来像这样

代码语言:javascript
复制
{
  "env": {
    "browser": true,
    "es2021": true,
    "node": true,
    "jest": true
  },
  "extends": [
    "plugin:react/recommended",
    "standard",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended"
  ],
  "settings": {
    "react": { "version": "detect" }
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint", "prettier"],
  "rules": {
    "prettier/prettier": "error",
    "space-before-function-paren": "off",
    "react/prop-types": "off"
  }
}

同样eslint给我一个错误,由于反应未使用的var,所以我注释如下

代码语言:javascript
复制
// eslint-disable-next-line no-use-before-define
import React from 'react'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67267467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档