0
点赞
收藏
分享

微信扫一扫

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"
    },
  },
}

React Native项目添加ESlint代码检查_ide

.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

React Native项目添加ESlint代码检查_ide_02

 

React Native项目添加ESlint代码检查_版本号_03

 

React Native项目添加ESlint代码检查_json_04

 

参考链接:



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




举报

相关推荐

0 条评论