.eslintrc.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const path = require('path');
  2. module.exports = {
  3. parser: 'babel-eslint',
  4. // JavaScript 语言解析选项
  5. parserOptions: {
  6. // ECMAScript 版本
  7. ecmaVersion: 6,
  8. sourceType: 'module',
  9. // 额外的语言特性:
  10. ecmaFeatures: {
  11. experimentalDecorators: true,
  12. experimentalObjectRestSpread: true,
  13. jsx: true,
  14. },
  15. },
  16. extends: [
  17. 'plugin:import/errors',
  18. 'plugin:import/warnings',
  19. 'plugin:react/recommended',
  20. 'plugin:prettier/recommended',
  21. 'prettier/react',
  22. 'prettier/standard',
  23. ],
  24. plugins: ['babel', 'import', 'flowtype', 'jsx-a11y', 'react', 'redux-saga', 'prettier'],
  25. settings: {
  26. react: {
  27. version: '16.0',
  28. },
  29. 'import/resolver': {
  30. webpack: {
  31. config: path.resolve(__dirname, './config/webpack.config.dev.js'),
  32. },
  33. },
  34. },
  35. globals: {
  36. _: true,
  37. },
  38. // 预定义的全局变量。
  39. env: {
  40. browser: true,
  41. commonjs: true,
  42. es6: true,
  43. node: true,
  44. },
  45. // 以当前目录为根目录,不再向上查找
  46. root: true,
  47. rules: {
  48. // indent: [
  49. // 2,
  50. // 2,
  51. // {
  52. // SwitchCase: 1,
  53. // },
  54. // ],
  55. // 'comma-dangle': [2, 'always-multiline'],
  56. 'babel/new-cap': 0,
  57. 'arrow-body-style': [2, 'as-needed'],
  58. 'max-len': 0,
  59. 'no-plusplus': 0,
  60. 'no-console': 1,
  61. 'no-unused-vars': 'warn',
  62. 'no-script-url': 0,
  63. 'import/first': 0,
  64. 'no-underscore-dangle': 0,
  65. 'global-require': 0,
  66. 'import/imports-first': 0,
  67. 'import/no-dynamic-require': 0,
  68. 'import/extensions': 0,
  69. 'import/no-unresolved': [
  70. 2,
  71. {
  72. commonjs: true,
  73. amd: true,
  74. },
  75. ],
  76. 'import/prefer-default-export': 0,
  77. 'redux-saga/no-yield-in-race': 2,
  78. 'redux-saga/yield-effects': 2,
  79. 'react/require-default-props': 0,
  80. 'react/forbid-prop-types': 0,
  81. 'react/display-name': 0,
  82. 'jsx-a11y/aria-props': 2,
  83. 'jsx-a11y/heading-has-content': 0,
  84. 'jsx-a11y/label-has-for': 2,
  85. 'jsx-a11y/mouse-events-have-key-events': 2,
  86. 'jsx-a11y/role-has-required-aria-props': 2,
  87. 'jsx-a11y/role-supports-aria-props': 2,
  88. 'jsx-a11y/media-has-caption': 0,
  89. 'jsx-a11y/anchor-is-valid': [
  90. 'error',
  91. {
  92. components: ['Link'],
  93. specialLink: ['to'],
  94. aspects: ['noHref', 'preferButton'],
  95. },
  96. ],
  97. // 'react/jsx-first-prop-new-line': [2, 'multiline'],
  98. // 设置jsx允许的文件扩展名
  99. 'react/jsx-filename-extension': [
  100. 1,
  101. {
  102. extensions: ['.js', '.jsx'],
  103. },
  104. ],
  105. 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
  106. 'prettier/prettier': [
  107. 'error',
  108. // prettier 规则配置
  109. {
  110. endOfLine: 'auto', // 换行cr检查
  111. },
  112. ],
  113. },
  114. };