@paciolan/code-standards 1.0.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 +27 -0
- package/README.md +170 -0
- package/eslint/base.mjs +22 -0
- package/eslint/index.mjs +8 -0
- package/eslint/lambda.mjs +23 -0
- package/eslint/nest.mjs +18 -0
- package/eslint/node.mjs +55 -0
- package/eslint/plugin/index.mjs +19 -0
- package/eslint/plugin/rules/no-direct-aws-sdk-v3-instance.mjs +61 -0
- package/eslint/react-query.mjs +20 -0
- package/eslint/react.mjs +37 -0
- package/eslint/typescript.mjs +44 -0
- package/package.json +103 -0
- package/prettier/index.cjs +8 -0
- package/tsconfig/base.json +17 -0
- package/tsconfig/layers/commonjs.json +7 -0
- package/tsconfig/layers/esmodule.json +7 -0
- package/tsconfig/layers/jest.json +7 -0
- package/tsconfig/layers/strict.json +8 -0
- package/tsconfig/layers/vitest.json +7 -0
- package/tsconfig/roles/lambda.json +6 -0
- package/tsconfig/roles/nest.json +10 -0
- package/tsconfig/roles/node-service.json +12 -0
- package/tsconfig/roles/react-lib.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Paciolan
|
|
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.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The TypeScript config preset structure (roles extended by layers) is adapted
|
|
26
|
+
from @code-style/typescript-configs, MIT License, Copyright (c) Louis Orleans
|
|
27
|
+
<louis@orleans.io> (https://github.com/dudeofawesome/code-style).
|
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @paciolan/code-standards
|
|
2
|
+
|
|
3
|
+
Paciolan's shared code standards in one package, consumed through three
|
|
4
|
+
subpath exports:
|
|
5
|
+
|
|
6
|
+
| Subpath | What it is |
|
|
7
|
+
| --- | --- |
|
|
8
|
+
| `@paciolan/code-standards/eslint/*` | ESLint **flat configs** (ESLint 9 and 10) plus the `pac` custom-rules plugin |
|
|
9
|
+
| `@paciolan/code-standards/prettier` | Org-wide Prettier settings |
|
|
10
|
+
| `@paciolan/code-standards/tsconfig/*` | TypeScript config presets (roles × layers) |
|
|
11
|
+
|
|
12
|
+
One dependency, one version bump per repo.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install --save-dev @paciolan/code-standards eslint prettier typescript
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Peer requirements: `eslint` ^9 or ^10, `prettier` ^3, `typescript` >=5 (only
|
|
19
|
+
if you use the TypeScript-aware configs or tsconfig presets).
|
|
20
|
+
|
|
21
|
+
## ESLint
|
|
22
|
+
|
|
23
|
+
Pick the entry matching the repo, re-export it from `eslint.config.mjs`, and
|
|
24
|
+
delete the repo's hand-rolled rules. Entries are cumulative — each one
|
|
25
|
+
includes everything below it in the table:
|
|
26
|
+
|
|
27
|
+
| Entry | Adds | Use for |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `eslint/base` | eslint recommended, Prettier-as-error | plain JS utilities |
|
|
30
|
+
| `eslint/typescript` | typescript-eslint recommended, unused-import auto-removal, `_`-prefix conventions | headless TS libraries |
|
|
31
|
+
| `eslint/react` | browser globals, react-hooks, import sorting | React components/libs |
|
|
32
|
+
| `eslint/react-query` | @tanstack/query correctness rules | operator remote components |
|
|
33
|
+
| `eslint/node` | node globals, security + n plugins, type-aware promise rules, `no-console` | node services (layered on `typescript`) |
|
|
34
|
+
| `eslint/nest` | Nest-specific guards | NestJS services |
|
|
35
|
+
| `eslint/lambda` | `pac/no-direct-aws-sdk-v3-instance` | AWS lambdas |
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
// eslint.config.mjs — operator remote component
|
|
39
|
+
import reactQuery from "@paciolan/code-standards/eslint/react-query";
|
|
40
|
+
|
|
41
|
+
export default reactQuery;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// eslint.config.mjs — node service / nest / lambda, adding repo-local tweaks
|
|
46
|
+
import node from "@paciolan/code-standards/eslint/node";
|
|
47
|
+
|
|
48
|
+
export default [
|
|
49
|
+
...node,
|
|
50
|
+
{ rules: { "@typescript-eslint/no-explicit-any": "off" } }
|
|
51
|
+
];
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Notes:
|
|
55
|
+
|
|
56
|
+
- **Type-aware rules** (`no-floating-promises`, `no-misused-promises`,
|
|
57
|
+
`return-await` in the node family) resolve your `tsconfig.json` via
|
|
58
|
+
typescript-eslint's project service. Run ESLint from the repo root; if you
|
|
59
|
+
don't, add
|
|
60
|
+
`{ languageOptions: { parserOptions: { tsconfigRootDir: import.meta.dirname } } }`.
|
|
61
|
+
- **react-hooks** is pinned to the classic pair (`rules-of-hooks` error,
|
|
62
|
+
`exhaustive-deps` warn). The plugin's v6+ `recommended` preset bundles the
|
|
63
|
+
React Compiler rule set; adopting those is a deliberate future change to
|
|
64
|
+
this package.
|
|
65
|
+
- **Unused code:** unused imports are removed by `--fix`; unused
|
|
66
|
+
vars/args/catch params warn unless named with a leading `_`.
|
|
67
|
+
- Repos that register additional plugins (e.g. `eslint-plugin-react`) do so
|
|
68
|
+
in their own config entry appended after the shared array.
|
|
69
|
+
|
|
70
|
+
### Custom rules (`pac/` plugin)
|
|
71
|
+
|
|
72
|
+
Standalone usage:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import pacPlugin from "@paciolan/code-standards/eslint/plugin";
|
|
76
|
+
|
|
77
|
+
export default [
|
|
78
|
+
{
|
|
79
|
+
plugins: { pac: pacPlugin },
|
|
80
|
+
rules: { "pac/no-direct-aws-sdk-v3-instance": "error" }
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### pac/no-direct-aws-sdk-v3-instance
|
|
86
|
+
|
|
87
|
+
Disallows binding `*Client` names from `@aws-sdk/client-*` packages (both
|
|
88
|
+
`import` and `require` destructuring), so lambdas and services reuse the
|
|
89
|
+
shared singleton clients instead of constructing their own per call site.
|
|
90
|
+
Enabled by the `lambda` entry; test files are exempt. Disable it inline in
|
|
91
|
+
the one module that owns the singletons:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
// eslint-disable-next-line pac/no-direct-aws-sdk-v3-instance
|
|
95
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Prettier
|
|
99
|
+
|
|
100
|
+
Point the `prettier` key of `package.json` at the shared config and delete
|
|
101
|
+
`.prettierrc`:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"prettier": "@paciolan/code-standards/prettier"
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Settings: `tabWidth: 2`, `trailingComma: "none"` (matches the operator fleet
|
|
110
|
+
and existing code; everything else is Prettier defaults). The ESLint configs
|
|
111
|
+
enforce the same settings through `prettier/prettier`, so editors and CI
|
|
112
|
+
can't drift.
|
|
113
|
+
|
|
114
|
+
## TypeScript
|
|
115
|
+
|
|
116
|
+
Extend one **role**, then stack **layers** as needed (later entries win):
|
|
117
|
+
|
|
118
|
+
| Role | For |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `tsconfig/react-lib` | browser React components/libs (typecheck-only; the bundler emits) |
|
|
121
|
+
| `tsconfig/node-service` | node services compiled with tsc (NodeNext, no DOM lib) |
|
|
122
|
+
| `tsconfig/nest` | NestJS services (CommonJS + legacy decorators) |
|
|
123
|
+
| `tsconfig/lambda` | AWS lambdas (node-service alias, stable extension point) |
|
|
124
|
+
|
|
125
|
+
| Layer | Effect |
|
|
126
|
+
| --- | --- |
|
|
127
|
+
| `tsconfig/strict` | extra strictness: `noUncheckedIndexedAccess`, `noImplicitReturns`, `noImplicitOverride` |
|
|
128
|
+
| `tsconfig/jest` | `types: ["node", "jest"]` |
|
|
129
|
+
| `tsconfig/vitest` | `types: ["node", "vitest/globals"]` |
|
|
130
|
+
| `tsconfig/esmodule` | NodeNext module semantics (flip a nest/service to ESM) |
|
|
131
|
+
| `tsconfig/commonjs` | CommonJS module semantics |
|
|
132
|
+
|
|
133
|
+
```jsonc
|
|
134
|
+
// tsconfig.json — React component with vitest
|
|
135
|
+
{
|
|
136
|
+
"extends": [
|
|
137
|
+
"@paciolan/code-standards/tsconfig/react-lib",
|
|
138
|
+
"@paciolan/code-standards/tsconfig/vitest"
|
|
139
|
+
],
|
|
140
|
+
"include": ["src"]
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```jsonc
|
|
145
|
+
// tsconfig.json — ESM NestJS service
|
|
146
|
+
{
|
|
147
|
+
"extends": [
|
|
148
|
+
"@paciolan/code-standards/tsconfig/nest",
|
|
149
|
+
"@paciolan/code-standards/tsconfig/esmodule"
|
|
150
|
+
],
|
|
151
|
+
"compilerOptions": { "baseUrl": "src/", "outDir": "dist/" },
|
|
152
|
+
"include": ["./"]
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Every role is `strict: true`. Heads-up: `types` **replaces** rather than
|
|
157
|
+
merges across extends — a repo needing extra ambient types (e.g.
|
|
158
|
+
`@testing-library/jest-dom`) sets the full `types` array itself.
|
|
159
|
+
|
|
160
|
+
## Versioning and publishing
|
|
161
|
+
|
|
162
|
+
Releases are cut by semantic-release from conventional commits on `master`
|
|
163
|
+
(`fix:` → patch, `feat:` → minor). A rule/config change that will produce new
|
|
164
|
+
errors in consuming repos is a **breaking change** — release it as a major.
|
|
165
|
+
|
|
166
|
+
## Attribution
|
|
167
|
+
|
|
168
|
+
The tsconfig preset structure (roles extended by layers) is adapted from the
|
|
169
|
+
MIT-licensed [@code-style/typescript-configs](https://github.com/dudeofawesome/code-style)
|
|
170
|
+
by Louis Orleans.
|
package/eslint/base.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import eslintConfigPrettier from "eslint-config-prettier";
|
|
3
|
+
import prettierPlugin from "eslint-plugin-prettier";
|
|
4
|
+
|
|
5
|
+
import prettierOptions from "../prettier/index.cjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base config for any JavaScript/TypeScript repo:
|
|
9
|
+
* eslint recommended + Prettier formatting enforced as an ESLint error,
|
|
10
|
+
* using the same options the /prettier subpath exports.
|
|
11
|
+
*/
|
|
12
|
+
export default [
|
|
13
|
+
{ ignores: ["**/dist/", "**/coverage/", "**/public/", "**/node_modules/"] },
|
|
14
|
+
js.configs.recommended,
|
|
15
|
+
eslintConfigPrettier,
|
|
16
|
+
{
|
|
17
|
+
plugins: { prettier: prettierPlugin },
|
|
18
|
+
rules: {
|
|
19
|
+
"prettier/prettier": ["error", prettierOptions]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
];
|
package/eslint/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as base } from "./base.mjs";
|
|
2
|
+
export { default as typescript } from "./typescript.mjs";
|
|
3
|
+
export { default as react } from "./react.mjs";
|
|
4
|
+
export { default as reactQuery } from "./react-query.mjs";
|
|
5
|
+
export { default as node } from "./node.mjs";
|
|
6
|
+
export { default as nest } from "./nest.mjs";
|
|
7
|
+
export { default as lambda } from "./lambda.mjs";
|
|
8
|
+
export { default as plugin } from "./plugin/index.mjs";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import node from "./node.mjs";
|
|
2
|
+
import pacPlugin from "./plugin/index.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AWS Lambda config, layered on node. Enforces the shared-singleton pattern
|
|
6
|
+
* for AWS SDK v3 clients; tests are exempt (they routinely construct client
|
|
7
|
+
* mocks). Disable the rule inline in the module that owns the singletons.
|
|
8
|
+
*/
|
|
9
|
+
export default [
|
|
10
|
+
...node,
|
|
11
|
+
{
|
|
12
|
+
plugins: { pac: pacPlugin },
|
|
13
|
+
rules: {
|
|
14
|
+
"pac/no-direct-aws-sdk-v3-instance": "error"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
files: ["**/__tests__/**", "**/*.test.*", "**/*.spec.*"],
|
|
19
|
+
rules: {
|
|
20
|
+
"pac/no-direct-aws-sdk-v3-instance": "off"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
];
|
package/eslint/nest.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import node from "./node.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* NestJS config, layered on node.
|
|
5
|
+
*/
|
|
6
|
+
export default [
|
|
7
|
+
...node,
|
|
8
|
+
{
|
|
9
|
+
rules: {
|
|
10
|
+
// @nestjs/terminus deep imports resolve to incorrect types.
|
|
11
|
+
// Guard ported from @code-style/eslint-config-nest.
|
|
12
|
+
"no-restricted-imports": [
|
|
13
|
+
"error",
|
|
14
|
+
{ patterns: ["@nestjs/terminus/dist/*"] }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
];
|
package/eslint/node.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import nodePlugin from "eslint-plugin-n";
|
|
2
|
+
import security from "eslint-plugin-security";
|
|
3
|
+
import globals from "globals";
|
|
4
|
+
|
|
5
|
+
import typescript from "./typescript.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Node config: typescript + node globals, eslint-plugin-security,
|
|
9
|
+
* eslint-plugin-n, and type-aware promise correctness rules.
|
|
10
|
+
*
|
|
11
|
+
* Type-aware rules use typescript-eslint's project service; run ESLint from
|
|
12
|
+
* the repo root, or set `parserOptions.tsconfigRootDir` in the consuming
|
|
13
|
+
* repo's eslint.config.mjs if it lints from elsewhere.
|
|
14
|
+
*
|
|
15
|
+
* Console output is reserved for the structured logger (`no-console`).
|
|
16
|
+
*/
|
|
17
|
+
export default [
|
|
18
|
+
...typescript,
|
|
19
|
+
security.configs.recommended,
|
|
20
|
+
{
|
|
21
|
+
// n's recommended rules without its preset: the preset hard-sets
|
|
22
|
+
// sourceType from package-type detection, which breaks repos mixing
|
|
23
|
+
// module kinds; ESLint's per-extension defaults are already correct.
|
|
24
|
+
plugins: { n: nodePlugin },
|
|
25
|
+
rules: { ...nodePlugin.configs["flat/recommended-module"].rules }
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
languageOptions: {
|
|
29
|
+
globals: { ...globals.node }
|
|
30
|
+
},
|
|
31
|
+
rules: {
|
|
32
|
+
"no-console": "error",
|
|
33
|
+
// TypeScript owns module resolution; these fire false positives on
|
|
34
|
+
// baseUrl/path aliases, type-only packages, and devDependency imports.
|
|
35
|
+
"n/no-missing-import": "off",
|
|
36
|
+
"n/no-missing-require": "off",
|
|
37
|
+
"n/no-unpublished-import": "off",
|
|
38
|
+
"n/no-unpublished-require": "off",
|
|
39
|
+
"n/no-extraneous-import": "off",
|
|
40
|
+
"n/no-extraneous-require": "off"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
files: ["**/*.{ts,tsx,mts,cts}"],
|
|
45
|
+
languageOptions: {
|
|
46
|
+
parserOptions: { projectService: true }
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
"@typescript-eslint/no-floating-promises": "error",
|
|
50
|
+
"@typescript-eslint/no-misused-promises": "error",
|
|
51
|
+
"no-return-await": "off",
|
|
52
|
+
"@typescript-eslint/return-await": ["error", "in-try-catch"]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import noDirectAwsSdkV3Instance from "./rules/no-direct-aws-sdk-v3-instance.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Paciolan custom ESLint rules. Registered as the `pac` namespace by the
|
|
5
|
+
* configs in this package; standalone consumers can register it themselves:
|
|
6
|
+
*
|
|
7
|
+
* import pacPlugin from "@paciolan/code-standards/eslint/plugin";
|
|
8
|
+
* export default [{ plugins: { pac: pacPlugin }, rules: { "pac/no-direct-aws-sdk-v3-instance": "error" } }];
|
|
9
|
+
*/
|
|
10
|
+
const plugin = {
|
|
11
|
+
meta: {
|
|
12
|
+
name: "@paciolan/code-standards"
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
"no-direct-aws-sdk-v3-instance": noDirectAwsSdkV3Instance
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default plugin;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disallow importing AWS SDK v3 client classes (`*Client` from
|
|
3
|
+
* `@aws-sdk/client-*`) so services go through the shared singleton
|
|
4
|
+
* instances instead of constructing their own. Ported from
|
|
5
|
+
* map-manager-lambda's custom-eslint-rules.
|
|
6
|
+
*/
|
|
7
|
+
export default {
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "disallow direct instantiation of AWS SDK v3 clients"
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noDirectAWSInstance:
|
|
15
|
+
"Do not create AWS SDK v3 clients directly. Import the shared singleton client instead."
|
|
16
|
+
},
|
|
17
|
+
schema: []
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
ImportDeclaration(node) {
|
|
22
|
+
if (node.source.value.startsWith("@aws-sdk/client-")) {
|
|
23
|
+
node.specifiers.forEach((specifier) => {
|
|
24
|
+
if (specifier.local.name.endsWith("Client")) {
|
|
25
|
+
context.report({
|
|
26
|
+
node: specifier,
|
|
27
|
+
messageId: "noDirectAWSInstance"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
VariableDeclarator(node) {
|
|
34
|
+
if (
|
|
35
|
+
node.init &&
|
|
36
|
+
node.init.type === "CallExpression" &&
|
|
37
|
+
node.init.callee.name === "require" &&
|
|
38
|
+
node.init.arguments.length &&
|
|
39
|
+
node.init.arguments[0].type === "Literal" &&
|
|
40
|
+
node.init.arguments[0].value.startsWith("@aws-sdk/client-")
|
|
41
|
+
) {
|
|
42
|
+
if (node.id.type === "ObjectPattern") {
|
|
43
|
+
node.id.properties.forEach((property) => {
|
|
44
|
+
// key is absent for rest elements and unnamed for computed keys
|
|
45
|
+
if (
|
|
46
|
+
property.key &&
|
|
47
|
+
property.key.name &&
|
|
48
|
+
property.key.name.endsWith("Client")
|
|
49
|
+
) {
|
|
50
|
+
context.report({
|
|
51
|
+
node: property,
|
|
52
|
+
messageId: "noDirectAWSInstance"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import pluginQuery from "@tanstack/eslint-plugin-query";
|
|
2
|
+
|
|
3
|
+
import react from "./react.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React Query config: react + the @tanstack/query correctness rules
|
|
7
|
+
* the operator fleet converged on, all at error severity.
|
|
8
|
+
*/
|
|
9
|
+
export default [
|
|
10
|
+
...react,
|
|
11
|
+
{
|
|
12
|
+
plugins: { "@tanstack/query": pluginQuery },
|
|
13
|
+
rules: {
|
|
14
|
+
"@tanstack/query/exhaustive-deps": "error",
|
|
15
|
+
"@tanstack/query/no-rest-destructuring": "error",
|
|
16
|
+
"@tanstack/query/stable-query-client": "error",
|
|
17
|
+
"@tanstack/query/no-unstable-deps": "error"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
];
|
package/eslint/react.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import reactHooks from "eslint-plugin-react-hooks";
|
|
2
|
+
import simpleImportSort from "eslint-plugin-simple-import-sort";
|
|
3
|
+
import globals from "globals";
|
|
4
|
+
|
|
5
|
+
import typescript from "./typescript.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* React config: typescript + browser globals, react-hooks, import sorting.
|
|
9
|
+
*
|
|
10
|
+
* react-hooks rules are pinned to the classic recommended pair rather than
|
|
11
|
+
* spreading `configs.recommended`: eslint-plugin-react-hooks v6+ added the
|
|
12
|
+
* React Compiler rule set to `recommended`, which would introduce a large
|
|
13
|
+
* class of new errors across existing repos. Adopting the compiler rules is
|
|
14
|
+
* a deliberate future change to this package, not a side effect.
|
|
15
|
+
*/
|
|
16
|
+
export default [
|
|
17
|
+
...typescript,
|
|
18
|
+
{
|
|
19
|
+
languageOptions: {
|
|
20
|
+
globals: { ...globals.browser }
|
|
21
|
+
},
|
|
22
|
+
plugins: {
|
|
23
|
+
"react-hooks": reactHooks,
|
|
24
|
+
"simple-import-sort": simpleImportSort
|
|
25
|
+
},
|
|
26
|
+
rules: {
|
|
27
|
+
"react-hooks/rules-of-hooks": "error",
|
|
28
|
+
"react-hooks/exhaustive-deps": "warn",
|
|
29
|
+
"simple-import-sort/imports": "error",
|
|
30
|
+
"simple-import-sort/exports": "error",
|
|
31
|
+
// TS repos don't need prop-types; inert unless a repo registers
|
|
32
|
+
// eslint-plugin-react itself (this package deliberately doesn't —
|
|
33
|
+
// registering it here would conflict with repo-local instances)
|
|
34
|
+
"react/prop-types": "off"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import unusedImports from "eslint-plugin-unused-imports";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
3
|
+
|
|
4
|
+
import base from "./base.mjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TypeScript config: base + typescript-eslint recommended, scoped to TS files.
|
|
8
|
+
*
|
|
9
|
+
* Unused-code handling: unused imports are auto-removed (`--fix`), while
|
|
10
|
+
* unused vars/args/catch params warn unless prefixed with `_`.
|
|
11
|
+
* `@typescript-eslint/no-unused-vars` is the single reporter; the duplicate
|
|
12
|
+
* reporters from eslint core and eslint-plugin-unused-imports are disabled.
|
|
13
|
+
*/
|
|
14
|
+
export default tseslint.config(...base, {
|
|
15
|
+
files: ["**/*.{ts,tsx,mts,cts}"],
|
|
16
|
+
extends: [...tseslint.configs.recommended],
|
|
17
|
+
plugins: {
|
|
18
|
+
"unused-imports": unusedImports
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
"unused-imports/no-unused-imports": "error",
|
|
22
|
+
"unused-imports/no-unused-vars": "off",
|
|
23
|
+
"no-unused-vars": "off",
|
|
24
|
+
"@typescript-eslint/no-unused-vars": [
|
|
25
|
+
"warn",
|
|
26
|
+
{
|
|
27
|
+
vars: "all",
|
|
28
|
+
varsIgnorePattern: "^_",
|
|
29
|
+
args: "after-used",
|
|
30
|
+
argsIgnorePattern: "^_",
|
|
31
|
+
caughtErrors: "all",
|
|
32
|
+
caughtErrorsIgnorePattern: "^_"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"@typescript-eslint/no-unused-expressions": [
|
|
36
|
+
"error",
|
|
37
|
+
{
|
|
38
|
+
allowShortCircuit: true,
|
|
39
|
+
allowTernary: true,
|
|
40
|
+
allowTaggedTemplates: true
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paciolan/code-standards",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Paciolan shared code standards: ESLint flat configs, Prettier config, and TypeScript config presets",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintconfig",
|
|
8
|
+
"prettier",
|
|
9
|
+
"tsconfig",
|
|
10
|
+
"paciolan"
|
|
11
|
+
],
|
|
12
|
+
"author": "Paciolan",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "ssh",
|
|
16
|
+
"url": "git@gitlabdev.paciolan.info:development/library/javascript/code-standards.git"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20.0.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"eslint",
|
|
23
|
+
"prettier",
|
|
24
|
+
"tsconfig"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
"./eslint": "./eslint/index.mjs",
|
|
28
|
+
"./eslint/base": "./eslint/base.mjs",
|
|
29
|
+
"./eslint/typescript": "./eslint/typescript.mjs",
|
|
30
|
+
"./eslint/react": "./eslint/react.mjs",
|
|
31
|
+
"./eslint/react-query": "./eslint/react-query.mjs",
|
|
32
|
+
"./eslint/node": "./eslint/node.mjs",
|
|
33
|
+
"./eslint/nest": "./eslint/nest.mjs",
|
|
34
|
+
"./eslint/lambda": "./eslint/lambda.mjs",
|
|
35
|
+
"./eslint/plugin": "./eslint/plugin/index.mjs",
|
|
36
|
+
"./prettier": "./prettier/index.cjs",
|
|
37
|
+
"./tsconfig/base": "./tsconfig/base.json",
|
|
38
|
+
"./tsconfig/react-lib": "./tsconfig/roles/react-lib.json",
|
|
39
|
+
"./tsconfig/node-service": "./tsconfig/roles/node-service.json",
|
|
40
|
+
"./tsconfig/nest": "./tsconfig/roles/nest.json",
|
|
41
|
+
"./tsconfig/lambda": "./tsconfig/roles/lambda.json",
|
|
42
|
+
"./tsconfig/strict": "./tsconfig/layers/strict.json",
|
|
43
|
+
"./tsconfig/jest": "./tsconfig/layers/jest.json",
|
|
44
|
+
"./tsconfig/vitest": "./tsconfig/layers/vitest.json",
|
|
45
|
+
"./tsconfig/esmodule": "./tsconfig/layers/esmodule.json",
|
|
46
|
+
"./tsconfig/commonjs": "./tsconfig/layers/commonjs.json",
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"release": {
|
|
53
|
+
"branches": [
|
|
54
|
+
"master"
|
|
55
|
+
],
|
|
56
|
+
"repositoryUrl": "git@gitlabdev.paciolan.info:development/library/javascript/code-standards.git",
|
|
57
|
+
"plugins": [
|
|
58
|
+
"@semantic-release/commit-analyzer",
|
|
59
|
+
"@semantic-release/release-notes-generator",
|
|
60
|
+
"@semantic-release/npm"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"lint": "eslint .",
|
|
65
|
+
"lint:fix": "eslint . --fix",
|
|
66
|
+
"test": "node --test tests/*.test.mjs tests/rules/*.test.mjs",
|
|
67
|
+
"prepare": "node .husky/install.mjs || true"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@eslint/js": "^9.39.5",
|
|
71
|
+
"@tanstack/eslint-plugin-query": "^5.101.4",
|
|
72
|
+
"eslint-config-prettier": "^10.1.8",
|
|
73
|
+
"eslint-plugin-n": "^17.24.0",
|
|
74
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
75
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
76
|
+
"eslint-plugin-security": "^4.0.1",
|
|
77
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
78
|
+
"eslint-plugin-unused-imports": "^4.4.1",
|
|
79
|
+
"globals": "^16.4.0",
|
|
80
|
+
"typescript-eslint": "^8.66.0"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"eslint": "^9.0.0 || ^10.0.0",
|
|
84
|
+
"prettier": "^3.0.0",
|
|
85
|
+
"typescript": ">=5.0.0"
|
|
86
|
+
},
|
|
87
|
+
"peerDependenciesMeta": {
|
|
88
|
+
"typescript": {
|
|
89
|
+
"optional": true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@commitlint/cli": "^21.2.1",
|
|
94
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
95
|
+
"@types/node": "^20.19.0",
|
|
96
|
+
"@types/react": "^18.3.23",
|
|
97
|
+
"eslint": "^9.39.5",
|
|
98
|
+
"eslint10": "npm:eslint@^10.8.0",
|
|
99
|
+
"husky": "^9.1.7",
|
|
100
|
+
"prettier": "^3.9.6",
|
|
101
|
+
"typescript": "^5.9.3"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Shared baseline for every @paciolan/code-standards tsconfig role.
|
|
3
|
+
// Preset structure (roles extended by layers) adapted from the MIT-licensed
|
|
4
|
+
// @code-style/typescript-configs by Louis Orleans.
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"target": "ES2022",
|
|
15
|
+
"lib": ["ES2022"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
// NestJS service: node-service + CommonJS output (Nest's default; add the
|
|
3
|
+
// esmodule layer after this role to flip, as the ESM services do) and
|
|
4
|
+
// pre-standardization decorator support for Nest's DI metadata.
|
|
5
|
+
"extends": ["./node-service.json", "../layers/commonjs.json"],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"emitDecoratorMetadata": true
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Node service: compiled with tsc and run on Node. No DOM lib, so
|
|
3
|
+
// window/document references are compile errors; sourcemaps stay on for
|
|
4
|
+
// APM stack traces.
|
|
5
|
+
"extends": "../base.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"module": "NodeNext",
|
|
8
|
+
"moduleResolution": "NodeNext",
|
|
9
|
+
"types": ["node"],
|
|
10
|
+
"noEmit": false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Browser React library/component: typechecked by tsc, emitted by a
|
|
3
|
+
// bundler (webpack/vite). Repos that emit with tsc (e.g. published
|
|
4
|
+
// libraries) override noEmit/outDir in their build tsconfigs.
|
|
5
|
+
"extends": "../base.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"target": "ES2020",
|
|
11
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true
|
|
14
|
+
}
|
|
15
|
+
}
|