react配置eslint

安装第三方依赖包

npm install eslint --save-dev
npm install eslint-config-airbnb --save-dev
npm install eslint-plugin-import --save-dev
npm install eslint-plugin-jsx-a11y --save-dev
npm install eslint-plugin-react --save-dev
npm install babel-eslint --save-dev
复制代码

新建.eslintrc.js

// 有需要再补充
module.exports = {
  "parser": "babel-eslint",
  "extends": "airbnb",
  "rules": {
    "jsx-a11y/click-events-have-key-events": [0],
    "generator-star-spacing": [0],
    "consistent-return": [0],
    "react/forbid-prop-types": [0],
    "react/jsx-filename-extension": [1, { "extensions": [".js"] }],
    "global-require": [0],
    "import/prefer-default-export": [0],
    "react/jsx-no-bind": [0],
    "react/prop-types": [0],
    "react/prefer-stateless-function": [0],
    "no-else-return": [0],
    "no-restricted-syntax": [0],
    "import/no-extraneous-dependencies": [0],
    "no-use-before-define": [0],
    "jsx-a11y/no-static-element-interactions": [0],
    "no-nested-ternary": [0],
    "arrow-body-style": [0],
    "import/extensions": [0],
    "no-bitwise": [0],
    "no-cond-assign": [0],
    "linebreak-style": [0],
    "import/no-unresolved": [0],
    "require-yield": [1],
    "prefer-template": [0],
    "no-undef": [0],
    "no-param-reassign": [0],
    "no-useless-escape": [0],
    "no-plusplus": [0],
    "no-mixed-operators": [0],
    "object-shorthand": [0],
    "no-console": [0],
    "no-loop-func": [0],
    "class-methods-use-this": [0],
    "radix": [0],
    "no-trailing-spaces": [0],
    "comma-dangle": [0],
    "no-underscore-dangle": [0],
    "react/require-default-props": [0],
    "no-unused-expressions": [0],
    "react/sort-comp": [0],
    "max-lines": [2, 500],
    "max-len": [2, 125],
    "react/jsx-boolean-value": [0],
    "react/react-in-jsx-scope": [0],
    "operator-assignment": [0],
    "no-fallthrough": [0],
    "react/no-array-index-key": [0],
    "eqeqeq": [0],
    "react/no-multi-comp": [0],
    "react/no-unused-prop-types": [0],
    "prefer-const": [0]
  },
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    }
  }
}

复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在React项目中关闭ESLint,你可以按照以下步骤进行操作: 1. 在根目录下创建一个`.eslintrc.json`文件,并设置自定义的ESLint配置。你可以在该文件中添加以下内容: ```json { "extends": ["react-app"], "rules": { "eqeqeq": "off" } } ``` 2. 在`package.json`文件中修改`eslintConfig`字段的值。将其修改为以下内容: ```json "eslintConfig": { "extends": "react-app", "rules": { "no-undef": "off", "no-restricted-globals": "off", "no-unused-vars": "off" } } ``` 3. 如果你的项目使用了Webpack,你还需要修改`webpack.config.js`文件。找到包含ESLint配置的部分,一般是一个加载器,并将其配置修改为以下内容: ```javascript { test: /\.(js|mjs|jsx|ts|tsx)$/, enforce: 'pre', use: [ { options: { cache: true, formatter: require.resolve('react-dev-utils/eslintFormatter'), eslintPath: require.resolve('eslint'), resolvePluginsRelativeTo: __dirname, ignore: isExtendingEslintConfig, baseConfig: isExtendingEslintConfig ? undefined : { extends: [require.resolve('eslint-config-react-app')], }, useEslintrc: isExtendingEslintConfig, }, loader: require.resolve('eslint-loader'), }, ], include: paths.appSrc, } ``` 4. 如果你只想在某些文件中关闭ESLint检查,你可以在该文件的最顶部添加注释`/*eslint-disable*/`。这将会关闭该文件中的所有ESLint检查。 通过以上步骤,你可以在React项目中关闭ESLint检查。请注意,关闭ESLint检查可能会导致代码质量下降,因此建议仅在必要时使用此功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [React开发eslint配置](https://blog.csdn.net/github_37759996/article/details/115765712)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [react怎么关闭eslint 或避免出现检测 整理](https://blog.csdn.net/v5666666/article/details/121378393)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值