版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

187 lines
5.0 KiB

  1. const WARN = 'warn';
  2. const ERROR = 'error';
  3. const OFF = 'off';
  4. const COMMON_CONFIG = {
  5. plugins: ['turbo', 'jsdoc', 'filenames', 'jest', 'import', 'prettier'],
  6. extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
  7. rules: {
  8. 'prettier/prettier': WARN,
  9. 'no-underscore-dangle': OFF,
  10. 'no-debugger': WARN,
  11. 'space-infix-ops': ERROR,
  12. 'no-console': WARN,
  13. 'wrap-iife': OFF,
  14. 'no-self-assign': ERROR,
  15. 'no-self-compare': ERROR,
  16. 'no-loop-func': OFF,
  17. 'array-callback-return': ERROR,
  18. curly: ERROR,
  19. 'no-fallthrough': OFF,
  20. 'dot-notation': OFF,
  21. 'prefer-const': WARN,
  22. 'no-empty-function': OFF,
  23. 'no-with': ERROR,
  24. 'one-var': [ERROR, 'never'],
  25. camelcase: [WARN, { properties: 'always', ignoreImports: true }],
  26. 'spaced-comment': [WARN, 'always'],
  27. 'capitalized-comments': [WARN, 'always', { ignorePattern: 'prettier' }],
  28. 'no-useless-rename': WARN,
  29. 'jsdoc/check-alignment': WARN,
  30. 'jsdoc/check-examples': OFF,
  31. 'jsdoc/check-indentation': WARN,
  32. 'jsdoc/check-syntax': WARN,
  33. 'jsdoc/check-tag-names': WARN,
  34. 'jsdoc/check-types': WARN,
  35. 'jsdoc/implements-on-classes': WARN,
  36. 'jsdoc/match-description': OFF,
  37. 'jsdoc/newline-after-description': WARN,
  38. 'jsdoc/no-types': OFF,
  39. 'jsdoc/no-undefined-types': OFF,
  40. 'jsdoc/require-description': OFF,
  41. 'jsdoc/require-description-complete-sentence': OFF,
  42. 'jsdoc/require-example': OFF,
  43. 'jsdoc/require-hyphen-before-param-description': [WARN, 'never'],
  44. 'jsdoc/require-param': WARN,
  45. 'jsdoc/require-param-name': WARN,
  46. 'jsdoc/require-returns-check': WARN,
  47. 'jsdoc/require-returns-description': WARN,
  48. 'jsdoc/valid-types': WARN,
  49. 'filenames/match-exported': WARN,
  50. 'jest/consistent-test-it': [WARN, { fn: 'it', withinDescribe: 'it' }],
  51. 'jest/valid-title': [
  52. WARN,
  53. {
  54. mustMatch: {
  55. // Describe: '^[A-Z][a-zA-Z0-9]+$|^[a-z][a-zA-Z0-9]+\\(\\)$',
  56. it: '^[A-Z](.+).$'
  57. }
  58. }
  59. ],
  60. 'jest/prefer-hooks-on-top': WARN,
  61. 'jest/no-duplicate-hooks': WARN,
  62. 'no-useless-constructor': WARN,
  63. 'jsdoc/require-jsdoc': [
  64. WARN,
  65. {
  66. require: {
  67. ArrowFunctionExpression: false,
  68. FunctionDeclaration: false,
  69. FunctionExpression: false,
  70. ClassDeclaration: true,
  71. MethodDefinition: true
  72. }
  73. }
  74. ],
  75. 'import/no-extraneous-dependencies': WARN
  76. }
  77. };
  78. const TS_PARSER_FIELDS = {
  79. parser: '@typescript-eslint/parser',
  80. parserOptions: {
  81. ecmaFeatures: {
  82. jsx: true
  83. },
  84. ecmaVersion: 2020,
  85. sourceType: 'module'
  86. }
  87. };
  88. module.exports = {
  89. env: {
  90. es6: true,
  91. browser: true,
  92. node: true,
  93. jest: true
  94. },
  95. overrides: [
  96. {
  97. files: ['*.js', '*.jsx', '*.mjs'],
  98. ...TS_PARSER_FIELDS,
  99. plugins: COMMON_CONFIG.plugins,
  100. extends: COMMON_CONFIG.extends,
  101. rules: {
  102. ...COMMON_CONFIG.rules,
  103. 'no-undef': ERROR,
  104. 'jsdoc/check-param-names': WARN,
  105. 'jsdoc/require-param-type': WARN,
  106. 'jsdoc/require-returns': WARN,
  107. 'jsdoc/require-param-description': WARN,
  108. 'jsdoc/require-returns-type': WARN,
  109. 'consistent-return': WARN
  110. }
  111. },
  112. {
  113. files: ['*.json'],
  114. plugins: ['json'],
  115. extends: ['eslint:recommended', 'plugin:json/recommended', 'plugin:jest/recommended']
  116. },
  117. {
  118. files: ['*.ts', '*.tsx'],
  119. plugins: [...COMMON_CONFIG.plugins, '@typescript-eslint'],
  120. ...TS_PARSER_FIELDS,
  121. extends: [...COMMON_CONFIG.extends, 'plugin:@typescript-eslint/recommended'],
  122. rules: {
  123. ...COMMON_CONFIG.rules,
  124. '@typescript-eslint/explicit-member-accessibility': [
  125. ERROR,
  126. { overrides: { constructors: 'no-public' } }
  127. ],
  128. '@typescript-eslint/no-unused-vars': OFF, // TSC is already doing this
  129. '@typescript-eslint/ban-types': OFF, // TSC is already doing this
  130. 'no-undef': OFF, // TSC is already doing this
  131. '@typescript-eslint/no-var-requires': OFF,
  132. '@typescript-eslint/explicit-module-boundary-types': OFF, // TSC is already doing this
  133. '@typescript-eslint/consistent-type-assertions': [
  134. WARN,
  135. { assertionStyle: 'angle-bracket' }
  136. ],
  137. '@typescript-eslint/no-explicit-any': ERROR,
  138. '@typescript-eslint/no-empty-function': OFF,
  139. '@typescript-eslint/no-use-before-define': OFF,
  140. '@typescript-eslint/no-this-alias': OFF,
  141. '@typescript-eslint/explicit-function-return-type': [ERROR, { allowExpressions: true }],
  142. '@typescript-eslint/member-ordering': [
  143. WARN,
  144. {
  145. default: ['signature', 'field', 'constructor', ['get', 'set'], 'method']
  146. }
  147. ],
  148. '@typescript-eslint/ban-ts-comment': OFF,
  149. 'jsdoc/no-types': WARN,
  150. 'import/named': WARN,
  151. 'import/no-named-as-default': WARN,
  152. 'import/no-extraneous-dependencies': WARN,
  153. '@typescript-eslint/naming-convention': [
  154. WARN,
  155. {
  156. selector: 'interface',
  157. format: ['PascalCase'],
  158. prefix: ['I']
  159. },
  160. {
  161. selector: 'enum',
  162. format: ['PascalCase'],
  163. suffix: ['Enum']
  164. },
  165. {
  166. selector: 'typeParameter',
  167. format: ['PascalCase']
  168. },
  169. {
  170. selector: 'memberLike',
  171. modifiers: ['private'],
  172. leadingUnderscore: 'allow',
  173. format: ['camelCase']
  174. },
  175. {
  176. selector: 'class',
  177. format: ['PascalCase']
  178. }
  179. ]
  180. }
  181. }
  182. ]
  183. };