.eslintrc.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // eslint does not properly load plugins loaded by presets
  2. // this fixes that
  3. require('@rushstack/eslint-patch/modern-module-resolution');
  4. module.exports = {
  5. root: true,
  6. extends: [
  7. '@ephys/eslint-config-typescript',
  8. '@ephys/eslint-config-typescript/node',
  9. '@ephys/eslint-config-typescript/commonjs',
  10. ],
  11. plugins: ['mocha', 'jsdoc'],
  12. rules: {
  13. 'jsdoc/check-param-names': 'error',
  14. 'jsdoc/check-tag-names': 'error',
  15. 'jsdoc/check-types': 'off',
  16. 'jsdoc/tag-lines': ['error', 'any', { startLines: 1 }],
  17. 'jsdoc/no-undefined-types': 'off',
  18. 'jsdoc/require-description-complete-sentence': 'off',
  19. 'jsdoc/require-example': 'off',
  20. 'jsdoc/require-hyphen-before-param-description': 'off',
  21. 'jsdoc/require-param': 'error',
  22. 'jsdoc/require-param-description': 'off',
  23. 'jsdoc/require-param-name': 'error',
  24. 'jsdoc/require-param-type': 'off',
  25. 'jsdoc/require-returns-description': 'off',
  26. 'jsdoc/require-returns-type': 'off',
  27. 'jsdoc/valid-types': 'error',
  28. 'jsdoc/no-types': 'error',
  29. // TODO: enable in follow-up PR. Requires the utils package.
  30. 'no-restricted-syntax': 'off',
  31. 'no-restricted-imports': 'off',
  32. '@typescript-eslint/ban-types': 'off',
  33. // TODO: enable in follow-up PR. Requires enabling TSC's noUncheckedIndexedAccess
  34. '@typescript-eslint/no-unnecessary-condition': 'off',
  35. // TODO: enable in follow-up PR. Requires manual code changes.
  36. '@typescript-eslint/naming-convention': 'off',
  37. '@typescript-eslint/unbound-method': 'off',
  38. '@typescript-eslint/member-ordering': 'off',
  39. 'unicorn/no-object-as-default-parameter': 'off',
  40. '@typescript-eslint/prefer-optional-chain': 'off',
  41. 'logical-assignment-operators': 'off',
  42. },
  43. overrides: [
  44. {
  45. files: ['**/*.{js,mjs,cjs}'],
  46. rules: {
  47. 'jsdoc/no-types': 'off',
  48. 'jsdoc/require-param-type': 'error',
  49. 'jsdoc/check-types': 'error',
  50. 'jsdoc/require-returns-type': 'error',
  51. },
  52. },
  53. {
  54. files: ['**/*.js'],
  55. rules: {
  56. // These rules have been disabled in .js files to ease adoption.
  57. // They'll be fixed during the TS migration.
  58. // Remove these once most files have been migrated to TS.
  59. // This will catch a lot of bugs with early-returns
  60. 'consistent-return': 'off',
  61. // code smells that should be resolved
  62. 'no-restricted-syntax': 'off',
  63. 'no-await-in-loop': 'off',
  64. 'default-case': 'off',
  65. 'no-loop-func': 'off',
  66. 'no-shadow': 'off',
  67. 'default-param-last': 'off',
  68. 'no-fallthrough': 'off',
  69. 'prefer-rest-params': 'off',
  70. 'no-loss-of-precision': 'off',
  71. // optimisation
  72. 'unicorn/consistent-function-scoping': 'off',
  73. // array.reduce is difficult to reason about and can almost always
  74. // be replaced by a more explicit method
  75. 'unicorn/no-array-reduce': 'off',
  76. 'unicorn/no-array-for-each': 'off',
  77. 'unicorn/prefer-spread': 'off',
  78. // makes code clearer
  79. 'unicorn/prefer-default-parameters': 'off',
  80. 'max-statements-per-line': 'off',
  81. // makes debug easier
  82. 'func-names': 'off',
  83. // multi-assigns can be difficult to understand
  84. // https://eslint.org/docs/rules/no-multi-assign
  85. 'no-multi-assign': 'off',
  86. // GitHub's display length is 125 chars.
  87. // This enforces that length.
  88. 'max-len': 'off',
  89. 'max-depth': 'off',
  90. // Reduce diff noise.
  91. 'import/order': 'off',
  92. // consistency
  93. 'unicorn/filename-case': 'off',
  94. // Passing a function reference to an array callback can accidentally introduce bug
  95. // due to array methods passing more than one parameter.
  96. 'unicorn/no-array-callback-reference': 'off',
  97. },
  98. },
  99. {
  100. // most tests are written in old JS style
  101. // let's disable the most problematic rules for now.
  102. // they're only disabled for .js files.
  103. // .ts files will need to migrate.
  104. files: ['packages/*/test/**/*.js'],
  105. rules: {
  106. 'func-names': 'off',
  107. 'import/order': 'off',
  108. 'consistent-this': 'off',
  109. 'no-invalid-this': 'off',
  110. 'unicorn/no-this-assignment': 'off',
  111. 'no-unused-expressions': 'off',
  112. camelcase: 'off',
  113. 'no-console': 'off',
  114. 'no-prototype-builtins': 'off',
  115. 'no-multi-spaces': 'off',
  116. 'unicorn/error-message': 'off',
  117. },
  118. },
  119. {
  120. // Disable slow rules that are not important in tests (perf)
  121. files: ['packages/*/test/**/*', '*.test.{ts,js}'],
  122. rules: {
  123. 'import/no-extraneous-dependencies': 'off',
  124. // no need to check jsdoc in tests & docs
  125. 'jsdoc/check-types': 'off',
  126. 'jsdoc/valid-types': 'off',
  127. 'jsdoc/tag-lines': 'off',
  128. 'jsdoc/check-tag-names': 'off',
  129. // Enable test-specific rules (perf)
  130. 'mocha/no-exclusive-tests': 'error',
  131. 'mocha/no-skipped-tests': 'warn',
  132. // it's fine if we're not very efficient in tests.
  133. 'no-inner-declarations': 'off',
  134. 'unicorn/no-unsafe-regex': 'off',
  135. // because of Chai
  136. '@typescript-eslint/no-unused-expressions': 'off',
  137. },
  138. env: {
  139. mocha: true,
  140. },
  141. },
  142. {
  143. files: ['packages/*/test/types/**/*'],
  144. rules: {
  145. // This code is never executed, it's typing only, so these rules make no sense:
  146. '@typescript-eslint/no-unused-vars': 'off',
  147. '@typescript-eslint/no-floating-promises': 'off',
  148. 'no-console': 'off',
  149. },
  150. },
  151. {
  152. files: ['**/tsconfig.json'],
  153. rules: {
  154. 'json/*': ['error', { allowComments: true }],
  155. },
  156. },
  157. {
  158. files: ['sscce.ts'],
  159. rules: {
  160. 'no-console': 'off',
  161. },
  162. },
  163. ],
  164. settings: {
  165. jsdoc: {
  166. tagNamePreference: {
  167. augments: 'extends',
  168. },
  169. structuredTags: {
  170. typeParam: {
  171. type: false,
  172. required: ['name'],
  173. },
  174. category: {
  175. type: false,
  176. required: ['name'],
  177. },
  178. internal: {
  179. type: false,
  180. },
  181. hidden: {
  182. type: false,
  183. },
  184. },
  185. },
  186. },
  187. parserOptions: {
  188. ecmaVersion: 2020,
  189. sourceType: 'module',
  190. },
  191. ignorePatterns: [
  192. 'packages/*/lib/**/*',
  193. 'packages/*/types/**/*',
  194. 'packages/**/skeletons/**/*',
  195. '.typedoc-build',
  196. 'packages/cli/migrations/**/*',
  197. 'packages/cli/seeds/**/*',
  198. ],
  199. env: {
  200. node: true,
  201. mocha: true,
  202. es6: true,
  203. es2020: true,
  204. },
  205. };