adamantite 0.44.0 → 0.46.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 +413 -122
- package/dist/index.js +638 -57
- package/dist/oxlint.js +1 -0
- package/dist/presets/analyze.js +1 -0
- package/dist/presets/lint/{react-doctor.d.ts → architecture.d.ts} +1 -1
- package/dist/presets/lint/architecture.js +8 -0
- package/dist/presets/lint/core.js +0 -1
- package/dist/presets/lint/effect.js +26 -1
- package/dist/presets/lint/jest.d.ts +13 -0
- package/dist/presets/lint/jest.js +88 -68
- package/dist/presets/lint/plugin/glob.d.ts +7 -0
- package/dist/presets/lint/plugin/glob.js +48 -0
- package/dist/presets/lint/plugin/imports.d.ts +4 -0
- package/dist/presets/lint/plugin/imports.js +4 -1
- package/dist/presets/lint/plugin/index.d.ts +3 -0
- package/dist/presets/lint/plugin/index.js +14 -8
- package/dist/presets/lint/plugin/options.d.ts +5 -5
- package/dist/presets/lint/plugin/options.js +19 -7
- package/dist/presets/lint/plugin/resolver.d.ts +8 -0
- package/dist/presets/lint/plugin/resolver.js +79 -0
- package/dist/presets/lint/plugin/rules/import-owners.d.ts +67 -0
- package/dist/presets/lint/plugin/rules/import-owners.js +310 -0
- package/dist/presets/lint/plugin/rules/layers.d.ts +136 -0
- package/dist/presets/lint/plugin/rules/layers.js +479 -0
- package/dist/presets/lint/plugin/rules/no-query-data-in-state.js +1 -1
- package/dist/presets/lint/plugin/rules/no-react-state-hooks.d.ts +0 -5
- package/dist/presets/lint/plugin/rules/no-react-state-hooks.js +3 -47
- package/dist/presets/lint/plugin/rules/query-from-loader.js +2 -2
- package/dist/presets/lint/plugin/rules/require-suppression-reason.d.ts +5 -0
- package/dist/presets/lint/plugin/rules/require-suppression-reason.js +32 -0
- package/dist/presets/lint/react-strict.js +22 -2
- package/dist/presets/lint/strict.js +35 -2
- package/dist/presets/lint/{antislop.d.ts → tailwind.d.ts} +1 -1
- package/dist/presets/lint/{shadcn.js → tailwind.js} +1 -1
- package/dist/presets/lint/vendor/antislop/license.md +26 -1
- package/dist/presets/lint/vendor/antislop/plugin.d.mts +3 -0
- package/dist/presets/lint/vendor/antislop/plugin.mjs +940 -31
- package/dist/presets/lint/vendor/antislop-effect/license.md +27 -0
- package/dist/presets/lint/vendor/antislop-effect/plugin.d.mts +17 -0
- package/dist/presets/lint/vendor/antislop-effect/plugin.mjs +579 -0
- package/dist/presets/lint/vitest.d.ts +13 -0
- package/dist/presets/lint/vitest.js +111 -91
- package/dist/presets/{lint → rules}/custom.d.ts +3 -20
- package/dist/presets/{lint → rules}/custom.js +50 -46
- package/dist/presets/rules/folder.d.ts +34 -0
- package/dist/presets/rules/folder.js +52 -0
- package/dist/presets/rules/index.d.ts +2 -9
- package/dist/presets/rules/index.js +1 -29
- package/dist/presets/rules/load.d.ts +8 -0
- package/dist/presets/rules/load.js +29 -0
- package/dist/presets/rules/plugin.d.ts +3 -0
- package/dist/presets/rules/plugin.js +1 -0
- package/dist/presets/rules/testing.d.ts +2 -0
- package/dist/presets/rules/testing.js +14 -0
- package/dist/presets/tsconfig.json +3 -0
- package/dist/runtime-CVZPDpfE.js +11 -0
- package/package.json +79 -18
- package/skills/adamantite/SKILL.md +112 -200
- package/skills/adamantite/references/custom-rules.md +120 -0
- package/skills/adamantite/references/lint-rules.md +158 -0
- package/skills/adamantite/references/setup.md +64 -0
- package/dist/presets/lint/antislop.js +0 -28
- package/dist/presets/lint/react-doctor.js +0 -20
- package/dist/presets/lint/shadcn.d.ts +0 -5
package/dist/oxlint.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,b as t,m as n,n as r,o as i,v as a}from"./runtime-CVZPDpfE.js";import*as o from"effect/Effect";import s from"node:process";import*as c from"effect/Result";import{pathToFileURL as l}from"node:url";import{join as u}from"node:path";import*as d from"@effect/platform-node/NodeFileSystem";import*as f from"@effect/platform-node/NodePath";const p=t(s.argv[1]??``,s.cwd(),s.env[a]),m=await o.runPromise(e(p).pipe(o.result,o.provide([d.layer,f.layer,n.layer])));c.isFailure(m)&&(s.stderr.write(`${m.failure.message}\n`),s.exit(1));const{backend:h,binding:g,oxlint:_}=m.success,v=e=>import(l(u(_,`dist`,e)).href);Object.assign(s.env,i(h)),g instanceof r&&(s.env.NAPI_RS_NATIVE_LIBRARY_PATH=g.path,await v(`bindings.js`),delete s.env.NAPI_RS_NATIVE_LIBRARY_PATH),await v(`cli.js`);export{};
|
package/dist/presets/analyze.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region presets/lint/architecture.ts
|
|
2
|
+
const PLUGIN_EXTENSION = import.meta.url.endsWith(".ts") ? "ts" : "js";
|
|
3
|
+
const config = { jsPlugins: [{
|
|
4
|
+
name: "adamantite",
|
|
5
|
+
specifier: new URL(`plugin/index.${PLUGIN_EXTENSION}`, import.meta.url).href
|
|
6
|
+
}] };
|
|
7
|
+
//#endregion
|
|
8
|
+
export { config as default };
|
|
@@ -116,7 +116,6 @@ const config = {
|
|
|
116
116
|
"no-class-assign": "error",
|
|
117
117
|
"no-compare-neg-zero": "error",
|
|
118
118
|
"no-cond-assign": "error",
|
|
119
|
-
"no-console": ["warn", { allow: ["info"] }],
|
|
120
119
|
"no-const-assign": "error",
|
|
121
120
|
"no-constant-binary-expression": "error",
|
|
122
121
|
"no-constant-condition": "error",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
//#region presets/lint/effect.ts
|
|
2
2
|
const config = {
|
|
3
|
+
jsPlugins: [{
|
|
4
|
+
name: "anti-slop-effect",
|
|
5
|
+
specifier: new URL("vendor/antislop-effect/plugin.mjs", import.meta.url).href
|
|
6
|
+
}],
|
|
3
7
|
options: { typeAware: true },
|
|
4
8
|
plugins: ["effecttsgo"],
|
|
5
9
|
rules: {
|
|
@@ -34,6 +38,7 @@ const config = {
|
|
|
34
38
|
"effecttsgo/effect-gen-uses-adapter": "error",
|
|
35
39
|
"effecttsgo/effect-in-failure": "error",
|
|
36
40
|
"effecttsgo/effect-in-void-success": "error",
|
|
41
|
+
"effecttsgo/effect-try-without-catch": "error",
|
|
37
42
|
"effecttsgo/global-error-in-effect-catch": "error",
|
|
38
43
|
"effecttsgo/global-error-in-effect-failure": "error",
|
|
39
44
|
"effecttsgo/layer-merge-all-with-dependencies": "error",
|
|
@@ -53,6 +58,7 @@ const config = {
|
|
|
53
58
|
"effecttsgo/global-console-in-effect": "error",
|
|
54
59
|
"effecttsgo/global-date-in-effect": "error",
|
|
55
60
|
"effecttsgo/global-fetch-in-effect": "error",
|
|
61
|
+
"effecttsgo/global-json-in-effect": "error",
|
|
56
62
|
"effecttsgo/global-random-in-effect": "error",
|
|
57
63
|
"effecttsgo/global-timers-in-effect": "error",
|
|
58
64
|
"effecttsgo/instance-of-schema": "error",
|
|
@@ -74,14 +80,23 @@ const config = {
|
|
|
74
80
|
"effecttsgo/effect-map-flatten": "error",
|
|
75
81
|
"effecttsgo/effect-map-void": "error",
|
|
76
82
|
"effecttsgo/effect-sleep-zero-to-yield-now": "error",
|
|
83
|
+
"effecttsgo/effect-succeed-with-undefined": "error",
|
|
77
84
|
"effecttsgo/effect-succeed-with-void": "error",
|
|
85
|
+
"effecttsgo/fail-cause-to-constructor": "error",
|
|
78
86
|
"effecttsgo/flat-map-conditional-to-filter-or-fail": "error",
|
|
87
|
+
"effecttsgo/flat-map-identity-to-flatten": "error",
|
|
79
88
|
"effecttsgo/flat-map-ignored-param-to-and-then": "error",
|
|
80
89
|
"effecttsgo/flat-map-to-map": "error",
|
|
81
90
|
"effecttsgo/flat-map-to-tap": "error",
|
|
91
|
+
"effecttsgo/manual-metric-tap-to-track": "error",
|
|
92
|
+
"effecttsgo/map-const-to-as": "error",
|
|
93
|
+
"effecttsgo/map-map-error-to-map-both": "error",
|
|
94
|
+
"effecttsgo/map-some-catch-no-such-element": "error",
|
|
82
95
|
"effecttsgo/map-some-to-as-some": "error",
|
|
96
|
+
"effecttsgo/match-boolean-to-is-success": "error",
|
|
83
97
|
"effecttsgo/match-effect-to-map-both": "error",
|
|
84
98
|
"effecttsgo/match-effect-to-match": "error",
|
|
99
|
+
"effecttsgo/match-to-result-or-option": "error",
|
|
85
100
|
"effecttsgo/multiple-catch-tag": "error",
|
|
86
101
|
"effecttsgo/nested-effect-gen-yield": "error",
|
|
87
102
|
"effecttsgo/option-match-to-from-option": "error",
|
|
@@ -89,22 +104,32 @@ const config = {
|
|
|
89
104
|
"effecttsgo/prefer-succeed-some-or-none": "error",
|
|
90
105
|
"effecttsgo/prefer-typed-schema-decoder": "error",
|
|
91
106
|
"effecttsgo/provide-layer-succeed-to-provide-service": "error",
|
|
107
|
+
"effecttsgo/provide-merge-all-to-array": "error",
|
|
92
108
|
"effecttsgo/race-first-with-sleep-to-timeout": "error",
|
|
93
109
|
"effecttsgo/redundant-map-error": "error",
|
|
94
110
|
"effecttsgo/redundant-or-die": "error",
|
|
95
111
|
"effecttsgo/redundant-schema-tag-identifier": "error",
|
|
112
|
+
"effecttsgo/result-match-to-from-result": "error",
|
|
96
113
|
"effecttsgo/run-of-exit-to-run-exit": "error",
|
|
97
114
|
"effecttsgo/schema-number": "error",
|
|
98
115
|
"effecttsgo/schema-struct-with-tag": "error",
|
|
99
116
|
"effecttsgo/schema-union-of-literals": "error",
|
|
100
117
|
"effecttsgo/service-not-as-class": "error",
|
|
118
|
+
"effecttsgo/suspend-fail-to-fail-sync": "error",
|
|
101
119
|
"effecttsgo/sync-to-succeed": "error",
|
|
102
120
|
"effecttsgo/timeout-catch-tag-to-timeout-or-else": "error",
|
|
103
121
|
"effecttsgo/unnecessary-effect-gen": "error",
|
|
104
122
|
"effecttsgo/unnecessary-fail-yieldable-error": "error",
|
|
105
123
|
"effecttsgo/unnecessary-pipe": "error",
|
|
106
124
|
"effecttsgo/unnecessary-pipe-chain": "error",
|
|
107
|
-
"effecttsgo/unnecessary-typeof-type": "error"
|
|
125
|
+
"effecttsgo/unnecessary-typeof-type": "error",
|
|
126
|
+
"anti-slop-effect/no-manual-effect-error-tag": "error",
|
|
127
|
+
"anti-slop-effect/no-manual-tag-comparison": "error",
|
|
128
|
+
"anti-slop-effect/no-manual-tagged-construction": "error",
|
|
129
|
+
"anti-slop-effect/no-service-constructor-imports": "error",
|
|
130
|
+
"anti-slop-effect/prefer-effect-match": "error",
|
|
131
|
+
"unicorn/no-array-callback-reference": "off",
|
|
132
|
+
"unicorn/no-array-method-this-argument": "off"
|
|
108
133
|
}
|
|
109
134
|
};
|
|
110
135
|
//#endregion
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { OxlintConfig } from "oxlint";
|
|
2
2
|
//#region presets/lint/jest.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The files that Jest runs as tests by default. The preset applies its rules only to these files.
|
|
5
|
+
* To change the files or a rule, use the preset in an override of your own instead of `extends`:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import jest, { testFiles } from "adamantite/lint/jest"
|
|
9
|
+
*
|
|
10
|
+
* export default defineConfig({
|
|
11
|
+
* overrides: [{ files: testFiles, plugins: jest.plugins, rules: { ...jest.rules } }],
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const testFiles: string[];
|
|
3
16
|
declare const config: OxlintConfig;
|
|
4
17
|
//#endregion
|
|
5
18
|
export { config as default };
|
|
@@ -1,71 +1,91 @@
|
|
|
1
1
|
//#region presets/lint/jest.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The files that Jest runs as tests by default. The preset applies its rules only to these files.
|
|
4
|
+
* To change the files or a rule, use the preset in an override of your own instead of `extends`:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import jest, { testFiles } from "adamantite/lint/jest"
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* overrides: [{ files: testFiles, plugins: jest.plugins, rules: { ...jest.rules } }],
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
const testFiles = ["**/*.{test,spec}.{js,jsx,mjs,cjs,ts,tsx,mts,cts}", "**/__tests__/**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"];
|
|
15
|
+
const plugins = ["jest"];
|
|
16
|
+
const rules = {
|
|
17
|
+
"jest/consistent-test-it": "error",
|
|
18
|
+
"jest/expect-expect": "error",
|
|
19
|
+
"jest/max-expects": "error",
|
|
20
|
+
"jest/max-nested-describe": "error",
|
|
21
|
+
"jest/no-alias-methods": "error",
|
|
22
|
+
"jest/no-commented-out-tests": "error",
|
|
23
|
+
"jest/no-conditional-expect": "error",
|
|
24
|
+
"jest/no-conditional-in-test": "error",
|
|
25
|
+
"jest/no-confusing-set-timeout": "error",
|
|
26
|
+
"jest/no-deprecated-functions": "error",
|
|
27
|
+
"jest/no-disabled-tests": "error",
|
|
28
|
+
"jest/no-done-callback": "error",
|
|
29
|
+
"jest/no-duplicate-hooks": "error",
|
|
30
|
+
"jest/no-export": "error",
|
|
31
|
+
"jest/no-focused-tests": "error",
|
|
32
|
+
"jest/no-hooks": "off",
|
|
33
|
+
"jest/no-identical-title": "error",
|
|
34
|
+
"jest/no-interpolation-in-snapshots": "error",
|
|
35
|
+
"jest/no-jasmine-globals": "error",
|
|
36
|
+
"jest/no-large-snapshots": "error",
|
|
37
|
+
"jest/no-mocks-import": "error",
|
|
38
|
+
"jest/no-restricted-jest-methods": "error",
|
|
39
|
+
"jest/no-restricted-matchers": "error",
|
|
40
|
+
"jest/no-standalone-expect": "error",
|
|
41
|
+
"jest/no-test-prefixes": "error",
|
|
42
|
+
"jest/no-test-return-statement": "error",
|
|
43
|
+
"jest/no-unneeded-async-expect-function": "error",
|
|
44
|
+
"jest/no-untyped-mock-factory": "error",
|
|
45
|
+
"jest/padding-around-after-all-blocks": "error",
|
|
46
|
+
"jest/padding-around-test-blocks": "error",
|
|
47
|
+
"jest/prefer-called-with": "error",
|
|
48
|
+
"jest/prefer-comparison-matcher": "error",
|
|
49
|
+
"jest/prefer-each": "error",
|
|
50
|
+
"jest/prefer-ending-with-an-expect": "error",
|
|
51
|
+
"jest/prefer-equality-matcher": "error",
|
|
52
|
+
"jest/prefer-expect-assertions": ["error", {
|
|
53
|
+
onlyFunctionsWithAsyncKeyword: true,
|
|
54
|
+
onlyFunctionsWithExpectInCallback: true,
|
|
55
|
+
onlyFunctionsWithExpectInLoop: true
|
|
56
|
+
}],
|
|
57
|
+
"jest/prefer-expect-resolves": "error",
|
|
58
|
+
"jest/prefer-hooks-in-order": "error",
|
|
59
|
+
"jest/prefer-hooks-on-top": "error",
|
|
60
|
+
"jest/prefer-jest-mocked": "error",
|
|
61
|
+
"jest/prefer-lowercase-title": "error",
|
|
62
|
+
"jest/prefer-mock-promise-shorthand": "error",
|
|
63
|
+
"jest/prefer-mock-return-shorthand": "error",
|
|
64
|
+
"jest/prefer-snapshot-hint": "error",
|
|
65
|
+
"jest/prefer-spy-on": "error",
|
|
66
|
+
"jest/prefer-strict-equal": "error",
|
|
67
|
+
"jest/prefer-to-be": "error",
|
|
68
|
+
"jest/prefer-to-contain": "error",
|
|
69
|
+
"jest/prefer-to-have-been-called": "error",
|
|
70
|
+
"jest/prefer-to-have-been-called-times": "error",
|
|
71
|
+
"jest/prefer-to-have-length": "error",
|
|
72
|
+
"jest/prefer-todo": "error",
|
|
73
|
+
"jest/require-hook": "error",
|
|
74
|
+
"jest/require-to-throw-message": "error",
|
|
75
|
+
"jest/require-top-level-describe": "error",
|
|
76
|
+
"jest/valid-describe-callback": "error",
|
|
77
|
+
"jest/valid-expect": "error",
|
|
78
|
+
"jest/valid-expect-in-promise": "error",
|
|
79
|
+
"jest/valid-title": "error"
|
|
69
80
|
};
|
|
81
|
+
const config = { overrides: [{
|
|
82
|
+
files: testFiles,
|
|
83
|
+
plugins,
|
|
84
|
+
rules
|
|
85
|
+
}] };
|
|
86
|
+
Object.defineProperties(config, {
|
|
87
|
+
plugins: { value: plugins },
|
|
88
|
+
rules: { value: rules }
|
|
89
|
+
});
|
|
70
90
|
//#endregion
|
|
71
|
-
export { config as default };
|
|
91
|
+
export { config as default, testFiles };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region presets/lint/plugin/glob.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert a glob to a regular expression that matches a whole path with forward slashes. Supports
|
|
4
|
+
* `**`, `*`, `?`, `[a-z]` and `[!a-z]` character classes, and `{a,b}` alternation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function globToRegExp(glob: string): RegExp;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region presets/lint/plugin/glob.ts
|
|
2
|
+
function escapeRegExp(text) {
|
|
3
|
+
return text.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Convert a glob to a regular expression that matches a whole path with forward slashes. Supports
|
|
7
|
+
* `**`, `*`, `?`, `[a-z]` and `[!a-z]` character classes, and `{a,b}` alternation.
|
|
8
|
+
*/
|
|
9
|
+
function globToRegExp(glob) {
|
|
10
|
+
let source = "";
|
|
11
|
+
let index = 0;
|
|
12
|
+
while (index < glob.length) {
|
|
13
|
+
const rest = glob.slice(index);
|
|
14
|
+
if (rest.startsWith("**/")) {
|
|
15
|
+
source += "(?:.*/)?";
|
|
16
|
+
index += 3;
|
|
17
|
+
} else if (rest === "/**") {
|
|
18
|
+
source += "(?:/.*)?";
|
|
19
|
+
index += 3;
|
|
20
|
+
} else if (rest.startsWith("**")) {
|
|
21
|
+
source += ".*";
|
|
22
|
+
index += 2;
|
|
23
|
+
} else if (rest.startsWith("*")) {
|
|
24
|
+
source += "[^/]*";
|
|
25
|
+
index += 1;
|
|
26
|
+
} else if (rest.startsWith("?")) {
|
|
27
|
+
source += "[^/]";
|
|
28
|
+
index += 1;
|
|
29
|
+
} else if (rest.startsWith("[") && rest.indexOf("]") > 1) {
|
|
30
|
+
const end = rest.indexOf("]");
|
|
31
|
+
const negated = rest.startsWith("[!");
|
|
32
|
+
const characters = rest.slice(negated ? 2 : 1, end).replaceAll(/[\\^]/g, String.raw`\$&`);
|
|
33
|
+
source += `[${negated ? "^" : ""}${characters}]`;
|
|
34
|
+
index += end + 1;
|
|
35
|
+
} else if (rest.startsWith("{") && rest.includes("}")) {
|
|
36
|
+
const end = rest.indexOf("}");
|
|
37
|
+
const alternatives = rest.slice(1, end).split(",").map((alternative) => escapeRegExp(alternative));
|
|
38
|
+
source += `(?:${alternatives.join("|")})`;
|
|
39
|
+
index += end + 1;
|
|
40
|
+
} else {
|
|
41
|
+
source += escapeRegExp(glob.charAt(index));
|
|
42
|
+
index += 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return new RegExp(`^${source}$`);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { globToRegExp };
|
|
@@ -10,6 +10,10 @@ export interface ImportedCall {
|
|
|
10
10
|
*/
|
|
11
11
|
readonly name: string;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Whether an expression is a string literal, such as the source of `import("./module.ts")`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isStringLiteral(node: ESTree.Expression): node is ESTree.StringLiteral;
|
|
13
17
|
/**
|
|
14
18
|
* Find the calls of the exports in `names` that `node` imports: direct calls through a named
|
|
15
19
|
* import, including aliased ones, and member calls such as `React.useState(0)` through a default or
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
function getImportedName(specifier) {
|
|
3
3
|
return specifier.imported.type === "Literal" ? specifier.imported.value : specifier.imported.name;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Whether an expression is a string literal, such as the source of `import("./module.ts")`.
|
|
7
|
+
*/
|
|
5
8
|
function isStringLiteral(node) {
|
|
6
9
|
return node.type === "Literal" && typeof node.value === "string";
|
|
7
10
|
}
|
|
@@ -50,4 +53,4 @@ function findImportedCalls(context, node, names) {
|
|
|
50
53
|
return calls;
|
|
51
54
|
}
|
|
52
55
|
//#endregion
|
|
53
|
-
export { findImportedCalls };
|
|
56
|
+
export { findImportedCalls, isStringLiteral };
|
|
@@ -2,10 +2,13 @@ import { Plugin, Rule } from "@oxlint/plugins";
|
|
|
2
2
|
//#region presets/lint/plugin/index.d.ts
|
|
3
3
|
interface AdamantitePlugin extends Plugin {
|
|
4
4
|
readonly rules: {
|
|
5
|
+
readonly "import-owners": Rule;
|
|
6
|
+
readonly layers: Rule;
|
|
5
7
|
readonly "no-overzealous-destructuring": Rule;
|
|
6
8
|
readonly "no-query-data-in-state": Rule;
|
|
7
9
|
readonly "no-react-state-hooks": Rule;
|
|
8
10
|
readonly "query-from-loader": Rule;
|
|
11
|
+
readonly "require-suppression-reason": Rule;
|
|
9
12
|
};
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import rule from "./rules/
|
|
2
|
-
import rule$1 from "./rules/
|
|
3
|
-
import rule$2 from "./rules/no-
|
|
4
|
-
import rule$3 from "./rules/query-
|
|
1
|
+
import rule from "./rules/import-owners.js";
|
|
2
|
+
import rule$1 from "./rules/layers.js";
|
|
3
|
+
import rule$2 from "./rules/no-overzealous-destructuring.js";
|
|
4
|
+
import rule$3 from "./rules/no-query-data-in-state.js";
|
|
5
|
+
import rule$4 from "./rules/no-react-state-hooks.js";
|
|
6
|
+
import rule$5 from "./rules/query-from-loader.js";
|
|
7
|
+
import rule$6 from "./rules/require-suppression-reason.js";
|
|
5
8
|
//#region presets/lint/plugin/index.ts
|
|
6
9
|
/**
|
|
7
10
|
* Adamantite's first-party Oxlint plugin. Presets load it by file URL, so target projects install
|
|
@@ -10,10 +13,13 @@ import rule$3 from "./rules/query-from-loader.js";
|
|
|
10
13
|
const plugin = {
|
|
11
14
|
meta: { name: "adamantite" },
|
|
12
15
|
rules: {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"no-
|
|
16
|
-
"query-
|
|
16
|
+
"import-owners": rule,
|
|
17
|
+
layers: rule$1,
|
|
18
|
+
"no-overzealous-destructuring": rule$2,
|
|
19
|
+
"no-query-data-in-state": rule$3,
|
|
20
|
+
"no-react-state-hooks": rule$4,
|
|
21
|
+
"query-from-loader": rule$5,
|
|
22
|
+
"require-suppression-reason": rule$6
|
|
17
23
|
}
|
|
18
24
|
};
|
|
19
25
|
//#endregion
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Options } from "@oxlint/plugins";
|
|
2
2
|
//#region presets/lint/plugin/options.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Read a string array from the rule's first option object.
|
|
5
|
-
*/
|
|
6
3
|
export declare function readStringArrayOption(options: Readonly<Options>, key: string): string[] | undefined;
|
|
4
|
+
export declare function readPositiveIntegerOption(options: Readonly<Options>, key: string): number | undefined;
|
|
5
|
+
export declare function readStringOption(options: Readonly<Options>, key: string): string | undefined;
|
|
6
|
+
export declare function readBooleanOption(options: Readonly<Options>, key: string): boolean | undefined;
|
|
7
7
|
/**
|
|
8
|
-
* Read
|
|
8
|
+
* Read an object from the rule's first option object.
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function readObjectOption(options: Readonly<Options>, key: string): Record<string, Options[number]> | undefined;
|
|
11
11
|
//#endregion
|
|
@@ -8,6 +8,9 @@ function isString(value) {
|
|
|
8
8
|
function isStringArray(value) {
|
|
9
9
|
return Array.isArray(value) && value.every((entry) => isString(entry));
|
|
10
10
|
}
|
|
11
|
+
function isBoolean(value) {
|
|
12
|
+
return typeof value === "boolean";
|
|
13
|
+
}
|
|
11
14
|
function isPositiveInteger(value) {
|
|
12
15
|
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
13
16
|
}
|
|
@@ -15,19 +18,28 @@ function readOption(options, key) {
|
|
|
15
18
|
const [first] = options;
|
|
16
19
|
return isOptionObject(first) ? first[key] : void 0;
|
|
17
20
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Read a string array from the rule's first option object.
|
|
20
|
-
*/
|
|
21
21
|
function readStringArrayOption(options, key) {
|
|
22
22
|
const value = readOption(options, key);
|
|
23
23
|
return isStringArray(value) ? value : void 0;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Read a positive integer from the rule's first option object.
|
|
27
|
-
*/
|
|
28
25
|
function readPositiveIntegerOption(options, key) {
|
|
29
26
|
const value = readOption(options, key);
|
|
30
27
|
return isPositiveInteger(value) ? value : void 0;
|
|
31
28
|
}
|
|
29
|
+
function readStringOption(options, key) {
|
|
30
|
+
const value = readOption(options, key);
|
|
31
|
+
return isString(value) ? value : void 0;
|
|
32
|
+
}
|
|
33
|
+
function readBooleanOption(options, key) {
|
|
34
|
+
const value = readOption(options, key);
|
|
35
|
+
return isBoolean(value) ? value : void 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Read an object from the rule's first option object.
|
|
39
|
+
*/
|
|
40
|
+
function readObjectOption(options, key) {
|
|
41
|
+
const value = readOption(options, key);
|
|
42
|
+
return isOptionObject(value) ? value : void 0;
|
|
43
|
+
}
|
|
32
44
|
//#endregion
|
|
33
|
-
export { readPositiveIntegerOption, readStringArrayOption };
|
|
45
|
+
export { readBooleanOption, readObjectOption, readPositiveIntegerOption, readStringArrayOption, readStringOption };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region presets/lint/plugin/resolver.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The file that `specifier` in `importer` resolves to, with `/` between folders, or undefined when
|
|
4
|
+
* it does not resolve. Oxlint caches the loaded plugin, so an editor language server needs a
|
|
5
|
+
* restart after a `package.json` or `tsconfig.json` changes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveImport(importer: string, specifier: string, conditions?: readonly string[]): string | undefined;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ResolverFactory } from "oxc-resolver";
|
|
2
|
+
//#region presets/lint/plugin/resolver.ts
|
|
3
|
+
const DEFAULT_CONDITIONS = [
|
|
4
|
+
"types",
|
|
5
|
+
"import",
|
|
6
|
+
"node",
|
|
7
|
+
"default"
|
|
8
|
+
];
|
|
9
|
+
const resolverOptions = {
|
|
10
|
+
extensionAlias: {
|
|
11
|
+
".cjs": [
|
|
12
|
+
".cts",
|
|
13
|
+
".d.cts",
|
|
14
|
+
".cjs"
|
|
15
|
+
],
|
|
16
|
+
".js": [
|
|
17
|
+
".ts",
|
|
18
|
+
".tsx",
|
|
19
|
+
".d.ts",
|
|
20
|
+
".js",
|
|
21
|
+
".jsx"
|
|
22
|
+
],
|
|
23
|
+
".jsx": [
|
|
24
|
+
".tsx",
|
|
25
|
+
".ts",
|
|
26
|
+
".d.ts",
|
|
27
|
+
".jsx",
|
|
28
|
+
".js"
|
|
29
|
+
],
|
|
30
|
+
".mjs": [
|
|
31
|
+
".mts",
|
|
32
|
+
".d.mts",
|
|
33
|
+
".mjs"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
extensions: [
|
|
37
|
+
".ts",
|
|
38
|
+
".tsx",
|
|
39
|
+
".mts",
|
|
40
|
+
".cts",
|
|
41
|
+
".d.ts",
|
|
42
|
+
".js",
|
|
43
|
+
".jsx",
|
|
44
|
+
".mjs",
|
|
45
|
+
".cjs",
|
|
46
|
+
".json"
|
|
47
|
+
],
|
|
48
|
+
symlinks: false,
|
|
49
|
+
tsconfig: "auto"
|
|
50
|
+
};
|
|
51
|
+
const baseResolver = new ResolverFactory({
|
|
52
|
+
...resolverOptions,
|
|
53
|
+
conditionNames: DEFAULT_CONDITIONS
|
|
54
|
+
});
|
|
55
|
+
const resolvers = /* @__PURE__ */ new Map();
|
|
56
|
+
function getResolver(conditions) {
|
|
57
|
+
if (conditions.length === 0) return baseResolver;
|
|
58
|
+
const key = conditions.join("\0");
|
|
59
|
+
let resolver = resolvers.get(key);
|
|
60
|
+
if (resolver === void 0) {
|
|
61
|
+
resolver = baseResolver.cloneWithOptions({
|
|
62
|
+
...resolverOptions,
|
|
63
|
+
conditionNames: [...conditions, ...DEFAULT_CONDITIONS]
|
|
64
|
+
});
|
|
65
|
+
resolvers.set(key, resolver);
|
|
66
|
+
}
|
|
67
|
+
return resolver;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The file that `specifier` in `importer` resolves to, with `/` between folders, or undefined when
|
|
71
|
+
* it does not resolve. Oxlint caches the loaded plugin, so an editor language server needs a
|
|
72
|
+
* restart after a `package.json` or `tsconfig.json` changes.
|
|
73
|
+
*/
|
|
74
|
+
function resolveImport(importer, specifier, conditions = []) {
|
|
75
|
+
const { path } = getResolver(conditions).resolveFileSync(importer, specifier);
|
|
76
|
+
return path === void 0 ? void 0 : path.replaceAll("\\", "/");
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { resolveImport };
|