adamantite 0.46.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 +82 -8
- package/dist/index.js +56 -66
- package/dist/presets/lint/core.js +1 -1
- package/dist/presets/lint/vendor/antislop/plugin.mjs +19 -2
- 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/package.json +3 -2
- package/skills/adamantite/SKILL.md +0 -2
- package/skills/adamantite/references/lint-rules.md +0 -6
- package/skills/adamantite/references/setup.md +8 -2
|
@@ -443,7 +443,7 @@ const config = {
|
|
|
443
443
|
"unicorn/no-useless-switch-case": "error",
|
|
444
444
|
"unicorn/no-useless-undefined": "error",
|
|
445
445
|
"unicorn/no-zero-fractions": "error",
|
|
446
|
-
"unicorn/number-literal-case": "
|
|
446
|
+
"unicorn/number-literal-case": "off",
|
|
447
447
|
"unicorn/numeric-separators-style": "error",
|
|
448
448
|
"unicorn/prefer-add-event-listener": "error",
|
|
449
449
|
"unicorn/prefer-array-find": "error",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Source: https://github.com/dmmulroy/anti-slop (MIT) at commit 13909c9e07590f5a85d93c62712259fe14a883f7.
|
|
3
3
|
// Its dependencies (MIT) are inlined so this file is self-contained.
|
|
4
4
|
// See license.md for the full license text.
|
|
5
|
+
// Patched with scripts/vendor-patches/anti-slop/no-unknown-parameters-rejection-callback.patch.
|
|
5
6
|
//
|
|
6
7
|
// Generated by scripts/vendor-plugins.ts — do not edit by hand.
|
|
7
8
|
//#region node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
|
|
@@ -1511,21 +1512,37 @@ function isTypePredicateSubject(owner, parameterName) {
|
|
|
1511
1512
|
const predicate = owner.returnType?.typeAnnotation;
|
|
1512
1513
|
return predicate?.type === "TSTypePredicate" && predicate.parameterName.type === "Identifier" && predicate.parameterName.name === parameterName;
|
|
1513
1514
|
}
|
|
1515
|
+
/** The argument position of the rejection callback for each promise method that takes one. */
|
|
1516
|
+
const REJECTION_CALLBACK_INDEX = /* @__PURE__ */ new Map([["catch", 0], ["then", 1]]);
|
|
1517
|
+
/**
|
|
1518
|
+
* Return whether a function is the rejection callback of `.catch()` or `.then()`. The promise
|
|
1519
|
+
* fixes the type of the rejection reason, so the callback cannot accept a parsed domain type.
|
|
1520
|
+
*/
|
|
1521
|
+
function isRejectionCallback(owner) {
|
|
1522
|
+
const call = owner.parent;
|
|
1523
|
+
if (call?.type !== "CallExpression") return false;
|
|
1524
|
+
const callee = call.callee;
|
|
1525
|
+
if (callee.type !== "MemberExpression" || callee.computed) return false;
|
|
1526
|
+
if (callee.property.type !== "Identifier") return false;
|
|
1527
|
+
const index = REJECTION_CALLBACK_INDEX.get(callee.property.name);
|
|
1528
|
+
return index !== void 0 && call.arguments[index] === owner;
|
|
1529
|
+
}
|
|
1514
1530
|
/** Disallow unknown inputs except explicitly named error-cause enrichment. */
|
|
1515
1531
|
const noUnknownParametersRule = defineRule({
|
|
1516
1532
|
meta: {
|
|
1517
1533
|
type: "problem",
|
|
1518
|
-
docs: { description: "Disallow explicitly unknown function parameters except `cause
|
|
1534
|
+
docs: { description: "Disallow explicitly unknown function parameters except `cause`, type-predicate subjects, and promise rejection reasons; decode unknown input at its I/O boundary instead." },
|
|
1519
1535
|
messages: { unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type; run the expected schema or parser at the I/O boundary before calling this function." }
|
|
1520
1536
|
},
|
|
1521
1537
|
createOnce(context) {
|
|
1522
1538
|
const checkParameters = (node) => {
|
|
1523
|
-
for (const parameter of node.params) {
|
|
1539
|
+
for (const [index, parameter] of node.params.entries()) {
|
|
1524
1540
|
const annotation = functionParameterTypeAnnotation(parameter);
|
|
1525
1541
|
if (annotation === null || annotation === void 0) continue;
|
|
1526
1542
|
if (!containsUnknownType(annotation.typeAnnotation)) continue;
|
|
1527
1543
|
const name = functionParameterBindingName(parameter, context.sourceCode);
|
|
1528
1544
|
if (name === "cause" || isTypePredicateSubject(node, name)) continue;
|
|
1545
|
+
if (index === 0 && isRejectionCallback(node)) continue;
|
|
1529
1546
|
context.report({
|
|
1530
1547
|
node: annotation.typeAnnotation,
|
|
1531
1548
|
messageId: "unknownParameter",
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adamantite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"description": "An strict and opinionated set of presets for modern TypeScript applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adamantite",
|
|
@@ -109,7 +109,8 @@
|
|
|
109
109
|
"types": "./dist/presets/rules/testing.d.ts",
|
|
110
110
|
"default": "./dist/presets/rules/testing.js"
|
|
111
111
|
},
|
|
112
|
-
"./
|
|
112
|
+
"./tsconfig": "./dist/presets/tsconfig.json",
|
|
113
|
+
"./typescript": "./dist/presets/typescript.json"
|
|
113
114
|
},
|
|
114
115
|
"dependencies": {
|
|
115
116
|
"@clack/prompts": "1.8.1",
|
|
@@ -72,8 +72,6 @@ The task is complete when the affected checks exit 0 and you have read their out
|
|
|
72
72
|
Run `adamantite doctor`. It assesses managed integrations without changing files.
|
|
73
73
|
Without a terminal, it prints a Markdown repair prompt and exits 1 when findings remain.
|
|
74
74
|
Follow each finding's current state, goal, reference, and verification command.
|
|
75
|
-
For old layer-map declarations, use the migration step in
|
|
76
|
-
[Configure layer maps and import owners](references/lint-rules.md#configure-layer-maps-and-import-owners).
|
|
77
75
|
For a finding about the previous custom-rules API, use the migration step in
|
|
78
76
|
[How to write and verify custom rules](references/custom-rules.md#repair-an-existing-rules-folder).
|
|
79
77
|
|
|
@@ -83,12 +83,6 @@ parent's actual matched folder, including when the top root is a glob. Declare e
|
|
|
83
83
|
concrete scope once. Keep separate option objects for roots that cannot nest without a
|
|
84
84
|
new intermediate map.
|
|
85
85
|
|
|
86
|
-
If the config uses the previous array-valued declarations, run `adamantite doctor` and
|
|
87
|
-
follow its migration instructions. Preserve every dependency and map setting. Nest only
|
|
88
|
-
existing compatible child scopes. Verify allowed and forbidden imports with
|
|
89
|
-
`adamantite check`, then run Doctor again. Continue when the migrated maps preserve the
|
|
90
|
-
project's intended imports and Doctor reports no layer-map migration finding.
|
|
91
|
-
|
|
92
86
|
For an import that belongs to one file or folder, set `adamantite/import-owners`:
|
|
93
87
|
|
|
94
88
|
```ts
|
|
@@ -3,13 +3,19 @@
|
|
|
3
3
|
## Select the setup
|
|
4
4
|
|
|
5
5
|
Read `adamantite init --help` for the available scripts, presets, and editors.
|
|
6
|
-
Use explicit `--non-interactive` setup as an agent. Include at least one `--script`.
|
|
6
|
+
Use explicit `--non-interactive` setup as an agent. Include at least one `--script` or `--typescript`.
|
|
7
7
|
For example, to configure checks, fixes, TypeScript, and agent instructions, run:
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npx adamantite init --non-interactive --script check --script fix --typescript --agents
|
|
10
|
+
npx adamantite init --non-interactive --script check --script fix --typescript typescript --agents
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
`--typescript typescript` writes `adamantite/typescript`, which adds type resets, so
|
|
14
|
+
`JSON.parse()` returns `unknown`. Use `--typescript tsconfig` for a library that publishes
|
|
15
|
+
declaration files, because those files can name reset helper types that consumers do not have.
|
|
16
|
+
A project that already has ts-reset can delete its `reset.d.ts` files and the
|
|
17
|
+
`@total-typescript/ts-reset` dependency after it extends `adamantite/typescript`.
|
|
18
|
+
|
|
13
19
|
Adapt the selected options to the request. Omitted boolean flags are disabled.
|
|
14
20
|
`--agents` adds instructions to `AGENTS.md` and writes this skill to `.agents/skills`, and
|
|
15
21
|
to `.claude/skills` or `.grok/skills` when the project has `.claude/` or `.grok/`.
|