@jasonsdevspace/config 0.0.0-stage → 0.1.0-bootstrap.0
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 +132 -2
- package/package.json +78 -5
- package/src/eslint.mjs +164 -0
- package/src/prettier.mjs +24 -0
- package/src/react.mjs +48 -0
- package/tsconfig.base.json +20 -0
- package/types/eslint.d.mts +36 -0
- package/types/prettier.d.mts +23 -0
- package/types/react.d.mts +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jason Poteet
|
|
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,133 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jasonsdevspace/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@jasonsdevspace/config)
|
|
4
|
+
[](https://github.com/jasonsdevspace/tooling/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/jasonsdevspace/tooling/blob/main/packages/config/LICENSE)
|
|
6
|
+
|
|
7
|
+
The lint, format and TypeScript settings the house's repositories share: ESLint presets, the
|
|
8
|
+
Prettier config and a strict TypeScript base. A rule raised here is raised in every repository that
|
|
9
|
+
moves its pin, rather than in the one copy it was edited in.
|
|
10
|
+
|
|
11
|
+
[Changelog](https://github.com/jasonsdevspace/tooling/blob/main/packages/config/CHANGELOG.md) ·
|
|
12
|
+
[Source](https://github.com/jasonsdevspace/tooling/tree/main/packages/config)
|
|
13
|
+
|
|
14
|
+
## Installing
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install --save-dev --save-exact @jasonsdevspace/config eslint typescript-eslint typescript@~6.0.0 prettier
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The package brings the lint plugins its presets name, at the versions it was tested with, so a
|
|
21
|
+
plugin update reaches a repository through a release of this package. ESLint, typescript-eslint,
|
|
22
|
+
TypeScript and Prettier stay the repository's own, since they are the tools it runs.
|
|
23
|
+
typescript-eslint names the TypeScript versions it supports, so the TypeScript installed is one in
|
|
24
|
+
its range, the 6.0 line in the line above, and the two move together in the repository's own
|
|
25
|
+
dependency updates. A repository that holds its own copy of a plugin the package brings removes it,
|
|
26
|
+
since ESLint refuses one plugin defined twice.
|
|
27
|
+
|
|
28
|
+
## The ESLint presets
|
|
29
|
+
|
|
30
|
+
Each preset is a function that returns flat config objects, which a repository spreads into its own
|
|
31
|
+
`eslint.config.js` and follows with its own blocks:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { base, tests, typed } from '@jasonsdevspace/config/eslint';
|
|
35
|
+
import { defineConfig } from 'eslint/config';
|
|
36
|
+
|
|
37
|
+
export default defineConfig(
|
|
38
|
+
...base({ ignores: ['packages/engine/smoke/types.ts'] }),
|
|
39
|
+
...typed({ tsconfigRootDir: import.meta.dirname, allowDefaultProject: ['vitest.config.ts'] }),
|
|
40
|
+
...tests(),
|
|
41
|
+
{
|
|
42
|
+
// This repository's own rules, such as the imports a folder that runs in a browser may not
|
|
43
|
+
// make.
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- **`base({ ignores })`** holds every kind of JavaScript and TypeScript file, CommonJS and module
|
|
49
|
+
files and markup among them, to ESLint's and
|
|
50
|
+
typescript-eslint's recommended sets, the rules that catch real mistakes, such as `eqeqeq` and
|
|
51
|
+
SonarJS's identical-branch checks, the size budgets a function may not grow past, and the
|
|
52
|
+
mechanical rules `eslint --fix` applies, such as import order. Every callable is a value, written
|
|
53
|
+
as an arrow function. A disable comment has to say why after `--`, and one whose rule no longer
|
|
54
|
+
fires fails the lint. A `.cjs` file reads as CommonJS, with `require` and `module.exports`. The
|
|
55
|
+
builds in `dist` and the coverage reports are left out, beside the paths given.
|
|
56
|
+
- **`typed({ tsconfigRootDir, allowDefaultProject })`** holds TypeScript files to
|
|
57
|
+
typescript-eslint's type-aware set, such as a promise nobody awaits and a condition that is
|
|
58
|
+
always true, read through each file's own tsconfig. `allowDefaultProject` names the files at the
|
|
59
|
+
root that no tsconfig includes.
|
|
60
|
+
- **`tests({ files })`** turns off `max-params` in the test files, every `*.test.*` file unless
|
|
61
|
+
named, so a fixture builder can take a record's fields in order, and turns off nothing else.
|
|
62
|
+
|
|
63
|
+
## React
|
|
64
|
+
|
|
65
|
+
React's rules of hooks live in a preset of their own, so a repository without React installs no
|
|
66
|
+
plugin for them. A repository with React installs the plugin, an optional peer of this package, and
|
|
67
|
+
adds the preset:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
npm install --save-dev --save-exact eslint-plugin-react-hooks
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { react } from '@jasonsdevspace/config/react';
|
|
75
|
+
|
|
76
|
+
// Inside defineConfig, after the presets above.
|
|
77
|
+
...react({ files: ['apps/web/**/*.{ts,tsx}'] }),
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**`react({ files })`** holds the files given to React's rules of hooks, every one the plugin
|
|
81
|
+
recommends raised to an error, with the browser's globals and markup parsed in JavaScript files too.
|
|
82
|
+
|
|
83
|
+
## Every rule an error
|
|
84
|
+
|
|
85
|
+
Every rule in every preset is an error, since a warning that does not fail the build is a rule
|
|
86
|
+
nobody follows. A repository keeps for itself what names its own folders: which ones run in a
|
|
87
|
+
browser or a worker, the imports one may not make, and the files only it holds.
|
|
88
|
+
|
|
89
|
+
## The Prettier config
|
|
90
|
+
|
|
91
|
+
Named from the repository's `package.json`:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"prettier": "@jasonsdevspace/config/prettier"
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Four spaces, single quotes, a hundred columns, semicolons, and the trailing commas ES5 allows.
|
|
100
|
+
|
|
101
|
+
## The TypeScript base
|
|
102
|
+
|
|
103
|
+
Extended from the repository's `tsconfig.json`, which adds what is its own, such as its `lib`, its
|
|
104
|
+
`types`, `jsx` and what it includes:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"extends": "@jasonsdevspace/config/tsconfig.json",
|
|
109
|
+
"compilerOptions": { "types": ["node"], "noEmit": true },
|
|
110
|
+
"include": ["src"]
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
It is strict, with `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, `noImplicitReturns`,
|
|
115
|
+
`noPropertyAccessFromIndexSignature`, `noImplicitOverride`, unused locals and parameters,
|
|
116
|
+
`verbatimModuleSyntax` and `isolatedModules`, and it checks library declarations too, with
|
|
117
|
+
`skipLibCheck` off, so a broken declaration in what a package ships or installs fails the type check
|
|
118
|
+
rather than reaching a repository that installs it. A tsconfig that compiles a dependency whose own
|
|
119
|
+
declarations are broken, and cannot be fixed from here, turns `skipLibCheck` back on for itself
|
|
120
|
+
alone.
|
|
121
|
+
|
|
122
|
+
## Versions and licenses
|
|
123
|
+
|
|
124
|
+
The package is versioned on its own. Until 1.0.0, a minor version can fail a build that passed
|
|
125
|
+
before, with a rule that asks more or a new one, and a patch never does, so read the changelog
|
|
126
|
+
before moving to a minor version.
|
|
127
|
+
|
|
128
|
+
The package is MIT licensed, and the terms are in
|
|
129
|
+
[LICENSE](https://github.com/jasonsdevspace/tooling/blob/main/packages/config/LICENSE). Among the
|
|
130
|
+
plugins it installs, SonarJS's ESLint plugin is under the GNU Lesser General Public License, version
|
|
131
|
+
3 only. The package declares it as a dependency and npm installs it unchanged from its own published
|
|
132
|
+
tarball, so none of its code is copied into or bundled with this package. Every other plugin it
|
|
133
|
+
installs is MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@jasonsdevspace/config",
|
|
3
|
+
"version": "0.1.0-bootstrap.0",
|
|
4
|
+
"description": "The house's shared lint, format and TypeScript settings: ESLint presets for any code, type-aware rules, tests and React hooks, the Prettier config and a strict TypeScript base.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint-config",
|
|
7
|
+
"prettier-config",
|
|
8
|
+
"tsconfig",
|
|
9
|
+
"eslint",
|
|
10
|
+
"prettier",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Jason Poteet",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/jasonsdevspace/tooling.git",
|
|
18
|
+
"directory": "packages/config"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/jasonsdevspace/tooling/tree/main/packages/config#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/jasonsdevspace/tooling/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=24"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
"./eslint": {
|
|
31
|
+
"types": "./types/eslint.d.mts",
|
|
32
|
+
"default": "./src/eslint.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./react": {
|
|
35
|
+
"types": "./types/react.d.mts",
|
|
36
|
+
"default": "./src/react.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./prettier": {
|
|
39
|
+
"types": "./types/prettier.d.mts",
|
|
40
|
+
"default": "./src/prettier.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./tsconfig.json": "./tsconfig.base.json",
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"src/*.mjs",
|
|
47
|
+
"types",
|
|
48
|
+
"tsconfig.base.json"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"types": "tsc -p tsconfig.types.json"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"eslint": "^10.0.0",
|
|
58
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
59
|
+
"prettier": "^3.0.0",
|
|
60
|
+
"typescript": ">=6.0.0",
|
|
61
|
+
"typescript-eslint": "^8.74.0"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"eslint-plugin-react-hooks": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"prettier": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@eslint-community/eslint-plugin-eslint-comments": "4.8.1",
|
|
73
|
+
"@eslint/js": "10.0.1",
|
|
74
|
+
"eslint-plugin-import-x": "4.18.1",
|
|
75
|
+
"eslint-plugin-simple-import-sort": "14.0.0",
|
|
76
|
+
"eslint-plugin-sonarjs": "4.2.3",
|
|
77
|
+
"globals": "17.14.0"
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/eslint.mjs
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import comments from '@eslint-community/eslint-plugin-eslint-comments';
|
|
3
|
+
import { defineConfig } from 'eslint/config';
|
|
4
|
+
import importX from 'eslint-plugin-import-x';
|
|
5
|
+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
|
|
6
|
+
import sonarjs from 'eslint-plugin-sonarjs';
|
|
7
|
+
import globals from 'globals';
|
|
8
|
+
import tseslint from 'typescript-eslint';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Three kinds of rule live here.
|
|
12
|
+
*
|
|
13
|
+
* Mechanical ones, such as import order, are fixed by `eslint --fix` and exist so a diff never
|
|
14
|
+
* carries reordering noise. Bug catchers, from typescript-eslint's type-aware set and SonarJS, flag
|
|
15
|
+
* code that is wrong rather than code that is unusual. Size budgets catch a function that has grown
|
|
16
|
+
* past what a reader can hold at once. Everything is an error, since a warning that does not fail
|
|
17
|
+
* the build is a rule nobody follows.
|
|
18
|
+
*
|
|
19
|
+
* Each preset is a function that returns flat config objects, so a repository spreads the ones it
|
|
20
|
+
* takes into its own `defineConfig` and adds its own blocks after them: the folders that run in a
|
|
21
|
+
* browser, the imports one folder may not make, the files no tsconfig includes. React's rules of
|
|
22
|
+
* hooks live apart, in `@jasonsdevspace/config/react`, so a repository without React installs no
|
|
23
|
+
* plugin for them.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Every file of code a preset reads. */
|
|
27
|
+
const CODE = ['**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}'];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Rules that fire on real mistakes and almost never on style.
|
|
31
|
+
*
|
|
32
|
+
* @type {import('eslint').Linter.RulesRecord}
|
|
33
|
+
*/
|
|
34
|
+
const bugCatchers = {
|
|
35
|
+
'sonarjs/no-identical-conditions': 'error',
|
|
36
|
+
'sonarjs/no-identical-expressions': 'error',
|
|
37
|
+
'sonarjs/no-all-duplicated-branches': 'error',
|
|
38
|
+
'sonarjs/no-element-overwrite': 'error',
|
|
39
|
+
'sonarjs/no-ignored-return': 'error',
|
|
40
|
+
'sonarjs/no-use-of-empty-return-value': 'error',
|
|
41
|
+
'sonarjs/no-empty-collection': 'error',
|
|
42
|
+
'sonarjs/no-unused-collection': 'error',
|
|
43
|
+
'sonarjs/no-collection-size-mischeck': 'error',
|
|
44
|
+
'sonarjs/no-extra-arguments': 'error',
|
|
45
|
+
'sonarjs/no-gratuitous-expressions': 'error',
|
|
46
|
+
'sonarjs/no-redundant-jump': 'error',
|
|
47
|
+
eqeqeq: ['error', 'always'],
|
|
48
|
+
'no-param-reassign': 'error',
|
|
49
|
+
'array-callback-return': 'error',
|
|
50
|
+
'no-return-assign': 'error',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* How large a function may grow before it should be split.
|
|
55
|
+
*
|
|
56
|
+
* @type {import('eslint').Linter.RulesRecord}
|
|
57
|
+
*/
|
|
58
|
+
const sizeBudgets = {
|
|
59
|
+
complexity: ['error', 15],
|
|
60
|
+
'sonarjs/cognitive-complexity': ['error', 15],
|
|
61
|
+
'max-depth': ['error', 4],
|
|
62
|
+
'max-params': ['error', 4],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The rules for any code, JavaScript and TypeScript alike: ESLint's and typescript-eslint's
|
|
67
|
+
* recommended sets, the bug catchers, the size budgets and the mechanical rules. A disable comment
|
|
68
|
+
* has to say why after `--`, and one whose rule no longer fires fails the lint, so neither outlives
|
|
69
|
+
* its reason.
|
|
70
|
+
*
|
|
71
|
+
* @param {{ ignores?: string[] }} [options] Paths left out of the lint, beside the builds and the
|
|
72
|
+
* coverage reports it always leaves out.
|
|
73
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
74
|
+
*/
|
|
75
|
+
export function base({ ignores = [] } = {}) {
|
|
76
|
+
return defineConfig(
|
|
77
|
+
{ linterOptions: { reportUnusedDisableDirectives: 'error' } },
|
|
78
|
+
{ ignores: ['**/coverage', '**/dist', ...ignores] },
|
|
79
|
+
{
|
|
80
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
81
|
+
files: CODE,
|
|
82
|
+
languageOptions: {
|
|
83
|
+
ecmaVersion: 2023,
|
|
84
|
+
globals: globals.node,
|
|
85
|
+
},
|
|
86
|
+
plugins: {
|
|
87
|
+
'@eslint-community/eslint-comments': comments,
|
|
88
|
+
'import-x': importX,
|
|
89
|
+
'simple-import-sort': simpleImportSort,
|
|
90
|
+
sonarjs,
|
|
91
|
+
},
|
|
92
|
+
rules: {
|
|
93
|
+
'@typescript-eslint/no-unused-vars': [
|
|
94
|
+
'error',
|
|
95
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
|
96
|
+
],
|
|
97
|
+
// Every callable is a value, so a file reads top to bottom with no hoisting
|
|
98
|
+
// surprises.
|
|
99
|
+
'func-style': ['error', 'expression'],
|
|
100
|
+
'prefer-arrow-callback': ['error', { allowNamedFunctions: false }],
|
|
101
|
+
'simple-import-sort/imports': 'error',
|
|
102
|
+
'simple-import-sort/exports': 'error',
|
|
103
|
+
'import-x/first': 'error',
|
|
104
|
+
'import-x/newline-after-import': 'error',
|
|
105
|
+
'import-x/no-duplicates': ['error', { 'prefer-inline': true }],
|
|
106
|
+
'@eslint-community/eslint-comments/require-description': 'error',
|
|
107
|
+
...bugCatchers,
|
|
108
|
+
...sizeBudgets,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
// A `.cjs` file is CommonJS whatever the package says, so it reads with `require` and
|
|
113
|
+
// assigns `module.exports`, and the rule that asks for imports instead does not apply.
|
|
114
|
+
files: ['**/*.cjs'],
|
|
115
|
+
languageOptions: { sourceType: 'commonjs' },
|
|
116
|
+
rules: { '@typescript-eslint/no-require-imports': 'off' },
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The rules that need the types, for TypeScript files, read through each file's own tsconfig by
|
|
123
|
+
* typescript-eslint's project service.
|
|
124
|
+
*
|
|
125
|
+
* @param {{ tsconfigRootDir: string, allowDefaultProject?: string[] }} options The folder the
|
|
126
|
+
* project service starts from, the repository's root, and the files at the root that no tsconfig
|
|
127
|
+
* includes, read with a default project.
|
|
128
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
129
|
+
*/
|
|
130
|
+
export function typed({ tsconfigRootDir, allowDefaultProject }) {
|
|
131
|
+
return defineConfig({
|
|
132
|
+
extends: [...tseslint.configs.recommendedTypeChecked],
|
|
133
|
+
files: ['**/*.{ts,tsx,mts,cts}'],
|
|
134
|
+
languageOptions: {
|
|
135
|
+
parserOptions: {
|
|
136
|
+
projectService: allowDefaultProject === undefined ? true : { allowDefaultProject },
|
|
137
|
+
tsconfigRootDir,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
rules: {
|
|
141
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
142
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
143
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
144
|
+
'@typescript-eslint/require-array-sort-compare': 'error',
|
|
145
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
|
146
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
147
|
+
'@typescript-eslint/no-unnecessary-condition': 'error',
|
|
148
|
+
'@typescript-eslint/prefer-readonly': 'error',
|
|
149
|
+
// A switch over a union names every case, so a new member left out fails the lint.
|
|
150
|
+
'@typescript-eslint/switch-exhaustiveness-check': 'error',
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The one rule a test may break: a fixture builder takes a record's fields in order, so a table of
|
|
157
|
+
* fixtures reads as one row per line, which an object of named fields would spread over several.
|
|
158
|
+
*
|
|
159
|
+
* @param {{ files?: string[] }} [options] The test files, every `*.test.*` file unless named.
|
|
160
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
161
|
+
*/
|
|
162
|
+
export function tests({ files = ['**/*.test.{ts,tsx,mts,cts,js,jsx,mjs,cjs}'] } = {}) {
|
|
163
|
+
return defineConfig({ files, rules: { 'max-params': 'off' } });
|
|
164
|
+
}
|
package/src/prettier.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The house's Prettier config: four spaces, single quotes, a hundred columns, semicolons, and the
|
|
3
|
+
* trailing commas ES5 allows. A repository names it from the `prettier` field of its `package.json`
|
|
4
|
+
* as `"@jasonsdevspace/config/prettier"`.
|
|
5
|
+
*
|
|
6
|
+
* @type {{
|
|
7
|
+
* semi: boolean,
|
|
8
|
+
* singleQuote: boolean,
|
|
9
|
+
* tabWidth: number,
|
|
10
|
+
* trailingComma: 'es5',
|
|
11
|
+
* printWidth: number,
|
|
12
|
+
* arrowParens: 'always',
|
|
13
|
+
* }}
|
|
14
|
+
*/
|
|
15
|
+
const config = {
|
|
16
|
+
semi: true,
|
|
17
|
+
singleQuote: true,
|
|
18
|
+
tabWidth: 4,
|
|
19
|
+
trailingComma: 'es5',
|
|
20
|
+
printWidth: 100,
|
|
21
|
+
arrowParens: 'always',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default config;
|
package/src/react.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint/config';
|
|
2
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React's rules of hooks, every one the plugin recommends raised to an error with its options
|
|
7
|
+
* kept, and the browser's globals, for the files that render in a browser. Markup is parsed in
|
|
8
|
+
* JavaScript files too, so a `.jsx` file is read as one. The plugin is an optional peer of this
|
|
9
|
+
* package, which a repository with React installs itself.
|
|
10
|
+
*
|
|
11
|
+
* @param {{ files: string[] }} options The files that hold components and hooks.
|
|
12
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
13
|
+
*/
|
|
14
|
+
export function react({ files }) {
|
|
15
|
+
/** @type {Record<string, import('eslint').Linter.RuleEntry>} */
|
|
16
|
+
const recommended = reactHooks.configs.flat.recommended.rules;
|
|
17
|
+
return defineConfig({
|
|
18
|
+
files,
|
|
19
|
+
languageOptions: {
|
|
20
|
+
globals: globals.browser,
|
|
21
|
+
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
22
|
+
},
|
|
23
|
+
// The plugin's own types describe its legacy configs beside the rules, which ESLint's
|
|
24
|
+
// plugin type does not admit, so it is passed on as the plugin it is at run time.
|
|
25
|
+
plugins: {
|
|
26
|
+
'react-hooks': /** @type {import('eslint').ESLint.Plugin} */ (
|
|
27
|
+
/** @type {unknown} */ (reactHooks)
|
|
28
|
+
),
|
|
29
|
+
},
|
|
30
|
+
rules: Object.fromEntries(
|
|
31
|
+
Object.entries(recommended).map(([rule, setting]) => [rule, raised(setting)])
|
|
32
|
+
),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A rule's setting with a warning raised to an error and its options kept.
|
|
38
|
+
*
|
|
39
|
+
* @param {import('eslint').Linter.RuleEntry} setting
|
|
40
|
+
* @returns {import('eslint').Linter.RuleEntry}
|
|
41
|
+
*/
|
|
42
|
+
const raised = (setting) => {
|
|
43
|
+
if (setting === 'warn' || setting === 1) return 'error';
|
|
44
|
+
if (Array.isArray(setting) && (setting[0] === 'warn' || setting[0] === 1)) {
|
|
45
|
+
return ['error', ...setting.slice(1)];
|
|
46
|
+
}
|
|
47
|
+
return setting;
|
|
48
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"lib": ["ES2023"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noUncheckedIndexedAccess": true,
|
|
9
|
+
"exactOptionalPropertyTypes": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noFallthroughCasesInSwitch": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"skipLibCheck": false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules for any code, JavaScript and TypeScript alike: ESLint's and typescript-eslint's
|
|
3
|
+
* recommended sets, the bug catchers, the size budgets and the mechanical rules. A disable comment
|
|
4
|
+
* has to say why after `--`, and one whose rule no longer fires fails the lint, so neither outlives
|
|
5
|
+
* its reason.
|
|
6
|
+
*
|
|
7
|
+
* @param {{ ignores?: string[] }} [options] Paths left out of the lint, beside the builds and the
|
|
8
|
+
* coverage reports it always leaves out.
|
|
9
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
10
|
+
*/
|
|
11
|
+
export function base({ ignores }?: {
|
|
12
|
+
ignores?: string[];
|
|
13
|
+
}): import("eslint").Linter.Config[];
|
|
14
|
+
/**
|
|
15
|
+
* The rules that need the types, for TypeScript files, read through each file's own tsconfig by
|
|
16
|
+
* typescript-eslint's project service.
|
|
17
|
+
*
|
|
18
|
+
* @param {{ tsconfigRootDir: string, allowDefaultProject?: string[] }} options The folder the
|
|
19
|
+
* project service starts from, the repository's root, and the files at the root that no tsconfig
|
|
20
|
+
* includes, read with a default project.
|
|
21
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
22
|
+
*/
|
|
23
|
+
export function typed({ tsconfigRootDir, allowDefaultProject }: {
|
|
24
|
+
tsconfigRootDir: string;
|
|
25
|
+
allowDefaultProject?: string[];
|
|
26
|
+
}): import("eslint").Linter.Config[];
|
|
27
|
+
/**
|
|
28
|
+
* The one rule a test may break: a fixture builder takes a record's fields in order, so a table of
|
|
29
|
+
* fixtures reads as one row per line, which an object of named fields would spread over several.
|
|
30
|
+
*
|
|
31
|
+
* @param {{ files?: string[] }} [options] The test files, every `*.test.*` file unless named.
|
|
32
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
33
|
+
*/
|
|
34
|
+
export function tests({ files }?: {
|
|
35
|
+
files?: string[];
|
|
36
|
+
}): import("eslint").Linter.Config[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default config;
|
|
2
|
+
/**
|
|
3
|
+
* The house's Prettier config: four spaces, single quotes, a hundred columns, semicolons, and the
|
|
4
|
+
* trailing commas ES5 allows. A repository names it from the `prettier` field of its `package.json`
|
|
5
|
+
* as `"@jasonsdevspace/config/prettier"`.
|
|
6
|
+
*
|
|
7
|
+
* @type {{
|
|
8
|
+
* semi: boolean,
|
|
9
|
+
* singleQuote: boolean,
|
|
10
|
+
* tabWidth: number,
|
|
11
|
+
* trailingComma: 'es5',
|
|
12
|
+
* printWidth: number,
|
|
13
|
+
* arrowParens: 'always',
|
|
14
|
+
* }}
|
|
15
|
+
*/
|
|
16
|
+
declare const config: {
|
|
17
|
+
semi: boolean;
|
|
18
|
+
singleQuote: boolean;
|
|
19
|
+
tabWidth: number;
|
|
20
|
+
trailingComma: "es5";
|
|
21
|
+
printWidth: number;
|
|
22
|
+
arrowParens: "always";
|
|
23
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React's rules of hooks, every one the plugin recommends raised to an error with its options
|
|
3
|
+
* kept, and the browser's globals, for the files that render in a browser. Markup is parsed in
|
|
4
|
+
* JavaScript files too, so a `.jsx` file is read as one. The plugin is an optional peer of this
|
|
5
|
+
* package, which a repository with React installs itself.
|
|
6
|
+
*
|
|
7
|
+
* @param {{ files: string[] }} options The files that hold components and hooks.
|
|
8
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
9
|
+
*/
|
|
10
|
+
export function react({ files }: {
|
|
11
|
+
files: string[];
|
|
12
|
+
}): import("eslint").Linter.Config[];
|