@nage-api/eslint-config 1.0.0-beta.2
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 +202 -0
- package/README.md +131 -0
- package/boundaries.js +90 -0
- package/index.js +145 -0
- package/layers.js +179 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @nage-api/eslint-config
|
|
2
|
+
|
|
3
|
+
The shared strict ESLint flat config (PLAN.md §20), and the registry that makes
|
|
4
|
+
the layered dependency rule of §7.2 a lint error rather than a convention.
|
|
5
|
+
|
|
6
|
+
Two jobs in one package, because they are the same job. §13 asks the framework to
|
|
7
|
+
hold itself to `no-explicit-any`, the `no-unsafe-*` family and
|
|
8
|
+
`no-floating-promises`; §7.2 asks it to keep dependencies pointing downward. Both
|
|
9
|
+
are rules nobody can enforce by reading a diff, so both are here.
|
|
10
|
+
|
|
11
|
+
The legacy framework had an `eslint.config.mjs` too. It extended
|
|
12
|
+
`recommendedTypeChecked` and then turned the guarantees back off:
|
|
13
|
+
`no-explicit-any: off`, the unsafe family off, `no-floating-promises` at `warn`,
|
|
14
|
+
`no-unused-vars` at `warn` (§2.5). The result was 146 explicit `any` annotations
|
|
15
|
+
in non-test source and a `ModelService<M>` whose generic was undone by `body: any`
|
|
16
|
+
at the `Job` boundary (§5.1). A rule at `warn` in a repository with no lint step
|
|
17
|
+
in CI (§2.5) is a comment.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// eslint.config.mjs
|
|
23
|
+
import { nageEslintConfig } from '@nage-api/eslint-config';
|
|
24
|
+
|
|
25
|
+
export default nageEslintConfig({ tsconfigRootDir: import.meta.dirname });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`tsconfigRootDir` is required rather than defaulted, and `projectService: true`
|
|
29
|
+
means the type-aware rules resolve every file through the nearest real
|
|
30
|
+
`tsconfig.json`. A default would guess the root, and the failure mode of a wrong
|
|
31
|
+
guess is not an error but silence: type-aware rules find nothing in a file the
|
|
32
|
+
service could not place, so the strictest rules in the config become the easiest
|
|
33
|
+
to lose.
|
|
34
|
+
|
|
35
|
+
ESLint 10 is the peer dependency; `typescript-eslint`, `globals` and
|
|
36
|
+
`eslint-config-prettier` are this package's own, so a consumer installs ESLint and
|
|
37
|
+
this and nothing else. The Prettier compatibility block is applied last on
|
|
38
|
+
purpose — it turns off the stylistic rules Prettier owns, and a block after it
|
|
39
|
+
would quietly reinstate them.
|
|
40
|
+
|
|
41
|
+
## What it enforces
|
|
42
|
+
|
|
43
|
+
| Area | Rules |
|
|
44
|
+
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
45
|
+
| Type safety (PLAN.md §13) | `no-explicit-any`, the `no-unsafe-*` family, `no-floating-promises`, `no-misused-promises`, `explicit-module-boundary-types` on package source |
|
|
46
|
+
| Security (PLAN.md §12) | `Math.random()` is banned — use `node:crypto` |
|
|
47
|
+
| Consistency | `consistent-type-imports`/`-exports`, `eqeqeq`, `prefer-const`, `no-console` (warn/error allowed) |
|
|
48
|
+
| Layering (PLAN.md §7.2) | generated `no-restricted-imports` rules — see below |
|
|
49
|
+
|
|
50
|
+
The `Math.random()` ban is a `no-restricted-syntax` selector on
|
|
51
|
+
`Math.random`, and it exists because of two specific functions: legacy `otp()`
|
|
52
|
+
and `randomString()` in `core.utils.ts` generated one-time codes and tokens from
|
|
53
|
+
a non-cryptographic PRNG (§12). Neither call looked wrong, which is the point of
|
|
54
|
+
enforcing it at the syntax level rather than in review.
|
|
55
|
+
|
|
56
|
+
Four blocks relax the baseline where a rule would fail honest code. Test files
|
|
57
|
+
drop the unsafe-assignment family and `unbound-method` — supertest types its
|
|
58
|
+
responses as `any`, and naming a method to identify a route handler is not a
|
|
59
|
+
`this`-binding mistake. `*.module.ts` drops `no-extraneous-class`, because a
|
|
60
|
+
`forRoot`-only module is the framework's own idiom and `@Module({})` needs a class
|
|
61
|
+
to decorate. Plain JS gets `disableTypeChecked` and `no-console: off`, since
|
|
62
|
+
tooling scripts print. Production source in `packages/*/src` keeps every rule and
|
|
63
|
+
adds `explicit-module-boundary-types`.
|
|
64
|
+
|
|
65
|
+
## Dependency boundaries
|
|
66
|
+
|
|
67
|
+
`layers.js` is the single source of truth for the package graph:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
apps → @nage-api/cli → drivers → feature packages → @nage-api/core → @nage-api/contracts
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- Dependencies point **downward only**.
|
|
74
|
+
- Feature packages may not import each other; they collaborate through
|
|
75
|
+
`@nage-api/contracts` interfaces and `@nage-api/core` DI tokens.
|
|
76
|
+
- `@nage-api/contracts` is types-only: no Nest, no `rxjs`, no `zod`, no runtime deps.
|
|
77
|
+
- Exceptions are explicit and justified in `ALLOWED_EXCEPTIONS` (e.g. a driver
|
|
78
|
+
may depend on the base package whose ports it implements).
|
|
79
|
+
|
|
80
|
+
Every package — including ones not yet scaffolded — is registered in
|
|
81
|
+
`PACKAGE_REGISTRY` with its directory and layer, so a new package cannot enter
|
|
82
|
+
the workspace without declaring where it sits in the graph.
|
|
83
|
+
|
|
84
|
+
`boundaries.js` turns that registry into a pair of flat-config blocks per package,
|
|
85
|
+
scoping a `no-restricted-imports` pattern list to that package's directory: one for
|
|
86
|
+
its TypeScript sources, one for its plain-JS tooling files. The TypeScript block
|
|
87
|
+
uses the `@typescript-eslint` variant of the rule, so `import type` cannot be used
|
|
88
|
+
to sidestep the direction — a type-only import is still a reason to open the other
|
|
89
|
+
package's source, which is the coupling the rule is about.
|
|
90
|
+
|
|
91
|
+
The same registry backs two checks ESLint cannot make:
|
|
92
|
+
|
|
93
|
+
- `tools/boundaries/check-manifests.mjs` reads every `package.json`, so a
|
|
94
|
+
violation cannot slip through as a declared-but-dynamically-imported
|
|
95
|
+
dependency. It also fails a package that is unregistered, or whose directory
|
|
96
|
+
disagrees with the registry.
|
|
97
|
+
- `tools/boundaries/check-relative-imports.mjs` catches
|
|
98
|
+
`import '../../data/src/thing.js'`, which is invisible to
|
|
99
|
+
`no-restricted-imports` because the specifier never names a package.
|
|
100
|
+
|
|
101
|
+
And `tools/boundaries/verify-enforcement.mjs` proves in CI that each of those
|
|
102
|
+
layers actually rejects a violation, by building six deliberately broken fixtures
|
|
103
|
+
in a throwaway tree. A rule nobody has watched fire is a rule nobody can trust,
|
|
104
|
+
and the failure mode here is quiet: a glob that stops matching disables a rule
|
|
105
|
+
without any error to notice.
|
|
106
|
+
|
|
107
|
+
## Consuming it in a generated workspace
|
|
108
|
+
|
|
109
|
+
The intent (§20) is that a generated app extends the same config the framework
|
|
110
|
+
holds itself to, and the boundary blocks are inert there: each is globbed to one
|
|
111
|
+
registry directory (`packages/auth/**`, `packages/data/data-sql/**`, …), and a
|
|
112
|
+
generated workspace has none of them. A generated app gets the §13 type-safety
|
|
113
|
+
rules and the `Math.random()` ban, and no layering.
|
|
114
|
+
|
|
115
|
+
The two manifest-level scripts are the repository's own, not a consumer's:
|
|
116
|
+
`check-manifests.mjs` fails any package it cannot find in `PACKAGE_REGISTRY`, so
|
|
117
|
+
pointing it at a generated workspace reports every app and shared package as
|
|
118
|
+
unregistered. Layering for generated workspaces is not solved by running these
|
|
119
|
+
scripts there.
|
|
120
|
+
|
|
121
|
+
## Not yet implemented
|
|
122
|
+
|
|
123
|
+
- No layer for the app side of a generated workspace: nothing stops
|
|
124
|
+
`apps/api` from importing `apps/admin` directly. §7.2 only describes the
|
|
125
|
+
framework's own graph.
|
|
126
|
+
- The config takes no options beyond `tsconfigRootDir` — no way to relax one rule
|
|
127
|
+
for one project without copying the array. That is deliberate for now: the
|
|
128
|
+
first escape hatch is the one every project takes.
|
|
129
|
+
- This package has no test suite of its own. Its behaviour is asserted from
|
|
130
|
+
outside, by `tools/boundaries/verify-enforcement.mjs` and by the repository
|
|
131
|
+
linting itself.
|
package/boundaries.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESLint flat-config blocks that enforce the layered dependency rule
|
|
3
|
+
* (PLAN.md §7.2) at the **source** level.
|
|
4
|
+
*
|
|
5
|
+
* The companion manifest check (`tools/boundaries/check-manifests.mjs`) enforces
|
|
6
|
+
* the same rule at the **package.json** level, so a violation cannot slip
|
|
7
|
+
* through by being declared as a dependency but imported dynamically.
|
|
8
|
+
*
|
|
9
|
+
* Cross-package *relative* imports (`../../data/src/thing`) are caught by the
|
|
10
|
+
* compiler instead: every package sets `rootDir: src`, so reaching outside it is
|
|
11
|
+
* a typecheck error.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import tseslint from 'typescript-eslint';
|
|
15
|
+
|
|
16
|
+
import { PACKAGE_REGISTRY, forbiddenDependencies } from './layers.js';
|
|
17
|
+
|
|
18
|
+
/** Packages that must stay free of any runtime/framework dependency. */
|
|
19
|
+
const PURE_TYPE_PACKAGES = ['@nage-api/contracts'];
|
|
20
|
+
|
|
21
|
+
/** Modules a types-only package may never pull in. */
|
|
22
|
+
const RUNTIME_MODULES = ['@nestjs/*', '@nestjs/*/**', 'rxjs', 'rxjs/**', 'zod', 'zod/**'];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} pkg
|
|
26
|
+
* @returns {string[]} minimatch patterns covering the package and its subpaths
|
|
27
|
+
*/
|
|
28
|
+
function importPatternsFor(pkg) {
|
|
29
|
+
return [pkg, `${pkg}/*`, `${pkg}/**`];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Build one ESLint config object per scaffolded package.
|
|
34
|
+
*
|
|
35
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
36
|
+
*/
|
|
37
|
+
export function boundaryConfigs() {
|
|
38
|
+
/** @type {import('eslint').Linter.Config[]} */
|
|
39
|
+
const configs = [];
|
|
40
|
+
|
|
41
|
+
for (const [pkg, meta] of Object.entries(PACKAGE_REGISTRY)) {
|
|
42
|
+
const forbidden = forbiddenDependencies(pkg).flatMap(importPatternsFor);
|
|
43
|
+
|
|
44
|
+
/** @type {{ group: string[]; message: string }[]} */
|
|
45
|
+
const patterns = [];
|
|
46
|
+
|
|
47
|
+
if (forbidden.length > 0) {
|
|
48
|
+
patterns.push({
|
|
49
|
+
group: forbidden,
|
|
50
|
+
message:
|
|
51
|
+
`Dependency-direction violation (PLAN.md §7.2): "${pkg}" (layer: ${meta.layer}) ` +
|
|
52
|
+
`may not import this package. Depend downward only — collaborate through ` +
|
|
53
|
+
`@nage-api/contracts interfaces and @nage-api/core DI tokens instead.`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (PURE_TYPE_PACKAGES.includes(pkg)) {
|
|
58
|
+
patterns.push({
|
|
59
|
+
group: RUNTIME_MODULES,
|
|
60
|
+
message:
|
|
61
|
+
`"${pkg}" is a types-only package (PLAN.md §8): no runtime code, no Nest, ` +
|
|
62
|
+
`no validation libraries. Move the implementation to @nage-api/core or a feature package.`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (patterns.length === 0) continue;
|
|
67
|
+
|
|
68
|
+
// TypeScript sources use the typescript-eslint variant so that `import type`
|
|
69
|
+
// cannot be used to sidestep the rule.
|
|
70
|
+
configs.push({
|
|
71
|
+
name: `nage/boundaries/${pkg}`,
|
|
72
|
+
files: [`${meta.dir}/**/*.{ts,tsx,mts,cts}`],
|
|
73
|
+
plugins: { '@typescript-eslint': tseslint.plugin },
|
|
74
|
+
rules: {
|
|
75
|
+
'@typescript-eslint/no-restricted-imports': ['error', { patterns }],
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Tooling and config files inside a package are plain JS.
|
|
80
|
+
configs.push({
|
|
81
|
+
name: `nage/boundaries/${pkg}/js`,
|
|
82
|
+
files: [`${meta.dir}/**/*.{js,mjs,cjs}`],
|
|
83
|
+
rules: {
|
|
84
|
+
'no-restricted-imports': ['error', { patterns }],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return configs;
|
|
90
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared strict ESLint flat config for the @nage-api monorepo.
|
|
3
|
+
*
|
|
4
|
+
* Implements PLAN.md §13 (Type-Safety Strategy):
|
|
5
|
+
* - `no-explicit-any` is an error
|
|
6
|
+
* - the `no-unsafe-*` family is an error (type-aware)
|
|
7
|
+
* - `no-floating-promises` is an error
|
|
8
|
+
* - `explicit-module-boundary-types` is an error for published source
|
|
9
|
+
* plus the layered dependency rules from §7.2 (see ./boundaries.js).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import globals from 'globals';
|
|
13
|
+
import tseslint from 'typescript-eslint';
|
|
14
|
+
import prettier from 'eslint-config-prettier';
|
|
15
|
+
|
|
16
|
+
import { boundaryConfigs } from './boundaries.js';
|
|
17
|
+
|
|
18
|
+
export const IGNORES = [
|
|
19
|
+
'**/node_modules/**',
|
|
20
|
+
'**/dist/**',
|
|
21
|
+
'**/coverage/**',
|
|
22
|
+
'**/.turbo/**',
|
|
23
|
+
'**/*.tsbuildinfo',
|
|
24
|
+
// Generated by the docs example gate (tools/docs/check-examples.mjs), which
|
|
25
|
+
// typechecks it against the real API. Linting extracted snippets would enforce
|
|
26
|
+
// rules on prose the reader is meant to adapt, not on code we ship.
|
|
27
|
+
'**/.examples/**',
|
|
28
|
+
// Docusaurus build output.
|
|
29
|
+
'**/.docusaurus/**',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ tsconfigRootDir: string }} options
|
|
34
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
35
|
+
*/
|
|
36
|
+
export function nageEslintConfig({ tsconfigRootDir }) {
|
|
37
|
+
return tseslint.config(
|
|
38
|
+
{ name: 'nage/ignores', ignores: IGNORES },
|
|
39
|
+
|
|
40
|
+
// ── Type-aware baseline for all TypeScript sources ──────────────────────
|
|
41
|
+
{
|
|
42
|
+
name: 'nage/typescript',
|
|
43
|
+
files: ['**/*.{ts,mts,cts}'],
|
|
44
|
+
extends: [...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked],
|
|
45
|
+
languageOptions: {
|
|
46
|
+
parserOptions: { projectService: true, tsconfigRootDir },
|
|
47
|
+
globals: { ...globals.node },
|
|
48
|
+
},
|
|
49
|
+
rules: {
|
|
50
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
51
|
+
'@typescript-eslint/no-unsafe-argument': 'error',
|
|
52
|
+
'@typescript-eslint/no-unsafe-assignment': 'error',
|
|
53
|
+
'@typescript-eslint/no-unsafe-call': 'error',
|
|
54
|
+
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
55
|
+
'@typescript-eslint/no-unsafe-return': 'error',
|
|
56
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
57
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
58
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
59
|
+
'error',
|
|
60
|
+
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
|
|
61
|
+
],
|
|
62
|
+
'@typescript-eslint/consistent-type-exports': 'error',
|
|
63
|
+
'@typescript-eslint/no-unused-vars': [
|
|
64
|
+
'error',
|
|
65
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
|
66
|
+
],
|
|
67
|
+
// Numbers in messages are unambiguous; objects and unions are not.
|
|
68
|
+
'@typescript-eslint/restrict-template-expressions': ['error', { allowNumber: true }],
|
|
69
|
+
'no-console': ['error', { allow: ['warn', 'error'] }],
|
|
70
|
+
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
|
71
|
+
'prefer-const': 'error',
|
|
72
|
+
'no-restricted-syntax': [
|
|
73
|
+
'error',
|
|
74
|
+
{
|
|
75
|
+
selector: "MemberExpression[object.name='Math'][property.name='random']",
|
|
76
|
+
message:
|
|
77
|
+
'Math.random() is not cryptographically secure (PLAN.md §12). Use node:crypto (randomInt/randomBytes).',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// ── Published package source: exported API must be explicitly typed ─────
|
|
84
|
+
{
|
|
85
|
+
name: 'nage/package-source',
|
|
86
|
+
files: ['packages/*/src/**/*.ts', 'packages/*/*/src/**/*.ts'],
|
|
87
|
+
rules: {
|
|
88
|
+
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// ── NestJS module classes ───────────────────────────────────────────────
|
|
93
|
+
// A `forRoot`-only module is the framework's own idiom, not a missing
|
|
94
|
+
// namespace: `@Module({})` needs a class to decorate.
|
|
95
|
+
{
|
|
96
|
+
name: 'nage/nest-modules',
|
|
97
|
+
files: ['**/*.module.ts'],
|
|
98
|
+
rules: {
|
|
99
|
+
'@typescript-eslint/no-extraneous-class': 'off',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// ── Tests: pragmatic relaxations ────────────────────────────────────────
|
|
104
|
+
// HTTP test clients (supertest) type their responses as `any`, test modules
|
|
105
|
+
// are legitimately empty classes, and referencing a method to identify a
|
|
106
|
+
// route handler is not a `this`-binding mistake. Production source keeps all
|
|
107
|
+
// of these as errors.
|
|
108
|
+
{
|
|
109
|
+
name: 'nage/tests',
|
|
110
|
+
files: ['**/test/**/*.ts', '**/*.spec.ts', '**/*.e2e-spec.ts'],
|
|
111
|
+
rules: {
|
|
112
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
113
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
114
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
115
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
116
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
117
|
+
'@typescript-eslint/no-extraneous-class': 'off',
|
|
118
|
+
'@typescript-eslint/unbound-method': 'off',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// ── Tooling scripts and flat configs (plain JS, not type-aware) ─────────
|
|
123
|
+
{
|
|
124
|
+
name: 'nage/javascript',
|
|
125
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
126
|
+
extends: [tseslint.configs.disableTypeChecked],
|
|
127
|
+
languageOptions: {
|
|
128
|
+
ecmaVersion: 2023,
|
|
129
|
+
sourceType: 'module',
|
|
130
|
+
globals: { ...globals.node },
|
|
131
|
+
},
|
|
132
|
+
rules: {
|
|
133
|
+
'no-console': 'off',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// ── Dependency-direction enforcement (§7.2) ─────────────────────────────
|
|
138
|
+
...boundaryConfigs(),
|
|
139
|
+
|
|
140
|
+
// Must stay last: turns off stylistic rules Prettier owns.
|
|
141
|
+
prettier,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export default nageEslintConfig;
|
package/layers.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the layered dependency rule (PLAN.md §7.2).
|
|
3
|
+
*
|
|
4
|
+
* apps
|
|
5
|
+
* ▼
|
|
6
|
+
* @nage-api/cli
|
|
7
|
+
* ▼
|
|
8
|
+
* drivers (@nage-api/data-sql, @nage-api/data-mongo)
|
|
9
|
+
* ▼
|
|
10
|
+
* feature packages (@nage-api/auth, @nage-api/data, @nage-api/config, …)
|
|
11
|
+
* ▼
|
|
12
|
+
* @nage-api/core
|
|
13
|
+
* ▼
|
|
14
|
+
* @nage-api/contracts + @nage-api/testing
|
|
15
|
+
*
|
|
16
|
+
* Rule: dependencies point **downward only**. Feature packages must not import
|
|
17
|
+
* each other — they collaborate through `@nage-api/contracts` interfaces and DI
|
|
18
|
+
* tokens exposed by `@nage-api/core`.
|
|
19
|
+
*
|
|
20
|
+
* Consumed by:
|
|
21
|
+
* - `boundaries.js` → ESLint `no-restricted-imports` rules (source level)
|
|
22
|
+
* - `tools/boundaries/*` → package.json manifest checks (dependency level)
|
|
23
|
+
*
|
|
24
|
+
* Packages are registered here before they exist so that a new package cannot be
|
|
25
|
+
* added to the workspace without declaring which layer it belongs to.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** @typedef {'contracts' | 'core' | 'feature' | 'driver' | 'cli' | 'tooling'} Layer */
|
|
29
|
+
|
|
30
|
+
/** Ordered from the bottom of the dependency graph upwards. */
|
|
31
|
+
export const LAYER_ORDER = /** @type {const} */ (['contracts', 'core', 'feature', 'driver', 'cli']);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Every package the framework owns, with its workspace directory and layer.
|
|
35
|
+
* `dir` is relative to the repository root and may be absent for packages that
|
|
36
|
+
* are planned but not yet scaffolded.
|
|
37
|
+
*
|
|
38
|
+
* @type {Record<string, { dir: string; layer: Layer; scaffolded: boolean }>}
|
|
39
|
+
*/
|
|
40
|
+
export const PACKAGE_REGISTRY = {
|
|
41
|
+
// ── layer: contracts ──────────────────────────────────────────────────────
|
|
42
|
+
'@nage-api/contracts': { dir: 'packages/contracts', layer: 'contracts', scaffolded: true },
|
|
43
|
+
'@nage-api/testing': { dir: 'packages/testing', layer: 'contracts', scaffolded: true },
|
|
44
|
+
|
|
45
|
+
// ── layer: core ───────────────────────────────────────────────────────────
|
|
46
|
+
'@nage-api/core': { dir: 'packages/core', layer: 'core', scaffolded: true },
|
|
47
|
+
|
|
48
|
+
// ── layer: feature ────────────────────────────────────────────────────────
|
|
49
|
+
'@nage-api/config': { dir: 'packages/config', layer: 'feature', scaffolded: true },
|
|
50
|
+
'@nage-api/data': { dir: 'packages/data', layer: 'feature', scaffolded: true },
|
|
51
|
+
'@nage-api/auth': { dir: 'packages/auth', layer: 'feature', scaffolded: true },
|
|
52
|
+
'@nage-api/cache': { dir: 'packages/cache', layer: 'feature', scaffolded: true },
|
|
53
|
+
'@nage-api/queue': { dir: 'packages/queue', layer: 'feature', scaffolded: true },
|
|
54
|
+
'@nage-api/storage': { dir: 'packages/storage', layer: 'feature', scaffolded: true },
|
|
55
|
+
'@nage-api/realtime': { dir: 'packages/realtime', layer: 'feature', scaffolded: true },
|
|
56
|
+
'@nage-api/notify': { dir: 'packages/notify', layer: 'feature', scaffolded: true },
|
|
57
|
+
'@nage-api/observability': {
|
|
58
|
+
dir: 'packages/observability',
|
|
59
|
+
layer: 'feature',
|
|
60
|
+
scaffolded: true,
|
|
61
|
+
},
|
|
62
|
+
'@nage-api/compat': { dir: 'packages/compat', layer: 'feature', scaffolded: true },
|
|
63
|
+
'@nage-api/integrations-email': {
|
|
64
|
+
dir: 'packages/integrations/email',
|
|
65
|
+
layer: 'feature',
|
|
66
|
+
scaffolded: false,
|
|
67
|
+
},
|
|
68
|
+
'@nage-api/integrations-sms': {
|
|
69
|
+
dir: 'packages/integrations/sms',
|
|
70
|
+
layer: 'feature',
|
|
71
|
+
scaffolded: false,
|
|
72
|
+
},
|
|
73
|
+
'@nage-api/integrations-firebase': {
|
|
74
|
+
dir: 'packages/integrations/firebase',
|
|
75
|
+
layer: 'feature',
|
|
76
|
+
scaffolded: false,
|
|
77
|
+
},
|
|
78
|
+
'@nage-api/integrations-stripe': {
|
|
79
|
+
dir: 'packages/integrations/stripe',
|
|
80
|
+
layer: 'feature',
|
|
81
|
+
scaffolded: false,
|
|
82
|
+
},
|
|
83
|
+
'@nage-api/integrations-square': {
|
|
84
|
+
dir: 'packages/integrations/square',
|
|
85
|
+
layer: 'feature',
|
|
86
|
+
scaffolded: false,
|
|
87
|
+
},
|
|
88
|
+
'@nage-api/integrations-recaptcha': {
|
|
89
|
+
dir: 'packages/integrations/recaptcha',
|
|
90
|
+
layer: 'feature',
|
|
91
|
+
scaffolded: true,
|
|
92
|
+
},
|
|
93
|
+
'@nage-api/integrations-geocoder': {
|
|
94
|
+
dir: 'packages/integrations/geocoder',
|
|
95
|
+
layer: 'feature',
|
|
96
|
+
scaffolded: false,
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// ── layer: driver ─────────────────────────────────────────────────────────
|
|
100
|
+
'@nage-api/data-sql': { dir: 'packages/data/data-sql', layer: 'driver', scaffolded: true },
|
|
101
|
+
'@nage-api/data-mongo': {
|
|
102
|
+
dir: 'packages/data/data-mongo',
|
|
103
|
+
layer: 'driver',
|
|
104
|
+
scaffolded: false,
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
// ── layer: cli ────────────────────────────────────────────────────────────
|
|
108
|
+
'@nage-api/cli': { dir: 'packages/cli', layer: 'cli', scaffolded: true },
|
|
109
|
+
|
|
110
|
+
// ── tooling (build-time only; never a runtime dependency) ─────────────────
|
|
111
|
+
'@nage-api/eslint-config': {
|
|
112
|
+
dir: 'packages/eslint-config',
|
|
113
|
+
layer: 'tooling',
|
|
114
|
+
scaffolded: true,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Explicit, justified exceptions to the strict layer rule. Anything added here
|
|
120
|
+
* needs a comment saying why the generic rule does not fit.
|
|
121
|
+
*
|
|
122
|
+
* @type {Record<string, readonly string[]>}
|
|
123
|
+
*/
|
|
124
|
+
export const ALLOWED_EXCEPTIONS = {
|
|
125
|
+
// `@nage-api/testing` ships fixtures typed against the shared contracts.
|
|
126
|
+
'@nage-api/testing': ['@nage-api/contracts'],
|
|
127
|
+
// Drivers implement the ports declared by their base package.
|
|
128
|
+
'@nage-api/data-sql': ['@nage-api/data'],
|
|
129
|
+
'@nage-api/data-mongo': ['@nage-api/data'],
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** Packages every workspace package may depend on as a *dev* dependency. */
|
|
133
|
+
export const TOOLING_PACKAGES = ['@nage-api/eslint-config', '@nage-api/testing'];
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Runtime dependencies `pkg` is allowed to declare/import.
|
|
137
|
+
*
|
|
138
|
+
* @param {string} pkg
|
|
139
|
+
* @returns {string[]}
|
|
140
|
+
*/
|
|
141
|
+
export function allowedDependencies(pkg) {
|
|
142
|
+
const entry = PACKAGE_REGISTRY[pkg];
|
|
143
|
+
if (entry === undefined) return [];
|
|
144
|
+
|
|
145
|
+
const exceptions = ALLOWED_EXCEPTIONS[pkg] ?? [];
|
|
146
|
+
if (entry.layer === 'tooling') return [...exceptions];
|
|
147
|
+
|
|
148
|
+
if (entry.layer === 'cli') {
|
|
149
|
+
// The CLI orchestrates the whole framework; it may depend on any package.
|
|
150
|
+
return Object.keys(PACKAGE_REGISTRY).filter((name) => name !== pkg);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const level = LAYER_ORDER.indexOf(entry.layer);
|
|
154
|
+
const lower = Object.entries(PACKAGE_REGISTRY)
|
|
155
|
+
.filter(([name, meta]) => {
|
|
156
|
+
if (name === pkg || meta.layer === 'tooling') return false;
|
|
157
|
+
const otherLevel = LAYER_ORDER.indexOf(meta.layer);
|
|
158
|
+
return otherLevel !== -1 && otherLevel < level;
|
|
159
|
+
})
|
|
160
|
+
.map(([name]) => name);
|
|
161
|
+
|
|
162
|
+
return [...new Set([...lower, ...exceptions])];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* `@nage-api/*` packages `pkg` must never import.
|
|
167
|
+
*
|
|
168
|
+
* @param {string} pkg
|
|
169
|
+
* @returns {string[]}
|
|
170
|
+
*/
|
|
171
|
+
export function forbiddenDependencies(pkg) {
|
|
172
|
+
const allowed = new Set(allowedDependencies(pkg));
|
|
173
|
+
return Object.keys(PACKAGE_REGISTRY).filter((name) => name !== pkg && !allowed.has(name));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** @returns {[string, { dir: string; layer: Layer; scaffolded: boolean }][]} */
|
|
177
|
+
export function scaffoldedPackages() {
|
|
178
|
+
return Object.entries(PACKAGE_REGISTRY).filter(([, meta]) => meta.scaffolded);
|
|
179
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nage-api/eslint-config",
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
|
+
"description": "Shared strict ESLint flat config + layered dependency-boundary rules for @nage-api packages",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./layers": "./layers.js",
|
|
11
|
+
"./boundaries": "./boundaries.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"layers.js",
|
|
16
|
+
"boundaries.js",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"eslint": ">=10.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"eslint-config-prettier": "10.1.8",
|
|
27
|
+
"globals": "17.11.0",
|
|
28
|
+
"typescript-eslint": "8.67.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {}
|
|
34
|
+
}
|