Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
63 lines (60 loc) · 3.48 KB
/
Copy patheslint.config.mjs
File metadata and controls
63 lines (60 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ESLint for the bugs a type checker misses, not for style: the recommended JavaScript and type-checked TypeScript
// rules, and SonarJS's bug detection. npm run lint
import js from '@eslint/js';
import sonarjs from 'eslint-plugin-sonarjs';
import tseslint from 'typescript-eslint';
export default tseslint.config(
{ ignores: ['dist/', 'docs/', 'bench/', 'coverage/', 'node_modules/'] },
{
files: ['src/**/*.ts'],
extends: [js.configs.recommended, ...tseslint.configs.recommendedTypeChecked],
plugins: { sonarjs },
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
rules: {
// every encoder and renderer returns a Promise (as since 1.x), also the ones that work synchronously
// (JPEG, WebP, TGA, GIF, SVG): async turns their errors into rejections like the others'
'@typescript-eslint/require-await': 'off',
// const enums are compared with the numbers of the tables they were made from (the HarfBuzz port)
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
// categories with two names (HarfBuzz's)
'@typescript-eslint/no-duplicate-enum-values': 'off',
// ({ removed: _, ...rest }) leaves out a property
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
// option checks live in util/options.ts, so one option is checked (and worded) the same everywhere: use a
// helper there, or add one (a check that only one place needs can say why with an eslint-disable)
'no-restricted-syntax': ['error', {
selector: "ThrowStatement > NewExpression[callee.name=/^(Range|Type)Error$/] > :matches(TemplateLiteral, Literal)[quasis.0.value.raw=/must be/], ThrowStatement > NewExpression[callee.name=/^(Range|Type)Error$/] > Literal[value=/must be/]",
message: "Check options with the helpers of util/options.ts (oneOf, finite, pixelLimit, ...) instead of a hand-written 'must be' error."
}],
// SonarJS: code that does nothing or something else than it reads like
'sonarjs/array-callback-without-return': 'error',
'sonarjs/no-all-duplicated-branches': 'error',
'sonarjs/no-collection-size-mischeck': 'error',
'sonarjs/no-dead-store': 'error',
'sonarjs/no-element-overwrite': 'error',
'sonarjs/no-empty-collection': 'error',
'sonarjs/no-gratuitous-expressions': 'error',
'sonarjs/no-identical-conditions': 'error',
'sonarjs/no-identical-expressions': 'error',
'sonarjs/no-identical-functions': 'error',
'sonarjs/no-ignored-return': 'error',
'sonarjs/no-misleading-array-reverse': 'error',
'sonarjs/no-unenclosed-multiline-block': 'error',
'sonarjs/no-unused-collection': 'error',
'sonarjs/no-use-of-empty-return-value': 'error',
// regular expressions that backtrack superlinearly (ReDoS)
'sonarjs/slow-regex': 'error'
}
},
{
// the dimension limits of a format aren't options (quantize.ts holds the dithering options, so it stays checked)
files: ['src/codecs/**/*.ts'],
ignores: ['src/codecs/quantize.ts'],
rules: { 'no-restricted-syntax': 'off' }
},
{
// (where the helpers are)
files: ['src/util/options.ts'],
rules: { 'no-restricted-syntax': 'off' }
}
);