adamantite 0.45.0 → 0.47.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 +447 -127
- package/dist/index.js +628 -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 +1 -2
- package/dist/presets/lint/effect.js +26 -1
- 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 +959 -33
- 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 → 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/presets/typescript/resets/array-includes.d.ts +15 -0
- package/dist/presets/typescript/resets/array-index-of.d.ts +23 -0
- package/dist/presets/typescript/resets/eval.d.ts +1 -0
- package/dist/presets/typescript/resets/fetch.d.ts +3 -0
- package/dist/presets/typescript/resets/filter-boolean.d.ts +24 -0
- package/dist/presets/typescript/resets/helpers.d.ts +15 -0
- package/dist/presets/typescript/resets/index.d.ts +20 -0
- package/dist/presets/typescript/resets/is-array.d.ts +3 -0
- package/dist/presets/typescript/resets/json-parse.d.ts +14 -0
- package/dist/presets/typescript/resets/license.md +12 -0
- package/dist/presets/typescript/resets/map-constructor.d.ts +3 -0
- package/dist/presets/typescript/resets/map-groupby.d.ts +3 -0
- package/dist/presets/typescript/resets/map-has.d.ts +9 -0
- package/dist/presets/typescript/resets/object-assign.d.ts +8 -0
- package/dist/presets/typescript/resets/object-get-prototype-of.d.ts +3 -0
- package/dist/presets/typescript/resets/object-groupby.d.ts +6 -0
- package/dist/presets/typescript/resets/object-values.d.ts +8 -0
- package/dist/presets/typescript/resets/reflect.d.ts +12 -0
- package/dist/presets/typescript/resets/set-has.d.ts +9 -0
- package/dist/presets/typescript/resets/storage.d.ts +3 -0
- package/dist/presets/typescript.json +13 -0
- package/dist/runtime-CVZPDpfE.js +11 -0
- package/package.json +81 -19
- package/skills/adamantite/SKILL.md +110 -207
- package/skills/adamantite/references/custom-rules.md +120 -0
- package/skills/adamantite/references/lint-rules.md +152 -0
- package/skills/adamantite/references/setup.md +70 -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,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,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference path="helpers.d.ts" />
|
|
2
|
+
|
|
3
|
+
interface ReadonlyArray<T> {
|
|
4
|
+
includes(
|
|
5
|
+
searchElement: T | (AdamantiteTypeScript.WidenLiteral<T> & {}),
|
|
6
|
+
fromIndex?: number
|
|
7
|
+
): boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Array<T> {
|
|
11
|
+
includes(
|
|
12
|
+
searchElement: T | (AdamantiteTypeScript.WidenLiteral<T> & {}),
|
|
13
|
+
fromIndex?: number
|
|
14
|
+
): boolean
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference path="helpers.d.ts" />
|
|
2
|
+
|
|
3
|
+
interface ReadonlyArray<T> {
|
|
4
|
+
lastIndexOf(
|
|
5
|
+
searchElement: T | (AdamantiteTypeScript.WidenLiteral<T> & {}),
|
|
6
|
+
fromIndex?: number
|
|
7
|
+
): number
|
|
8
|
+
indexOf(
|
|
9
|
+
searchElement: T | (AdamantiteTypeScript.WidenLiteral<T> & {}),
|
|
10
|
+
fromIndex?: number
|
|
11
|
+
): number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Array<T> {
|
|
15
|
+
lastIndexOf(
|
|
16
|
+
searchElement: T | (AdamantiteTypeScript.WidenLiteral<T> & {}),
|
|
17
|
+
fromIndex?: number
|
|
18
|
+
): number
|
|
19
|
+
indexOf(
|
|
20
|
+
searchElement: T | (AdamantiteTypeScript.WidenLiteral<T> & {}),
|
|
21
|
+
fromIndex?: number
|
|
22
|
+
): number
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare function eval(x: string): unknown
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference path="helpers.d.ts" />
|
|
2
|
+
|
|
3
|
+
// NoInfer<S> prevents contextual typing from flowing backward through S when
|
|
4
|
+
// .filter(Boolean) is used inline as a function argument, which would silently
|
|
5
|
+
// skip structural checks on array elements. See total-typescript/ts-reset#233.
|
|
6
|
+
//
|
|
7
|
+
// The <S extends T> generic is not needed for inference (NoInfer kills that) —
|
|
8
|
+
// it exists solely to keep TypeScript's overload resolution correct so that
|
|
9
|
+
// non-Boolean predicates on union arrays (e.g. string[] | number[]) fall
|
|
10
|
+
// through to the built-in filter signature instead of matching this overload.
|
|
11
|
+
|
|
12
|
+
interface Array<T> {
|
|
13
|
+
filter<S extends T>(
|
|
14
|
+
predicate: BooleanConstructor,
|
|
15
|
+
thisArg?: unknown
|
|
16
|
+
): Array<AdamantiteTypeScript.NonFalsy<NoInfer<S>>>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ReadonlyArray<T> {
|
|
20
|
+
filter<S extends T>(
|
|
21
|
+
predicate: BooleanConstructor,
|
|
22
|
+
thisArg?: unknown
|
|
23
|
+
): Array<AdamantiteTypeScript.NonFalsy<NoInfer<S>>>
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare namespace AdamantiteTypeScript {
|
|
2
|
+
type NonFalsy<T> = T extends false | 0 | "" | null | undefined | 0n ? never : T
|
|
3
|
+
|
|
4
|
+
type WidenLiteral<T> = T extends string
|
|
5
|
+
? string
|
|
6
|
+
: T extends number
|
|
7
|
+
? number
|
|
8
|
+
: T extends boolean
|
|
9
|
+
? boolean
|
|
10
|
+
: T extends bigint
|
|
11
|
+
? bigint
|
|
12
|
+
: T extends symbol
|
|
13
|
+
? symbol
|
|
14
|
+
: T
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Adamantite's type resets, which `adamantite/typescript` loads. Each file replaces the type of
|
|
2
|
+
// one built-in API. The resets started from ts-reset at commit f36610ba441b8ea1c7cf7349dd71bee26c2e6a3b. See license.md.
|
|
3
|
+
|
|
4
|
+
/// <reference path="fetch.d.ts" />
|
|
5
|
+
/// <reference path="filter-boolean.d.ts" />
|
|
6
|
+
/// <reference path="is-array.d.ts" />
|
|
7
|
+
/// <reference path="json-parse.d.ts" />
|
|
8
|
+
/// <reference path="array-includes.d.ts" />
|
|
9
|
+
/// <reference path="set-has.d.ts" />
|
|
10
|
+
/// <reference path="map-constructor.d.ts" />
|
|
11
|
+
/// <reference path="map-has.d.ts" />
|
|
12
|
+
/// <reference path="array-index-of.d.ts" />
|
|
13
|
+
/// <reference path="map-groupby.d.ts" />
|
|
14
|
+
/// <reference path="object-groupby.d.ts" />
|
|
15
|
+
/// <reference path="storage.d.ts" />
|
|
16
|
+
/// <reference path="object-values.d.ts" />
|
|
17
|
+
/// <reference path="object-assign.d.ts" />
|
|
18
|
+
/// <reference path="object-get-prototype-of.d.ts" />
|
|
19
|
+
/// <reference path="reflect.d.ts" />
|
|
20
|
+
/// <reference path="eval.d.ts" />
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface JSON {
|
|
2
|
+
/**
|
|
3
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
4
|
+
*
|
|
5
|
+
* @param text A valid JSON string.
|
|
6
|
+
* @param reviver A function that transforms the results. This function is called for each member
|
|
7
|
+
* of the object. If a member contains nested objects, the nested objects are transformed before
|
|
8
|
+
* the parent object is.
|
|
9
|
+
*/
|
|
10
|
+
parse(text: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown
|
|
11
|
+
// A reviver that annotates `this` or `value` does not match the overload above. This overload
|
|
12
|
+
// takes it, so the call does not fall through to the library overload that returns `any`.
|
|
13
|
+
parse(text: string, reviver: (this: never, key: string, value: never) => unknown): unknown
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Type reset license
|
|
2
|
+
|
|
3
|
+
Adamantite's type resets started from [ts-reset](https://github.com/total-typescript/ts-reset) at
|
|
4
|
+
commit f36610ba441b8ea1c7cf7349dd71bee26c2e6a3b. The files that come from ts-reset keep its license:
|
|
5
|
+
|
|
6
|
+
Copyright 2023 Matthew Pocock
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The library's typed overloads come first, because TypeScript places this block's overloads
|
|
2
|
+
// before the library's. Without them, the variadic overload would also take typed calls.
|
|
3
|
+
interface ObjectConstructor {
|
|
4
|
+
assign<T extends {}, U>(target: T, source: U): T & U
|
|
5
|
+
assign<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V
|
|
6
|
+
assign<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W
|
|
7
|
+
assign(target: object, ...sources: unknown[]): unknown
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The library's typed overloads come first, because TypeScript places this block's overloads
|
|
2
|
+
// before the library's. Without them, the `{}` overloads would also take records and arrays.
|
|
3
|
+
interface ObjectConstructor {
|
|
4
|
+
values<T>(o: { [s: string]: T } | ArrayLike<T>): T[]
|
|
5
|
+
values(o: {}): unknown[]
|
|
6
|
+
entries<T>(o: { [s: string]: T } | ArrayLike<T>): Array<[string, T]>
|
|
7
|
+
entries(o: {}): Array<[string, unknown]>
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare namespace Reflect {
|
|
2
|
+
function apply(
|
|
3
|
+
target: Function,
|
|
4
|
+
thisArgument: unknown,
|
|
5
|
+
argumentsList: ArrayLike<unknown>
|
|
6
|
+
): unknown
|
|
7
|
+
function construct(
|
|
8
|
+
target: Function,
|
|
9
|
+
argumentsList: ArrayLike<unknown>,
|
|
10
|
+
newTarget?: Function
|
|
11
|
+
): unknown
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
// The strict options of the tsconfig preset, and Adamantite's type resets. JSON.parse(),
|
|
4
|
+
// response.json(), and property reads on localStorage return `unknown` instead of `any`.
|
|
5
|
+
// Libraries should extend `adamantite/tsconfig`, because their declaration files can name the
|
|
6
|
+
// `AdamantiteTypeScript` helper types that consumers do not have. A project without the resets
|
|
7
|
+
// extends `adamantite/tsconfig`.
|
|
8
|
+
"extends": "./tsconfig.json",
|
|
9
|
+
"files": ["./typescript/resets/index.d.ts"],
|
|
10
|
+
// A `files` list empties the default include, so include the extending project's files again.
|
|
11
|
+
// A config that sets its own `files` still inherits this `include`.
|
|
12
|
+
"include": ["${configDir}/**/*"]
|
|
13
|
+
}
|