@frankmeza/affirm 0.0.0-stage → 0.0.1
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/AGENTS.md +130 -0
- package/LICENSE +21 -0
- package/README.md +116 -2
- package/dist/affirm.d.ts +79 -0
- package/dist/checks/arrays.d.ts +10 -0
- package/dist/checks/composition.d.ts +10 -0
- package/dist/checks/equality.d.ts +7 -0
- package/dist/checks/nullish.d.ts +9 -0
- package/dist/checks/numbers.d.ts +11 -0
- package/dist/checks/objects.d.ts +9 -0
- package/dist/checks/runtime-type.d.ts +14 -0
- package/dist/checks/size.d.ts +8 -0
- package/dist/checks/strings.d.ts +6 -0
- package/dist/core/check-def.d.ts +93 -0
- package/dist/core/describe.d.ts +11 -0
- package/dist/core/errors.d.ts +18 -0
- package/dist/core/evaluate.d.ts +8 -0
- package/dist/core/registry.d.ts +18 -0
- package/dist/core/report.d.ts +22 -0
- package/dist/core/util/deep-equal.d.ts +12 -0
- package/dist/core/util/kind.d.ts +22 -0
- package/dist/core/util/levenshtein.d.ts +3 -0
- package/dist/core/util/same-value-zero.d.ts +5 -0
- package/dist/core/util/standard-schema.d.ts +62 -0
- package/dist/core/validate-params.d.ts +8 -0
- package/dist/eslint/check-keys.d.ts +7 -0
- package/dist/eslint/const-params.d.ts +2 -0
- package/dist/eslint/guard-naming.d.ts +2 -0
- package/dist/eslint/index.d.ts +29 -0
- package/dist/eslint/no-negated-affirm.d.ts +2 -0
- package/dist/eslint/shared.d.ts +65 -0
- package/dist/eslint.js +734 -0
- package/dist/eslint.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +967 -0
- package/dist/index.js.map +1 -0
- package/dist/types/affirmed.d.ts +55 -0
- package/dist/types/arrays.d.ts +64 -0
- package/dist/types/composition.d.ts +53 -0
- package/dist/types/contradictions.d.ts +90 -0
- package/dist/types/equality.d.ts +65 -0
- package/dist/types/narrowing.d.ts +66 -0
- package/dist/types/nullish.d.ts +80 -0
- package/dist/types/numbers.d.ts +94 -0
- package/dist/types/objects.d.ts +99 -0
- package/dist/types/params.d.ts +14 -0
- package/dist/types/runtime-type.d.ts +129 -0
- package/dist/types/size.d.ts +76 -0
- package/dist/types/strings.d.ts +49 -0
- package/docs/client-usage.md +850 -0
- package/package.json +58 -4
package/dist/eslint.js
ADDED
|
@@ -0,0 +1,734 @@
|
|
|
1
|
+
// src/eslint/check-keys.ts
|
|
2
|
+
var CHECK_KEYS = /* @__PURE__ */ new Set([
|
|
3
|
+
"isNull",
|
|
4
|
+
"isUndefined",
|
|
5
|
+
"isNullish",
|
|
6
|
+
"isDefined",
|
|
7
|
+
"isPresent",
|
|
8
|
+
"isTruthy",
|
|
9
|
+
"isFalsy",
|
|
10
|
+
"isType",
|
|
11
|
+
"isArray",
|
|
12
|
+
"isPlainObject",
|
|
13
|
+
"isFunction",
|
|
14
|
+
"isInstanceOf",
|
|
15
|
+
"isValidDate",
|
|
16
|
+
"isInteger",
|
|
17
|
+
"isFiniteNumber",
|
|
18
|
+
"isNaN",
|
|
19
|
+
"is",
|
|
20
|
+
"isNot",
|
|
21
|
+
"isOneOf",
|
|
22
|
+
"isNotOneOf",
|
|
23
|
+
"isDeepEqual",
|
|
24
|
+
"isEmpty",
|
|
25
|
+
"isNotEmpty",
|
|
26
|
+
"isBlank",
|
|
27
|
+
"hasLength",
|
|
28
|
+
"hasMinLength",
|
|
29
|
+
"hasMaxLength",
|
|
30
|
+
"isGreaterThan",
|
|
31
|
+
"isAtLeast",
|
|
32
|
+
"isLessThan",
|
|
33
|
+
"isAtMost",
|
|
34
|
+
"isBetween",
|
|
35
|
+
"isPositive",
|
|
36
|
+
"isNegative",
|
|
37
|
+
"isMultipleOf",
|
|
38
|
+
"startsWith",
|
|
39
|
+
"endsWith",
|
|
40
|
+
"includes",
|
|
41
|
+
"matches",
|
|
42
|
+
"shape",
|
|
43
|
+
"hasKey",
|
|
44
|
+
"hasKeys",
|
|
45
|
+
"hasAnyKey",
|
|
46
|
+
"hasOnlyKeys",
|
|
47
|
+
"hasPath",
|
|
48
|
+
"contains",
|
|
49
|
+
"containsAll",
|
|
50
|
+
"containsAny",
|
|
51
|
+
"everyItem",
|
|
52
|
+
"someItem",
|
|
53
|
+
"not",
|
|
54
|
+
"anyOf",
|
|
55
|
+
"satisfies"
|
|
56
|
+
]);
|
|
57
|
+
/**
|
|
58
|
+
* Check names that are ordinary words in other objects (`{ shape: 'circle' }`, a manifest's `matches`,
|
|
59
|
+
* JSON Schema's `anyOf` / `not` / `contains`). An object made only of these is not taken for params
|
|
60
|
+
* unless its nested params are distinctive.
|
|
61
|
+
*/
|
|
62
|
+
var GENERIC_KEYS = /* @__PURE__ */ new Set([
|
|
63
|
+
"is",
|
|
64
|
+
"not",
|
|
65
|
+
"anyOf",
|
|
66
|
+
"shape",
|
|
67
|
+
"includes",
|
|
68
|
+
"matches",
|
|
69
|
+
"contains",
|
|
70
|
+
"startsWith",
|
|
71
|
+
"endsWith",
|
|
72
|
+
"satisfies"
|
|
73
|
+
]);
|
|
74
|
+
// src/eslint/shared.ts
|
|
75
|
+
var MAX_USAGE = 60;
|
|
76
|
+
var ADVICE = "Negating affirm() is true when any check fails for any reason, so it tells you nothing reliable about the value. Use affirm.assert(value, params) to stop on bad data, affirm.explain(value, params) to handle failures by reason, or a positive check for the state you mean (e.g. `isNullish: true`).";
|
|
77
|
+
/** Wrappers that don't change the value: `affirm?.()`, `affirm() as boolean`, `affirm()!`, … (parentheses aren't nodes). */
|
|
78
|
+
var TRANSPARENT = /* @__PURE__ */ new Set([
|
|
79
|
+
"ChainExpression",
|
|
80
|
+
"TSAsExpression",
|
|
81
|
+
"TSSatisfiesExpression",
|
|
82
|
+
"TSNonNullExpression",
|
|
83
|
+
"TSTypeAssertion"
|
|
84
|
+
]);
|
|
85
|
+
/** The outermost transparent wrapper around `node`. */
|
|
86
|
+
function outermost(node) {
|
|
87
|
+
let current = node;
|
|
88
|
+
while (current.parent !== null && TRANSPARENT.has(current.parent.type)) current = current.parent;
|
|
89
|
+
return current;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The whole expression carrying a value's result through `&&` / `||` (and transparent wrappers):
|
|
93
|
+
* for `affirm(a) && ok` that is the `&&` expression. Negating it negates the affirm() inside.
|
|
94
|
+
*/
|
|
95
|
+
function carrier(node) {
|
|
96
|
+
let current = outermost(node);
|
|
97
|
+
while (current.parent?.type === "LogicalExpression" && current.parent.operator !== "??") current = outermost(current.parent);
|
|
98
|
+
return current;
|
|
99
|
+
}
|
|
100
|
+
/** `!x`, `x === false`, `x == false`, `x !== true`, `x != true` (either side): the node that negates `expr`, if any. */
|
|
101
|
+
function negationOf(expr) {
|
|
102
|
+
const value = outermost(expr);
|
|
103
|
+
const parent = value.parent;
|
|
104
|
+
if (parent?.type === "UnaryExpression" && parent.operator === "!") return parent;
|
|
105
|
+
if (parent?.type === "BinaryExpression") {
|
|
106
|
+
const other = parent.left === value ? parent.right : parent.left;
|
|
107
|
+
if (other.type !== "Literal" || typeof other.value !== "boolean") return void 0;
|
|
108
|
+
const equals = parent.operator === "===" || parent.operator === "==";
|
|
109
|
+
const differs = parent.operator === "!==" || parent.operator === "!=";
|
|
110
|
+
if (equals && other.value === false || differs && other.value === true) return parent;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** One assignment at most (its initializer), so every read sees the same value. */
|
|
114
|
+
function assignedOnce(variable) {
|
|
115
|
+
return variable.references.filter((reference) => reference.isWrite()).length <= 1;
|
|
116
|
+
}
|
|
117
|
+
/** The variable a function is bound to: `function f() {}`, `const f = () => …`, `const f = function () {}`. */
|
|
118
|
+
function functionVariable(fn, sourceCode) {
|
|
119
|
+
if (fn.type === "FunctionDeclaration") return fn.id ? sourceCode.getDeclaredVariables(fn).find((v) => v.name === fn.id.name) : void 0;
|
|
120
|
+
const declarator = outermost(fn).parent;
|
|
121
|
+
if (declarator?.type !== "VariableDeclarator" || declarator.init !== outermost(fn) || declarator.id.type !== "Identifier") return void 0;
|
|
122
|
+
return sourceCode.getDeclaredVariables(declarator)[0];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The function whose entire body is `value`: `(v) => value`, or a body that is only `return value`.
|
|
126
|
+
* Calling such a function is the same as evaluating `value`.
|
|
127
|
+
*/
|
|
128
|
+
function wrapperOf(value) {
|
|
129
|
+
const parent = value.parent;
|
|
130
|
+
if (parent?.type === "ArrowFunctionExpression" && parent.body === value) return parent;
|
|
131
|
+
if (parent?.type !== "ReturnStatement") return void 0;
|
|
132
|
+
const block = parent.parent;
|
|
133
|
+
if (block?.type !== "BlockStatement" || block.body.length !== 1) return void 0;
|
|
134
|
+
const fn = block.parent;
|
|
135
|
+
return fn?.type === "FunctionDeclaration" || fn?.type === "FunctionExpression" || fn?.type === "ArrowFunctionExpression" ? fn : void 0;
|
|
136
|
+
}
|
|
137
|
+
function findVariable(scope, name) {
|
|
138
|
+
for (let s = scope; s !== null; s = s.upper) {
|
|
139
|
+
const variable = s.set.get(name);
|
|
140
|
+
if (variable !== void 0) return variable;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** `'named'` for `import { affirm }` (any local name), `'namespace'` for `import * as ns`, from one of `sources`. */
|
|
144
|
+
function importKind(variable, sources) {
|
|
145
|
+
const def = variable?.defs[0];
|
|
146
|
+
if (def?.type !== "ImportBinding") return void 0;
|
|
147
|
+
const declaration = def.parent;
|
|
148
|
+
if (!sources.has(declaration?.source?.value)) return void 0;
|
|
149
|
+
const spec = def.node;
|
|
150
|
+
if (spec.type === "ImportNamespaceSpecifier") return "namespace";
|
|
151
|
+
if (spec.type !== "ImportSpecifier") return void 0;
|
|
152
|
+
return (spec.imported?.type === "Identifier" ? spec.imported.name : spec.imported?.value) === "affirm" ? "named" : void 0;
|
|
153
|
+
}
|
|
154
|
+
/** `affirm`, `check` (aliased import) or `ns.affirm` / `ns['affirm']` (namespace import): the affirm function itself. */
|
|
155
|
+
function isAffirmReference(expr, scope, sources) {
|
|
156
|
+
if (expr.type === "Identifier") return importKind(findVariable(scope, expr.name), sources) === "named";
|
|
157
|
+
if (expr.type === "MemberExpression" && expr.object.type === "Identifier") return memberName(expr) === "affirm" && importKind(findVariable(scope, expr.object.name), sources) === "namespace";
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
/** `x.name` or `x['name']`: the property name, if it is static. */
|
|
161
|
+
function memberName(expr) {
|
|
162
|
+
if (expr.type !== "MemberExpression") return void 0;
|
|
163
|
+
if (!expr.computed) return expr.property.type === "Identifier" ? expr.property.name : void 0;
|
|
164
|
+
return expr.property.type === "Literal" && typeof expr.property.value === "string" ? expr.property.value : void 0;
|
|
165
|
+
}
|
|
166
|
+
/** `affirm(…)`, `check(…)` (aliased import) or `ns.affirm(…)` / `ns['affirm'](…)` (namespace import). */
|
|
167
|
+
function isAffirmCall(node, sourceCode, sources) {
|
|
168
|
+
return node.type === "CallExpression" && isAffirmReference(node.callee, sourceCode.getScope(node), sources);
|
|
169
|
+
}
|
|
170
|
+
/** Any call that takes affirm params second: `affirm(v, p)`, `affirm.assert(v, p, msg)`, `affirm.explain(v, p)`. */
|
|
171
|
+
function takesAffirmParams(node, sourceCode, sources) {
|
|
172
|
+
if (node.type !== "CallExpression") return false;
|
|
173
|
+
if (isAffirmCall(node, sourceCode, sources)) return true;
|
|
174
|
+
const callee = node.callee;
|
|
175
|
+
const method = memberName(callee);
|
|
176
|
+
return callee.type === "MemberExpression" && (method === "assert" || method === "explain") && isAffirmReference(callee.object, sourceCode.getScope(node), sources);
|
|
177
|
+
}
|
|
178
|
+
function truncate(text) {
|
|
179
|
+
return text.length <= MAX_USAGE ? text : `${text.slice(0, 59)}…`;
|
|
180
|
+
}
|
|
181
|
+
/** The offending code, on one line, shortened for the message. */
|
|
182
|
+
function usageText(sourceCode, node) {
|
|
183
|
+
return truncate(sourceCode.getText(node).replace(/\s+/g, " "));
|
|
184
|
+
}
|
|
185
|
+
function settingsOf(context) {
|
|
186
|
+
const settings = context.settings.affirm;
|
|
187
|
+
if (settings === void 0) return {};
|
|
188
|
+
if (typeof settings !== "object" || settings === null) throw new Error("affirm: `settings.affirm` must be an object");
|
|
189
|
+
return settings;
|
|
190
|
+
}
|
|
191
|
+
/** `sources` from the rule's own option (if given), else `settings.affirm.sources`, else `['@frankmeza/affirm']`. */
|
|
192
|
+
function sourcesOf(context, option) {
|
|
193
|
+
const sources = option ?? settingsOf(context).sources ?? ["@frankmeza/affirm"];
|
|
194
|
+
if (!Array.isArray(sources) || sources.some((s) => typeof s !== "string")) throw new Error("affirm: `settings.affirm.sources` must be an array of module specifiers");
|
|
195
|
+
return new Set(sources);
|
|
196
|
+
}
|
|
197
|
+
/** `settings.affirm.guards` compiled, or `undefined` when no guard pattern is configured. */
|
|
198
|
+
function guardPatternOf(context) {
|
|
199
|
+
const pattern = settingsOf(context).guards;
|
|
200
|
+
if (pattern === void 0) return void 0;
|
|
201
|
+
if (typeof pattern !== "string" || pattern === "") throw new Error("affirm: `settings.affirm.guards` must be a non-empty regular expression string, e.g. \"^isValid\"");
|
|
202
|
+
try {
|
|
203
|
+
return new RegExp(pattern, "u");
|
|
204
|
+
} catch (error) {
|
|
205
|
+
throw new Error(`affirm: \`settings.affirm.guards\` is not a valid regular expression: ${error.message}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** `guardModules` as a list of prefixes (default none: only relative imports count as project code). */
|
|
209
|
+
function guardModulesOf(context) {
|
|
210
|
+
const modules = settingsOf(context).guardModules ?? [];
|
|
211
|
+
if (!Array.isArray(modules) || modules.some((m) => typeof m !== "string" || m === "")) throw new Error("affirm: `settings.affirm.guardModules` must be an array of import prefixes, e.g. ['@/']");
|
|
212
|
+
return modules;
|
|
213
|
+
}
|
|
214
|
+
/** The module an imported variable comes from, or `undefined` when it isn't an import. */
|
|
215
|
+
function importSourceOf(variable) {
|
|
216
|
+
const def = variable?.defs[0];
|
|
217
|
+
if (def?.type !== "ImportBinding") return void 0;
|
|
218
|
+
const source = def.parent?.source?.value;
|
|
219
|
+
return typeof source === "string" ? source : void 0;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Whether a call that matches the guard pattern can be one of the project's guards: defined in this
|
|
223
|
+
* file, imported from a relative path or a `guardModules` prefix, or a method on a local value.
|
|
224
|
+
* Calls into packages (`import validator from 'validator'; validator.isValidX()`) are not.
|
|
225
|
+
*/
|
|
226
|
+
function isProjectCall(call, sourceCode, guardModules) {
|
|
227
|
+
if (call.type !== "CallExpression") return false;
|
|
228
|
+
const callee = call.callee;
|
|
229
|
+
const root = callee.type === "Identifier" ? callee : callee.type === "MemberExpression" && callee.object.type === "Identifier" ? callee.object : void 0;
|
|
230
|
+
if (root === void 0) return true;
|
|
231
|
+
const variable = findVariable(sourceCode.getScope(call), root.name);
|
|
232
|
+
if (variable === void 0) return callee.type !== "Identifier";
|
|
233
|
+
const source = importSourceOf(variable);
|
|
234
|
+
if (source === void 0) return true;
|
|
235
|
+
return source.startsWith(".") || guardModules.some((prefix) => source.startsWith(prefix));
|
|
236
|
+
}
|
|
237
|
+
/** The name a function is bound to, and the node to report on: declarations, variables, object and class members. */
|
|
238
|
+
function functionName(fn) {
|
|
239
|
+
if (fn.type === "FunctionDeclaration") return fn.id ? {
|
|
240
|
+
name: fn.id.name,
|
|
241
|
+
node: fn.id
|
|
242
|
+
} : void 0;
|
|
243
|
+
const holder = outermost(fn).parent;
|
|
244
|
+
if (holder?.type === "VariableDeclarator" && holder.init === outermost(fn) && holder.id.type === "Identifier") return {
|
|
245
|
+
name: holder.id.name,
|
|
246
|
+
node: holder.id
|
|
247
|
+
};
|
|
248
|
+
const member = holder;
|
|
249
|
+
if ((member?.type === "Property" || member?.type === "MethodDefinition" || member?.type === "PropertyDefinition") && member.value === outermost(fn) && !member.computed && member.key?.type === "Identifier") return {
|
|
250
|
+
name: member.key.name,
|
|
251
|
+
node: member.key
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/** The name a call goes through: `isValidOrder(x)` or `guards.isValidOrder(x)`. */
|
|
255
|
+
function calleeName(call) {
|
|
256
|
+
if (call.type !== "CallExpression") return void 0;
|
|
257
|
+
const callee = call.callee;
|
|
258
|
+
if (callee.type === "Identifier") return callee.name;
|
|
259
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier") return callee.property.name;
|
|
260
|
+
}
|
|
261
|
+
// src/eslint/const-params.ts
|
|
262
|
+
var TS_FILE = /\.[cm]?tsx?$/;
|
|
263
|
+
/** `to` relative to `from` when it's inside it (for readable messages); otherwise unchanged. */
|
|
264
|
+
function relativePath(from, to) {
|
|
265
|
+
const base = from.endsWith("/") ? from : `${from}/`;
|
|
266
|
+
return to.startsWith(base) ? to.slice(base.length) : to;
|
|
267
|
+
}
|
|
268
|
+
/** Nodes that wrap an expression without changing what it is, for walking into params. */
|
|
269
|
+
var WRAPPERS = /* @__PURE__ */ new Set([
|
|
270
|
+
"TSAsExpression",
|
|
271
|
+
"TSSatisfiesExpression",
|
|
272
|
+
"TSNonNullExpression",
|
|
273
|
+
"TSTypeAssertion"
|
|
274
|
+
]);
|
|
275
|
+
function isAsConst(node) {
|
|
276
|
+
if (node.type !== "TSAsExpression") return false;
|
|
277
|
+
const type = node.typeAnnotation;
|
|
278
|
+
return type.type === "TSTypeReference" && type.typeName?.type === "Identifier" && type.typeName.name === "const";
|
|
279
|
+
}
|
|
280
|
+
var isLiteral = (node) => node?.type === "ObjectExpression" || node?.type === "ArrayExpression";
|
|
281
|
+
function expressionOf(node) {
|
|
282
|
+
return node.expression;
|
|
283
|
+
}
|
|
284
|
+
/** Whether a reference sits inside a type query (`typeof p` in a type), which `as const` only improves. */
|
|
285
|
+
function inTypeQuery(identifier) {
|
|
286
|
+
for (let n = identifier.parent; n !== null; n = n.parent) {
|
|
287
|
+
if (n.type === "TSTypeQuery") return true;
|
|
288
|
+
if (!n.type.startsWith("TS") && n.type !== "MemberExpression") return false;
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
/** `ts.SymbolFlags.Alias` (1 << 21), stable across TypeScript versions. */
|
|
293
|
+
var SYMBOL_FLAGS_ALIAS = 2097152;
|
|
294
|
+
/** typescript-eslint's services, when the client lints with type information; otherwise `undefined`. */
|
|
295
|
+
function typedServicesOf(sourceCode) {
|
|
296
|
+
const services = sourceCode.parserServices;
|
|
297
|
+
return services?.program && services.esTreeNodeToTSNodeMap ? services : void 0;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Why a declaration in another file widens its value, if it does: a list or object literal declared
|
|
301
|
+
* `const` without `as const` (or with a type annotation). `undefined` when it's fine or unknowable:
|
|
302
|
+
* `as const` / `<const>`, a call such as `loadRoles()`, `let`, or an ambient `.d.ts` declaration.
|
|
303
|
+
*/
|
|
304
|
+
function widenedBy(declaration) {
|
|
305
|
+
let init = declaration.initializer;
|
|
306
|
+
if (!init || !("name" in declaration)) return void 0;
|
|
307
|
+
if (!/^const\b/.test(declaration.parent?.getText() ?? "")) return void 0;
|
|
308
|
+
if (declaration.type) return `with the type \`${declaration.type.getText()}\``;
|
|
309
|
+
while ("type" in init && "expression" in init) {
|
|
310
|
+
if (init.type.getText() === "const") return void 0;
|
|
311
|
+
init = init.expression;
|
|
312
|
+
}
|
|
313
|
+
return "elements" in init || "properties" in init ? "without `as const`" : void 0;
|
|
314
|
+
}
|
|
315
|
+
/** A property's static key: `isOneOf`, `'isOneOf'`. */
|
|
316
|
+
function keyOf(property) {
|
|
317
|
+
if (property.type !== "Property" || property.computed) return void 0;
|
|
318
|
+
const key = property.key;
|
|
319
|
+
if (key.type === "Identifier") return key.name;
|
|
320
|
+
return key.type === "Literal" && typeof key.value === "string" ? key.value : void 0;
|
|
321
|
+
}
|
|
322
|
+
/** Keys whose value is itself params (or, for `shape`, an object of params; for `anyOf`, a list of params). */
|
|
323
|
+
function nestedParams(key, value) {
|
|
324
|
+
if (key === "not" || key === "everyItem" || key === "someItem") return [value];
|
|
325
|
+
if (key === "shape" && value.type === "ObjectExpression") return value.properties.flatMap((p) => p.type === "Property" ? [p.value] : []);
|
|
326
|
+
if (key === "anyOf" && value.type === "ArrayExpression") return value.elements.filter((e) => e?.type === "ObjectExpression");
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Whether an object literal is unmistakably affirm params: every key is a check name, and at least
|
|
331
|
+
* one key (here or in nested params) is distinctive. `{ isOneOf: […] }` and `{ shape: { id: { isType: 'string' } } }`
|
|
332
|
+
* are params; `{ shape: 'circle' }`, a manifest's `{ matches: […] }` and JSON Schema's `{ anyOf: […] }` are not.
|
|
333
|
+
*/
|
|
334
|
+
function looksLikeParams(node, depth = 0) {
|
|
335
|
+
if (node?.type !== "ObjectExpression" || depth > 8) return false;
|
|
336
|
+
const keyed = node.properties.filter((p) => p.type === "Property");
|
|
337
|
+
if (keyed.length === 0) return false;
|
|
338
|
+
let distinctive = false;
|
|
339
|
+
for (const property of keyed) {
|
|
340
|
+
const key = keyOf(property);
|
|
341
|
+
if (key === void 0 || !CHECK_KEYS.has(key)) return false;
|
|
342
|
+
if (!GENERIC_KEYS.has(key)) distinctive = true;
|
|
343
|
+
}
|
|
344
|
+
if (distinctive) return true;
|
|
345
|
+
return keyed.some((property) => nestedParams(keyOf(property), property.value).some((inner) => looksLikeParams(inner, depth + 1)));
|
|
346
|
+
}
|
|
347
|
+
/** The object literal a declaration is written as, under `satisfies` / `as` (including `as const`). */
|
|
348
|
+
function literalOf(init) {
|
|
349
|
+
let node = init;
|
|
350
|
+
while (node && WRAPPERS.has(node.type)) node = expressionOf(node);
|
|
351
|
+
return node ?? void 0;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* What's wrong with a `const` declaration used as params, if anything:
|
|
355
|
+
* `{…}` → plain; `: T = {…}` or `{…} as T` → typed. `{…} as const` (optionally `satisfies T`) is fine.
|
|
356
|
+
*/
|
|
357
|
+
function classify(declarator, variable) {
|
|
358
|
+
if (declarator.type !== "VariableDeclarator" || declarator.id.type !== "Identifier" || !declarator.init) return void 0;
|
|
359
|
+
const id = declarator.id;
|
|
360
|
+
let init = declarator.init;
|
|
361
|
+
if (init.type === "TSSatisfiesExpression") init = expressionOf(init);
|
|
362
|
+
if (isAsConst(init)) return void 0;
|
|
363
|
+
if (init.type === "TSAsExpression" && isLiteral(expressionOf(init))) {
|
|
364
|
+
const type = init.typeAnnotation;
|
|
365
|
+
return {
|
|
366
|
+
variable,
|
|
367
|
+
id,
|
|
368
|
+
literal: expressionOf(init),
|
|
369
|
+
kind: "typed",
|
|
370
|
+
type,
|
|
371
|
+
cast: init
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
if (!isLiteral(init)) return void 0;
|
|
375
|
+
if (id.typeAnnotation) return {
|
|
376
|
+
variable,
|
|
377
|
+
id,
|
|
378
|
+
literal: init,
|
|
379
|
+
kind: "typed",
|
|
380
|
+
type: id.typeAnnotation.typeAnnotation
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
variable,
|
|
384
|
+
id,
|
|
385
|
+
literal: init,
|
|
386
|
+
kind: "plain"
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
/** `{…} as const`, or for a typed declaration `{…} as const satisfies T` (keeps the type check). */
|
|
390
|
+
function fixFor(finding, sourceCode) {
|
|
391
|
+
return (fixer) => {
|
|
392
|
+
if (finding.kind === "plain") return fixer.insertTextAfter(finding.literal, " as const");
|
|
393
|
+
const typeText = sourceCode.getText(finding.type);
|
|
394
|
+
if (finding.cast) return fixer.replaceText(finding.cast, `${sourceCode.getText(finding.literal)} as const satisfies ${typeText}`);
|
|
395
|
+
const annotation = finding.id.typeAnnotation;
|
|
396
|
+
return [fixer.remove(annotation), fixer.insertTextAfter(finding.literal, ` as const satisfies ${typeText}`)];
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
var constParams = {
|
|
400
|
+
meta: {
|
|
401
|
+
type: "problem",
|
|
402
|
+
fixable: "code",
|
|
403
|
+
hasSuggestions: true,
|
|
404
|
+
docs: { description: "Require `as const` on params declared apart from the affirm() call, so their literal types (and narrowing) survive." },
|
|
405
|
+
schema: [],
|
|
406
|
+
messages: {
|
|
407
|
+
needsConst: "affirm: params `{{name}}` need `as const`. Without it TypeScript widens their values ('a' → string, true → boolean) before affirm() sees them, so narrowing is silently lost. Declare `const {{name}} = { … } as const`.",
|
|
408
|
+
typed: "affirm: params `{{name}}` are typed as `{{type}}`, which erases their exact values, so affirm() can only narrow with the general type. Use `as const satisfies {{type}}` instead: it keeps both the type check and the exact values.",
|
|
409
|
+
suggestConst: "Add `as const` (`{{name}}` is also used outside affirm params; check those uses still compile).",
|
|
410
|
+
suggestTyped: "Replace the `{{type}}` type with `as const satisfies {{type}}`.",
|
|
411
|
+
importedWidened: "affirm: `{{name}}` is used in params here, but it is declared {{reason}} in {{file}}:{{line}}, so TypeScript widened its values ('a' → string) before affirm() sees them, and narrowing is silently lost. Fix that declaration: `= … as const`."
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
create(context) {
|
|
415
|
+
if (!TS_FILE.test(context.filename)) return {};
|
|
416
|
+
const { sourceCode } = context;
|
|
417
|
+
const sources = sourcesOf(context);
|
|
418
|
+
const typed = typedServicesOf(sourceCode);
|
|
419
|
+
const reportedRemote = /* @__PURE__ */ new Set();
|
|
420
|
+
const paramRefs = /* @__PURE__ */ new Set();
|
|
421
|
+
const seen = /* @__PURE__ */ new Set();
|
|
422
|
+
const findings = [];
|
|
423
|
+
/** Visits everything that ends up in params: the literal, nested values, spreads, and hoisted variables. */
|
|
424
|
+
function walk(node) {
|
|
425
|
+
if (!node) return;
|
|
426
|
+
if (WRAPPERS.has(node.type)) return walk(expressionOf(node));
|
|
427
|
+
if (node.type === "ObjectExpression") for (const property of node.properties) walk(property.type === "SpreadElement" ? property.argument : property.value);
|
|
428
|
+
else if (node.type === "ArrayExpression") for (const element of node.elements) walk(element?.type === "SpreadElement" ? element.argument : element);
|
|
429
|
+
else if (node.type === "Identifier") {
|
|
430
|
+
paramRefs.add(node);
|
|
431
|
+
const variable = findVariable(sourceCode.getScope(node), node.name);
|
|
432
|
+
if (variable?.defs[0]?.type === "ImportBinding" || variable === void 0) checkRemote(node);
|
|
433
|
+
else inspect(variable);
|
|
434
|
+
} else if (node.type === "MemberExpression" && !node.computed) checkRemote(node.property);
|
|
435
|
+
}
|
|
436
|
+
/** With type information: a name declared in another file, widened where it's declared. */
|
|
437
|
+
function checkRemote(node) {
|
|
438
|
+
if (typed === void 0) return;
|
|
439
|
+
const checker = typed.program.getTypeChecker();
|
|
440
|
+
const here = typed.esTreeNodeToTSNodeMap.get(node);
|
|
441
|
+
let symbol = checker.getSymbolAtLocation(here);
|
|
442
|
+
if (symbol !== void 0 && (symbol.flags & SYMBOL_FLAGS_ALIAS) !== 0) symbol = checker.getAliasedSymbol(symbol);
|
|
443
|
+
const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
|
|
444
|
+
if (declaration === void 0 || declaration.getSourceFile() === here.getSourceFile() || reportedRemote.has(declaration)) return;
|
|
445
|
+
const reason = widenedBy(declaration);
|
|
446
|
+
if (reason === void 0) return;
|
|
447
|
+
reportedRemote.add(declaration);
|
|
448
|
+
const source = declaration.getSourceFile();
|
|
449
|
+
const file = relativePath(context.cwd, source.fileName);
|
|
450
|
+
const line = String(source.getLineAndCharacterOfPosition(declaration.getStart()).line + 1);
|
|
451
|
+
const name = node.type === "Identifier" ? node.name : sourceCode.getText(node);
|
|
452
|
+
context.report({
|
|
453
|
+
node,
|
|
454
|
+
messageId: "importedWidened",
|
|
455
|
+
data: {
|
|
456
|
+
name,
|
|
457
|
+
reason,
|
|
458
|
+
file,
|
|
459
|
+
line
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/** Checks a `const` that holds params (once), then everything inside it: nested hoisted params need `as const` too. */
|
|
464
|
+
function inspect(variable) {
|
|
465
|
+
if (variable === void 0 || seen.has(variable)) return;
|
|
466
|
+
seen.add(variable);
|
|
467
|
+
const def = variable.defs[0];
|
|
468
|
+
if (def?.type !== "Variable" || def.parent?.kind !== "const") return;
|
|
469
|
+
const finding = classify(def.node, variable);
|
|
470
|
+
if (finding) findings.push(finding);
|
|
471
|
+
walk(def.node.init);
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
CallExpression(node) {
|
|
475
|
+
if (takesAffirmParams(node, sourceCode, sources)) walk(node.arguments[1]);
|
|
476
|
+
},
|
|
477
|
+
VariableDeclarator(node) {
|
|
478
|
+
if (node.id.type !== "Identifier" || node.parent.kind !== "const") return;
|
|
479
|
+
if (!looksLikeParams(literalOf(node.init))) return;
|
|
480
|
+
for (const variable of sourceCode.getDeclaredVariables(node)) inspect(variable);
|
|
481
|
+
},
|
|
482
|
+
"Program:exit"() {
|
|
483
|
+
for (const finding of findings) {
|
|
484
|
+
const name = finding.variable.name;
|
|
485
|
+
const fix = fixFor(finding, sourceCode);
|
|
486
|
+
if (finding.kind === "typed") {
|
|
487
|
+
const type = sourceCode.getText(finding.type);
|
|
488
|
+
context.report({
|
|
489
|
+
node: finding.id,
|
|
490
|
+
messageId: "typed",
|
|
491
|
+
data: {
|
|
492
|
+
name,
|
|
493
|
+
type
|
|
494
|
+
},
|
|
495
|
+
suggest: [{
|
|
496
|
+
messageId: "suggestTyped",
|
|
497
|
+
data: { type },
|
|
498
|
+
fix
|
|
499
|
+
}]
|
|
500
|
+
});
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const onlyParams = finding.variable.references.every((ref) => ref.identifier === finding.id || paramRefs.has(ref.identifier) || inTypeQuery(ref.identifier));
|
|
504
|
+
context.report({
|
|
505
|
+
node: finding.id,
|
|
506
|
+
messageId: "needsConst",
|
|
507
|
+
data: { name },
|
|
508
|
+
...onlyParams ? { fix } : { suggest: [{
|
|
509
|
+
messageId: "suggestConst",
|
|
510
|
+
data: { name },
|
|
511
|
+
fix
|
|
512
|
+
}] }
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
// src/eslint/guard-naming.ts
|
|
520
|
+
var guardNaming = {
|
|
521
|
+
meta: {
|
|
522
|
+
type: "problem",
|
|
523
|
+
docs: { description: "With `settings.affirm.guards`, require functions that return affirm(…) to match the guard pattern, and reserve the pattern for them." },
|
|
524
|
+
schema: [],
|
|
525
|
+
messages: {
|
|
526
|
+
unnamedGuard: "affirm: `{{name}}` returns affirm(…), so its name must match the guard pattern `{{pattern}}` (settings.affirm.guards). That lets affirm/no-negated-affirm catch `!{{name}}(…)` in the files that import it.",
|
|
527
|
+
reservedName: "affirm: `{{name}}` matches the guard pattern `{{pattern}}` (settings.affirm.guards), which is reserved for functions whose whole body returns affirm(…). Rename it, or make it return affirm(…) (negating it is reported as negating a guard)."
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
create(context) {
|
|
531
|
+
const guards = guardPatternOf(context);
|
|
532
|
+
if (guards === void 0) return {};
|
|
533
|
+
const sources = sourcesOf(context);
|
|
534
|
+
const { sourceCode } = context;
|
|
535
|
+
const wrappers = /* @__PURE__ */ new Set();
|
|
536
|
+
const named = /* @__PURE__ */ new Map();
|
|
537
|
+
function collect(fn) {
|
|
538
|
+
const binding = functionName(fn);
|
|
539
|
+
if (binding !== void 0 && guards.test(binding.name)) named.set(fn, binding);
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
FunctionDeclaration: collect,
|
|
543
|
+
FunctionExpression: collect,
|
|
544
|
+
ArrowFunctionExpression: collect,
|
|
545
|
+
CallExpression(node) {
|
|
546
|
+
if (!isAffirmCall(node, sourceCode, sources)) return;
|
|
547
|
+
const wrapper = wrapperOf(carrier(node));
|
|
548
|
+
if (wrapper === void 0 || wrappers.has(wrapper)) return;
|
|
549
|
+
wrappers.add(wrapper);
|
|
550
|
+
const binding = functionName(wrapper);
|
|
551
|
+
if (binding !== void 0 && !guards.test(binding.name)) context.report({
|
|
552
|
+
node: binding.node,
|
|
553
|
+
messageId: "unnamedGuard",
|
|
554
|
+
data: {
|
|
555
|
+
name: binding.name,
|
|
556
|
+
pattern: guards.source
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
},
|
|
560
|
+
"Program:exit"() {
|
|
561
|
+
for (const [fn, binding] of named) {
|
|
562
|
+
if (wrappers.has(fn)) continue;
|
|
563
|
+
context.report({
|
|
564
|
+
node: binding.node,
|
|
565
|
+
messageId: "reservedName",
|
|
566
|
+
data: {
|
|
567
|
+
name: binding.name,
|
|
568
|
+
pattern: guards.source
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
// src/eslint/no-negated-affirm.ts
|
|
577
|
+
/**
|
|
578
|
+
* `if (!affirm(v, p)) throw new X('msg')` → `affirm.assert(v, p, 'msg')`. A suggestion, never an autofix:
|
|
579
|
+
* the thrown error becomes an `AffirmError`.
|
|
580
|
+
*/
|
|
581
|
+
function assertSuggestion(negation, call, sourceCode) {
|
|
582
|
+
const statement = negation.parent;
|
|
583
|
+
if (negation.type !== "UnaryExpression" || statement?.type !== "IfStatement") return void 0;
|
|
584
|
+
if (statement.test !== negation || statement.alternate) return void 0;
|
|
585
|
+
if (call.type !== "CallExpression" || call.optional || call.arguments.length < 2) return void 0;
|
|
586
|
+
const consequent = statement.consequent;
|
|
587
|
+
const thrown = consequent.type === "ThrowStatement" ? consequent : consequent.type === "BlockStatement" && consequent.body.length === 1 && consequent.body[0].type === "ThrowStatement" ? consequent.body[0] : void 0;
|
|
588
|
+
if (thrown === void 0) return void 0;
|
|
589
|
+
const args = call.arguments;
|
|
590
|
+
const argsText = sourceCode.text.slice(args[0].range[0], args[args.length - 1].range[1]);
|
|
591
|
+
const error = thrown.argument;
|
|
592
|
+
let message = "";
|
|
593
|
+
if (error.type === "NewExpression" && error.arguments.length === 1) {
|
|
594
|
+
const arg = error.arguments[0];
|
|
595
|
+
if (arg.type === "Literal" && typeof arg.value === "string" || arg.type === "TemplateLiteral" && arg.expressions.length === 0) message = `, ${sourceCode.getText(arg)}`;
|
|
596
|
+
}
|
|
597
|
+
const replacement = `${sourceCode.getText(call.callee)}.assert(${argsText}${message})`;
|
|
598
|
+
return {
|
|
599
|
+
messageId: "suggestAssert",
|
|
600
|
+
data: { replacement: truncate(replacement.replace(/\s+/g, " ")) },
|
|
601
|
+
fix: (fixer) => fixer.replaceText(statement, replacement)
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
// src/eslint/index.ts
|
|
605
|
+
/**
|
|
606
|
+
* ESLint plugin for projects that use `affirm` (flat config, ESLint 9+).
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* // eslint.config.js
|
|
610
|
+
* import affirm from '@frankmeza/affirm/eslint'
|
|
611
|
+
* export default [affirm.configs.recommended]
|
|
612
|
+
*
|
|
613
|
+
* // Optional: catch negated guards imported from other files, and/or a local re-export of affirm.
|
|
614
|
+
* export default [
|
|
615
|
+
* affirm.configs.recommended,
|
|
616
|
+
* { settings: { affirm: { guards: '^isValid', sources: ['@frankmeza/affirm', '@/lib/affirm'] } } },
|
|
617
|
+
* ]
|
|
618
|
+
*/
|
|
619
|
+
var plugin = {
|
|
620
|
+
meta: { name: "@frankmeza/affirm/eslint" },
|
|
621
|
+
rules: {
|
|
622
|
+
"no-negated-affirm": {
|
|
623
|
+
meta: {
|
|
624
|
+
type: "problem",
|
|
625
|
+
docs: { description: "Disallow negating affirm() (`!affirm(…)`, `affirm(…) === false`, …): its negation is too broad to rely on." },
|
|
626
|
+
hasSuggestions: true,
|
|
627
|
+
schema: [{
|
|
628
|
+
type: "object",
|
|
629
|
+
properties: { sources: {
|
|
630
|
+
type: "array",
|
|
631
|
+
items: { type: "string" },
|
|
632
|
+
minItems: 1
|
|
633
|
+
} },
|
|
634
|
+
additionalProperties: false
|
|
635
|
+
}],
|
|
636
|
+
messages: {
|
|
637
|
+
negated: `affirm: \`{{usage}}\` is not allowed. ${ADVICE}`,
|
|
638
|
+
negatedResult: `affirm: \`{{usage}}\` negates the affirm() result stored in \`{{name}}\`, which is not allowed. ${ADVICE}`,
|
|
639
|
+
negatedWrapper: `affirm: \`{{usage}}\` negates \`{{name}}\`, which returns affirm(…), which is not allowed. ${ADVICE}`,
|
|
640
|
+
negatedGuard: `affirm: \`{{usage}}\` negates \`{{name}}\`, a guard built on affirm() (its name matches the guard pattern \`{{pattern}}\`), which is not allowed. ${ADVICE}`,
|
|
641
|
+
suggestAssert: "Replace with `{{replacement}}` (throws AffirmError with the full report instead)."
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
create(context) {
|
|
645
|
+
const { sourceCode } = context;
|
|
646
|
+
const sources = sourcesOf(context, (context.options[0] ?? {}).sources);
|
|
647
|
+
const guards = guardPatternOf(context);
|
|
648
|
+
const guardModules = guardModulesOf(context);
|
|
649
|
+
const reported = /* @__PURE__ */ new Set();
|
|
650
|
+
function report(negation, problem) {
|
|
651
|
+
if (reported.has(negation)) return;
|
|
652
|
+
reported.add(negation);
|
|
653
|
+
context.report({
|
|
654
|
+
node: negation,
|
|
655
|
+
...problem
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
/** Reports negated reads of a variable holding an affirm() result, or calls of a wrapper function. */
|
|
659
|
+
function checkVariable(variable, asWrapper) {
|
|
660
|
+
if (!assignedOnce(variable)) return;
|
|
661
|
+
for (const reference of variable.references) {
|
|
662
|
+
if (!reference.isRead()) continue;
|
|
663
|
+
let value = reference.identifier;
|
|
664
|
+
if (asWrapper) {
|
|
665
|
+
const call = value.parent;
|
|
666
|
+
if (call?.type !== "CallExpression" || call.callee !== value) continue;
|
|
667
|
+
value = call;
|
|
668
|
+
}
|
|
669
|
+
const negation = negationOf(carrier(value));
|
|
670
|
+
if (negation === void 0) continue;
|
|
671
|
+
report(negation, {
|
|
672
|
+
messageId: asWrapper ? "negatedWrapper" : "negatedResult",
|
|
673
|
+
data: {
|
|
674
|
+
usage: usageText(sourceCode, negation),
|
|
675
|
+
name: variable.name
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return { CallExpression(node) {
|
|
681
|
+
if (!isAffirmCall(node, sourceCode, sources)) {
|
|
682
|
+
const name = calleeName(node);
|
|
683
|
+
if (guards === void 0 || name === void 0 || !guards.test(name)) return;
|
|
684
|
+
if (!isProjectCall(node, sourceCode, guardModules)) return;
|
|
685
|
+
const negation = negationOf(carrier(node));
|
|
686
|
+
if (negation !== void 0) report(negation, {
|
|
687
|
+
messageId: "negatedGuard",
|
|
688
|
+
data: {
|
|
689
|
+
usage: usageText(sourceCode, negation),
|
|
690
|
+
name,
|
|
691
|
+
pattern: guards.source
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const value = carrier(node);
|
|
697
|
+
const negation = negationOf(value);
|
|
698
|
+
if (negation !== void 0) {
|
|
699
|
+
const suggestion = value === outermost(node) ? assertSuggestion(negation, node, sourceCode) : void 0;
|
|
700
|
+
report(negation, {
|
|
701
|
+
messageId: "negated",
|
|
702
|
+
data: { usage: usageText(sourceCode, negation) },
|
|
703
|
+
...suggestion ? { suggest: [suggestion] } : {}
|
|
704
|
+
});
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const declarator = value.parent;
|
|
708
|
+
if (declarator?.type === "VariableDeclarator" && declarator.init === value && declarator.id.type === "Identifier") {
|
|
709
|
+
for (const variable of sourceCode.getDeclaredVariables(declarator)) checkVariable(variable, false);
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const wrapper = wrapperOf(value);
|
|
713
|
+
const variable = wrapper && functionVariable(wrapper, sourceCode);
|
|
714
|
+
if (variable) checkVariable(variable, true);
|
|
715
|
+
} };
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
"guard-naming": guardNaming,
|
|
719
|
+
"const-params": constParams
|
|
720
|
+
},
|
|
721
|
+
configs: {}
|
|
722
|
+
};
|
|
723
|
+
plugin.configs.recommended = {
|
|
724
|
+
name: "affirm/recommended",
|
|
725
|
+
plugins: { affirm: plugin },
|
|
726
|
+
rules: {
|
|
727
|
+
"affirm/no-negated-affirm": "error",
|
|
728
|
+
"affirm/guard-naming": "error",
|
|
729
|
+
"affirm/const-params": "error"
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
export { plugin as default };
|
|
733
|
+
|
|
734
|
+
//# sourceMappingURL=eslint.js.map
|