eslint.config.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. 'use strict';
  2. const globals = require('globals');
  3. const SHIMS = 'tools/shim/*.js';
  4. const SRC_GLOBALS = {
  5. ...globals.es2024,
  6. chrome: false,
  7. browser: false,
  8. global: false,
  9. __: false,
  10. };
  11. let v;
  12. module.exports = [
  13. //#region Global exclusions
  14. {
  15. ignores: [
  16. 'dist/',
  17. 'src/vendor/',
  18. 'src/vendor-overwrites/',
  19. ],
  20. },
  21. //#endregion
  22. //#region Global rules
  23. {
  24. rules: {
  25. 'accessor-pairs': [2],
  26. 'array-bracket-spacing': [2, 'never'],
  27. 'array-callback-return': [0],
  28. 'arrow-body-style': [2, 'as-needed'],
  29. 'arrow-parens': [2, 'as-needed'],
  30. 'arrow-spacing': [2, {before: true, after: true}],
  31. 'block-scoped-var': [2],
  32. 'brace-style': [2, '1tbs', {allowSingleLine: true}],
  33. 'camelcase': [2, {properties: 'never', ignoreGlobals: true, allow: ['^k_']}],
  34. 'class-methods-use-this': [2],
  35. 'comma-dangle': [2, {
  36. arrays: 'always-multiline',
  37. objects: 'always-multiline',
  38. exports: 'always-multiline',
  39. imports: 'always-multiline',
  40. functions: 'only-multiline',
  41. }],
  42. 'comma-spacing': [2, {before: false, after: true}],
  43. 'comma-style': [2, 'last'],
  44. 'complexity': [0],
  45. 'computed-property-spacing': [2, 'never'],
  46. 'consistent-return': [0],
  47. 'constructor-super': [2],
  48. 'curly': [0, 'multi-or-nest', 'consistent'],
  49. 'default-case': [0],
  50. 'dot-location': [2, 'property'],
  51. 'dot-notation': [0],
  52. 'eol-last': [2],
  53. 'eqeqeq': [1, 'smart'],
  54. 'func-call-spacing': [2, 'never'],
  55. 'func-name-matching': [0],
  56. 'func-names': [0],
  57. 'generator-star-spacing': [2, 'before'],
  58. 'global-require': [0],
  59. 'guard-for-in': [0],
  60. 'handle-callback-err': [2, '^(err|error)$'],
  61. 'id-blacklist': [0],
  62. 'id-length': [0],
  63. 'id-match': [0],
  64. 'indent': [2, 2, {
  65. SwitchCase: 1,
  66. ignoreComments: true,
  67. ignoredNodes: [
  68. 'TemplateLiteral > *',
  69. 'ConditionalExpression',
  70. 'ForStatement',
  71. ],
  72. }],
  73. 'jsx-quotes': [0],
  74. 'key-spacing': [0],
  75. 'keyword-spacing': [2],
  76. 'lines-around-comment': [0],
  77. 'lines-around-directive': [0],
  78. 'max-len': [2, {
  79. code: 100,
  80. ignoreComments: true,
  81. ignoreRegExpLiterals: true,
  82. }],
  83. 'max-lines': [0],
  84. 'max-nested-callbacks': [0],
  85. 'max-params': [0],
  86. 'max-statements-per-line': [0],
  87. 'max-statements': [0],
  88. 'multiline-ternary': [0],
  89. 'new-cap': [0],
  90. 'new-parens': [2],
  91. 'newline-before-return': [0],
  92. 'newline-per-chained-call': [0],
  93. 'no-alert': [0],
  94. 'no-array-constructor': [0],
  95. 'no-bitwise': [0],
  96. 'no-caller': [2],
  97. 'no-case-declarations': [2],
  98. 'no-class-assign': [2],
  99. 'no-cond-assign': [2, 'except-parens'],
  100. 'no-confusing-arrow': [0, {allowParens: true}],
  101. 'no-const-assign': [2],
  102. 'no-constant-condition': [0],
  103. 'no-continue': [0],
  104. 'no-control-regex': [0],
  105. 'no-debugger': [2],
  106. 'no-delete-var': [2],
  107. 'no-div-regex': [0],
  108. 'no-dupe-args': [2],
  109. 'no-dupe-class-members': [2],
  110. 'no-dupe-keys': [2],
  111. 'no-duplicate-case': [2],
  112. 'no-duplicate-imports': [2],
  113. 'no-else-return': [0],
  114. 'no-empty-character-class': [2],
  115. 'no-empty-function': [0],
  116. 'no-empty-pattern': [2],
  117. 'no-empty': [2, {allowEmptyCatch: true}],
  118. 'no-eq-null': [0],
  119. 'no-eval': [2],
  120. 'no-ex-assign': [0],
  121. 'no-extend-native': [2],
  122. 'no-extra-bind': [2],
  123. 'no-extra-boolean-cast': [2],
  124. 'no-extra-label': [0],
  125. 'no-extra-parens': [0],
  126. 'no-extra-semi': [2],
  127. 'no-fallthrough': [2, {commentPattern: 'fallthrough.*'}],
  128. 'no-floating-decimal': [0],
  129. 'no-func-assign': [2],
  130. 'no-global-assign': [2],
  131. 'no-implicit-coercion': [2, {allow: ['!!', '+']}],
  132. 'no-implicit-globals': [0],
  133. 'no-implied-eval': [2],
  134. 'no-inline-comments': [0],
  135. 'no-inner-declarations': [2],
  136. 'no-invalid-regexp': [2],
  137. 'no-invalid-this': [0],
  138. 'no-irregular-whitespace': [2],
  139. 'no-iterator': [2],
  140. 'no-label-var': [2],
  141. 'no-labels': [2, {allowLoop: true}],
  142. 'no-lone-blocks': [2],
  143. 'no-lonely-if': [0],
  144. 'no-loop-func': [0],
  145. 'no-magic-numbers': [0],
  146. 'no-mixed-operators': [0],
  147. 'no-mixed-requires': [2, true],
  148. 'no-mixed-spaces-and-tabs': [2],
  149. 'no-multi-spaces': [2, {ignoreEOLComments: true}],
  150. 'no-multi-str': [2],
  151. 'no-multiple-empty-lines': [2, {
  152. max: 2,
  153. maxEOF: 0,
  154. maxBOF: 0,
  155. }],
  156. 'no-native-reassign': [2],
  157. 'no-negated-condition': [0],
  158. 'no-negated-in-lhs': [2],
  159. 'no-nested-ternary': [0],
  160. 'no-new-func': [2],
  161. 'no-new-object': [2],
  162. 'no-new-require': [2],
  163. 'no-new-symbol': [2],
  164. 'no-new-wrappers': [2],
  165. 'no-new': [0],
  166. 'no-obj-calls': [2],
  167. 'no-octal-escape': [2],
  168. 'no-octal': [2],
  169. 'no-path-concat': [0],
  170. 'no-process-exit': [0],
  171. 'no-proto': [2],
  172. 'no-redeclare': [2],
  173. 'no-regex-spaces': [2],
  174. 'no-restricted-globals': [2, 'name', 'event'],
  175. 'no-restricted-imports': [0],
  176. 'no-restricted-modules': [2, 'domain', 'freelist', 'smalloc', 'sys'],
  177. 'no-restricted-syntax': [2, 'WithStatement', {
  178. selector: 'MemberExpression > Identifier.property[name="isIntersecting"]',
  179. message: 'Requires Chrome 58+. Please use intersectionRatio instead.',
  180. }],
  181. 'no-return-assign': [2, 'except-parens'],
  182. 'no-return-await': [2],
  183. 'no-script-url': [2],
  184. 'no-self-assign': [2, {props: true}],
  185. 'no-self-compare': [2],
  186. 'no-sequences': [2, {allowInParentheses: true}],
  187. 'no-shadow-restricted-names': [2],
  188. 'no-shadow': [2, {hoist: 'all'}],
  189. 'no-spaced-func': [2],
  190. 'no-sparse-arrays': [2],
  191. 'no-tabs': [2],
  192. 'no-template-curly-in-string': [2],
  193. 'no-this-before-super': [2],
  194. 'no-throw-literal': [0],
  195. 'no-trailing-spaces': [2],
  196. 'no-undef-init': [2],
  197. 'no-undef': [2],
  198. 'no-underscore-dangle': [0],
  199. 'no-unexpected-multiline': [2],
  200. 'no-unmodified-loop-condition': [0],
  201. 'no-unneeded-ternary': [2],
  202. 'no-unreachable': [2],
  203. 'no-unsafe-finally': [2],
  204. 'no-unsafe-negation': [2],
  205. 'no-unused-expressions': [2],
  206. 'no-unused-labels': [0],
  207. 'no-unused-vars': [2, {
  208. args: 'after-used',
  209. argsIgnorePattern: '^_',
  210. }],
  211. 'no-use-before-define': [2, {functions: false, variables: false}],
  212. 'no-useless-call': [2],
  213. 'no-useless-computed-key': [2],
  214. 'no-useless-concat': [2],
  215. 'no-useless-constructor': [2],
  216. 'no-useless-escape': [2],
  217. 'no-var': [1],
  218. 'no-warning-comments': [0],
  219. 'no-whitespace-before-property': [2],
  220. 'no-with': [2],
  221. 'object-curly-newline': [0],
  222. 'object-curly-spacing': [2, 'never'],
  223. 'object-shorthand': [0],
  224. 'one-var-declaration-per-line': [1],
  225. 'one-var': [2, {initialized: 'never'}],
  226. 'operator-assignment': [2, 'always'],
  227. 'operator-linebreak': [2, 'after', {
  228. overrides: {
  229. '?': 'ignore',
  230. ':': 'ignore',
  231. '&&': 'ignore',
  232. '||': 'ignore',
  233. },
  234. }],
  235. 'padded-blocks': [0],
  236. 'prefer-numeric-literals': [2],
  237. 'prefer-rest-params': [0],
  238. 'prefer-const': [1, {
  239. destructuring: 'all',
  240. ignoreReadBeforeAssign: true,
  241. }],
  242. 'quote-props': [0],
  243. 'quotes': [1, 'single', {
  244. avoidEscape: true,
  245. allowTemplateLiterals: true,
  246. }],
  247. 'radix': [0, 'always'],
  248. 'require-jsdoc': [0],
  249. 'require-yield': [2],
  250. 'semi-spacing': [2, {before: false, after: true}],
  251. 'semi': [2, 'always'],
  252. 'sort-imports': [0],
  253. 'sort-keys': [0],
  254. 'space-before-blocks': [2, 'always'],
  255. 'space-before-function-paren': [2, {
  256. anonymous: 'always',
  257. asyncArrow: 'always',
  258. named: 'never',
  259. }],
  260. 'space-in-parens': [2, 'never'],
  261. 'space-infix-ops': [2],
  262. 'space-unary-ops': [2],
  263. 'spaced-comment': [0, 'always', {markers: ['!']}],
  264. 'strict': [2, 'global'],
  265. 'symbol-description': [2],
  266. 'template-curly-spacing': [2, 'never'],
  267. 'unicode-bom': [2, 'never'],
  268. 'use-isnan': [2],
  269. 'valid-typeof': [2],
  270. 'wrap-iife': [2, 'inside'],
  271. 'yield-star-spacing': [2, {before: true, after: false}],
  272. 'yoda': [2, 'never'],
  273. },
  274. },
  275. //#endregion
  276. //#region Tooling
  277. v = {
  278. files: ['tools/**/*.mjs', '*.mjs'],
  279. ignores: [SHIMS],
  280. languageOptions: {
  281. globals: globals.node,
  282. ecmaVersion: 2023, // nodejs 20 per https://compat-table.github.io/compat-table/es2016plus/
  283. },
  284. },
  285. {
  286. ...v,
  287. files: ['tools/**/*.js', '*.js'],
  288. languageOptions: {...v.languageOptions, sourceType: 'commonjs'},
  289. },
  290. //#endregion
  291. //#region SHIMS
  292. {
  293. files: [SHIMS],
  294. languageOptions: {
  295. globals: {
  296. ...globals.node,
  297. ...globals.es2024,
  298. },
  299. },
  300. },
  301. //#endregion
  302. //#region SRC
  303. {
  304. files: ['src/**/*.js'],
  305. languageOptions: {
  306. ecmaVersion: 2024,
  307. globals: {
  308. ...globals.browser,
  309. ...SRC_GLOBALS,
  310. $: false,
  311. $$: false,
  312. $id: false,
  313. $root: false,
  314. $rootCL: false,
  315. $tag: false,
  316. },
  317. sourceType: 'module',
  318. },
  319. },
  320. //#endregion
  321. //#region SRC copied
  322. {
  323. files: ['src/content/install*.js'],
  324. languageOptions: {
  325. globals: {
  326. ...globals.browser,
  327. ...SRC_GLOBALS,
  328. },
  329. },
  330. },
  331. //#endregion
  332. //#region Background service worker
  333. {
  334. files: ['src/background/sw/**/*'],
  335. languageOptions: {
  336. globals: {
  337. ...globals.serviceworker,
  338. ...SRC_GLOBALS,
  339. },
  340. },
  341. },
  342. //#region Workers
  343. {
  344. files: ['src/**/*worker*.js'],
  345. languageOptions: {
  346. globals: {
  347. ...globals.worker,
  348. ...SRC_GLOBALS,
  349. },
  350. },
  351. },
  352. //#endregion
  353. ];