@zukhruf/eslint 0.3.54 → 0.3.56
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/README.md +30 -1
- package/dist/better-auth/config.d.ts +3 -0
- package/dist/better-auth/config.d.ts.map +1 -0
- package/dist/better-auth/config.js +22 -0
- package/dist/better-auth/config.js.map +1 -0
- package/dist/better-auth/no-api-error-instanceof.d.ts +3 -0
- package/dist/better-auth/no-api-error-instanceof.d.ts.map +1 -0
- package/dist/better-auth/no-api-error-instanceof.js +62 -0
- package/dist/better-auth/no-api-error-instanceof.js.map +1 -0
- package/dist/better-auth/no-on-api-error-throw.d.ts +9 -0
- package/dist/better-auth/no-on-api-error-throw.d.ts.map +1 -0
- package/dist/better-auth/no-on-api-error-throw.js +15 -0
- package/dist/better-auth/no-on-api-error-throw.js.map +1 -0
- package/dist/hono/config.d.ts.map +1 -1
- package/dist/hono/config.js +7 -1
- package/dist/hono/config.js.map +1 -1
- package/dist/hono/no-catch-around-next.d.ts +4 -0
- package/dist/hono/no-catch-around-next.d.ts.map +1 -0
- package/dist/hono/no-catch-around-next.js +56 -0
- package/dist/hono/no-catch-around-next.js.map +1 -0
- package/dist/hono/no-http-exception-factory.d.ts +11 -0
- package/dist/hono/no-http-exception-factory.d.ts.map +1 -0
- package/dist/hono/no-http-exception-factory.js +21 -0
- package/dist/hono/no-http-exception-factory.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -1
- package/dist/test-files/no-test-lifecycle-hooks.d.ts.map +1 -1
- package/dist/test-files/no-test-lifecycle-hooks.js +130 -7
- package/dist/test-files/no-test-lifecycle-hooks.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,7 +49,8 @@ Put framework presets (for example Nx's `flat/react`) **before** the zukhruf con
|
|
|
49
49
|
| `packaged-app` | TypeScript, not tests | `no-bare-spawn` |
|
|
50
50
|
| `react` | `.tsx`, `.jsx` | `no-as-child` |
|
|
51
51
|
| `react-router` | source | `require-loader-data-type-argument`; outside tests: `no-raw-route-path`, `no-internal-anchor`; TypeScript: `only-throw-error` allows a `Response` and `DataWithResponseInit` |
|
|
52
|
-
| `hono` | TypeScript, not tests | `no-untyped-empty-json`
|
|
52
|
+
| `hono` | TypeScript, not tests | `no-untyped-empty-json`, `no-http-exception-factory`, `no-catch-around-next` |
|
|
53
|
+
| `better-auth` | TypeScript, not tests | `no-api-error-instanceof`, `no-on-api-error-throw` |
|
|
53
54
|
| `tailwind` | source | `no-h-screen`, `no-arbitrary-z-index`, `no-will-change` |
|
|
54
55
|
| `pulumi` | TypeScript | `require-server-replace-guard` |
|
|
55
56
|
| `nx-project-json` | `project.json` | `no-missing-asset-input` |
|
|
@@ -60,6 +61,16 @@ Put framework presets (for example Nx's `flat/react`) **before** the zukhruf con
|
|
|
60
61
|
|
|
61
62
|
`zukhruf/no-phase-flag` reads each class field's type too. It reports a field that is a boolean, or that can be `undefined`, when code outside the constructor sets it. A callback that the constructor creates runs later, so its assignment counts as outside. Such a field records a phase, and every reader must know which phase holds. Push the fact as an event, wait on a one-shot latch, keep the phases in state objects, or ask the platform for the fact.
|
|
62
63
|
|
|
64
|
+
`zukhruf/no-test-lifecycle-hooks` keeps the arrange and the teardown of a test in that test. A hook moves them out, so the reader does not see the full test, and the state that one test leaves can reach the next test. A per-test `t.after()` of node:test also moves the teardown out of the flow of the test. The rule reads the names of the scope, not only the text. It reports a hook from the Vitest, Jest or Mocha globals, and from an import, also under a different name (`import { after as cleanup }`). It reports a hook on `test` or `it` of node:test, or on its namespace (`test.after()`). It reports a hook on a test context: the first parameter of a test callback or a subtest callback of node:test, or a parameter of the type `TestContext`. A function of the file that has the name `after` is not a hook. Put the teardown in `try`/`finally`, or use `await using` with a disposable.
|
|
65
|
+
|
|
66
|
+
`zukhruf/no-http-exception-factory` reports a function that only returns `new HTTPException(…)`. The function hides the status and the cause code behind a name, so the reader of the throw site cannot see what the client gets. Write `throw new HTTPException(status, { message, cause: { code, detail } })` in full at each throw site, also when many sites use the same code. A function with more statements than the `return`, such as a branch, stays. A lookup in the arguments of the exception does not change the result: put the lookup in a function of its own, and keep the exception at the throw site. A class method that returns the exception, such as `toHTTPException()`, also stays: each class translates its own error.
|
|
67
|
+
|
|
68
|
+
`zukhruf/no-catch-around-next` reports the `catch` of a `try` block that only calls `await next()` or `return next()`. Hono's `compose()` catches the error of each handler and gives it to the app's error handler. An app always has an error handler, because Hono adds a default one. Thus `next()` does not reject with an `Error`, and the `catch` never runs. Translate the error at the throw site, or read `c.error` after `next()`. The rule applies only to a file that imports `hono` or `hono/*`. In Koa, the same `catch` is the error handler that the Koa documentation shows.
|
|
69
|
+
|
|
70
|
+
`zukhruf/no-api-error-instanceof` reports `instanceof APIError` when `APIError` comes from `better-auth`, `better-auth/api`, `@better-auth/core/error`, `better-call` or `better-call/error`. The `APIError` of better-auth extends the `APIError` of better-call. Thus an `APIError` that better-call throws is not an instance of the better-auth class, and the error goes to the 500 path. Use `isAPIError(error)` from `better-auth/api`. It checks the two classes and the name of the error. An `APIError` from a different module, such as a generated client, is not reported.
|
|
71
|
+
|
|
72
|
+
`zukhruf/no-on-api-error-throw` reports `onAPIError: { throw: true }`. With this option, better-auth throws the error again before `onAPIError.onError` and before its own log. The router of better-call catches that error and makes a response from it, so the error handler of the app does not run, and no log shows a 4xx error. Log the error in `onAPIError.onError`.
|
|
73
|
+
|
|
63
74
|
### Options for a repo
|
|
64
75
|
|
|
65
76
|
Give repo-specific values as rule options. For example:
|
|
@@ -218,3 +229,21 @@ npx nx run eslint:test # builds, then runs the rule and composition tests
|
|
|
218
229
|
```
|
|
219
230
|
|
|
220
231
|
The composition tests run the real ESLint CLI on temporary workspaces. They load the built package, which is what consumers install.
|
|
232
|
+
|
|
233
|
+
### Add a check
|
|
234
|
+
|
|
235
|
+
A check is a rule under its own key ([ADR 0001](./docs/adr/0001-one-key-per-check.md)). Before you write a visitor by hand, use the builders in `src/authoring/`:
|
|
236
|
+
|
|
237
|
+
- `importBanRule()` bans packages and their subpaths. It reports static imports, re-exports and literal dynamic imports, type-only ones included.
|
|
238
|
+
- `selectorRule()` reports each node that one of its esquery selectors matches. The substring operator `*=` never matches a Literal's `value`, so write a regex selector (`[value=/…/]`). A `:has(> A > B)` with more than one level never matches, so nest it: `:has(> A:has(> B))`.
|
|
239
|
+
- `scopedRule()` turns a rule on only for the files that its function accepts. Build that function from `isTestFile()`, `inRoots()` and `matchesAnyGlob()` in `path-scope.ts`. A rule finds its scope from the linted file, not from a config glob ([ADR 0002](./docs/adr/0002-scope-from-the-linted-file.md)).
|
|
240
|
+
- `ast.ts` has the type guards for a visitor: `isAstNode()`, `isType()` and `identifierName()`.
|
|
241
|
+
|
|
242
|
+
Folders that differ from repo to repo are `roots` options. A fact about the repo is a repo setting. A rule whose options a repo extends gets an option factory ([ADR 0004](./docs/adr/0004-option-factories.md)).
|
|
243
|
+
|
|
244
|
+
1. Put the rule in the folder of the subject that it checks, such as `src/async-values/` or `src/imports/`. The file exports the rule as its default.
|
|
245
|
+
2. Put `<rule>.test.ts` next to it. Use `typescriptRuleTester()` from `src/testing/rule-tester.ts`, or `typedRuleTester(root)` when the rule reads types. Call `run()` inside a node:test `test()`.
|
|
246
|
+
3. Add the rule to the `rules` map in the `config.ts` of its concept, and turn on `zukhruf/<rule>` in that concept's config. A new concept also goes into the `concepts` list in `src/plugin.ts`. The composition tests fail when not exactly one config turns on a rule, when a config sets a repo-owned rule, or when a shipped glob does not start with `**`.
|
|
247
|
+
4. Add the rule to its concept's row in the Configs table. Below the table, write a paragraph that tells why the check exists.
|
|
248
|
+
5. Fix the findings that the new rule reports in the other packages of this workspace, in the same commit (for example 20b34e0). The workspace lints itself with this source. When a package must keep its code, turn the rule off for those files in the root `eslint.config.mjs`, with a comment that tells why (for example 495f19d).
|
|
249
|
+
6. Run `npx nx run eslint:test` and `npx nx run eslint:typecheck`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/better-auth/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;AAUrD,eAAO,MAAM,UAAU,EAAE,OAYxB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { enable } from "../concept.js";
|
|
2
|
+
import { TESTS, TEST_SUPPORT, TYPESCRIPT } from "../files.js";
|
|
3
|
+
import noApiErrorInstanceof from "./no-api-error-instanceof.js";
|
|
4
|
+
import noOnApiErrorThrow from "./no-on-api-error-throw.js";
|
|
5
|
+
const rules = {
|
|
6
|
+
'no-api-error-instanceof': noApiErrorInstanceof,
|
|
7
|
+
'no-on-api-error-throw': noOnApiErrorThrow,
|
|
8
|
+
};
|
|
9
|
+
export const betterAuth = {
|
|
10
|
+
name: 'better-auth',
|
|
11
|
+
rules,
|
|
12
|
+
config: (plugins) => [
|
|
13
|
+
{ name: 'zukhruf/better-auth/plugins', plugins },
|
|
14
|
+
{
|
|
15
|
+
name: 'zukhruf/better-auth',
|
|
16
|
+
files: TYPESCRIPT,
|
|
17
|
+
ignores: [...TESTS, ...TEST_SUPPORT],
|
|
18
|
+
rules: enable(rules),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/better-auth/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAE3D,MAAM,KAAK,GAAG;IACZ,yBAAyB,EAAE,oBAAoB;IAC/C,uBAAuB,EAAE,iBAAiB;CAC3C,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAY;IACjC,IAAI,EAAE,aAAa;IACnB,KAAK;IACL,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QACnB,EAAE,IAAI,EAAE,6BAA6B,EAAE,OAAO,EAAE;QAChD;YACE,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,YAAY,CAAC;YACpC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;SACrB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-api-error-instanceof.d.ts","sourceRoot":"","sources":["../../src/better-auth/no-api-error-instanceof.ts"],"names":[],"mappings":";AAmFA,wBAAgC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ESLintUtils, } from '@typescript-eslint/utils';
|
|
2
|
+
import { eslintRule } from "../authoring/rule-module.js";
|
|
3
|
+
const SOURCES = new Set([
|
|
4
|
+
'better-auth',
|
|
5
|
+
'better-auth/api',
|
|
6
|
+
'@better-auth/core/error',
|
|
7
|
+
'better-call',
|
|
8
|
+
'better-call/error',
|
|
9
|
+
]);
|
|
10
|
+
function importOf(scope, node) {
|
|
11
|
+
const definition = scope.references.find((reference) => reference.identifier === node)?.resolved?.defs[0];
|
|
12
|
+
return definition?.type === 'ImportBinding' &&
|
|
13
|
+
definition.parent.type === 'ImportDeclaration' &&
|
|
14
|
+
SOURCES.has(definition.parent.source.value)
|
|
15
|
+
? definition.node
|
|
16
|
+
: undefined;
|
|
17
|
+
}
|
|
18
|
+
function isApiErrorClass(scope, right) {
|
|
19
|
+
if (right.type === 'MemberExpression' &&
|
|
20
|
+
!right.computed &&
|
|
21
|
+
right.property.type === 'Identifier' &&
|
|
22
|
+
right.property.name === 'APIError') {
|
|
23
|
+
return importOf(scope, right.object)?.type === 'ImportNamespaceSpecifier';
|
|
24
|
+
}
|
|
25
|
+
const node = importOf(scope, right);
|
|
26
|
+
return (node?.type === 'ImportSpecifier' &&
|
|
27
|
+
node.imported.type === 'Identifier' &&
|
|
28
|
+
node.imported.name === 'APIError');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* better-auth's `APIError` extends better-call's, so an `APIError` that
|
|
32
|
+
* better-call throws itself fails `instanceof` against better-auth's class,
|
|
33
|
+
* and the error falls through to the 500 path. `isAPIError()` checks both
|
|
34
|
+
* classes and the error's name, which also covers a second copy of
|
|
35
|
+
* better-call (its CommonJS and ESM builds have separate classes).
|
|
36
|
+
*/
|
|
37
|
+
const rule = ESLintUtils.RuleCreator.withoutDocs({
|
|
38
|
+
meta: {
|
|
39
|
+
type: 'problem',
|
|
40
|
+
docs: {
|
|
41
|
+
description: 'Disallow instanceof against better-auth and better-call APIError',
|
|
42
|
+
},
|
|
43
|
+
schema: [],
|
|
44
|
+
messages: {
|
|
45
|
+
instanceof: "instanceof misses an APIError of another class: better-auth's APIError subclasses better-call's, so an APIError that better-call throws is not an instance of it. Use isAPIError(error) from 'better-auth/api'.",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
defaultOptions: [],
|
|
49
|
+
create(context) {
|
|
50
|
+
return {
|
|
51
|
+
BinaryExpression(node) {
|
|
52
|
+
if (node.operator !== 'instanceof')
|
|
53
|
+
return;
|
|
54
|
+
if (isApiErrorClass(context.sourceCode.getScope(node), node.right)) {
|
|
55
|
+
context.report({ node, messageId: 'instanceof' });
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
export default eslintRule(rule);
|
|
62
|
+
//# sourceMappingURL=no-api-error-instanceof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-api-error-instanceof.js","sourceRoot":"","sources":["../../src/better-auth/no-api-error-instanceof.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAGZ,MAAM,0BAA0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C;AAED;;;;;;GAMG;AACH,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IAC/C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,kEAAkE;SACrE;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,UAAU,EACR,iNAAiN;SACpN;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,gBAAgB,CAAC,IAAI;gBACnB,IAAI,IAAI,CAAC,QAAQ,KAAK,YAAY;oBAAE,OAAO;gBAC3C,IAAI,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACnE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;gBACpD,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In better-auth 1.7, `onAPIError.throw` rethrows before `onAPIError.onError`
|
|
3
|
+
* and before better-auth logs the error. better-call's router catches the
|
|
4
|
+
* rethrow and turns it into a response, so the app's own error handler never
|
|
5
|
+
* runs, and no 4xx is logged anywhere.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("eslint").Rule.RuleModule;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=no-on-api-error-throw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-on-api-error-throw.d.ts","sourceRoot":"","sources":["../../src/better-auth/no-on-api-error-throw.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;;AACH,wBAOG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { selectorRule } from "../authoring/selector-rule.js";
|
|
2
|
+
/**
|
|
3
|
+
* In better-auth 1.7, `onAPIError.throw` rethrows before `onAPIError.onError`
|
|
4
|
+
* and before better-auth logs the error. better-call's router catches the
|
|
5
|
+
* rethrow and turns it into a response, so the app's own error handler never
|
|
6
|
+
* runs, and no 4xx is logged anywhere.
|
|
7
|
+
*/
|
|
8
|
+
export default selectorRule({
|
|
9
|
+
description: "Disallow better-auth's onAPIError.throw",
|
|
10
|
+
selectors: [
|
|
11
|
+
"Property:matches([key.name='onAPIError'], [key.value='onAPIError']) > ObjectExpression > Property:matches([key.name='throw'], [key.value='throw'])[value.value=true]",
|
|
12
|
+
],
|
|
13
|
+
message: "onAPIError.throw rethrows before better-auth logs the error, and better-call turns the rethrow into a response, so the app's error handler never sees it. Log in onAPIError.onError instead.",
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=no-on-api-error-throw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-on-api-error-throw.js","sourceRoot":"","sources":["../../src/better-auth/no-on-api-error-throw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D;;;;;GAKG;AACH,eAAe,YAAY,CAAC;IAC1B,WAAW,EAAE,yCAAyC;IACtD,SAAS,EAAE;QACT,sKAAsK;KACvK;IACD,OAAO,EACL,8LAA8L;CACjM,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/hono/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/hono/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;AAYrD,eAAO,MAAM,IAAI,EAAE,OAYlB,CAAC"}
|
package/dist/hono/config.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { enable } from "../concept.js";
|
|
2
2
|
import { TESTS, TEST_SUPPORT, TYPESCRIPT } from "../files.js";
|
|
3
|
+
import noCatchAroundNext from "./no-catch-around-next.js";
|
|
4
|
+
import noHttpExceptionFactory from "./no-http-exception-factory.js";
|
|
3
5
|
import noUntypedEmptyJson from "./no-untyped-empty-json.js";
|
|
4
|
-
const rules = {
|
|
6
|
+
const rules = {
|
|
7
|
+
'no-untyped-empty-json': noUntypedEmptyJson,
|
|
8
|
+
'no-http-exception-factory': noHttpExceptionFactory,
|
|
9
|
+
'no-catch-around-next': noCatchAroundNext,
|
|
10
|
+
};
|
|
5
11
|
export const hono = {
|
|
6
12
|
name: 'hono',
|
|
7
13
|
rules,
|
package/dist/hono/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/hono/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAE5D,MAAM,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/hono/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AACpE,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAE5D,MAAM,KAAK,GAAG;IACZ,uBAAuB,EAAE,kBAAkB;IAC3C,2BAA2B,EAAE,sBAAsB;IACnD,sBAAsB,EAAE,iBAAiB;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAY;IAC3B,IAAI,EAAE,MAAM;IACZ,KAAK;IACL,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QACnB,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE;QACzC;YACE,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,YAAY,CAAC;YACpC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;SACrB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-catch-around-next.d.ts","sourceRoot":"","sources":["../../src/hono/no-catch-around-next.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;;AAsEnC,wBAAyD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import { eslintRule } from "../authoring/rule-module.js";
|
|
3
|
+
import { scopedRule } from "../authoring/scoped-rule.js";
|
|
4
|
+
function isNextCall(expression) {
|
|
5
|
+
return (expression?.type === 'CallExpression' &&
|
|
6
|
+
expression.callee.type === 'Identifier' &&
|
|
7
|
+
expression.callee.name === 'next' &&
|
|
8
|
+
expression.arguments.length === 0);
|
|
9
|
+
}
|
|
10
|
+
function isAwaitedNext(expression) {
|
|
11
|
+
return (expression?.type === 'AwaitExpression' && isNextCall(expression.argument));
|
|
12
|
+
}
|
|
13
|
+
function onlyCallsNext([statement, ...rest]) {
|
|
14
|
+
if (statement === undefined || rest.length > 0)
|
|
15
|
+
return false;
|
|
16
|
+
if (statement.type === 'ExpressionStatement') {
|
|
17
|
+
return isAwaitedNext(statement.expression);
|
|
18
|
+
}
|
|
19
|
+
return (statement.type === 'ReturnStatement' &&
|
|
20
|
+
(isAwaitedNext(statement.argument) || isNextCall(statement.argument)));
|
|
21
|
+
}
|
|
22
|
+
function importsHono(context) {
|
|
23
|
+
return context.sourceCode.ast.body.some((statement) => statement.type === 'ImportDeclaration' &&
|
|
24
|
+
/^hono(?:\/|$)/.test(String(statement.source.value)));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Hono's `compose()` catches an error of each handler and passes it to the
|
|
28
|
+
* app's error handler, which always exists, so `await next()` never rejects
|
|
29
|
+
* and a `catch` around it never runs. Translate the error where it is thrown,
|
|
30
|
+
* or read `c.error` after `next()`. The rule runs only in a file that imports
|
|
31
|
+
* Hono: in Koa, the same `catch` is the documented error handler.
|
|
32
|
+
*/
|
|
33
|
+
const rule = ESLintUtils.RuleCreator.withoutDocs({
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
docs: {
|
|
37
|
+
description: 'Disallow a catch around only next() in Hono middleware',
|
|
38
|
+
},
|
|
39
|
+
schema: [],
|
|
40
|
+
messages: {
|
|
41
|
+
deadCatch: "Hono catches a handler's error before next() returns, so this catch never runs. Translate the error where it is thrown, or read c.error after next().",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
defaultOptions: [],
|
|
45
|
+
create(context) {
|
|
46
|
+
return {
|
|
47
|
+
TryStatement(node) {
|
|
48
|
+
if (node.handler && onlyCallsNext(node.block.body)) {
|
|
49
|
+
context.report({ node: node.handler, messageId: 'deadCatch' });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
export default scopedRule(eslintRule(rule), importsHono);
|
|
56
|
+
//# sourceMappingURL=no-catch-around-next.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-catch-around-next.js","sourceRoot":"","sources":["../../src/hono/no-catch-around-next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;A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AC,WAAW,CAAC;IAC/C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,wDAAwD;SACtE;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,SAAS,EACP,uJAAuJ;SAC1J;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,YAAY,CAAC,IAAI;gBACf,IAAI,IAAI,CAAC,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;oBACnD,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that only returns `new HTTPException(…)` hides the status and the
|
|
3
|
+
* cause code behind a name, so the reader at the throw site cannot see what
|
|
4
|
+
* the client receives. Write the exception in full at each throw site; give a
|
|
5
|
+
* function of its own only to behavior: a branch, a lookup, a transformation.
|
|
6
|
+
* A class method that returns the exception is polymorphic translation and
|
|
7
|
+
* stays.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: import("eslint").Rule.RuleModule;
|
|
10
|
+
export default _default;
|
|
11
|
+
//# sourceMappingURL=no-http-exception-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-http-exception-factory.d.ts","sourceRoot":"","sources":["../../src/hono/no-http-exception-factory.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;;AACH,wBAUG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { selectorRule } from "../authoring/selector-rule.js";
|
|
2
|
+
const NEW_HTTP_EXCEPTION = "NewExpression[callee.name='HTTPException']";
|
|
3
|
+
const RETURNS_ONLY_HTTP_EXCEPTION = `BlockStatement[body.length=1]:has(> ReturnStatement:has(> ${NEW_HTTP_EXCEPTION}))`;
|
|
4
|
+
/**
|
|
5
|
+
* A function that only returns `new HTTPException(…)` hides the status and the
|
|
6
|
+
* cause code behind a name, so the reader at the throw site cannot see what
|
|
7
|
+
* the client receives. Write the exception in full at each throw site; give a
|
|
8
|
+
* function of its own only to behavior: a branch, a lookup, a transformation.
|
|
9
|
+
* A class method that returns the exception is polymorphic translation and
|
|
10
|
+
* stays.
|
|
11
|
+
*/
|
|
12
|
+
export default selectorRule({
|
|
13
|
+
description: 'Disallow a function whose only statement returns a new HTTPException',
|
|
14
|
+
selectors: [
|
|
15
|
+
`FunctionDeclaration:has(> ${RETURNS_ONLY_HTTP_EXCEPTION})`,
|
|
16
|
+
`VariableDeclarator > :matches(FunctionExpression, ArrowFunctionExpression):has(> ${RETURNS_ONLY_HTTP_EXCEPTION})`,
|
|
17
|
+
`VariableDeclarator > ArrowFunctionExpression:has(> ${NEW_HTTP_EXCEPTION})`,
|
|
18
|
+
],
|
|
19
|
+
message: 'This function only builds an HTTPException, so the status and the cause code are hidden at the throw site. Write throw new HTTPException(status, { message, cause }) in full where you throw it.',
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=no-http-exception-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-http-exception-factory.js","sourceRoot":"","sources":["../../src/hono/no-http-exception-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AACxE,MAAM,2BAA2B,GAAG,6DAA6D,kBAAkB,IAAI,CAAC;AAExH;;;;;;;GAOG;AACH,eAAe,YAAY,CAAC;IAC1B,WAAW,EACT,sEAAsE;IACxE,SAAS,EAAE;QACT,6BAA6B,2BAA2B,GAAG;QAC3D,oFAAoF,2BAA2B,GAAG;QAClH,sDAAsD,kBAAkB,GAAG;KAC5E;IACD,OAAO,EACL,kMAAkM;CACrM,CAAC,CAAC"}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AA2C7C,QAAA,MAAM,MAAM;;;;;;;;;;CAUa,CAAC;AAM1B,eAAe,MAAM,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { findPackageJSON } from 'node:module';
|
|
3
3
|
import { base } from "./base/config.js";
|
|
4
|
+
import { betterAuth } from "./better-auth/config.js";
|
|
4
5
|
import { diagnostics } from "./diagnostics/config.js";
|
|
5
6
|
import { env } from "./environment/config.js";
|
|
6
7
|
import { hono } from "./hono/config.js";
|
|
@@ -21,6 +22,7 @@ const concepts = [
|
|
|
21
22
|
react,
|
|
22
23
|
reactRouter,
|
|
23
24
|
hono,
|
|
25
|
+
betterAuth,
|
|
24
26
|
tailwind,
|
|
25
27
|
pulumi,
|
|
26
28
|
nxProjectJson,
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;
|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,CAAC,SAAS,CAAC,KAAK,QAAQ;QAClE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QACrB,CAAC,CAAC,OAAO,CAAC;AACd,CAAC;AAED,MAAM,OAAO,GAAoC,EAAE,CAAC;AAEpD,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,cAAc,EAAE;QACzB,SAAS,EAAE,SAAS;KACrB;IACD,KAAK,EAAE,MAAM,CAAC,WAAW,CACvB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAC7D;IACD,OAAO;CACgB,CAAC;AAE1B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-test-lifecycle-hooks.d.ts","sourceRoot":"","sources":["../../src/test-files/no-test-lifecycle-hooks.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"no-test-lifecycle-hooks.d.ts","sourceRoot":"","sources":["../../src/test-files/no-test-lifecycle-hooks.ts"],"names":[],"mappings":";AA+KA,wBAAgC"}
|
|
@@ -1,9 +1,132 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { ASTUtils, ESLintUtils, } from '@typescript-eslint/utils';
|
|
2
|
+
import { eslintRule } from "../authoring/rule-module.js";
|
|
3
|
+
const HOOKS = new Set([
|
|
4
|
+
'before',
|
|
5
|
+
'after',
|
|
6
|
+
'beforeEach',
|
|
7
|
+
'afterEach',
|
|
8
|
+
'beforeAll',
|
|
9
|
+
'afterAll',
|
|
10
|
+
]);
|
|
11
|
+
const NODE_TEST = /^(node:)?test$/;
|
|
12
|
+
const TEST_FUNCTIONS = new Set(['test', 'it']);
|
|
13
|
+
const MODIFIERS = new Set(['only', 'skip', 'todo']);
|
|
14
|
+
function importClause(resolve, node) {
|
|
15
|
+
if (node.type !== 'Identifier')
|
|
16
|
+
return undefined;
|
|
17
|
+
const definition = resolve(node)?.defs[0];
|
|
18
|
+
return definition?.type === 'ImportBinding' &&
|
|
19
|
+
definition.node.type !== 'TSImportEqualsDeclaration'
|
|
20
|
+
? definition.node
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
23
|
+
function importedName(specifier) {
|
|
24
|
+
return specifier.imported.type === 'Identifier'
|
|
25
|
+
? specifier.imported.name
|
|
26
|
+
: specifier.imported.value;
|
|
27
|
+
}
|
|
28
|
+
function nodeTestImport(resolve, node) {
|
|
29
|
+
const clause = importClause(resolve, node);
|
|
30
|
+
return clause?.parent.type === 'ImportDeclaration' &&
|
|
31
|
+
NODE_TEST.test(clause.parent.source.value)
|
|
32
|
+
? clause
|
|
33
|
+
: undefined;
|
|
34
|
+
}
|
|
35
|
+
function isNodeTestNamespace(resolve, node) {
|
|
36
|
+
return nodeTestImport(resolve, node)?.type === 'ImportNamespaceSpecifier';
|
|
37
|
+
}
|
|
38
|
+
/** `test` or `it` of node:test, also as `ns.test`, `test.only`, or the subtest `t.test`. */
|
|
39
|
+
function isTestFunction(resolve, node) {
|
|
40
|
+
if (node.type === 'Identifier') {
|
|
41
|
+
const clause = nodeTestImport(resolve, node);
|
|
42
|
+
return (clause?.type === 'ImportDefaultSpecifier' ||
|
|
43
|
+
(clause?.type === 'ImportSpecifier' &&
|
|
44
|
+
TEST_FUNCTIONS.has(importedName(clause))));
|
|
45
|
+
}
|
|
46
|
+
if (node.type !== 'MemberExpression' || node.property.type !== 'Identifier') {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const property = node.property.name;
|
|
50
|
+
return ((MODIFIERS.has(property) && isTestFunction(resolve, node.object)) ||
|
|
51
|
+
(TEST_FUNCTIONS.has(property) &&
|
|
52
|
+
isNodeTestNamespace(resolve, node.object)) ||
|
|
53
|
+
(property === 'test' && isTestContext(resolve, node.object)));
|
|
54
|
+
}
|
|
55
|
+
function isTestContextType(resolve, annotation) {
|
|
56
|
+
if (annotation.type !== 'TSTypeReference')
|
|
57
|
+
return false;
|
|
58
|
+
const clause = nodeTestImport(resolve, annotation.typeName);
|
|
59
|
+
return (clause?.type === 'ImportSpecifier' && importedName(clause) === 'TestContext');
|
|
60
|
+
}
|
|
61
|
+
/** A parameter typed `TestContext`, or the first parameter of a test function's callback. */
|
|
62
|
+
function isTestContext(resolve, node) {
|
|
63
|
+
if (node.type !== 'Identifier')
|
|
64
|
+
return false;
|
|
65
|
+
const definition = resolve(node)?.defs[0];
|
|
66
|
+
if (definition?.type !== 'Parameter')
|
|
67
|
+
return false;
|
|
68
|
+
const parameter = definition.name;
|
|
69
|
+
if (parameter.typeAnnotation &&
|
|
70
|
+
isTestContextType(resolve, parameter.typeAnnotation.typeAnnotation)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const callback = definition.node;
|
|
74
|
+
const call = callback.parent;
|
|
75
|
+
return (callback.params[0] === parameter &&
|
|
76
|
+
call.type === 'CallExpression' &&
|
|
77
|
+
call.arguments.some((argument) => argument === callback) &&
|
|
78
|
+
isTestFunction(resolve, call.callee));
|
|
79
|
+
}
|
|
80
|
+
function isHook(resolve, callee) {
|
|
81
|
+
if (callee.type === 'Identifier') {
|
|
82
|
+
const variable = resolve(callee);
|
|
83
|
+
if (!variable || variable.defs.length === 0)
|
|
84
|
+
return HOOKS.has(callee.name);
|
|
85
|
+
const clause = importClause(resolve, callee);
|
|
86
|
+
return (clause !== undefined &&
|
|
87
|
+
(HOOKS.has(callee.name) ||
|
|
88
|
+
(clause.type === 'ImportSpecifier' && HOOKS.has(importedName(clause)))));
|
|
89
|
+
}
|
|
90
|
+
return (callee.type === 'MemberExpression' &&
|
|
91
|
+
callee.property.type === 'Identifier' &&
|
|
92
|
+
HOOKS.has(callee.property.name) &&
|
|
93
|
+
(isTestFunction(resolve, callee.object) ||
|
|
94
|
+
isNodeTestNamespace(resolve, callee.object) ||
|
|
95
|
+
isTestContext(resolve, callee.object)));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A lifecycle hook moves arrange or teardown out of the test that needs it:
|
|
99
|
+
* the reader no longer sees the whole test in one place, and state that one
|
|
100
|
+
* test leaves behind reaches the next. A per-test `t.after()` of node:test has
|
|
101
|
+
* the same cost, because the teardown is out of the test's own flow. The rule
|
|
102
|
+
* reads a hook from Vitest, Jest or Mocha globals, from an import (also under
|
|
103
|
+
* another name), from node:test's `test`, `it` or namespace (`test.after`), and
|
|
104
|
+
* from a TestContext: the first parameter of a node:test test or subtest
|
|
105
|
+
* callback, or a parameter typed `TestContext`. A function of the file that is
|
|
106
|
+
* named `after` is not a hook.
|
|
107
|
+
*/
|
|
108
|
+
const rule = ESLintUtils.RuleCreator.withoutDocs({
|
|
109
|
+
meta: {
|
|
110
|
+
type: 'problem',
|
|
111
|
+
docs: {
|
|
112
|
+
description: 'Disallow test lifecycle hooks; each test arranges and tears down its own state',
|
|
113
|
+
},
|
|
114
|
+
schema: [],
|
|
115
|
+
messages: {
|
|
116
|
+
matched: 'No test lifecycle hooks. Write self-contained AAA tests: inline arrange in each test and run teardown (cleanup, mock restore, resource stop) in a per-test try/finally or with `await using` a disposable.',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
defaultOptions: [],
|
|
120
|
+
create(context) {
|
|
121
|
+
const resolve = (identifier) => ASTUtils.findVariable(context.sourceCode.getScope(identifier), identifier);
|
|
122
|
+
return {
|
|
123
|
+
CallExpression(node) {
|
|
124
|
+
if (isHook(resolve, node.callee)) {
|
|
125
|
+
context.report({ node, messageId: 'matched' });
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
},
|
|
8
130
|
});
|
|
131
|
+
export default eslintRule(rule);
|
|
9
132
|
//# sourceMappingURL=no-test-lifecycle-hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-test-lifecycle-hooks.js","sourceRoot":"","sources":["../../src/test-files/no-test-lifecycle-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"no-test-lifecycle-hooks.js","sourceRoot":"","sources":["../../src/test-files/no-test-lifecycle-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,GAGZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC;IACpB,QAAQ;IACR,OAAO;IACP,YAAY;IACZ,WAAW;IACX,WAAW;IACX,UAAU;CACX,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAMpD,SAAS,YAAY,CACnB,OAAgB,EAChB,IAAmB;IAEnB,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IACjD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1C,OAAO,UAAU,EAAE,IAAI,KAAK,eAAe;QACzC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,2BAA2B;QACpD,CAAC,CAAC,UAAU,CAAC,IAAI;QACjB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,Y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,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IAC/C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,gFAAgF;SACnF;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,OAAO,EACL,4MAA4M;SAC/M;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,OAAO,GAAY,CAAC,UAAU,EAAE,EAAE,CACtC,QAAQ,CAAC,YAAY,CACnB,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,EACvC,UAAU,CACX,CAAC;QACJ,OAAO;YACL,cAAc,CAAC,IAAI;gBACjB,IAAI,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBACjC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;gBACjD,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,eAAe,UAAU,CAAC,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/eslint",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.56",
|
|
4
4
|
"description": "ESLint rules and configs shared across workspaces. Every check is its own named rule, so a repo's own config cannot silently erase it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"ts-api-utils": "^2.5.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@zukhruf/testing": "^0.3.
|
|
59
|
+
"@zukhruf/testing": "^0.3.56"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@eslint/js": "^9.30.0 || ^10.0.0",
|