eslint.config.mjs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // @ts-check
  2. import eslint from '@eslint/js';
  3. import tseslint from 'typescript-eslint';
  4. import globals from "globals";
  5. export default tseslint.config(
  6. {
  7. ignores: [
  8. "**/*", // ignore everything...
  9. "!src/**/", "!src/**/*.ts", // ... except our TypeScript source files...
  10. "!test/**/", "!test/**/*.js", // ... and our tests
  11. ],
  12. },
  13. eslint.configs.recommended,
  14. tseslint.configs.recommended,
  15. {
  16. files: ['src/**/*.ts'],
  17. languageOptions: {
  18. parserOptions: {
  19. projectService: true,
  20. tsconfigRootDir: import.meta.dirname,
  21. },
  22. },
  23. extends: [tseslint.configs.recommendedTypeChecked],
  24. rules: {
  25. // Not sure if these actually serve a purpose, but they provide a way to enforce SOME of what
  26. // would be imposed by having "verbatimModuleSyntax": true in our tsconfig.json without
  27. // actually doing that.
  28. "@typescript-eslint/consistent-type-imports": 2,
  29. "@typescript-eslint/consistent-type-exports": 2,
  30. // Things from the recommendedTypeChecked shared config that are disabled simply because they
  31. // caused lots of errors in our existing code when tried. Plausibly useful to turn on if
  32. // possible and somebody fancies doing the work:
  33. "@typescript-eslint/no-unsafe-argument": 0,
  34. "@typescript-eslint/no-unsafe-assignment": 0,
  35. "@typescript-eslint/no-unsafe-call": 0,
  36. "@typescript-eslint/no-unsafe-member-access": 0,
  37. "@typescript-eslint/no-unsafe-return": 0,
  38. }
  39. },
  40. {
  41. languageOptions: {
  42. globals: {
  43. ...globals.browser,
  44. },
  45. },
  46. rules: {
  47. // Possible Errors //
  48. //-----------------//
  49. "comma-dangle": [2, "never"],
  50. "no-console": 1, // Allow for debugging
  51. "no-debugger": 1, // Allow for debugging
  52. "no-extra-parens": [2, "functions"],
  53. "no-extra-semi": 2,
  54. "no-negated-in-lhs": 2,
  55. "no-unreachable": 1, // Optimizer and coverage will handle/highlight this and can be useful for debugging
  56. // Best Practices //
  57. //----------------//
  58. curly: 2,
  59. "default-case": 1,
  60. "dot-notation": [2, {
  61. allowKeywords: false,
  62. }],
  63. "guard-for-in": 1,
  64. "no-alert": 2,
  65. "no-caller": 2,
  66. "no-div-regex": 1,
  67. "no-eval": 2,
  68. "no-extend-native": 2,
  69. "no-extra-bind": 2,
  70. "no-floating-decimal": 2,
  71. "no-implied-eval": 2,
  72. "no-iterator": 2,
  73. "no-labels": 2,
  74. "no-lone-blocks": 2,
  75. "no-multi-spaces": 2,
  76. "no-multi-str": 1,
  77. "no-native-reassign": 2,
  78. "no-new": 2,
  79. "no-new-func": 2,
  80. "no-new-wrappers": 2,
  81. "no-octal-escape": 2,
  82. "no-process-env": 2,
  83. "no-proto": 2,
  84. "no-return-assign": 2,
  85. "no-script-url": 2,
  86. "no-self-compare": 2,
  87. "no-sequences": 2,
  88. "no-throw-literal": 2,
  89. "no-unused-expressions": 2,
  90. "no-warning-comments": 1,
  91. radix: 2,
  92. "wrap-iife": 2,
  93. // Variables //
  94. //-----------//
  95. "no-catch-shadow": 2,
  96. "no-label-var": 2,
  97. "no-undef-init": 2,
  98. // Node.js //
  99. //---------//
  100. // Stylistic //
  101. //-----------//
  102. "brace-style": [2, "1tbs", {
  103. allowSingleLine: true,
  104. }],
  105. camelcase: 2,
  106. "comma-spacing": [2, {
  107. before: false,
  108. after: true,
  109. }],
  110. "comma-style": [2, "last"],
  111. "consistent-this": [1, "self"],
  112. "eol-last": 2,
  113. "func-style": [2, "declaration"],
  114. "key-spacing": [2, {
  115. beforeColon: false,
  116. afterColon: true,
  117. }],
  118. "new-cap": 2,
  119. "new-parens": 2,
  120. "no-array-constructor": 2,
  121. "no-lonely-if": 2,
  122. "no-mixed-spaces-and-tabs": 2,
  123. "no-nested-ternary": 1,
  124. "no-new-object": 2,
  125. "no-spaced-func": 2,
  126. "no-trailing-spaces": 2,
  127. "quote-props": [2, "as-needed", {
  128. keywords: true,
  129. }],
  130. quotes: [2, "single", "avoid-escape"],
  131. semi: 2,
  132. "semi-spacing": [2, {
  133. before: false,
  134. after: true,
  135. }],
  136. "space-before-blocks": [2, "always"],
  137. "space-before-function-paren": [2, {
  138. anonymous: "never",
  139. named: "never",
  140. }],
  141. "space-in-parens": [2, "never"],
  142. "space-infix-ops": 2,
  143. "space-unary-ops": 2,
  144. "spaced-comment": [2, "always"],
  145. "wrap-regex": 1,
  146. "no-var": 2,
  147. // Typescript //
  148. //------------//
  149. "@typescript-eslint/no-explicit-any": 0, // Very strict rule, incompatible with our code
  150. // We use these intentionally - e.g.
  151. // export interface DiffCssOptions extends CommonDiffOptions {}
  152. // for the options argument to diffCss which currently takes no options beyond the ones
  153. // common to all diffFoo functions. Doing this allows consistency (one options interface per
  154. // diffFoo function) and future-proofs against the API having to change in future if we add a
  155. // non-common option to one of these functions.
  156. "@typescript-eslint/no-empty-object-type": [2, {allowInterfaces: 'with-single-extends'}],
  157. },
  158. },
  159. {
  160. files: ['test/**/*.js'],
  161. languageOptions: {
  162. globals: {
  163. ...globals.node,
  164. ...globals.mocha,
  165. },
  166. },
  167. rules: {
  168. "no-unused-expressions": 0, // Needs disabling to support Chai `.to.be.undefined` etc syntax
  169. "@typescript-eslint/no-unused-expressions": 0, // (as above)
  170. },
  171. }
  172. );