@zukhruf/eslint 0.6.16 → 0.8.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/README.md CHANGED
@@ -40,20 +40,20 @@ Put framework configs (for example [`@zukhruf/eslint/react`](#react)) **before**
40
40
 
41
41
  ## Configs
42
42
 
43
- | Config | Files | Rules |
44
- | ----------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
45
- | `base` | all source | `@eslint/js` and `typescript-eslint` recommended; `consistent-type-assertions` (never), `no-namespace` (a `declare` namespace allowed), `zukhruf/no-enum`, `no-empty-object-type` (an interface that extends one type allowed, such as `ProcessEnv` in `env.ts`; `no-empty-interface`, which it replaced, is off); `import-x/no-duplicates`, `import-x/no-unassigned-import` (allows `**/*.css`, `**/env.ts` and `**/startup.ts`); `functional/no-let` (module scope); `zukhruf/no-state-managers`, `zukhruf/no-playwright-test`, `zukhruf/no-other-test-runner`, `zukhruf/no-test-file-import`, `zukhruf/no-collect-loop`; typed lint: `no-floating-promises`, `no-misused-promises`, `only-throw-error`, `switch-exhaustiveness-check` (a `default` counts as exhaustive), `no-deprecated`, `zukhruf/no-promise-field`, `zukhruf/no-phase-flag`; `no-require-imports` is off in `.cjs` and `.cts`, because `require()` is the only import form in a CommonJS file |
46
- | `tests` | test files, `src/testing` | `no-test-lifecycle-hooks`, `no-process-env-write`, `no-direct-msw-server`, `no-catch-all-msw-handler`, `no-timer-race`, `no-sleep-poll-loop`, `no-global-test-mock`, `no-raw-temp-directory` |
47
- | `diagnostics` | source, not tests | `no-fabricated-fallback`, `no-hardcoded-id-shape`, `consistent-event-name` |
48
- | `env` | TypeScript, not tests or tool configs | `no-undeclared-process-env`, `no-single-env-read-wrapper`, `no-default-for-path-env` |
49
- | `packaged-app` | TypeScript, not tests | `no-bare-spawn` |
50
- | `react` | `.tsx`, `.jsx` | `no-as-child` |
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`, `no-http-exception-factory`, `no-catch-around-next` |
53
- | `better-auth` | TypeScript, not tests | `no-api-error-instanceof`, `no-on-api-error-throw` |
54
- | `tailwind` | source | `no-h-screen`, `no-arbitrary-z-index`, `no-will-change` |
55
- | `pulumi` | TypeScript | `require-server-replace-guard` |
56
- | `nx-project-json` | `project.json` | `no-missing-asset-input` |
43
+ | Config | Files | Rules |
44
+ | ----------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
45
+ | `base` | all source | `@eslint/js` and `typescript-eslint` recommended; `consistent-type-assertions` (never), `no-namespace` (a `declare` namespace allowed), `zukhruf/no-enum`, `no-empty-object-type` (an interface that extends one type allowed, such as `ProcessEnv` in `env.ts`; `no-empty-interface`, which it replaced, is off); `import-x/no-duplicates`, `import-x/no-unassigned-import` (allows `**/*.css`, `**/env.ts` and `**/startup.ts`); `functional/no-let` (module scope); `zukhruf/no-state-managers`, `zukhruf/no-playwright-test`, `zukhruf/no-other-test-runner`, `zukhruf/no-test-file-import`, `zukhruf/no-raw-database-sync`, `zukhruf/no-collect-loop`; typed lint: `no-floating-promises`, `no-misused-promises`, `only-throw-error`, `switch-exhaustiveness-check` (a `default` counts as exhaustive), `no-deprecated`, `zukhruf/no-promise-field`, `zukhruf/no-phase-flag`; `no-require-imports` is off in `.cjs` and `.cts`, because `require()` is the only import form in a CommonJS file |
46
+ | `tests` | test files, `src/testing` | `no-test-lifecycle-hooks`, `no-process-env-write`, `no-direct-msw-server`, `no-catch-all-msw-handler`, `no-timer-race`, `no-sleep-poll-loop`, `no-global-test-mock`, `no-raw-temp-directory` |
47
+ | `diagnostics` | source, not tests | `no-fabricated-fallback`, `no-hardcoded-id-shape`, `consistent-event-name` |
48
+ | `env` | TypeScript, not tests or tool configs | `no-undeclared-process-env`, `no-single-env-read-wrapper`, `no-default-for-path-env` |
49
+ | `packaged-app` | TypeScript, not tests | `no-bare-spawn` |
50
+ | `react` | `.tsx`, `.jsx` | `no-as-child` |
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`, `no-http-exception-factory`, `no-catch-around-next` |
53
+ | `better-auth` | TypeScript, not tests | `no-api-error-instanceof`, `no-on-api-error-throw` |
54
+ | `tailwind` | source | `no-h-screen`, `no-arbitrary-z-index`, `no-will-change` |
55
+ | `pulumi` | TypeScript | `require-server-replace-guard` |
56
+ | `nx-project-json` | `project.json` | `no-missing-asset-input` |
57
57
 
58
58
  `base` turns on typed lint (`parserOptions.projectService`). Each linted TypeScript file must be in a tsconfig.
59
59
 
@@ -69,6 +69,8 @@ A lazy memo is not a phase, so the rule does not report it. In a lazy memo, each
69
69
 
70
70
  `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.
71
71
 
72
+ `zukhruf/no-raw-database-sync` reports `new DatabaseSync` of `node:sqlite`. Each such open sets up its connection in its own way: its busy timeout, its journal, and which errors mean that the file is missing or denied. `open(path, options)` of `@zukhruf/sqlite-open` takes the same options and does that setup in one place; a reader is `open(path, { readOnly: true })`. The rule follows the bindings of the file: a named import under any local name, a namespace or default import, and `require` or `import()` of `node:sqlite`. A type-only import constructs nothing, so the rule does not report it. Turn it off only where a package cannot depend on `@zukhruf/sqlite-open`, and write the reason beside the override.
73
+
72
74
  `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.
73
75
 
74
76
  `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.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/base/config.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;AAkCrD;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,OA2JlB,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/base/config.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;AAoCrD;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,OA2JlB,CAAC"}
@@ -11,6 +11,7 @@ import { enable } from "../concept.js";
11
11
  import { BUILD_OUTPUT, COMMONJS, FIXTURES, JAVASCRIPT, SOURCE, TESTS, TEST_SUPPORT, TYPESCRIPT, } from "../files.js";
12
12
  import noOtherTestRunner from "../imports/no-other-test-runner.js";
13
13
  import noPlaywrightTest from "../imports/no-playwright-test.js";
14
+ import noRawDatabaseSync from "../imports/no-raw-database-sync.js";
14
15
  import noStateManagers from "../imports/no-state-managers.js";
15
16
  import noTestFileImport from "../imports/no-test-file-import.js";
16
17
  import noEnum from "../language/no-enum.js";
@@ -21,6 +22,7 @@ const importBans = {
21
22
  'no-playwright-test': noPlaywrightTest,
22
23
  'no-other-test-runner': noOtherTestRunner,
23
24
  'no-test-file-import': noTestFileImport,
25
+ 'no-raw-database-sync': noRawDatabaseSync,
24
26
  };
25
27
  const rules = {
26
28
  'no-enum': noEnum,
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/base/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAEzC,OAAO,aAAa,MAAM,oCAAoC,CAAC;AAC/D,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAgB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,KAAK,EACL,YAAY,EACZ,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,iBAAiB,MAAM,oCAAoC,CAAC;AACnE,OA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KACF,CACF;CACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Each `new DatabaseSync` set up its connection in its own way: its busy
4
+ * timeout, its journal, and which errors mean that the file is missing or
5
+ * denied. `open` of `@zukhruf/sqlite-open` does that setup in one place. The
6
+ * rule follows the bindings of the file: a named import under any local name,
7
+ * a namespace or default import, and `require` or `import()` of `node:sqlite`.
8
+ */
9
+ declare const rule: Rule.RuleModule;
10
+ export default rule;
11
+ //# sourceMappingURL=no-raw-database-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-raw-database-sync.d.ts","sourceRoot":"","sources":["../../src/imports/no-raw-database-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAkCnC;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UA2EhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,110 @@
1
+ import { identifierName, isAstNode, isType, } from "../authoring/ast.js";
2
+ const SQLITE = 'node:sqlite';
3
+ function propertyName(node, key) {
4
+ const value = node[key];
5
+ return isType(value, 'Literal') && typeof value['value'] === 'string'
6
+ ? value['value']
7
+ : identifierName(value);
8
+ }
9
+ // `require('node:sqlite')` or `await import('node:sqlite')`.
10
+ function loadsSqlite(node) {
11
+ const call = isType(node, 'AwaitExpression') ? node['argument'] : node;
12
+ if (isType(call, 'ImportExpression'))
13
+ return (isType(call['source'], 'Literal') && call['source']['value'] === SQLITE);
14
+ if (!isType(call, 'CallExpression'))
15
+ return false;
16
+ const [argument] = Array.isArray(call['arguments']) ? call['arguments'] : [];
17
+ return (identifierName(call['callee']) === 'require' &&
18
+ isType(argument, 'Literal') &&
19
+ argument['value'] === SQLITE);
20
+ }
21
+ /**
22
+ * Each `new DatabaseSync` set up its connection in its own way: its busy
23
+ * timeout, its journal, and which errors mean that the file is missing or
24
+ * denied. `open` of `@zukhruf/sqlite-open` does that setup in one place. The
25
+ * rule follows the bindings of the file: a named import under any local name,
26
+ * a namespace or default import, and `require` or `import()` of `node:sqlite`.
27
+ */
28
+ const rule = {
29
+ meta: {
30
+ type: 'problem',
31
+ docs: {
32
+ description: 'Disallow new DatabaseSync of node:sqlite; use open of @zukhruf/sqlite-open',
33
+ },
34
+ schema: [],
35
+ messages: {
36
+ matched: 'Open SQLite with `open(path, options)` from @zukhruf/sqlite-open, which takes the options of new DatabaseSync: a reader is `open(path, { readOnly: true })`. It sets the journal, the busy timeout and the errors of an unavailable file in one place.',
37
+ },
38
+ },
39
+ create(context) {
40
+ const constructors = new Set();
41
+ const modules = new Set();
42
+ function bindPattern(pattern) {
43
+ const name = identifierName(pattern);
44
+ if (name !== undefined) {
45
+ modules.add(name);
46
+ return;
47
+ }
48
+ if (!isType(pattern, 'ObjectPattern'))
49
+ return;
50
+ const properties = Array.isArray(pattern['properties'])
51
+ ? pattern['properties']
52
+ : [];
53
+ for (const property of properties) {
54
+ if (!isType(property, 'Property'))
55
+ continue;
56
+ if (propertyName(property, 'key') !== 'DatabaseSync')
57
+ continue;
58
+ const local = identifierName(property['value']);
59
+ if (local !== undefined)
60
+ constructors.add(local);
61
+ }
62
+ }
63
+ function isDatabaseSync(callee) {
64
+ const name = identifierName(callee);
65
+ if (name !== undefined)
66
+ return constructors.has(name);
67
+ if (!isType(callee, 'MemberExpression'))
68
+ return false;
69
+ if (propertyName(callee, 'property') !== 'DatabaseSync')
70
+ return false;
71
+ const object = callee['object'];
72
+ const objectName = identifierName(object);
73
+ return objectName !== undefined
74
+ ? modules.has(objectName)
75
+ : loadsSqlite(object);
76
+ }
77
+ return {
78
+ ImportDeclaration(node) {
79
+ if (!isAstNode(node) || node['importKind'] === 'type')
80
+ return;
81
+ if (!isAstNode(node['source']) || node['source']['value'] !== SQLITE)
82
+ return;
83
+ const specifiers = Array.isArray(node['specifiers'])
84
+ ? node['specifiers']
85
+ : [];
86
+ for (const specifier of specifiers) {
87
+ if (!isAstNode(specifier) || specifier['importKind'] === 'type')
88
+ continue;
89
+ const local = identifierName(specifier['local']);
90
+ if (local === undefined)
91
+ continue;
92
+ if (specifier.type !== 'ImportSpecifier')
93
+ modules.add(local);
94
+ else if (propertyName(specifier, 'imported') === 'DatabaseSync')
95
+ constructors.add(local);
96
+ }
97
+ },
98
+ VariableDeclarator(node) {
99
+ if (isAstNode(node) && loadsSqlite(node['init']))
100
+ bindPattern(node['id']);
101
+ },
102
+ NewExpression(node) {
103
+ if (isAstNode(node) && isDatabaseSync(node['callee']))
104
+ context.report({ node, messageId: 'matched' });
105
+ },
106
+ };
107
+ },
108
+ };
109
+ export default rule;
110
+ //# sourceMappingURL=no-raw-database-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-raw-database-sync.js","sourceRoot":"","sources":["../../src/imports/no-raw-database-sync.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,cAAc,EACd,SAAS,EACT,MAAM,GACP,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,GAAG,aAAa,CAAC;AAE7B,SAAS,YAAY,CAAC,IAAa,EAAE,GAAW;IAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ;QACnE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAChB,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,6DAA6D;AAC7D,SAAS,WAAW,CAAC,IAAa;IAChC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,IAAI,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC;QAClC,OAAO,CACL,MAAM,CAAC,IAAI,CAAC,QAA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"version": "0.6.16",
3
+ "version": "0.8.0",
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": {
@@ -62,7 +62,7 @@
62
62
  "ts-api-utils": "^2.5.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@zukhruf/testing": "^0.6.16"
65
+ "@zukhruf/testing": "^0.8.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@eslint-react/eslint-plugin": "^5.28.8",