.eslintrc.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.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. 'babel/new-cap': 0,
  49. 'arrow-body-style': [2, 'as-needed'],
  50. 'max-len': 0,
  51. 'no-plusplus': 0,
  52. 'no-console': 1,
  53. 'no-unused-vars': 'warn',
  54. 'no-script-url': 0,
  55. 'import/first': 0,
  56. 'no-underscore-dangle': 0,
  57. 'global-require': 0,
  58. 'prettier/prettier': 'error',
  59. 'import/imports-first': 0,
  60. 'import/no-dynamic-require': 0,
  61. 'import/extensions': 0,
  62. 'import/no-unresolved': [
  63. 0,
  64. {
  65. commonjs: true,
  66. amd: true,
  67. },
  68. ],
  69. 'import/named': 0,
  70. 'import/prefer-default-export': 0,
  71. 'redux-saga/no-yield-in-race': 2,
  72. 'redux-saga/yield-effects': 2,
  73. 'react/require-default-props': 0,
  74. 'react/forbid-prop-types': 0,
  75. 'jsx-a11y/aria-props': 2,
  76. 'jsx-a11y/heading-has-content': 0,
  77. 'jsx-a11y/label-has-for': 2,
  78. 'jsx-a11y/mouse-events-have-key-events': 2,
  79. 'jsx-a11y/role-has-required-aria-props': 2,
  80. 'jsx-a11y/role-supports-aria-props': 2,
  81. 'jsx-a11y/media-has-caption': 0,
  82. 'jsx-a11y/anchor-is-valid': [
  83. 0,
  84. {
  85. components: ['Link'],
  86. specialLink: ['to'],
  87. aspects: ['noHref', 'preferButton'],
  88. },
  89. ],
  90. // 'react/jsx-first-prop-new-line': [2, 'multiline'],
  91. // 设置jsx允许的文件扩展名
  92. 'react/jsx-filename-extension': [
  93. 1,
  94. {
  95. extensions: ['.js', '.jsx'],
  96. },
  97. ],
  98. 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
  99. 'prettier/prettier': [
  100. 'error',
  101. {
  102. endOfLine: 'auto',
  103. },
  104. ],
  105. },
  106. };