@sssb/eslint-plugin 0.0.0 → 0.2.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/package.json +40 -5
- package/src/app-config.js +401 -0
- package/src/check-fences.d.ts +20 -0
- package/src/check-fences.js +269 -0
- package/src/import-ban.js +150 -0
- package/src/index.d.ts +22 -0
- package/src/index.js +31 -0
- package/src/patterns.js +318 -0
- package/src/probes.js +129 -0
- package/src/rules.js +611 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rice University
|
|
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/package.json
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sssb/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Reserved for SSSB, a web app foundation maintained by SafeInsights. Not yet released.",
|
|
3
|
+
"version": "0.2.0",
|
|
5
4
|
"license": "MIT",
|
|
6
|
-
"repository": {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/safeinsights/sssb.git",
|
|
8
|
+
"directory": "packages/eslint-plugin"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"description": "SSSB's lint fences as one ESLint plugin: every sssb/* rule, the configs.app({ root }) preset an app composes with its own config, and the probes `sssb check-fences` runs through that composed config. Plain JavaScript that ESLint loads directly; it never depends on @sssb/kit (ADR-0014, part 4).",
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"!src/**/*.test.*"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./src/index.d.ts",
|
|
20
|
+
"default": "./src/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./check-fences": {
|
|
23
|
+
"types": "./src/check-fences.d.ts",
|
|
24
|
+
"default": "./src/check-fences.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=24"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@eslint/js": "^10.0.1",
|
|
32
|
+
"@next/eslint-plugin-next": "^16.4.6",
|
|
33
|
+
"eslint-config-prettier": "^10.1.8",
|
|
34
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
35
|
+
"eslint-plugin-react": "^7.37.5",
|
|
36
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
37
|
+
"ignore": "^5.3.2",
|
|
38
|
+
"typescript-eslint": "^8.72.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"eslint": "^10.13.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
// THE APP PRESET: `await sssb.configs.app({ root })` (ADR-0014, part 4). An app's own `eslint.config.mjs` composes
|
|
2
|
+
// it with whatever else it wants:
|
|
3
|
+
//
|
|
4
|
+
// import sssb from '@sssb/eslint-plugin'
|
|
5
|
+
// export default [...(await sssb.configs.app({ root: import.meta.dirname })), ...myOwnBlocks]
|
|
6
|
+
//
|
|
7
|
+
// `root` is the app's directory, as an ABSOLUTE path: a relative one would be relative to wherever ESLint was
|
|
8
|
+
// started, so the preset refuses it. Every block it returns carries `basePath` (`root` itself, or its parent
|
|
9
|
+
// directory when `root`'s last segment is `*`), and its globs are relative to the app (`src/**`), so the same preset works from the app's own config, from a workspace-root config that passes
|
|
10
|
+
// `join(import.meta.dirname, 'apps/console')`, and whether ESLint runs from the app or from the workspace root. A
|
|
11
|
+
// root whose last segment is `*` (`join(import.meta.dirname, 'apps/*')`) means every app in that directory; SSSB's
|
|
12
|
+
// own repository lints both of its apps that way.
|
|
13
|
+
//
|
|
14
|
+
// It returns the base config an app needs (JavaScript, TypeScript, React, hooks, a11y and Next, with the carve-outs
|
|
15
|
+
// for CommonJS files and migrations, and Prettier's turn-offs last) and every app-side fence, each a rule with an id
|
|
16
|
+
// of its own, so nothing an adopter writes after it in an ordinary `no-restricted-imports` or
|
|
17
|
+
// `no-restricted-syntax` block can replace a fence. What CAN change one (turning an sssb/* rule off, a later block's
|
|
18
|
+
// `ignores`, a nested config file) is what `sssb check-fences` compares against this preset.
|
|
19
|
+
//
|
|
20
|
+
// It is async because it reads the app's own `lint-exceptions.mjs` (below), an ES module. It also reads the app's
|
|
21
|
+
// `package.json` for the vendor SDKs the app's own adapters wrap (`"sssb": { "vendors": [...] }`, below).
|
|
22
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
23
|
+
import { basename, dirname, isAbsolute, join } from 'node:path'
|
|
24
|
+
import { pathToFileURL } from 'node:url'
|
|
25
|
+
import js from '@eslint/js'
|
|
26
|
+
import nextPlugin from '@next/eslint-plugin-next'
|
|
27
|
+
import prettierConfig from 'eslint-config-prettier'
|
|
28
|
+
import jsxA11y from 'eslint-plugin-jsx-a11y'
|
|
29
|
+
import reactPlugin from 'eslint-plugin-react'
|
|
30
|
+
import reactHooksPlugin from 'eslint-plugin-react-hooks'
|
|
31
|
+
import typescriptEslint from 'typescript-eslint'
|
|
32
|
+
import { SRC_EXT, STORY_FILES, TEST_FILES } from './patterns.js'
|
|
33
|
+
|
|
34
|
+
// APP-OWNED LINT EXCEPTIONS. A fence that takes named exceptions should not make an adopter edit SSSB's config, so
|
|
35
|
+
// each app lists its own in `lint-exceptions.mjs` at its root, by path relative to the app, and the preset reads it.
|
|
36
|
+
// The file's default export maps a rule id to entries of `{ file, reason }`; only the rules in APP_EXCEPTION_RULES
|
|
37
|
+
// take one.
|
|
38
|
+
//
|
|
39
|
+
// Each entry names ONE existing file under the app's src/ and says why. Anything else fails the config load, naming
|
|
40
|
+
// the app's file and the entry: a glob, a directory, a path out of the app, a missing reason, a rule that takes no
|
|
41
|
+
// exceptions, or a file that no longer exists. So an exception cannot quietly widen or outlive the file it names (one
|
|
42
|
+
// that outlives its NEED is still the app's to delete). The path is matched literally (a Next route's `[locale]` is
|
|
43
|
+
// not a glob).
|
|
44
|
+
const APP_EXCEPTION_RULES = ['sssb/no-raw-db-handle']
|
|
45
|
+
// The backslash is a glob special too: it escapes the character after it, so a literal one must be escaped itself,
|
|
46
|
+
// or a name holding one would match a different path (a directory read from disk may have one on POSIX).
|
|
47
|
+
const GLOB_SPECIALS = /[\\*?[\]{}()!+@#]/g
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* One app's exceptions, as `ignores` entries relative to the app (glob specials escaped), by rule id.
|
|
51
|
+
* @param {string} appDir
|
|
52
|
+
* @returns {Promise<Record<string, string[]>>}
|
|
53
|
+
*/
|
|
54
|
+
export async function loadAppLintExceptions(appDir) {
|
|
55
|
+
const ignoresByRule = Object.fromEntries(APP_EXCEPTION_RULES.map((rule) => [rule, []]))
|
|
56
|
+
const source = join(appDir, 'lint-exceptions.mjs')
|
|
57
|
+
if (!existsSync(source)) return ignoresByRule
|
|
58
|
+
const fail = (why) => {
|
|
59
|
+
throw new Error(`${source}: ${why}`)
|
|
60
|
+
}
|
|
61
|
+
// Keyed by the file's mtime, so when a config runs again in one process it reads the file as it is now, not the
|
|
62
|
+
// module it cached the first time. ESLint re-runs a config only when the config file itself changes, so an
|
|
63
|
+
// editor's lint server still needs a restart to see an edit to lint-exceptions.mjs.
|
|
64
|
+
const { default: exceptions } = await import(`${pathToFileURL(source).href}?mtime=${statSync(source).mtimeMs}`)
|
|
65
|
+
if (!exceptions || typeof exceptions !== 'object' || Array.isArray(exceptions)) {
|
|
66
|
+
fail('its default export must be an object mapping a rule id to its entries')
|
|
67
|
+
}
|
|
68
|
+
for (const [rule, entries] of Object.entries(exceptions)) {
|
|
69
|
+
if (!APP_EXCEPTION_RULES.includes(rule)) {
|
|
70
|
+
fail(`\`${rule}\` takes no app exceptions (only ${APP_EXCEPTION_RULES.join(', ')} does)`)
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(entries)) fail(`\`${rule}\` must map to an array of { file, reason } entries`)
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const { file, reason } = entry ?? {}
|
|
75
|
+
if (typeof file !== 'string' || file.trim() === '') fail(`an entry under \`${rule}\` names no file`)
|
|
76
|
+
if (/[*?]/.test(file)) fail(`\`${file}\` is a glob: an exception names one file`)
|
|
77
|
+
if (!file.startsWith('src/') || file.includes('\\') || file.split('/').includes('..')) {
|
|
78
|
+
fail(`\`${file}\` must be a path under the app's src/, relative to the app, with / separators`)
|
|
79
|
+
}
|
|
80
|
+
const target = join(appDir, file)
|
|
81
|
+
if (!existsSync(target) || !statSync(target).isFile()) {
|
|
82
|
+
fail(`\`${file}\` names no file: an exception names one existing file, never a directory`)
|
|
83
|
+
}
|
|
84
|
+
if (typeof reason !== 'string' || reason.trim() === '') fail(`\`${file}\` needs a reason`)
|
|
85
|
+
ignoresByRule[rule].push(file.replace(GLOB_SPECIALS, '\\$&'))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return ignoresByRule
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// THE APP'S OWN VENDORS. An adapter the app owns (docs/recipes/app-owned-adapter.md) wraps a vendor SDK SSSB's list
|
|
92
|
+
// does not name, and the app adds it to the ban in its own package.json: `"sssb": { "vendors": ["stripe", "stripe/*"] }`,
|
|
93
|
+
// in the gitignore-style patterns SSSB's list uses. A file, not a `configs.app` option, so `sssb check-fences` reads
|
|
94
|
+
// the same list the preset does and compares the rules' options EXACTLY: a later block that sets the vendor rules'
|
|
95
|
+
// options for some directory, replacing the app's list there, shows up as options the preset does not set. A pattern
|
|
96
|
+
// that starts with `!` is refused: in gitignore syntax it is a negation, and it would take a vendor OFF SSSB's list.
|
|
97
|
+
/**
|
|
98
|
+
* The app's own vendor patterns, from its package.json's `sssb.vendors`; [] when it names none.
|
|
99
|
+
* @param {string} appDir
|
|
100
|
+
* @returns {string[]}
|
|
101
|
+
*/
|
|
102
|
+
function loadAppVendors(appDir) {
|
|
103
|
+
const manifest = join(appDir, 'package.json')
|
|
104
|
+
if (!existsSync(manifest)) return []
|
|
105
|
+
const vendors = JSON.parse(readFileSync(manifest, 'utf8')).sssb?.vendors
|
|
106
|
+
if (vendors === undefined) return []
|
|
107
|
+
const fail = (why) => {
|
|
108
|
+
throw new Error(`${manifest}: sssb.vendors ${why}`)
|
|
109
|
+
}
|
|
110
|
+
if (!Array.isArray(vendors)) fail('must be a list of package patterns, such as ["stripe", "stripe/*"]')
|
|
111
|
+
for (const vendor of vendors) {
|
|
112
|
+
if (typeof vendor !== 'string' || vendor.trim() === '' || vendor !== vendor.trim()) {
|
|
113
|
+
fail(`holds ${JSON.stringify(vendor)}: each entry is a package pattern, such as "stripe" or "stripe/*"`)
|
|
114
|
+
}
|
|
115
|
+
if (vendor.startsWith('!')) {
|
|
116
|
+
fail(
|
|
117
|
+
`holds ${JSON.stringify(vendor)}: a leading ! un-bans a vendor, and the app's list only adds to SSSB's`,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return vendors
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Where the preset's blocks are anchored, and the apps under it: `{ basePath, prefix, apps }`, where `prefix` is
|
|
126
|
+
* prepended to every app-relative glob and `apps` lists each app's directory and its prefix.
|
|
127
|
+
* @param {string} root
|
|
128
|
+
*/
|
|
129
|
+
function resolveRoot(root) {
|
|
130
|
+
if (typeof root !== 'string' || !isAbsolute(root)) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
"@sssb/eslint-plugin: configs.app({ root }) takes the app's directory as an ABSOLUTE path " +
|
|
133
|
+
`(import.meta.dirname from the app's eslint.config.mjs), not ${JSON.stringify(root)}: a relative ` +
|
|
134
|
+
'root would be relative to wherever ESLint was started.',
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
if (basename(root) !== '*') return { basePath: root, prefix: '', apps: [{ dir: root, prefix: '' }] }
|
|
138
|
+
const parent = dirname(root)
|
|
139
|
+
if (parent.includes('*')) throw new Error(`@sssb/eslint-plugin: only a last segment of \`*\` is a glob (${root})`)
|
|
140
|
+
const apps = existsSync(parent)
|
|
141
|
+
? readdirSync(parent, { withFileTypes: true })
|
|
142
|
+
.filter((entry) => entry.isDirectory())
|
|
143
|
+
.map((entry) => entry.name)
|
|
144
|
+
.sort()
|
|
145
|
+
.map((name) => ({
|
|
146
|
+
dir: join(parent, name),
|
|
147
|
+
// The directory's name is matched literally, as an exception's file is.
|
|
148
|
+
prefix: `${name.replace(GLOB_SPECIALS, '\\$&')}/`,
|
|
149
|
+
}))
|
|
150
|
+
: []
|
|
151
|
+
return { basePath: parent, prefix: '*/', apps }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* `dir` as a glob Next's `settings.next.rootDir` matches to exactly that directory. Next replaces every backslash with
|
|
156
|
+
* a slash before fast-glob reads it, so a backslash escape becomes a path separator; a one-character class (`[(]`)
|
|
157
|
+
* survives. `!` stays as it is: `[!]` would be a negated class, and a `!` past the start of a pattern is literal.
|
|
158
|
+
* @param {string} dir
|
|
159
|
+
*/
|
|
160
|
+
const nextRootDir = (dir) => dir.replace(/[*?{}()+@#[\]]/g, (char) => `[${char}]`)
|
|
161
|
+
|
|
162
|
+
// Next loads its config from these four names and no other (CONFIG_FILES in next's shared/lib/constants).
|
|
163
|
+
const NEXT_CONFIG = 'next.config.{ts,mts,js,mjs}'
|
|
164
|
+
// The files that legitimately reach a vendor directly, under an app prefix: Next's config, the contract tests, and the
|
|
165
|
+
// app's deployment (`infra/`, a CDK project of its own beside the app, never on its module graph; ADR-0014, D8).
|
|
166
|
+
const carveOuts = (prefix) => [`${prefix}${NEXT_CONFIG}`, `${prefix}tests/contract/**`, `${prefix}infra/**`]
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @param {import('eslint').ESLint.Plugin} plugin the one plugin object (./index.js)
|
|
170
|
+
* @param {{ root: string }} options
|
|
171
|
+
* @returns {Promise<import('eslint').Linter.Config[]>}
|
|
172
|
+
*/
|
|
173
|
+
export async function appConfig(plugin, options = /** @type {any} */ ({})) {
|
|
174
|
+
const { root, ...rest } = options
|
|
175
|
+
if (Object.keys(rest).length > 0) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`@sssb/eslint-plugin: configs.app takes { root } and nothing else, not ${Object.keys(rest).join(', ')}: ` +
|
|
178
|
+
'an app\'s own vendor SDKs go in its package.json, as "sssb": { "vendors": [...] }',
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
const { basePath, prefix: P, apps } = resolveRoot(root)
|
|
182
|
+
const exceptions = { 'sssb/no-raw-db-handle': [] }
|
|
183
|
+
for (const app of apps) {
|
|
184
|
+
const loaded = await loadAppLintExceptions(app.dir)
|
|
185
|
+
for (const [rule, files] of Object.entries(loaded)) {
|
|
186
|
+
exceptions[rule].push(...files.map((file) => `${app.prefix}${file}`))
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const src = (dir) => `${P}src/${dir}`
|
|
190
|
+
// Every file under each app-relative directory, every extension; '' is the whole app.
|
|
191
|
+
const files = (...dirs) => dirs.map((dir) => `${P}${dir ? `${dir}/` : ''}**/*.${SRC_EXT}`)
|
|
192
|
+
const sssb = { sssb: plugin }
|
|
193
|
+
/** @type {(name: string, block: import('eslint').Linter.Config) => import('eslint').Linter.Config} */
|
|
194
|
+
const at = (name, block) => ({ ...block, name: `sssb/app/${name}`, basePath })
|
|
195
|
+
|
|
196
|
+
return [
|
|
197
|
+
at('ignores', {
|
|
198
|
+
// Build and test output, at the app's root only: the same names deeper in the app (`src/coverage/`) are
|
|
199
|
+
// source a route can import, and fenced like any other.
|
|
200
|
+
ignores: [
|
|
201
|
+
'**/node_modules/**',
|
|
202
|
+
`${P}.next/**`,
|
|
203
|
+
`${P}.data/**`,
|
|
204
|
+
`${P}next-env.d.ts`,
|
|
205
|
+
`${P}.ladle/dist/**`,
|
|
206
|
+
`${P}dist-demo/**`,
|
|
207
|
+
`${P}test-results/**`,
|
|
208
|
+
`${P}playwright-report/**`,
|
|
209
|
+
`${P}coverage/**`,
|
|
210
|
+
`${P}infra/cdk.out/**`,
|
|
211
|
+
// What Panda 2's codegen writes there (`.js` and `.d.ts`, its default `outExtension`): a hand-written
|
|
212
|
+
// `.ts`, `.mjs` or any other extension in that directory is fenced like any other module. A
|
|
213
|
+
// hand-written `.js` is not, since it has the extension of Panda's own output.
|
|
214
|
+
`${src('styles/generated')}/**/*.{js,d.ts}`,
|
|
215
|
+
],
|
|
216
|
+
}),
|
|
217
|
+
|
|
218
|
+
// ---- the base config ---------------------------------------------------------------------------------
|
|
219
|
+
at('js', js.configs.recommended),
|
|
220
|
+
// typescript-eslint's `configs.recommended` is a getter that records the calling config file's directory as a
|
|
221
|
+
// candidate tsconfigRootDir, and its parser refuses to guess once there are two (a workspace-root config and an
|
|
222
|
+
// app's own, loaded by one ESLint run). So the preset reads the same objects from the raw plugin, which records
|
|
223
|
+
// nothing, and names the root itself.
|
|
224
|
+
...typescriptEslint.plugin.configs['flat/recommended'].map((block, i) => at(`typescript-${i}`, block)),
|
|
225
|
+
at('typescript-root', { languageOptions: { parserOptions: { tsconfigRootDir: basePath } } }),
|
|
226
|
+
at('commonjs', {
|
|
227
|
+
files: ['**/*.cjs'],
|
|
228
|
+
languageOptions: {
|
|
229
|
+
sourceType: 'commonjs',
|
|
230
|
+
globals: { module: 'writable', require: 'readonly', __dirname: 'readonly', process: 'readonly' },
|
|
231
|
+
},
|
|
232
|
+
}),
|
|
233
|
+
// Kysely migrations are conventionally typed Kysely<any> (the schema evolves under them).
|
|
234
|
+
at('migrations', { files: ['**/migrations/**/*.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off' } }),
|
|
235
|
+
// Every extension: sssb/no-jsx-literals runs react's rule, and a `.mjs` screen renders copy too.
|
|
236
|
+
at('react', {
|
|
237
|
+
files: [`**/*.${SRC_EXT}`],
|
|
238
|
+
plugins: { react: reactPlugin, 'react-hooks': reactHooksPlugin, 'jsx-a11y': jsxA11y },
|
|
239
|
+
rules: {
|
|
240
|
+
...reactPlugin.configs.recommended.rules,
|
|
241
|
+
...reactPlugin.configs['jsx-runtime'].rules,
|
|
242
|
+
...reactHooksPlugin.configs.recommended.rules,
|
|
243
|
+
...jsxA11y.configs.recommended.rules,
|
|
244
|
+
'react/prop-types': 'off',
|
|
245
|
+
},
|
|
246
|
+
// Explicit version: eslint-plugin-react's 'detect' path uses context.getFilename, which ESLint 10
|
|
247
|
+
// removed. Bump alongside React upgrades.
|
|
248
|
+
settings: { react: { version: '19.2' } },
|
|
249
|
+
}),
|
|
250
|
+
at('next', {
|
|
251
|
+
files: files('src'),
|
|
252
|
+
plugins: { '@next/next': nextPlugin },
|
|
253
|
+
rules: nextPlugin.configs.recommended.rules,
|
|
254
|
+
// Where Next's rules look for each app's `app/` and `pages/` (`no-html-link-for-pages`): the apps, not the
|
|
255
|
+
// directory ESLint runs from, which from the workspace root has neither, and warns "Pages directory cannot
|
|
256
|
+
// be found". Each is a glob to Next (fast-glob), which turns every backslash into a slash first, so a
|
|
257
|
+
// special character in a path is escaped as a one-character class instead (nextRootDir).
|
|
258
|
+
settings: { next: { rootDir: apps.map((app) => nextRootDir(app.dir)) } },
|
|
259
|
+
}),
|
|
260
|
+
|
|
261
|
+
// ---- the fences ----------------------------------------------------------------------------------------
|
|
262
|
+
// THE TENANCY BAN (ADR-0004), deny-by-default: no module in the app's src/ takes the raw db handle, so every
|
|
263
|
+
// tenant-scoped query goes through withTenant and RLS tenant context is always set. A directory nobody has
|
|
264
|
+
// thought of yet is inside, and what needs the raw client is a named exception in the app's
|
|
265
|
+
// lint-exceptions.mjs, with a reason. Tests are exempt (a test resolving seed ids by slug to arrange a case
|
|
266
|
+
// is not a request path), except a route's or a screen's, which drives the code a request runs (the next
|
|
267
|
+
// block).
|
|
268
|
+
at('tenancy', {
|
|
269
|
+
files: files('src'),
|
|
270
|
+
ignores: [TEST_FILES, ...exceptions['sssb/no-raw-db-handle']],
|
|
271
|
+
plugins: sssb,
|
|
272
|
+
rules: { 'sssb/no-raw-db-handle': 'error' },
|
|
273
|
+
}),
|
|
274
|
+
at('tenancy-in-screen-tests', {
|
|
275
|
+
files: ['app', 'components', 'demo-static'].map((dir) => `${src(dir)}/${TEST_FILES}`),
|
|
276
|
+
ignores: exceptions['sssb/no-raw-db-handle'],
|
|
277
|
+
plugins: sssb,
|
|
278
|
+
rules: { 'sssb/no-raw-db-handle': 'error' },
|
|
279
|
+
}),
|
|
280
|
+
// PARAMS CENTRALIZATION: process.env is read ONLY inside an app's own real adapters (and SSSB's). Every other
|
|
281
|
+
// module imports the resolved value: the app's config/params.ts for deployment params, isSimulated/isDemoMode
|
|
282
|
+
// from @sssb/kit/adapters for the run mode. config/ too: params.ts records names and placeholders and never
|
|
283
|
+
// reads the environment, and without it the directory beside src/ was the obvious place for a helper that
|
|
284
|
+
// hands the registry its own reading of APP_MODE. Exempt: real/, Next's two instrumentation hooks under the
|
|
285
|
+
// default pageExtensions (NEXT_PUBLIC_* needs literal inlining; `instrumentation-helpers.ts` is an ordinary
|
|
286
|
+
// module), and tests (which set APP_DATA_DIR for isolation). The app-root tool configs (Playwright, Vite,
|
|
287
|
+
// Ladle) may read it.
|
|
288
|
+
at('process-env', {
|
|
289
|
+
files: files('src', 'config'),
|
|
290
|
+
ignores: [`${src('adapters/real')}/**`, `${src('instrumentation{,-client}')}.{ts,tsx,js,jsx}`, TEST_FILES],
|
|
291
|
+
plugins: sssb,
|
|
292
|
+
rules: { 'sssb/no-process-env': 'error' },
|
|
293
|
+
}),
|
|
294
|
+
// An app's REAL adapters read their own configuration from process.env, but never the run mode.
|
|
295
|
+
at('run-mode', {
|
|
296
|
+
files: files('src/adapters/real'),
|
|
297
|
+
ignores: [TEST_FILES],
|
|
298
|
+
plugins: sssb,
|
|
299
|
+
rules: { 'sssb/no-run-mode-env': 'error' },
|
|
300
|
+
}),
|
|
301
|
+
// Accessible names, placeholders, titles and alt text are copy (ADR-0008). Routes, screens and the adapters
|
|
302
|
+
// directory, where a real-mode-only component (a vendor widget) or a fake renders copy. Stories render
|
|
303
|
+
// fixtures, not shipped copy.
|
|
304
|
+
at('a11y-copy', {
|
|
305
|
+
files: files('src/app', 'src/components', 'src/adapters'),
|
|
306
|
+
ignores: [TEST_FILES, STORY_FILES],
|
|
307
|
+
plugins: sssb,
|
|
308
|
+
rules: { 'sssb/no-literal-a11y-copy': 'error' },
|
|
309
|
+
}),
|
|
310
|
+
// i18n: UI code holds no hard-coded strings (ADR-0008). demo-static is included: the `file://` shell and the
|
|
311
|
+
// app's static twin are user-visible UI that ships to whoever is handed dist-demo/index.html.
|
|
312
|
+
at('jsx-literals', {
|
|
313
|
+
files: files('src/app', 'src/components', 'src/demo-static', 'src/adapters'),
|
|
314
|
+
plugins: sssb,
|
|
315
|
+
rules: { 'sssb/no-jsx-literals': 'error' },
|
|
316
|
+
}),
|
|
317
|
+
// THE PORTS BOUNDARY: vendor SDKs only in the app's real adapters (ADR-0012, addendum 2026-11-16), in every
|
|
318
|
+
// file of the app, not only src/: `config/app.ts` is on the runtime module graph and `config/params.ts` is
|
|
319
|
+
// imported by `next.config.ts`. The three carve-outs (carveOuts) are the only files that legitimately reach a
|
|
320
|
+
// vendor directly, and all three are outside the request path: `next.config.*` composes the Sentry BUILD plugin
|
|
321
|
+
// (`withSentryConfig`), a bundler wrapper rather than an SDK call (ADR-0010); `tests/contract/**` drives real
|
|
322
|
+
// Postgres through `pg` on purpose, which IS the anti-drift proof; `infra/**` is the app's deployment, a CDK
|
|
323
|
+
// project that runs at synth. The registry and fakes are NOT carved out:
|
|
324
|
+
// they are what keep `pnpm dev` hermetic, so they keep the ban.
|
|
325
|
+
//
|
|
326
|
+
// SSSB's list holds for every app, an app directory not yet created included. An app that names its own vendors
|
|
327
|
+
// (loadAppVendors) gets a second block after it, over that app's files alone, whose options carry the app's list:
|
|
328
|
+
// a later block's options replace an earlier one's for the files both match.
|
|
329
|
+
at('vendor', {
|
|
330
|
+
files: files(''),
|
|
331
|
+
ignores: [`${src('adapters/real')}/**`, ...carveOuts(P)],
|
|
332
|
+
plugins: sssb,
|
|
333
|
+
rules: { 'sssb/no-vendor-import': 'error', 'sssb/no-dynamic-vendor-import': 'error' },
|
|
334
|
+
}),
|
|
335
|
+
...apps.flatMap((app) => {
|
|
336
|
+
const vendors = loadAppVendors(app.dir)
|
|
337
|
+
if (vendors.length === 0) return []
|
|
338
|
+
const A = app.prefix
|
|
339
|
+
const ban = ['error', { vendors }]
|
|
340
|
+
return [
|
|
341
|
+
at(`vendor/${A ? A.slice(0, -1) : 'app'}`, {
|
|
342
|
+
files: [`${A}**/*.${SRC_EXT}`],
|
|
343
|
+
ignores: [`${A}src/adapters/real/**`, ...carveOuts(A)],
|
|
344
|
+
plugins: sssb,
|
|
345
|
+
rules: { 'sssb/no-vendor-import': ban, 'sssb/no-dynamic-vendor-import': ban },
|
|
346
|
+
}),
|
|
347
|
+
]
|
|
348
|
+
}),
|
|
349
|
+
// Hermetic dev, everywhere in the app but its deployment, which is not app source.
|
|
350
|
+
at('next-font', {
|
|
351
|
+
files: files(''),
|
|
352
|
+
ignores: [`${P}infra/**`],
|
|
353
|
+
plugins: sssb,
|
|
354
|
+
rules: { 'sssb/no-next-font-google': 'error' },
|
|
355
|
+
}),
|
|
356
|
+
// Outside the adapters directory, the app's real adapters are reached through its registry. The same three
|
|
357
|
+
// carve-outs as the vendor ban.
|
|
358
|
+
at('real-adapters-via-registry', {
|
|
359
|
+
files: files(''),
|
|
360
|
+
ignores: [`${src('adapters')}/**`, ...carveOuts(P)],
|
|
361
|
+
plugins: sssb,
|
|
362
|
+
rules: { 'sssb/no-real-adapter-import': 'error' },
|
|
363
|
+
}),
|
|
364
|
+
// SSSB's real adapters load their vendor SDK, so they are reached only by import(), deny-by-default over every
|
|
365
|
+
// file of the app, tests and stories included: a module outside src/ (a `lib/`, a test helper, a script) could
|
|
366
|
+
// otherwise re-export one into src/ with every check green. Ignored where the vendor ban is: the app's own real
|
|
367
|
+
// adapters, which may build on one as they import a vendor, and the three carve-outs.
|
|
368
|
+
at('kit-real-adapters-by-import', {
|
|
369
|
+
files: files(''),
|
|
370
|
+
ignores: [`${src('adapters/real')}/**`, ...carveOuts(P)],
|
|
371
|
+
plugins: sssb,
|
|
372
|
+
rules: { 'sssb/no-kit-real-adapter-import': 'error' },
|
|
373
|
+
}),
|
|
374
|
+
// Inside it, the registry and the fakes: no static import of real/ (the registry's import() is the only way
|
|
375
|
+
// in).
|
|
376
|
+
at('registry-and-fakes', {
|
|
377
|
+
files: files('src/adapters'),
|
|
378
|
+
ignores: [`${src('adapters/real')}/**`],
|
|
379
|
+
plugins: sssb,
|
|
380
|
+
rules: { 'sssb/no-static-real-adapter-import': 'error' },
|
|
381
|
+
}),
|
|
382
|
+
// ...and only the registry loads real/ dynamically. The registry is `index.ts` and nothing else, as the
|
|
383
|
+
// recipe names it: an `index.mjs` beside it is one more module that may not load real/. Stories keep it: a
|
|
384
|
+
// fake's story that did `import('../real/kv')` would put the vendor SDK in the workshop.
|
|
385
|
+
at('only-the-registry-loads-real', {
|
|
386
|
+
files: files('src/adapters'),
|
|
387
|
+
ignores: [`${src('adapters/real')}/**`, `${src('adapters')}/index.ts`, TEST_FILES],
|
|
388
|
+
plugins: sssb,
|
|
389
|
+
rules: { 'sssb/no-dynamic-real-adapter-import': 'error' },
|
|
390
|
+
}),
|
|
391
|
+
// No raw mkdtemp in tests: every unit test, and everything under tests/ (Playwright's default testMatch picks
|
|
392
|
+
// up `.spec.mjs` and `.test.js`, and a support helper can be either).
|
|
393
|
+
at('no-direct-mkdtemp', {
|
|
394
|
+
files: [`${P}${TEST_FILES}`, ...files('tests')],
|
|
395
|
+
plugins: sssb,
|
|
396
|
+
rules: { 'sssb/no-direct-mkdtemp': 'error' },
|
|
397
|
+
}),
|
|
398
|
+
|
|
399
|
+
at('prettier', prettierConfig),
|
|
400
|
+
]
|
|
401
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ESLint } from 'eslint'
|
|
2
|
+
|
|
3
|
+
export interface CheckFencesOptions {
|
|
4
|
+
/** The app's directory. */
|
|
5
|
+
appDir: string
|
|
6
|
+
/** The ESLint class to probe with; by default, the `eslint` the app's directory resolves. */
|
|
7
|
+
ESLint?: typeof ESLint
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CheckFencesResult {
|
|
11
|
+
/** One line per fence the app's composed config has lost; empty when every fence holds. */
|
|
12
|
+
problems: string[]
|
|
13
|
+
/** How many of the app's source files had their effective config compared with the preset's. */
|
|
14
|
+
files: number
|
|
15
|
+
/** How many virtual files were linted: the fence probes, and two per lint-exceptions.mjs entry. */
|
|
16
|
+
probes: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Probe an app's composed lint config against `configs.app({ root: appDir })`. */
|
|
20
|
+
export function checkFences(options: CheckFencesOptions): Promise<CheckFencesResult>
|