@formancy/code-style 0.0.0-stage → 0.12.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 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/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ formancy
2
+ Copyright 2026 Daniel Bacher
3
+
4
+ This product includes software developed by the formancy project.
package/README.md CHANGED
@@ -1,3 +1,106 @@
1
- # Temporary Holding Version
1
+ <!-- Part of formancy: https://github.com/sharkysan/formancy.ai -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @formancy/code-style
4
+
5
+ The lint rules and the format the formancy repositories share: an ESLint
6
+ configuration and Prettier's options, in one JavaScript module that each
7
+ repository calls with its own paths. It names no path of any repository, so
8
+ the repositories hold one set of rules and one style without a copy each.
9
+
10
+ ## Use
11
+
12
+ ```bash
13
+ npm install --save-dev @formancy/code-style eslint prettier typescript
14
+ ```
15
+
16
+ ESLint, Prettier and TypeScript are peers: a repository installs them at
17
+ versions of its own, inside the ranges the manifest declares, each of which
18
+ starts at the version this package's suite runs.
19
+
20
+ It declares no Node of its own. The Node it runs on is ESLint's, which its
21
+ `eslint` peer and its `@eslint/js` dependency both declare as
22
+ `^20.19.0 || ^22.13.0 || >=24` (ESLint 10.13.0 and `@eslint/js` 10.0.1, read on
23
+ 2026-10-30). That is the floor that binds, and it is above the `>=22.12.0`
24
+ formancy.ai's own manifest declares.
25
+
26
+ `eslint.config.mjs`:
27
+
28
+ ```js
29
+ import { eslintConfig } from '@formancy/code-style'
30
+
31
+ export default eslintConfig({
32
+ root: import.meta.dirname,
33
+ project: ['./packages/*/tsconfig.json'],
34
+ ignoreFiles: ['.gitignore'],
35
+ tests: ['**/*.test.{ts,tsx,mjs}'],
36
+ })
37
+ ```
38
+
39
+ `prettier.config.mjs`:
40
+
41
+ ```js
42
+ export { prettierConfig as default } from '@formancy/code-style'
43
+ ```
44
+
45
+ `FILES` is the glob a repository's `format` and `format:check` scripts hand
46
+ Prettier, and `EXTENSIONS` its extensions: TypeScript's and JavaScript's, so
47
+ that neither tool reads a file the other does not.
48
+
49
+ ## The paths a repository passes
50
+
51
+ The module's doc comment on `eslintConfig` is the reference; in short:
52
+
53
+ - **`root`**, absolute: the repository, which the other paths are read from.
54
+ - **`project`**: the tsconfigs that type its TypeScript, by glob.
55
+ - **`ignoreFiles`**: its `.gitignore` files, each read for its own directory, as
56
+ git reads it. Build output, coverage and test results are ignored besides.
57
+ - **`tests`**: its test files, which alone are relaxed.
58
+ - **`untyped`**: TypeScript no tsconfig holds, linted without types.
59
+ - **`browser`**: files that drive a page, which know the page's globals.
60
+ - **`react`**: its React components and hooks.
61
+
62
+ The first four are required, and a call without one is refused where the
63
+ configuration is made: without `tests`, every file would be relaxed. A
64
+ repository's own exception, such as a generated file, is written where it calls
65
+ this, as a `globalIgnores` beside it and a line in `.prettierignore`, and never
66
+ in the module.
67
+
68
+ ## What it holds
69
+
70
+ - **The rules** are `@eslint/js`'s recommended set and typescript-eslint's
71
+ type-aware one, every rule an error or off: a warning is a finding nobody has
72
+ to fix. A name may go unused only if it begins with `_`. A disable comment
73
+ says why after `--`, and one that disables nothing is an error. A typographic
74
+ space is allowed in a string, a template and JSX text, and refused between two
75
+ tokens. Where `react` points, a hook may not run under a condition or miss a
76
+ dependency.
77
+ - **A test is relaxed** for the `no-unsafe-*` rules, `no-explicit-any` and `unbound-method`
78
+ alone, and held to everything else. `require-await` is off in every file: an `async`
79
+ function with no `await` is how a synchronous implementation of an async contract keeps
80
+ its throws as rejections, and `no-floating-promises` and `no-misused-promises` still
81
+ catch a forgotten `await`.
82
+ - **The format** is Prettier's defaults but five: no semicolons, single quotes,
83
+ trailing commas wherever they are allowed, 160 columns, and code embedded in
84
+ a string left as written, because an Angular template's whitespace renders.
85
+
86
+ It ships no type declarations: a repository imports it from a JavaScript
87
+ configuration file. A configuration TypeScript checks with `checkJs` has nothing
88
+ of it typed. Measured with TypeScript 6.0.3 on 2026-10-30: under `noImplicitAny`,
89
+ which `strict` sets, the import is error TS7016, a module with no declaration
90
+ file; without it, every name imported is `any`, so a misspelled option passes the
91
+ check, and a required path left out is refused only when ESLint loads the
92
+ configuration.
93
+
94
+ ## Where it comes from
95
+
96
+ The module and its test, `src/code-style.mjs` and `src/code-style.test.mjs`,
97
+ were written for Formancy Health (formancy.ai-health 0017) and are carried here
98
+ byte for byte; the repositories that copied them pin this package in their place
99
+ once it is released. The test is this package's suite. It lints a repository of
100
+ its own, written to the system's temporary directory, and holds that each rule
101
+ runs at error on the kind of file it is for and that each path does what it
102
+ says. It does not hold that what a rule reports is a defect.
103
+
104
+ `pnpm test:e2e:install` installs the packed tarball with its dependencies and
105
+ peers into a project outside the workspace, and lints and formats a file there
106
+ with it.
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@formancy/code-style",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.12.0",
4
+ "description": "The ESLint rules and the Prettier format the formancy repositories share: one module, which each repository calls with its own paths.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": "./src/code-style.mjs"
10
+ },
11
+ "files": [
12
+ "src/code-style.mjs",
13
+ "LICENSE",
14
+ "NOTICE"
15
+ ],
16
+ "//check:pkg": [
17
+ "publint only, as for @formancy/themes: this package ships one JavaScript module",
18
+ "and no types, so there is nothing for attw to resolve. Nothing here builds or",
19
+ "type-checks either: the module is published as it is written, byte for byte the",
20
+ "copy formancy.ai-health and formancy.ai-data carry until they pin this package."
21
+ ],
22
+ "dependencies": {
23
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.8.1",
24
+ "@eslint/js": "^10.0.1",
25
+ "eslint-plugin-react-hooks": "^7.1.1",
26
+ "globals": "^17.13.0",
27
+ "typescript-eslint": "^8.72.1"
28
+ },
29
+ "peerDependencies": {
30
+ "eslint": "^10.13.0",
31
+ "prettier": "^3.9.10",
32
+ "typescript": "~6.0.3"
33
+ },
34
+ "//peerDependencies": [
35
+ "The tools a repository runs, at versions it chooses, so they are peers. Each",
36
+ "range starts at the version this package's suite runs, which the workspace",
37
+ "catalog pins exactly, and the install gate installs the newest each admits: the",
38
+ "bound of a range is a version something ran (0134). TypeScript's is the",
39
+ "catalog's own range, for 0039's reason; typescript-eslint asks for it."
40
+ ],
41
+ "devDependencies": {
42
+ "@vitest/coverage-v8": "^5.0.1",
43
+ "eslint": "10.13.0",
44
+ "prettier": "3.9.10",
45
+ "publint": "^0.3.24",
46
+ "typescript": "~6.0.3",
47
+ "vitest": "^5.0.1"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/sharkysan/formancy.ai.git",
55
+ "directory": "packages/code-style"
56
+ },
57
+ "homepage": "https://github.com/sharkysan/formancy.ai",
58
+ "bugs": "https://github.com/sharkysan/formancy.ai/issues",
59
+ "scripts": {
60
+ "test:coverage": "vitest run --coverage",
61
+ "test": "vitest run",
62
+ "check:pkg": "publint"
63
+ }
6
64
  }
@@ -0,0 +1,192 @@
1
+ import eslintComments from '@eslint-community/eslint-plugin-eslint-comments/configs'
2
+ import js from '@eslint/js'
3
+ import { defineConfig, includeIgnoreFile } from 'eslint/config'
4
+ import reactHooks from 'eslint-plugin-react-hooks'
5
+ import globals from 'globals'
6
+ import { isAbsolute, resolve } from 'node:path'
7
+ import tseslint from 'typescript-eslint'
8
+
9
+ /**
10
+ * The lint rules and the format the four formancy repositories share: what
11
+ * formancy.ai will publish as `@formancy/code-style`, and until then this
12
+ * file, copied byte for byte into each repository, which calls it with its
13
+ * own paths and pins the package in its place once it is released
14
+ * (formancy.ai-health 0017). Nothing here names a path of one repository;
15
+ * a reason that holds for one alone is written where that one calls it.
16
+ *
17
+ * The rules are @eslint/js's recommended set and typescript-eslint's
18
+ * type-aware one, every rule `error` or `off`: a warning is a finding
19
+ * nobody has to fix. `code-style.test.mjs`, beside this file, holds what
20
+ * each rule and each path does; a repository's own guard holds what it
21
+ * passes, and that every file it holds is linted and formatted by them.
22
+ */
23
+
24
+ const TYPESCRIPT = ['ts', 'tsx', 'mts', 'cts']
25
+ const JAVASCRIPT = ['js', 'jsx', 'mjs', 'cjs']
26
+ const filesOf = (extensions) => `**/*.{${extensions.join(',')}}`
27
+
28
+ /**
29
+ * TypeScript's extensions, then JavaScript's: every file ESLint lints and
30
+ * Prettier formats, one list, so that neither reads a file the other does
31
+ * not.
32
+ */
33
+ export const EXTENSIONS = [...TYPESCRIPT, ...JAVASCRIPT]
34
+
35
+ /** The same, as the glob a repository's `format` and `format:check` scripts hand Prettier. */
36
+ export const FILES = filesOf(EXTENSIONS)
37
+
38
+ /**
39
+ * Prettier's options, and its defaults otherwise. Of the widths measured,
40
+ * 160 columns rewrote the fewest lines (formancy.ai-health 0017), and one
41
+ * width across the four repositories is the point. Code embedded in a
42
+ * string is left as written: Prettier reflowed an Angular component's
43
+ * inline template, whose whitespace renders (formancy.ai-health 0017).
44
+ */
45
+ export const prettierConfig = { semi: false, singleQuote: true, trailingComma: 'all', printWidth: 160, embeddedLanguageFormatting: 'off' }
46
+
47
+ /**
48
+ * Unused names fail unless they begin with `_` -- arguments, variables,
49
+ * caught errors, destructured array elements -- the convention the
50
+ * repositories already had. Both base sets name an unused-variable rule;
51
+ * typescript-eslint's recommended set turns @eslint/js's off, in
52
+ * JavaScript as in TypeScript, so there is one rule and one report per
53
+ * finding.
54
+ */
55
+ const UNUSED_NAMES = {
56
+ args: 'all',
57
+ argsIgnorePattern: '^_',
58
+ vars: 'all',
59
+ varsIgnorePattern: '^_',
60
+ caughtErrors: 'all',
61
+ caughtErrorsIgnorePattern: '^_',
62
+ destructuredArrayIgnorePattern: '^_',
63
+ }
64
+
65
+ /**
66
+ * Off in a test alone: a test reads an untyped body on purpose, and vitest
67
+ * is handed methods to `expect`. `no-explicit-any` is off there for the same
68
+ * reason as the `no-unsafe-*` family: a test types the untyped body it
69
+ * reads as `any` (seven disables in formancy.ai-data's lint fixes quoted it
70
+ * word for word); source is still held to it. Nothing else is relaxed, and
71
+ * test support -- a corpus, a package's test helpers -- is held to every
72
+ * rule.
73
+ */
74
+ const TEST_RELAXATIONS = {
75
+ '@typescript-eslint/no-unsafe-assignment': 'off',
76
+ '@typescript-eslint/no-unsafe-member-access': 'off',
77
+ '@typescript-eslint/no-unsafe-call': 'off',
78
+ '@typescript-eslint/no-unsafe-argument': 'off',
79
+ '@typescript-eslint/no-unsafe-return': 'off',
80
+ '@typescript-eslint/unbound-method': 'off',
81
+ '@typescript-eslint/no-explicit-any': 'off',
82
+ }
83
+
84
+ /**
85
+ * `only-throw-error` allows throwing a value typed `any` or `unknown` by
86
+ * default, and rejecting with the same forwarded value is the same act, so
87
+ * `prefer-promise-reject-errors` allows it too, everywhere: a signal's
88
+ * `reason`, a driver's rejection passed on (nine disable comments in
89
+ * formancy.ai-data's lint fixes gave exactly that reason). A rejection with
90
+ * a known non-Error value, a string or object literal, is still refused.
91
+ */
92
+ const REJECT_ERRORS = ['error', { allowThrowingAny: true, allowThrowingUnknown: true }]
93
+
94
+ /**
95
+ * `require-await` is off everywhere, not in tests alone: an `async` function
96
+ * with no `await` is how a synchronous implementation of an asynchronous
97
+ * contract keeps its throws as rejections, and the rule cannot tell that
98
+ * from an `async` left behind by a refactor. Every repository met it where
99
+ * the contract is async and the body is not. formancy.ai-data, measured on
100
+ * 30 October 2026: 220 findings, 201 of them in tests (`fetch: async () =>
101
+ * new Response(...)`, `readFile: async (p) => ...`), the other 19 Fastify
102
+ * handlers and hooks and test support. formancy.ai, the same day: 68
103
+ * findings left after every other rule was fixed, all in test-support
104
+ * implementations of Promise-returning ports outside test files, each of
105
+ * which throws, so that `async` gives the rejection the real port gives and
106
+ * `Promise.resolve` would change what the code under test meets. A forgotten
107
+ * `await` is still caught by `no-floating-promises` and
108
+ * `no-misused-promises`; what is no longer reported anywhere is a pointless
109
+ * `async` a refactor left behind.
110
+ */
111
+ const NO_REQUIRE_AWAIT = 'off'
112
+
113
+ /**
114
+ * The ESLint configuration for one repository, given its paths:
115
+ *
116
+ * - `root`, absolute: the repository, which the other paths are read from;
117
+ * - `project`: the tsconfigs that type its TypeScript, by glob -- those its
118
+ * typecheck runs, so that a package added is linted with types without
119
+ * an edit;
120
+ * - `ignoreFiles`: its `.gitignore` files, each read for its own directory,
121
+ * as git reads it; build output, coverage and test results are ignored
122
+ * besides;
123
+ * - `tests`: its test files, which alone are relaxed;
124
+ * - `untyped`: TypeScript that none of its tsconfigs holds, linted without
125
+ * types as JavaScript is;
126
+ * - `browser`: files that drive a page, whose callbacks run there, and know
127
+ * the page's globals beside Node's;
128
+ * - `react`: its React components and hooks.
129
+ *
130
+ * The first four are required: one left out would lint otherwise than the
131
+ * repository holds -- without `tests`, every file would be relaxed -- so it
132
+ * is refused here. The last three may be empty.
133
+ */
134
+ export function eslintConfig({ root, project, ignoreFiles, tests, untyped = [], browser = [], react = [] }) {
135
+ if (typeof root !== 'string' || !isAbsolute(root)) throw new TypeError('code-style: root must be an absolute path')
136
+ for (const [name, globs] of Object.entries({ project, ignoreFiles, tests })) {
137
+ if (!Array.isArray(globs) || globs.length === 0) throw new TypeError(`code-style: ${name} must name at least one path`)
138
+ }
139
+ return defineConfig(
140
+ includeIgnoreFile(
141
+ ignoreFiles.map((file) => resolve(root, file)),
142
+ { gitignoreResolution: true },
143
+ ),
144
+ { ignores: ['**/dist/**', '**/coverage/**', '**/test-results/**'] },
145
+ {
146
+ linterOptions: { reportUnusedDisableDirectives: 'error', reportUnusedInlineConfigs: 'error' },
147
+ },
148
+ {
149
+ // typescript-eslint's documented pairing: its type-aware set on every
150
+ // file, and its typed half turned off below where nothing types the
151
+ // file, so that JavaScript is held to its rules that need no types --
152
+ // an expression whose value is dropped, an assertion missing its call
153
+ // among them -- as TypeScript is. Its overrides of @eslint/js's rules
154
+ // that the compiler holds apply to TypeScript alone.
155
+ files: [FILES],
156
+ extends: [js.configs.recommended, tseslint.configs.recommendedTypeChecked],
157
+ languageOptions: { parserOptions: { project, tsconfigRootDir: root } },
158
+ rules: {
159
+ '@typescript-eslint/no-unused-vars': ['error', UNUSED_NAMES],
160
+ '@typescript-eslint/prefer-promise-reject-errors': REJECT_ERRORS,
161
+ '@typescript-eslint/require-await': NO_REQUIRE_AWAIT,
162
+ },
163
+ },
164
+ {
165
+ // JavaScript, and TypeScript that no tsconfig holds, are linted without
166
+ // types, and run in Node: no-undef stays on for JavaScript, and is
167
+ // what is left to catch a misspelt name in a script before the one run
168
+ // that reaches it fails.
169
+ files: [filesOf(JAVASCRIPT), ...untyped],
170
+ extends: [tseslint.configs.disableTypeChecked],
171
+ languageOptions: { globals: globals.node },
172
+ },
173
+ // A page.evaluate callback runs in the page.
174
+ ...(browser.length === 0 ? [] : [{ files: browser, languageOptions: { globals: { ...globals.node, ...globals.browser } } }]),
175
+ {
176
+ // The products speak several languages, whose typography puts narrow
177
+ // spaces in strings and templates; between two tokens of code the
178
+ // same character is an invisible bug.
179
+ rules: { 'no-irregular-whitespace': ['error', { skipStrings: true, skipTemplates: true, skipJSXText: true }] },
180
+ },
181
+ // The two rules a hook's caller breaks, and not react-hooks 7's whole
182
+ // recommended set, which adds the React Compiler's.
183
+ ...(react.length === 0
184
+ ? []
185
+ : [{ files: react, plugins: { 'react-hooks': reactHooks }, rules: { 'react-hooks/rules-of-hooks': 'error', 'react-hooks/exhaustive-deps': 'error' } }]),
186
+ // A disable comment says why, after `--`: a bare one hides a finding
187
+ // without a reason. One that disables nothing is an error above.
188
+ eslintComments.recommended,
189
+ { rules: { '@eslint-community/eslint-comments/require-description': 'error' } },
190
+ { files: tests, rules: TEST_RELAXATIONS },
191
+ )
192
+ }