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
|
@@ -1,94 +1,114 @@
|
|
|
1
1
|
//#region presets/lint/vitest.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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The files that Vitest 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 vitest, { testFiles } from "adamantite/lint/vitest"
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* overrides: [{ files: testFiles, plugins: vitest.plugins, rules: { ...vitest.rules } }],
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
const testFiles = ["**/*.{test,spec}.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"];
|
|
15
|
+
const plugins = ["vitest"];
|
|
16
|
+
const rules = {
|
|
17
|
+
"vitest/consistent-each-for": "error",
|
|
18
|
+
"vitest/consistent-test-it": "error",
|
|
19
|
+
"vitest/hoisted-apis-on-top": "error",
|
|
20
|
+
"vitest/max-expects": "error",
|
|
21
|
+
"vitest/max-nested-describe": "error",
|
|
22
|
+
"vitest/no-alias-methods": "error",
|
|
23
|
+
"vitest/no-commented-out-tests": "error",
|
|
24
|
+
"vitest/no-conditional-expect": "error",
|
|
25
|
+
"vitest/no-conditional-in-test": "error",
|
|
26
|
+
"vitest/no-conditional-tests": "error",
|
|
27
|
+
"vitest/no-disabled-tests": "error",
|
|
28
|
+
"vitest/no-duplicate-hooks": "error",
|
|
29
|
+
"vitest/no-focused-tests": "error",
|
|
30
|
+
"vitest/no-hooks": "off",
|
|
31
|
+
"vitest/no-identical-title": "error",
|
|
32
|
+
"vitest/no-import-node-test": "error",
|
|
33
|
+
"vitest/no-importing-vitest-globals": "off",
|
|
34
|
+
"vitest/no-interpolation-in-snapshots": "error",
|
|
35
|
+
"vitest/no-large-snapshots": "error",
|
|
36
|
+
"vitest/no-mocks-import": "error",
|
|
37
|
+
"vitest/no-restricted-matchers": "error",
|
|
38
|
+
"vitest/no-standalone-expect": ["error", { additionalTestBlockFunctions: [
|
|
39
|
+
"it.effect",
|
|
40
|
+
"it.effect.each",
|
|
41
|
+
"it.effect.fails",
|
|
42
|
+
"it.effect.only",
|
|
43
|
+
"it.effect.prop",
|
|
44
|
+
"it.effect.runIf",
|
|
45
|
+
"it.effect.skip",
|
|
46
|
+
"it.effect.skipIf",
|
|
47
|
+
"it.live",
|
|
48
|
+
"it.live.each",
|
|
49
|
+
"it.live.fails",
|
|
50
|
+
"it.live.only",
|
|
51
|
+
"it.live.prop",
|
|
52
|
+
"it.live.runIf",
|
|
53
|
+
"it.live.skip",
|
|
54
|
+
"it.live.skipIf",
|
|
55
|
+
"it.prop"
|
|
56
|
+
] }],
|
|
57
|
+
"vitest/no-test-prefixes": "error",
|
|
58
|
+
"vitest/no-test-return-statement": "error",
|
|
59
|
+
"vitest/no-unneeded-async-expect-function": "error",
|
|
60
|
+
"vitest/padding-around-test-blocks": "error",
|
|
61
|
+
"vitest/prefer-called-exactly-once-with": "error",
|
|
62
|
+
"vitest/prefer-called-once": "error",
|
|
63
|
+
"vitest/prefer-called-times": "off",
|
|
64
|
+
"vitest/prefer-called-with": "error",
|
|
65
|
+
"vitest/prefer-comparison-matcher": "error",
|
|
66
|
+
"vitest/prefer-describe-function-title": "off",
|
|
67
|
+
"vitest/prefer-each": "error",
|
|
68
|
+
"vitest/prefer-equality-matcher": "error",
|
|
69
|
+
"vitest/prefer-expect-assertions": ["error", {
|
|
70
|
+
onlyFunctionsWithAsyncKeyword: true,
|
|
71
|
+
onlyFunctionsWithExpectInCallback: true,
|
|
72
|
+
onlyFunctionsWithExpectInLoop: true
|
|
73
|
+
}],
|
|
74
|
+
"vitest/prefer-expect-resolves": "error",
|
|
75
|
+
"vitest/prefer-expect-type-of": "error",
|
|
76
|
+
"vitest/prefer-hooks-in-order": "error",
|
|
77
|
+
"vitest/prefer-hooks-on-top": "error",
|
|
78
|
+
"vitest/prefer-import-in-mock": "error",
|
|
79
|
+
"vitest/prefer-importing-vitest-globals": "error",
|
|
80
|
+
"vitest/prefer-lowercase-title": "error",
|
|
81
|
+
"vitest/prefer-mock-promise-shorthand": "error",
|
|
82
|
+
"vitest/prefer-mock-return-shorthand": "error",
|
|
83
|
+
"vitest/prefer-snapshot-hint": "error",
|
|
84
|
+
"vitest/prefer-spy-on": "error",
|
|
85
|
+
"vitest/prefer-strict-boolean-matchers": "error",
|
|
86
|
+
"vitest/prefer-strict-equal": "error",
|
|
87
|
+
"vitest/prefer-to-be": "error",
|
|
88
|
+
"vitest/prefer-to-be-object": "error",
|
|
89
|
+
"vitest/prefer-to-contain": "error",
|
|
90
|
+
"vitest/prefer-to-have-been-called-times": "error",
|
|
91
|
+
"vitest/prefer-to-have-length": "error",
|
|
92
|
+
"vitest/prefer-todo": "error",
|
|
93
|
+
"vitest/require-awaited-expect-poll": "error",
|
|
94
|
+
"vitest/require-hook": "error",
|
|
95
|
+
"vitest/require-local-test-context-for-concurrent-snapshots": "error",
|
|
96
|
+
"vitest/require-mock-type-parameters": "error",
|
|
97
|
+
"vitest/require-to-throw-message": "error",
|
|
98
|
+
"vitest/require-top-level-describe": "error",
|
|
99
|
+
"vitest/valid-describe-callback": "error",
|
|
100
|
+
"vitest/valid-expect": "error",
|
|
101
|
+
"vitest/valid-expect-in-promise": "error",
|
|
102
|
+
"vitest/valid-title": "error"
|
|
92
103
|
};
|
|
104
|
+
const config = { overrides: [{
|
|
105
|
+
files: testFiles,
|
|
106
|
+
plugins,
|
|
107
|
+
rules
|
|
108
|
+
}] };
|
|
109
|
+
Object.defineProperties(config, {
|
|
110
|
+
plugins: { value: plugins },
|
|
111
|
+
rules: { value: rules }
|
|
112
|
+
});
|
|
93
113
|
//#endregion
|
|
94
|
-
export { config as default };
|
|
114
|
+
export { config as default, testFiles };
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
import { DummyRule, OxlintConfig } from "oxlint";
|
|
2
|
-
//#region presets/
|
|
3
|
-
/**
|
|
4
|
-
* The plugin name that `custom()` uses when no `name` is given.
|
|
5
|
-
*/
|
|
6
|
-
export declare const DEFAULT_PLUGIN_NAME = "project";
|
|
7
|
-
/**
|
|
8
|
-
* The rule name that a rule file defines: its file name without the extension.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getRuleName(file: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Whether a file in a rules folder is a rule: it has a JavaScript or TypeScript extension, is not a
|
|
13
|
-
* declaration file, and does not start with `_`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function isRuleFile(name: string): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* The rule files in a rules folder. Subfolders are not read, so helpers can also live there.
|
|
18
|
-
*/
|
|
19
|
-
export declare function listRuleFiles(dir: string): string[];
|
|
2
|
+
//#region presets/rules/custom.d.ts
|
|
20
3
|
export interface CustomRulesOptions {
|
|
21
4
|
/**
|
|
22
5
|
* The rules folder. A relative path resolves from the file that calls `custom()`, not from the
|
|
23
|
-
* working directory. Default: `.adamantite/
|
|
6
|
+
* working directory. Default: `.adamantite/lint`.
|
|
24
7
|
*/
|
|
25
8
|
readonly dir?: string;
|
|
26
9
|
/**
|
|
@@ -51,7 +34,7 @@ export declare function findCallerFile(stack: string, ownFile: string): string |
|
|
|
51
34
|
* ```ts
|
|
52
35
|
* import { defineConfig } from "oxlint"
|
|
53
36
|
* import core from "adamantite/lint"
|
|
54
|
-
* import custom from "adamantite/
|
|
37
|
+
* import custom from "adamantite/rules"
|
|
55
38
|
*
|
|
56
39
|
* export default defineConfig({ extends: [core, custom()] })
|
|
57
40
|
* ```
|
|
@@ -1,42 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CACHE_DIRECTORY, getRuleName, listRuleFiles } from "./folder.js";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { tmpdir } from "node:os";
|
|
4
|
-
import { dirname,
|
|
5
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
5
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
-
//#region presets/
|
|
8
|
+
//#region presets/rules/custom.ts
|
|
7
9
|
const MODULE_EXTENSION = import.meta.url.endsWith(".ts") ? "ts" : "js";
|
|
8
|
-
const RULES_MODULE_URL = new URL(
|
|
9
|
-
const DEFAULT_DIRECTORY = ".adamantite/rules";
|
|
10
|
-
const CACHE_DIRECTORY = join("node_modules", ".cache", "adamantite");
|
|
11
|
-
/**
|
|
12
|
-
* The plugin name that `custom()` uses when no `name` is given.
|
|
13
|
-
*/
|
|
14
|
-
const DEFAULT_PLUGIN_NAME = "project";
|
|
15
|
-
const RULE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
16
|
-
".js",
|
|
17
|
-
".mjs",
|
|
18
|
-
".mts",
|
|
19
|
-
".ts"
|
|
20
|
-
]);
|
|
21
|
-
/**
|
|
22
|
-
* The rule name that a rule file defines: its file name without the extension.
|
|
23
|
-
*/
|
|
24
|
-
function getRuleName(file) {
|
|
25
|
-
return file.slice(0, -extname(file).length);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Whether a file in a rules folder is a rule: it has a JavaScript or TypeScript extension, is not a
|
|
29
|
-
* declaration file, and does not start with `_`.
|
|
30
|
-
*/
|
|
31
|
-
function isRuleFile(name) {
|
|
32
|
-
return RULE_FILE_EXTENSIONS.has(extname(name)) && !name.startsWith("_") && !/\.d\.m?ts$/.test(name);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The rule files in a rules folder. Subfolders are not read, so helpers can also live there.
|
|
36
|
-
*/
|
|
37
|
-
function listRuleFiles(dir) {
|
|
38
|
-
return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && isRuleFile(entry.name)).map((entry) => entry.name);
|
|
39
|
-
}
|
|
10
|
+
const RULES_MODULE_URL = new URL(`load.${MODULE_EXTENSION}`, import.meta.url).href;
|
|
40
11
|
/**
|
|
41
12
|
* Normalize a file from a stack frame: drop the query string and hash, which Oxlint adds to bypass
|
|
42
13
|
* the module cache, and convert a file URL to a path.
|
|
@@ -76,18 +47,50 @@ function findNodeModules(from) {
|
|
|
76
47
|
if (dirname(current) === current) return;
|
|
77
48
|
}
|
|
78
49
|
}
|
|
50
|
+
function hasContent(path, content) {
|
|
51
|
+
return existsSync(path) && readFileSync(path, "utf8") === content;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Write `content` to `path` unless the file already holds it. Several Oxlint processes can load the
|
|
55
|
+
* config at once, as in a monorepo task runner, and one can import the module while another writes
|
|
56
|
+
* it. A write in place truncates the file first, so the module goes to a temporary file that a
|
|
57
|
+
* rename moves over `path` in one step.
|
|
58
|
+
*/
|
|
79
59
|
function writeIfChanged(path, content) {
|
|
80
|
-
if (
|
|
60
|
+
if (hasContent(path, content)) return;
|
|
81
61
|
mkdirSync(dirname(path), { recursive: true });
|
|
82
|
-
|
|
62
|
+
const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
63
|
+
writeFileSync(temporary, content, { flag: "wx" });
|
|
64
|
+
try {
|
|
65
|
+
renameSync(temporary, path);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
rmSync(temporary, { force: true });
|
|
68
|
+
if (!hasContent(path, content)) throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A folder in the OS temporary directory that only the current user can write. The temporary
|
|
73
|
+
* directory can be shared, so another user could create a folder there first, and then replace an
|
|
74
|
+
* entry module after `custom()` writes it. Windows gives each user a temporary directory.
|
|
75
|
+
*/
|
|
76
|
+
function getPrivateTemporaryDirectory() {
|
|
77
|
+
const uid = process.geteuid?.();
|
|
78
|
+
const dir = join(tmpdir(), uid === void 0 ? "adamantite" : `adamantite-${uid}`);
|
|
79
|
+
mkdirSync(dir, {
|
|
80
|
+
mode: 448,
|
|
81
|
+
recursive: true
|
|
82
|
+
});
|
|
83
|
+
const stats = lstatSync(dir);
|
|
84
|
+
if (uid !== void 0 && (!stats.isDirectory() || stats.uid !== uid || (stats.mode & 18) !== 0)) throw new Error(`${dir} is not a folder that only the current user can write.`);
|
|
85
|
+
return dir;
|
|
83
86
|
}
|
|
84
87
|
/**
|
|
85
88
|
* Write the entry module for a rules folder and return its file URL. The module goes to
|
|
86
|
-
* `node_modules/.cache/adamantite` above the folder, or to the OS temporary
|
|
87
|
-
* `node_modules` folder is found or it cannot be written.
|
|
89
|
+
* `node_modules/.cache/adamantite` above the folder, or to a private folder in the OS temporary
|
|
90
|
+
* directory when no `node_modules` folder is found or it cannot be written.
|
|
88
91
|
*/
|
|
89
92
|
function writeEntryModule(dir, name) {
|
|
90
|
-
const fileName = `rules-${createHash("sha256").update(`${dir}\0${name}`).digest("hex").slice(0, 16)}.mjs`;
|
|
93
|
+
const fileName = `rules-${createHash("sha256").update(`${RULES_MODULE_URL}\0${dir}\0${name}`).digest("hex").slice(0, 16)}.mjs`;
|
|
91
94
|
const content = [
|
|
92
95
|
`import { loadRules } from ${JSON.stringify(RULES_MODULE_URL)}`,
|
|
93
96
|
"",
|
|
@@ -95,9 +98,10 @@ function writeEntryModule(dir, name) {
|
|
|
95
98
|
""
|
|
96
99
|
].join("\n");
|
|
97
100
|
const root = findNodeModules(dir);
|
|
98
|
-
const
|
|
101
|
+
const folders = [...root === void 0 ? [] : [() => join(root, CACHE_DIRECTORY)], () => getPrivateTemporaryDirectory()];
|
|
99
102
|
const failures = [];
|
|
100
|
-
for (const
|
|
103
|
+
for (const folder of folders) try {
|
|
104
|
+
const path = join(folder(), fileName);
|
|
101
105
|
writeIfChanged(path, content);
|
|
102
106
|
return pathToFileURL(path).href;
|
|
103
107
|
} catch (error) {
|
|
@@ -116,14 +120,14 @@ function writeEntryModule(dir, name) {
|
|
|
116
120
|
* ```ts
|
|
117
121
|
* import { defineConfig } from "oxlint"
|
|
118
122
|
* import core from "adamantite/lint"
|
|
119
|
-
* import custom from "adamantite/
|
|
123
|
+
* import custom from "adamantite/rules"
|
|
120
124
|
*
|
|
121
125
|
* export default defineConfig({ extends: [core, custom()] })
|
|
122
126
|
* ```
|
|
123
127
|
*/
|
|
124
128
|
function custom(options = {}) {
|
|
125
129
|
const name = options.name ?? "project";
|
|
126
|
-
const dir = resolveRulesDirectory(options.dir ??
|
|
130
|
+
const dir = resolveRulesDirectory(options.dir ?? ".adamantite/lint", (/* @__PURE__ */ new Error("custom()")).stack ?? "");
|
|
127
131
|
if (!existsSync(dir)) return {};
|
|
128
132
|
const files = listRuleFiles(dir);
|
|
129
133
|
if (files.length === 0) return {};
|
|
@@ -139,4 +143,4 @@ function custom(options = {}) {
|
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
145
|
//#endregion
|
|
142
|
-
export {
|
|
146
|
+
export { custom as default, findCallerFile };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region presets/rules/folder.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The rules folder that `custom()` loads when no `dir` is given, relative to the file that calls
|
|
4
|
+
* it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_DIRECTORY = ".adamantite/lint";
|
|
7
|
+
/**
|
|
8
|
+
* The folder, relative to a project, where `custom()` writes the entry module of each rules folder.
|
|
9
|
+
* A test in the CLI checks that the trial copy of `adamantite rule try` does not link this folder
|
|
10
|
+
* to the project.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CACHE_DIRECTORY: string;
|
|
13
|
+
/**
|
|
14
|
+
* The plugin name that prefixes every rule when `custom()` is given no `name`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_PLUGIN_NAME = "project";
|
|
17
|
+
/**
|
|
18
|
+
* The extensions of rule files.
|
|
19
|
+
*/
|
|
20
|
+
export declare const RULE_FILE_EXTENSIONS: ReadonlySet<string>;
|
|
21
|
+
export declare function getRuleName(file: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Whether a file in a rules folder is a rule: it has a JavaScript or TypeScript extension, is not a
|
|
24
|
+
* declaration or test file, and does not start with `_`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isRuleFile(name: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The rule files in a rules folder. Subfolders are not read, so helpers can also live there. Each
|
|
29
|
+
* rule name must have one file, because `custom()` and `loadRules` key the rules by name. Two files
|
|
30
|
+
* for one name, such as `no-foo.js` and `no-foo.ts`, throw instead of one silently replacing the
|
|
31
|
+
* other.
|
|
32
|
+
*/
|
|
33
|
+
export declare function listRuleFiles(dir: string): string[];
|
|
34
|
+
//#endregion
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { extname, join } from "node:path";
|
|
3
|
+
//#region presets/rules/folder.ts
|
|
4
|
+
/**
|
|
5
|
+
* The rules folder that `custom()` loads when no `dir` is given, relative to the file that calls
|
|
6
|
+
* it.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_DIRECTORY = ".adamantite/lint";
|
|
9
|
+
/**
|
|
10
|
+
* The folder, relative to a project, where `custom()` writes the entry module of each rules folder.
|
|
11
|
+
* A test in the CLI checks that the trial copy of `adamantite rule try` does not link this folder
|
|
12
|
+
* to the project.
|
|
13
|
+
*/
|
|
14
|
+
const CACHE_DIRECTORY = join("node_modules", ".cache", "adamantite");
|
|
15
|
+
/**
|
|
16
|
+
* The plugin name that prefixes every rule when `custom()` is given no `name`.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_PLUGIN_NAME = "project";
|
|
19
|
+
/**
|
|
20
|
+
* The extensions of rule files.
|
|
21
|
+
*/
|
|
22
|
+
const RULE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
23
|
+
".js",
|
|
24
|
+
".mjs",
|
|
25
|
+
".mts",
|
|
26
|
+
".ts"
|
|
27
|
+
]);
|
|
28
|
+
function getRuleName(file) {
|
|
29
|
+
return file.slice(0, -extname(file).length);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether a file in a rules folder is a rule: it has a JavaScript or TypeScript extension, is not a
|
|
33
|
+
* declaration or test file, and does not start with `_`.
|
|
34
|
+
*/
|
|
35
|
+
function isRuleFile(name) {
|
|
36
|
+
return RULE_FILE_EXTENSIONS.has(extname(name)) && !name.startsWith("_") && !/\.(?:d\.m?ts|test\.[^.]+)$/.test(name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The rule files in a rules folder. Subfolders are not read, so helpers can also live there. Each
|
|
40
|
+
* rule name must have one file, because `custom()` and `loadRules` key the rules by name. Two files
|
|
41
|
+
* for one name, such as `no-foo.js` and `no-foo.ts`, throw instead of one silently replacing the
|
|
42
|
+
* other.
|
|
43
|
+
*/
|
|
44
|
+
function listRuleFiles(dir) {
|
|
45
|
+
const files = readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && isRuleFile(entry.name)).map((entry) => entry.name);
|
|
46
|
+
const filesByRule = /* @__PURE__ */ new Map();
|
|
47
|
+
for (const file of files) filesByRule.set(getRuleName(file), [...filesByRule.get(getRuleName(file)) ?? [], file]);
|
|
48
|
+
for (const [rule, ruleFiles] of filesByRule) if (ruleFiles.length > 1) throw new Error(`The rules folder ${dir} has more than one file for the rule \`${rule}\`: ${ruleFiles.join(", ")}. Keep one of them.`);
|
|
49
|
+
return files;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { CACHE_DIRECTORY, DEFAULT_DIRECTORY, DEFAULT_PLUGIN_NAME, RULE_FILE_EXTENSIONS, getRuleName, isRuleFile, listRuleFiles };
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Import every rule file in a rules folder and return them as one Oxlint plugin. The entry module
|
|
5
|
-
* that `custom()` writes calls this function.
|
|
6
|
-
*/
|
|
7
|
-
export declare function loadRules(dir: string, name?: string): Promise<Plugin>;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { type Context, type Diagnostic, type ESTree, type Fix, type Fixer, type Node, type Options, type Rule, type RuleMeta, type SourceCode, type Visitor, type VisitorWithHooks, defineRule };
|
|
1
|
+
import custom, { CustomRulesOptions } from "./custom.js";
|
|
2
|
+
export { type CustomRulesOptions, custom as default };
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { defineRule } from "@oxlint/plugins";
|
|
5
|
-
//#region presets/rules/index.ts
|
|
6
|
-
async function importRule(path) {
|
|
7
|
-
let module;
|
|
8
|
-
try {
|
|
9
|
-
module = await import(pathToFileURL(path).href);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
12
|
-
throw new Error(`Custom rule ${path} failed to load: ${reason}\nRule files run with type stripping, so use erasable TypeScript only: no enum, namespace, or parameter properties.`, { cause: error });
|
|
13
|
-
}
|
|
14
|
-
if (module.default === void 0) throw new Error(`Custom rule ${path} has no default export. Export the rule as default.`);
|
|
15
|
-
return module.default;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Import every rule file in a rules folder and return them as one Oxlint plugin. The entry module
|
|
19
|
-
* that `custom()` writes calls this function.
|
|
20
|
-
*/
|
|
21
|
-
async function loadRules(dir, name = DEFAULT_PLUGIN_NAME) {
|
|
22
|
-
const rules = await Promise.all(listRuleFiles(dir).map(async (file) => [getRuleName(file), await importRule(join(dir, file))]));
|
|
23
|
-
return {
|
|
24
|
-
meta: { name },
|
|
25
|
-
rules: Object.fromEntries(rules)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { defineRule, loadRules };
|
|
1
|
+
export { default } from "./custom.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from "@oxlint/plugins";
|
|
2
|
+
//#region presets/rules/load.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Import every rule file in a rules folder and return them as one Oxlint plugin. The entry module
|
|
5
|
+
* that `custom()` writes calls this function.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadRules(dir: string, name?: string): Promise<Plugin>;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DEFAULT_PLUGIN_NAME, getRuleName, listRuleFiles } from "./folder.js";
|
|
2
|
+
import { definePlugin } from "./plugin.js";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
//#region presets/rules/load.ts
|
|
6
|
+
async function importRule(path) {
|
|
7
|
+
let module;
|
|
8
|
+
try {
|
|
9
|
+
module = await import(pathToFileURL(path).href);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
12
|
+
throw new Error(`Custom rule ${path} failed to load: ${reason}\nRule files run with type stripping, so use erasable TypeScript only: no enum, namespace, or parameter properties.`, { cause: error });
|
|
13
|
+
}
|
|
14
|
+
if (module.default === void 0) throw new Error(`Custom rule ${path} has no default export. Export the rule as default.`);
|
|
15
|
+
return module.default;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Import every rule file in a rules folder and return them as one Oxlint plugin. The entry module
|
|
19
|
+
* that `custom()` writes calls this function.
|
|
20
|
+
*/
|
|
21
|
+
async function loadRules(dir, name = DEFAULT_PLUGIN_NAME) {
|
|
22
|
+
const rules = await Promise.all(listRuleFiles(dir).map(async (file) => [getRuleName(file), await importRule(join(dir, file))]));
|
|
23
|
+
return definePlugin({
|
|
24
|
+
meta: { name },
|
|
25
|
+
rules: Object.fromEntries(rules)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { loadRules };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { definePlugin, defineRule, eslintCompatPlugin } from "@oxlint/plugins";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import { RuleTester, RuleTester as RuleTester$1 } from "oxlint/plugins-dev";
|
|
3
|
+
//#region presets/rules/testing.ts
|
|
4
|
+
RuleTester$1.describe = (text, method) => {
|
|
5
|
+
describe(text, method);
|
|
6
|
+
};
|
|
7
|
+
RuleTester$1.it = (text, method) => {
|
|
8
|
+
it(text, method);
|
|
9
|
+
};
|
|
10
|
+
RuleTester$1.itOnly = (text, method) => {
|
|
11
|
+
it.only(text, method);
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { RuleTester };
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"strict": true,
|
|
18
18
|
|
|
19
19
|
"allowUnreachableCode": false,
|
|
20
|
+
// Node.js type stripping, Bun, and custom rule files run only erasable syntax. Core lint
|
|
21
|
+
// reports namespaces and parameter properties, but no lint rule bans `enum`.
|
|
22
|
+
"erasableSyntaxOnly": true,
|
|
20
23
|
"forceConsistentCasingInFileNames": true,
|
|
21
24
|
"noImplicitAny": true,
|
|
22
25
|
"noImplicitOverride": true,
|