@baukit/eslint-config 0.0.0-stage → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -2
- package/index.d.ts +18 -0
- package/index.js +97 -0
- package/package.json +69 -4
- package/react-web.d.ts +8 -0
- package/react-web.js +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Koss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@baukit/eslint-config`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared ESLint flat configs for Baukit packages and products. Each export is a function that
|
|
4
|
+
returns an array of config objects, so a consumer spreads it into `defineConfig` and adds its own
|
|
5
|
+
parser options.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { defineConfig } from 'eslint/config';
|
|
9
|
+
import { react, scripts } from '@baukit/eslint-config';
|
|
10
|
+
|
|
11
|
+
export default defineConfig(
|
|
12
|
+
{ ignores: ['dist/**'] },
|
|
13
|
+
...react({ files: ['src/**/*.{ts,tsx}'] }),
|
|
14
|
+
{
|
|
15
|
+
files: ['src/**/*.{ts,tsx}'],
|
|
16
|
+
languageOptions: {
|
|
17
|
+
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
...scripts({ files: ['scripts/**/*.mjs'] }),
|
|
21
|
+
);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- `base` is `@eslint/js` recommended, typescript-eslint `strictTypeChecked` and
|
|
25
|
+
`stylisticTypeChecked`, and the Baukit limits: 80 lines per function, 500 lines per file,
|
|
26
|
+
depth 4, 4 parameters, complexity 15, no object literal type assertions,
|
|
27
|
+
`strict-boolean-expressions` and explicit module boundary types. Test files (`*.test.ts(x)`,
|
|
28
|
+
`__tests__/`) drop the function, file and parameter limits.
|
|
29
|
+
- `react` adds `eslint-plugin-react-hooks` recommended.
|
|
30
|
+
- `reactWeb` from `@baukit/eslint-config/react-web` adds `eslint-plugin-jsx-a11y` recommended for
|
|
31
|
+
`domFiles`. Install `eslint-plugin-jsx-a11y` next to this package to use it.
|
|
32
|
+
- `scripts` lints plain JavaScript without type information and with Node globals.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
|
|
3
|
+
export interface ConfigOptions {
|
|
4
|
+
readonly files?: string[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ScriptConfigOptions extends ConfigOptions {
|
|
8
|
+
readonly globals?: Linter.Globals;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare const sourceFiles: string[];
|
|
12
|
+
export declare const testFiles: string[];
|
|
13
|
+
export declare const scriptFiles: string[];
|
|
14
|
+
export declare const baseRules: Linter.RulesRecord;
|
|
15
|
+
export declare const testRelaxedRules: Linter.RulesRecord;
|
|
16
|
+
export declare function base(options?: ConfigOptions): Linter.Config[];
|
|
17
|
+
export declare function react(options?: ConfigOptions): Linter.Config[];
|
|
18
|
+
export declare function scripts(options?: ScriptConfigOptions): Linter.Config[];
|
package/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import eslintComments from '@eslint-community/eslint-plugin-eslint-comments';
|
|
2
|
+
import eslint from '@eslint/js';
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
4
|
+
import globals from 'globals';
|
|
5
|
+
import tseslint from 'typescript-eslint';
|
|
6
|
+
|
|
7
|
+
export const sourceFiles = ['**/*.{ts,tsx,mts,cts}'];
|
|
8
|
+
export const testFiles = ['**/*.test.{ts,tsx}', '**/__tests__/**'];
|
|
9
|
+
export const scriptFiles = ['**/*.{js,mjs,cjs}'];
|
|
10
|
+
|
|
11
|
+
const MAX_FUNCTION_LINES = 80;
|
|
12
|
+
const MAX_FILE_LINES = 500;
|
|
13
|
+
const MAX_DEPTH = 4;
|
|
14
|
+
const MAX_PARAMS = 4;
|
|
15
|
+
const MAX_COMPLEXITY = 15;
|
|
16
|
+
|
|
17
|
+
/** Rules Baukit adds on top of the typescript-eslint strict and stylistic presets. */
|
|
18
|
+
export const baseRules = {
|
|
19
|
+
'max-lines-per-function': [
|
|
20
|
+
'error',
|
|
21
|
+
{ max: MAX_FUNCTION_LINES, skipBlankLines: true, skipComments: true },
|
|
22
|
+
],
|
|
23
|
+
'max-lines': ['error', { max: MAX_FILE_LINES, skipBlankLines: true, skipComments: true }],
|
|
24
|
+
'max-depth': ['error', MAX_DEPTH],
|
|
25
|
+
'max-params': ['error', MAX_PARAMS],
|
|
26
|
+
complexity: ['error', MAX_COMPLEXITY],
|
|
27
|
+
'@typescript-eslint/consistent-type-assertions': [
|
|
28
|
+
'error',
|
|
29
|
+
{ assertionStyle: 'as', objectLiteralTypeAssertions: 'never' },
|
|
30
|
+
],
|
|
31
|
+
'@typescript-eslint/strict-boolean-expressions': 'error',
|
|
32
|
+
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
|
33
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Size limits that do not fit test suites, which group many cases in one `describe`. */
|
|
37
|
+
export const testRelaxedRules = {
|
|
38
|
+
'max-lines-per-function': 'off',
|
|
39
|
+
'max-lines': 'off',
|
|
40
|
+
'max-params': 'off',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Every eslint-disable names a rule and gives a `-- reason`; stale directives fail. */
|
|
44
|
+
function directiveConfigs(files) {
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
files,
|
|
48
|
+
plugins: { '@eslint-community/eslint-comments': eslintComments },
|
|
49
|
+
linterOptions: { reportUnusedDisableDirectives: 'error' },
|
|
50
|
+
rules: {
|
|
51
|
+
'@eslint-community/eslint-comments/require-description': 'error',
|
|
52
|
+
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Type-checked TypeScript rules for `files`. Consumers add their own
|
|
60
|
+
* `languageOptions.parserOptions` (`projectService` or `project` plus `tsconfigRootDir`).
|
|
61
|
+
*/
|
|
62
|
+
export function base({ files = sourceFiles } = {}) {
|
|
63
|
+
return [
|
|
64
|
+
{ ...eslint.configs.recommended, files },
|
|
65
|
+
...[...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked].map(
|
|
66
|
+
(config) => ({ ...config, files }),
|
|
67
|
+
),
|
|
68
|
+
{ files, rules: baseRules },
|
|
69
|
+
...directiveConfigs(files),
|
|
70
|
+
{ files: testFiles, rules: testRelaxedRules },
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `base` plus the React hooks rules. */
|
|
75
|
+
export function react({ files = sourceFiles } = {}) {
|
|
76
|
+
return [...base({ files }), { ...reactHooks.configs.flat.recommended, files }];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const scriptRules = {
|
|
80
|
+
...Object.fromEntries(
|
|
81
|
+
Object.entries(baseRules).filter(([rule]) => !rule.startsWith('@typescript-eslint/')),
|
|
82
|
+
),
|
|
83
|
+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Plain JavaScript build and test scripts: no type information, Node globals by default. */
|
|
87
|
+
export function scripts({ files = scriptFiles, globals: scriptGlobals = globals.node } = {}) {
|
|
88
|
+
return [
|
|
89
|
+
{ ...eslint.configs.recommended, files },
|
|
90
|
+
...directiveConfigs(files),
|
|
91
|
+
{
|
|
92
|
+
files,
|
|
93
|
+
languageOptions: { sourceType: 'module', globals: scriptGlobals },
|
|
94
|
+
rules: scriptRules,
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/eslint-config",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.19.1",
|
|
4
|
+
"description": "Shared ESLint flat configs for Baukit packages and the products built on them.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Patrick Koss",
|
|
7
|
+
"homepage": "https://github.com/PatrickKoss/baukit#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/PatrickKoss/baukit.git",
|
|
11
|
+
"directory": "typescript/packages/eslint-config"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/PatrickKoss/baukit/issues"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=24.0.0"
|
|
22
|
+
},
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./index.d.ts",
|
|
27
|
+
"import": "./index.js",
|
|
28
|
+
"default": "./index.js"
|
|
29
|
+
},
|
|
30
|
+
"./react-web": {
|
|
31
|
+
"types": "./react-web.d.ts",
|
|
32
|
+
"import": "./react-web.js",
|
|
33
|
+
"default": "./react-web.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"index.d.ts",
|
|
39
|
+
"react-web.js",
|
|
40
|
+
"react-web.d.ts",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "node --test index.test.js",
|
|
46
|
+
"lint": "eslint . --max-warnings=0",
|
|
47
|
+
"format:check": "prettier --check *.js *.d.ts package.json README.md"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@eslint-community/eslint-plugin-eslint-comments": "4.8.1",
|
|
51
|
+
"@eslint/js": "10.0.1",
|
|
52
|
+
"eslint-plugin-react-hooks": "7.1.1",
|
|
53
|
+
"globals": "17.13.0",
|
|
54
|
+
"typescript-eslint": "8.71.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"eslint": "^10.11.0",
|
|
58
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
59
|
+
"typescript": "^6.0.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"eslint-plugin-jsx-a11y": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"eslint": "10.12.0",
|
|
68
|
+
"eslint-plugin-jsx-a11y": "6.10.2",
|
|
69
|
+
"typescript": "6.0.3"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/react-web.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
import type { ConfigOptions } from './index.js';
|
|
3
|
+
|
|
4
|
+
export interface ReactWebConfigOptions extends ConfigOptions {
|
|
5
|
+
readonly domFiles?: string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare function reactWeb(options?: ReactWebConfigOptions): Linter.Config[];
|
package/react-web.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
|
2
|
+
import { react, sourceFiles } from './index.js';
|
|
3
|
+
|
|
4
|
+
/** `react` plus the jsx-a11y recommended rules for DOM JSX in `domFiles`. */
|
|
5
|
+
export function reactWeb({ files = sourceFiles, domFiles = ['**/*.tsx'] } = {}) {
|
|
6
|
+
return [...react({ files }), { ...jsxA11y.flatConfigs.recommended, files: domFiles }];
|
|
7
|
+
}
|