React Native项目添加ESlint代码检查

装包:

yarn add eslint
yarn add onchange

.eslintrc.js:

module.exports = {
  env: {
    jest: true,
    browser: true,
    commonjs: true,
    es2021: true,
  },
  extends: ['eslint:recommended', 'plugin:react/recommended'],
  overrides: [],
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },

  plugins: ['react'],
  rules: {
    //prop-types来检查类型
    'react/prop-types': 'off',
    'react/react-in-jsx-scope': 'off',
  },
  globals: {
    process: true,
    Buffer: true,
  },

  // 在 .eslintrc.js 中需要指定react版本号:
  settings: {
    react: {
      /**
       * "detect" automatically picks the version you have installed.
       * You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
       * default to latest and warns if missing
       */

      version: '999.999.999', // It will default to "detect" in the future

      // "version": "detect"
      // "version": "16.12.0"
    },
  },
}

.eslintignore:

/src/static

package.json:

  "scripts": {
    "lint": "./node_modules/.bin/eslint src/** --ext .js,.jsx,.ts,.tsx",
    "watch": "onchange -i \"**\" -- npm run lint"
  },

运行:

yarn watch

 

 

参考链接:

https://blog.csdn.net/zlq_CSDN/article/details/105628773

https://blog.csdn.net/tuzi007a/article/details/129867139

https://stackoverflow.com/questions/42640636/react-must-be-in-scope-when-using-jsx-react-react-in-jsx-scope
 

https://blog.csdn.net/weixin_43820866/article/details/116522307

猜你喜欢

转载自blog.csdn.net/xutongbao/article/details/130821224