@formspec/eslint-plugin 0.1.0-alpha.8 → 0.1.0-alpha.9
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 +32 -12
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/rules/consistent-constraints.d.ts +22 -0
- package/dist/rules/consistent-constraints.d.ts.map +1 -0
- package/dist/rules/consistent-constraints.js +178 -0
- package/dist/rules/consistent-constraints.js.map +1 -0
- package/dist/rules/constraints/allowed-field-types.d.ts.map +1 -1
- package/dist/rules/constraints/allowed-field-types.js.map +1 -1
- package/dist/rules/constraints/allowed-layouts.d.ts.map +1 -1
- package/dist/rules/constraints/allowed-layouts.js.map +1 -1
- package/dist/rules/decorator-allowed-field-types.d.ts +17 -0
- package/dist/rules/decorator-allowed-field-types.d.ts.map +1 -0
- package/dist/rules/decorator-allowed-field-types.js +71 -0
- package/dist/rules/decorator-allowed-field-types.js.map +1 -0
- package/dist/rules/decorator-field-type-mismatch.d.ts +3 -4
- package/dist/rules/decorator-field-type-mismatch.d.ts.map +1 -1
- package/dist/rules/decorator-field-type-mismatch.js +46 -17
- package/dist/rules/decorator-field-type-mismatch.js.map +1 -1
- package/dist/rules/enum-options-match-type.d.ts.map +1 -1
- package/dist/rules/enum-options-match-type.js +2 -2
- package/dist/rules/enum-options-match-type.js.map +1 -1
- package/dist/rules/index.d.ts +3 -1
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +3 -1
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-conflicting-decorators.d.ts +2 -6
- package/dist/rules/no-conflicting-decorators.d.ts.map +1 -1
- package/dist/rules/no-conflicting-decorators.js +2 -6
- package/dist/rules/no-conflicting-decorators.js.map +1 -1
- package/dist/rules/no-duplicate-decorators.d.ts +2 -2
- package/dist/rules/no-duplicate-decorators.d.ts.map +1 -1
- package/dist/rules/no-duplicate-decorators.js +4 -19
- package/dist/rules/no-duplicate-decorators.js.map +1 -1
- package/dist/rules/prefer-custom-decorator.d.ts +22 -0
- package/dist/rules/prefer-custom-decorator.d.ts.map +1 -0
- package/dist/rules/prefer-custom-decorator.js +72 -0
- package/dist/rules/prefer-custom-decorator.js.map +1 -0
- package/dist/rules/showwhen-field-exists.d.ts.map +1 -1
- package/dist/rules/showwhen-field-exists.js.map +1 -1
- package/dist/rules/showwhen-suggests-optional.d.ts.map +1 -1
- package/dist/rules/showwhen-suggests-optional.js.map +1 -1
- package/dist/utils/decorator-utils.d.ts +8 -6
- package/dist/utils/decorator-utils.d.ts.map +1 -1
- package/dist/utils/decorator-utils.js +16 -22
- package/dist/utils/decorator-utils.js.map +1 -1
- package/dist/utils/jsdoc-utils.d.ts +31 -0
- package/dist/utils/jsdoc-utils.d.ts.map +1 -0
- package/dist/utils/jsdoc-utils.js +81 -0
- package/dist/utils/jsdoc-utils.js.map +1 -0
- package/dist/utils/type-utils.d.ts.map +1 -1
- package/dist/utils/type-utils.js +30 -6
- package/dist/utils/type-utils.js.map +1 -1
- package/package.json +3 -2
- package/dist/rules/min-max-valid-range.d.ts +0 -26
- package/dist/rules/min-max-valid-range.d.ts.map +0 -1
- package/dist/rules/min-max-valid-range.js +0 -82
- package/dist/rules/min-max-valid-range.js.map +0 -1
|
@@ -2,28 +2,32 @@
|
|
|
2
2
|
* Rule: decorator-field-type-mismatch
|
|
3
3
|
*
|
|
4
4
|
* Ensures FormSpec decorators are applied to fields with compatible types:
|
|
5
|
-
* - @
|
|
6
|
-
* - @
|
|
7
|
-
* - @Placeholder only on string fields
|
|
5
|
+
* - @Minimum/@Maximum/@ExclusiveMinimum/@ExclusiveMaximum only on number fields
|
|
6
|
+
* - @MinLength/@MaxLength/@Pattern only on string fields
|
|
8
7
|
*/
|
|
9
8
|
import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
10
9
|
import { getFormSpecDecorators, DECORATOR_TYPE_HINTS, } from "../utils/decorator-utils.js";
|
|
10
|
+
import { getJSDocConstraints } from "../utils/jsdoc-utils.js";
|
|
11
11
|
import { getPropertyType, getFieldTypeCategory, } from "../utils/type-utils.js";
|
|
12
12
|
const createRule = ESLintUtils.RuleCreator((name) => `https://formspec.dev/eslint-plugin/rules/${name}`);
|
|
13
13
|
const EXPECTED_TYPES = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
Minimum: ["number"],
|
|
15
|
+
Maximum: ["number"],
|
|
16
|
+
ExclusiveMinimum: ["number"],
|
|
17
|
+
ExclusiveMaximum: ["number"],
|
|
18
|
+
MinLength: ["string"],
|
|
19
|
+
MaxLength: ["string"],
|
|
20
|
+
Pattern: ["string"],
|
|
19
21
|
EnumOptions: ["string", "union"], // Handled by separate rule
|
|
20
22
|
};
|
|
21
23
|
const DECORATOR_MESSAGE_IDS = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Minimum: "numericOnNonNumber",
|
|
25
|
+
Maximum: "numericOnNonNumber",
|
|
26
|
+
ExclusiveMinimum: "numericOnNonNumber",
|
|
27
|
+
ExclusiveMaximum: "numericOnNonNumber",
|
|
28
|
+
MinLength: "stringOnNonString",
|
|
29
|
+
MaxLength: "stringOnNonString",
|
|
30
|
+
Pattern: "stringOnNonString",
|
|
27
31
|
};
|
|
28
32
|
export const decoratorFieldTypeMismatch = createRule({
|
|
29
33
|
name: "decorator-field-type-mismatch",
|
|
@@ -33,9 +37,8 @@ export const decoratorFieldTypeMismatch = createRule({
|
|
|
33
37
|
description: "Ensures FormSpec decorators are applied to fields with compatible types",
|
|
34
38
|
},
|
|
35
39
|
messages: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
placeholderOnNonString: "@Placeholder can only be used on string fields, but field '{{field}}' has type '{{actualType}}'",
|
|
40
|
+
numericOnNonNumber: "@{{decorator}} can only be used on number fields, but field '{{field}}' has type '{{actualType}}'",
|
|
41
|
+
stringOnNonString: "@{{decorator}} can only be used on string fields, but field '{{field}}' has type '{{actualType}}'",
|
|
39
42
|
},
|
|
40
43
|
schema: [],
|
|
41
44
|
},
|
|
@@ -46,7 +49,9 @@ export const decoratorFieldTypeMismatch = createRule({
|
|
|
46
49
|
return {
|
|
47
50
|
PropertyDefinition(node) {
|
|
48
51
|
const decorators = getFormSpecDecorators(node);
|
|
49
|
-
|
|
52
|
+
const jsdocConstraints = getJSDocConstraints(node, context.sourceCode);
|
|
53
|
+
// Nothing to check if there are no decorators or JSDoc constraints
|
|
54
|
+
if (decorators.length === 0 && jsdocConstraints.length === 0)
|
|
50
55
|
return;
|
|
51
56
|
const type = getPropertyType(node, services);
|
|
52
57
|
if (!type)
|
|
@@ -80,6 +85,30 @@ export const decoratorFieldTypeMismatch = createRule({
|
|
|
80
85
|
});
|
|
81
86
|
}
|
|
82
87
|
}
|
|
88
|
+
// Also check JSDoc constraint tags for type compatibility
|
|
89
|
+
for (const constraint of jsdocConstraints) {
|
|
90
|
+
const constraintName = constraint.name;
|
|
91
|
+
if (!(constraintName in DECORATOR_TYPE_HINTS))
|
|
92
|
+
continue;
|
|
93
|
+
if (constraintName === "EnumOptions")
|
|
94
|
+
continue;
|
|
95
|
+
const expectedTypes = EXPECTED_TYPES[constraintName];
|
|
96
|
+
const isCompatible = expectedTypes.includes(fieldTypeCategory);
|
|
97
|
+
if (!isCompatible) {
|
|
98
|
+
const messageId = DECORATOR_MESSAGE_IDS[constraintName];
|
|
99
|
+
if (!messageId)
|
|
100
|
+
continue;
|
|
101
|
+
context.report({
|
|
102
|
+
loc: constraint.comment.loc,
|
|
103
|
+
messageId,
|
|
104
|
+
data: {
|
|
105
|
+
decorator: constraintName,
|
|
106
|
+
field: fieldName,
|
|
107
|
+
actualType,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
83
112
|
},
|
|
84
113
|
};
|
|
85
114
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorator-field-type-mismatch.js","sourceRoot":"","sources":["../../src/rules/decorator-field-type-mismatch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decorator-field-type-mismatch.js","sourceRoot":"","sources":["../../src/rules/decorator-field-type-mismatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,oBAAoB,GAErB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,cAAc,GAAmD;IACrE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,gBAAgB,EAAE,CAAC,QAAQ,CAAC;IAC5B,gBAAgB,EAAE,CAAC,QAAQ,CAAC;IAC5B,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,OAAO,EAAE,CAAC,QAAQ,CAAC;IACnB,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,2BAA2B;CAC9D,CAAC;AAEF,MAAM,qBAAqB,GAAmD;IAC5E,OAAO,EAAE,oBAAoB;IAC7B,OAAO,EAAE,oBAAoB;IAC7B,gBAAgB,EAAE,oBAAoB;IACtC,gBAAgB,EAAE,oBAAoB;IACtC,SAAS,EAAE,mBAAmB;IAC9B,SAAS,EAAE,mBAAmB;IAC9B,OAAO,EAAE,mBAAmB;CAC7B,CAAC;AAEF,MAAM,CAAC,M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;4BACT,IAAI,EAAE;gCACJ,SAAS,EAAE,cAAc;gCACzB,KAAK,EAAE,SAAS;gCAChB,UAAU;6BACX;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-options-match-type.d.ts","sourceRoot":"","sources":["../../src/rules/enum-options-match-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"enum-options-match-type.d.ts","sourceRoot":"","sources":["../../src/rules/enum-options-match-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAQvD,KAAK,UAAU,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AAEpF,eAAO,MAAM,oBAAoB;;CAmG/B,CAAC"}
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* field!: "x" | "y"; // Mismatch
|
|
19
19
|
*/
|
|
20
20
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
21
|
-
import { findDecorator, getDecoratorArrayArg
|
|
22
|
-
import { getPropertyType, getStringLiteralUnionValues, isStringType
|
|
21
|
+
import { findDecorator, getDecoratorArrayArg } from "../utils/decorator-utils.js";
|
|
22
|
+
import { getPropertyType, getStringLiteralUnionValues, isStringType } from "../utils/type-utils.js";
|
|
23
23
|
const createRule = ESLintUtils.RuleCreator((name) => `https://formspec.dev/eslint-plugin/rules/${name}`);
|
|
24
24
|
export const enumOptionsMatchType = createRule({
|
|
25
25
|
name: "enum-options-match-type",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-options-match-type.js","sourceRoot":"","sources":["../../src/rules/enum-options-match-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"enum-options-match-type.js","sourceRoot":"","sources":["../../src/rules/enum-options-match-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEpG,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAiB;IAC7D,IAAI,EAAE,yBAAyB;IAC/B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,qEAAqE;SACnF;QACD,QAAQ,EAAE;YACR,mBAAmB,EACjB,yFAAyF;YAC3F,kBAAkB,EAChB,0EAA0E;YAC5E,gBAAgB,EAAE,4DAA4D;SAC/E;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,QAAQ,GAAG,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAElD,OAAO;YACL,kBAAkB,CAAC,IAAI;gBACrB,MAAM,oBAAoB,GAAG,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;gBAChE,IAAI,CAAC,oBAAoB;oBAAE,OAAO;gBAElC,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,QAA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AAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBAClB,CAAC;gBACH,CAAC;gBAED,iDAAiD;gBACjD,MAAM,KAAK,GAAa,EAAE,CAAC;gBAC3B,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;oBAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;wBACpB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBAChB,CAAC;gBACH,CAAC;gBAED,yBAAyB;gBACzB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACvB,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,oBAAoB,CAAC,IAAI;wBAC/B,SAAS,EAAE,oBAAoB;wBAC/B,IAAI,EAAE;4BACJ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;yBACjD;qBACF,CAAC,CAAC;gBACL,CAAC;gBAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACrB,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,oBAAoB,CAAC,IAAI;wBAC/B,SAAS,EAAE,kBAAkB;wBAC7B,IAAI,EAAE;4BACJ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;yBAC7C;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export { decoratorFieldTypeMismatch } from "./decorator-field-type-mismatch.js";
|
|
|
5
5
|
export { enumOptionsMatchType } from "./enum-options-match-type.js";
|
|
6
6
|
export { showwhenFieldExists } from "./showwhen-field-exists.js";
|
|
7
7
|
export { showwhenSuggestsOptional } from "./showwhen-suggests-optional.js";
|
|
8
|
-
export {
|
|
8
|
+
export { consistentConstraints } from "./consistent-constraints.js";
|
|
9
9
|
export { noConflictingDecorators } from "./no-conflicting-decorators.js";
|
|
10
10
|
export { noDuplicateDecorators } from "./no-duplicate-decorators.js";
|
|
11
|
+
export { decoratorAllowedFieldTypes } from "./decorator-allowed-field-types.js";
|
|
12
|
+
export { preferCustomDecorator } from "./prefer-custom-decorator.js";
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/rules/index.js
CHANGED
|
@@ -5,7 +5,9 @@ export { decoratorFieldTypeMismatch } from "./decorator-field-type-mismatch.js";
|
|
|
5
5
|
export { enumOptionsMatchType } from "./enum-options-match-type.js";
|
|
6
6
|
export { showwhenFieldExists } from "./showwhen-field-exists.js";
|
|
7
7
|
export { showwhenSuggestsOptional } from "./showwhen-suggests-optional.js";
|
|
8
|
-
export {
|
|
8
|
+
export { consistentConstraints } from "./consistent-constraints.js";
|
|
9
9
|
export { noConflictingDecorators } from "./no-conflicting-decorators.js";
|
|
10
10
|
export { noDuplicateDecorators } from "./no-duplicate-decorators.js";
|
|
11
|
+
export { decoratorAllowedFieldTypes } from "./decorator-allowed-field-types.js";
|
|
12
|
+
export { preferCustomDecorator } from "./prefer-custom-decorator.js";
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
package/dist/rules/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -4,13 +4,9 @@
|
|
|
4
4
|
* Ensures a field doesn't have decorators that imply conflicting types.
|
|
5
5
|
*
|
|
6
6
|
* Invalid:
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
7
|
+
* @Minimum(0) // Implies number
|
|
8
|
+
* @MinLength(1) // Implies string
|
|
9
9
|
* field!: string;
|
|
10
|
-
*
|
|
11
|
-
* @MinItems(1) // Implies array
|
|
12
|
-
* @Min(0) // Implies number
|
|
13
|
-
* field!: number[];
|
|
14
10
|
*/
|
|
15
11
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
16
12
|
export declare const noConflictingDecorators: ESLintUtils.RuleModule<"conflictingDecorators", [], unknown, ESLintUtils.RuleListener> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-conflicting-decorators.d.ts","sourceRoot":"","sources":["../../src/rules/no-conflicting-decorators.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"no-conflicting-decorators.d.ts","sourceRoot":"","sources":["../../src/rules/no-conflicting-decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAavD,eAAO,MAAM,uBAAuB;;CA4DlC,CAAC"}
|
|
@@ -4,13 +4,9 @@
|
|
|
4
4
|
* Ensures a field doesn't have decorators that imply conflicting types.
|
|
5
5
|
*
|
|
6
6
|
* Invalid:
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
7
|
+
* @Minimum(0) // Implies number
|
|
8
|
+
* @MinLength(1) // Implies string
|
|
9
9
|
* field!: string;
|
|
10
|
-
*
|
|
11
|
-
* @MinItems(1) // Implies array
|
|
12
|
-
* @Min(0) // Implies number
|
|
13
|
-
* field!: number[];
|
|
14
10
|
*/
|
|
15
11
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
16
12
|
import { getFormSpecDecorators, DECORATOR_TYPE_HINTS, } from "../utils/decorator-utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-conflicting-decorators.js","sourceRoot":"","sources":["../../src/rules/no-conflicting-decorators.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"no-conflicting-decorators.js","sourceRoot":"","sources":["../../src/rules/no-conflicting-decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AAErC,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAiB;IAChE,IAAI,EAAE,2BAA2B;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sEAAsE;SACpF;QACD,QAAQ,EAAE;YACR,qBAAqB,EACnB,4GAA4G;SAC/G;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,kBAAkB,CAAC,IAAI;gBACrB,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;gBAC/C,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;oBAAE,OAAO;gBAElC,qCAAqC;gBACrC,MAAM,SAAS,GAA0C,EAAE,CAAC;gBAE5D,KA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esn't have the same decorator applied multiple times.
|
|
5
5
|
*
|
|
6
6
|
* Invalid:
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
7
|
+
* @Field({ displayName: "First" })
|
|
8
|
+
* @Field({ displayName: "Second" }) // Duplicate
|
|
9
9
|
* field!: string;
|
|
10
10
|
*
|
|
11
11
|
* @EnumOptions(["a", "b"])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-duplicate-decorators.d.ts","sourceRoot":"","sources":["../../src/rules/no-duplicate-decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"no-duplicate-decorators.d.ts","sourceRoot":"","sources":["../../src/rules/no-duplicate-decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AASvD,eAAO,MAAM,qBAAqB;;CAyChC,CAAC"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Ensures a field doesn't have the same decorator applied multiple times.
|
|
5
5
|
*
|
|
6
6
|
* Invalid:
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
7
|
+
* @Field({ displayName: "First" })
|
|
8
|
+
* @Field({ displayName: "Second" }) // Duplicate
|
|
9
9
|
* field!: string;
|
|
10
10
|
*
|
|
11
11
|
* @EnumOptions(["a", "b"])
|
|
@@ -13,23 +13,8 @@
|
|
|
13
13
|
* field!: string;
|
|
14
14
|
*/
|
|
15
15
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
16
|
-
import { getFormSpecDecorators } from "../utils/decorator-utils.js";
|
|
16
|
+
import { getFormSpecDecorators, FORMSPEC_DECORATORS } from "../utils/decorator-utils.js";
|
|
17
17
|
const createRule = ESLintUtils.RuleCreator((name) => `https://formspec.dev/eslint-plugin/rules/${name}`);
|
|
18
|
-
/**
|
|
19
|
-
* Decorators that should only appear once per field.
|
|
20
|
-
*/
|
|
21
|
-
const SINGLE_USE_DECORATORS = new Set([
|
|
22
|
-
"Label",
|
|
23
|
-
"Placeholder",
|
|
24
|
-
"Optional",
|
|
25
|
-
"Min",
|
|
26
|
-
"Max",
|
|
27
|
-
"MinItems",
|
|
28
|
-
"MaxItems",
|
|
29
|
-
"EnumOptions",
|
|
30
|
-
"Group",
|
|
31
|
-
"ShowWhen",
|
|
32
|
-
]);
|
|
33
18
|
export const noDuplicateDecorators = createRule({
|
|
34
19
|
name: "no-duplicate-decorators",
|
|
35
20
|
meta: {
|
|
@@ -52,7 +37,7 @@ export const noDuplicateDecorators = createRule({
|
|
|
52
37
|
// Track seen decorators
|
|
53
38
|
const seen = new Map();
|
|
54
39
|
for (const decorator of decorators) {
|
|
55
|
-
if (!
|
|
40
|
+
if (!FORMSPEC_DECORATORS.has(decorator.name))
|
|
56
41
|
continue;
|
|
57
42
|
if (seen.has(decorator.name)) {
|
|
58
43
|
context.report({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-duplicate-decorators.js","sourceRoot":"","sources":["../../src/rules/no-duplicate-decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"no-duplicate-decorators.js","sourceRoot":"","sources":["../../src/rules/no-duplicate-decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEzF,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAiB;IAC9D,IAAI,EAAE,yBAAyB;IAC/B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,wEAAwE;SACtF;QACD,QAAQ,EAAE;YACR,kBAAkB,EAChB,uFAAuF;SAC1F;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,kBAAkB,CAAC,IAAI;gBACrB,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;gBAC/C,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;oBAAE,OAAO;gBAElC,wBAAwB;gBACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAmB,CAAC;gBAExC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;oBACnC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;wBAAE,SAAS;oBAEvD,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC7B,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,SAAS,CAAC,IAAI;4BACpB,SAAS,EAAE,oBAAoB;4BAC/B,IAAI,EAAE;gCACJ,SAAS,EAAE,SAAS,CAAC,IAAI;6BAC1B;yBACF,CAAC,CAAC;oBACL,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBACjC,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: prefer-custom-decorator
|
|
3
|
+
*
|
|
4
|
+
* When a project has symbols with FormSpecExtendsBrand<'Field'> type,
|
|
5
|
+
* flags direct usage of @Field from @formspec/decorators.
|
|
6
|
+
*
|
|
7
|
+
* TODO: Full implementation requires type-checker integration to detect
|
|
8
|
+
* FormSpecExtendsBrand symbols in scope. Currently implemented as a
|
|
9
|
+
* configurable rule that accepts a list of decorator names that should
|
|
10
|
+
* be preferred over @Field.
|
|
11
|
+
*
|
|
12
|
+
* Config example:
|
|
13
|
+
* "@formspec/prefer-custom-decorator": ["warn", { prefer: { "Field": "MyCustomField" } }]
|
|
14
|
+
*/
|
|
15
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
16
|
+
export interface PreferCustomDecoratorOptions {
|
|
17
|
+
prefer: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export declare const preferCustomDecorator: ESLintUtils.RuleModule<"preferCustomDecorator", [PreferCustomDecoratorOptions], unknown, ESLintUtils.RuleListener> & {
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=prefer-custom-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-custom-decorator.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-custom-decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AASvD,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,qBAAqB;;CAwDhC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: prefer-custom-decorator
|
|
3
|
+
*
|
|
4
|
+
* When a project has symbols with FormSpecExtendsBrand<'Field'> type,
|
|
5
|
+
* flags direct usage of @Field from @formspec/decorators.
|
|
6
|
+
*
|
|
7
|
+
* TODO: Full implementation requires type-checker integration to detect
|
|
8
|
+
* FormSpecExtendsBrand symbols in scope. Currently implemented as a
|
|
9
|
+
* configurable rule that accepts a list of decorator names that should
|
|
10
|
+
* be preferred over @Field.
|
|
11
|
+
*
|
|
12
|
+
* Config example:
|
|
13
|
+
* "@formspec/prefer-custom-decorator": ["warn", { prefer: { "Field": "MyCustomField" } }]
|
|
14
|
+
*/
|
|
15
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
16
|
+
import { getFormSpecDecorators } from "../utils/decorator-utils.js";
|
|
17
|
+
const createRule = ESLintUtils.RuleCreator((name) => `https://formspec.dev/eslint-plugin/rules/${name}`);
|
|
18
|
+
export const preferCustomDecorator = createRule({
|
|
19
|
+
name: "prefer-custom-decorator",
|
|
20
|
+
meta: {
|
|
21
|
+
type: "suggestion",
|
|
22
|
+
docs: {
|
|
23
|
+
description: "Suggests using a custom decorator instead of a built-in FormSpec decorator when a project-specific alternative exists",
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
preferCustomDecorator: "Prefer @{{preferred}} over @{{builtin}}. This project provides a custom decorator that extends the built-in.",
|
|
27
|
+
},
|
|
28
|
+
schema: [
|
|
29
|
+
{
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
prefer: {
|
|
33
|
+
type: "object",
|
|
34
|
+
additionalProperties: { type: "string" },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
required: ["prefer"],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
defaultOptions: [{ prefer: {} }],
|
|
43
|
+
create(context, [options]) {
|
|
44
|
+
const preferMap = options.prefer;
|
|
45
|
+
const builtinNames = new Set(Object.keys(preferMap));
|
|
46
|
+
if (builtinNames.size === 0)
|
|
47
|
+
return {};
|
|
48
|
+
return {
|
|
49
|
+
PropertyDefinition(node) {
|
|
50
|
+
const decorators = getFormSpecDecorators(node);
|
|
51
|
+
if (decorators.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
for (const decorator of decorators) {
|
|
54
|
+
if (builtinNames.has(decorator.name)) {
|
|
55
|
+
const preferred = preferMap[decorator.name];
|
|
56
|
+
if (!preferred)
|
|
57
|
+
continue;
|
|
58
|
+
context.report({
|
|
59
|
+
node: decorator.node,
|
|
60
|
+
messageId: "preferCustomDecorator",
|
|
61
|
+
data: {
|
|
62
|
+
builtin: decorator.name,
|
|
63
|
+
preferred,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=prefer-custom-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-custom-decorator.js","sourceRoot":"","sources":["../../src/rules/prefer-custom-decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAQF,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAA6C;IAC1F,IAAI,EAAE,yBAAyB;IAC/B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,uHAAuH;SAC1H;QACD,QAAQ,EAAE;YACR,qBAAqB,EACnB,8GAA8G;SACjH;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,QAAQ;wBACd,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;qBACzC;iBACF;gBACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;gBACpB,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF;IACD,cAAc,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAChC,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC;QACvB,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;QACjC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAErD,IAAI,YAAY,CAAC,IAAI,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAEvC,OAAO;YACL,kBAAkB,CAAC,IAAI;gBACrB,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;gBAC/C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;oBAAE,OAAO;gBAEpC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;oBACnC,IAAI,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;wBACrC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;wBAC5C,IAAI,CAAC,SAAS;4BAAE,SAAS;wBAEzB,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,SAAS,CAAC,IAAI;4BACpB,SAAS,EAAE,uBAAuB;4BAClC,IAAI,EAAE;gCACJ,OAAO,EAAE,SAAS,CAAC,IAAI;gCACvB,SAAS;6BACV;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"showwhen-field-exists.d.ts","sourceRoot":"","sources":["../../src/rules/showwhen-field-exists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAC;AAavE,eAAO,MAAM,mBAAmB;;
|
|
1
|
+
{"version":3,"file":"showwhen-field-exists.d.ts","sourceRoot":"","sources":["../../src/rules/showwhen-field-exists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAC;AAavE,eAAO,MAAM,mBAAmB;;CAoD9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"showwhen-field-exists.js","sourceRoot":"","sources":["../../src/rules/showwhen-field-exists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AAErC,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAiB;IAC5D,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,
|
|
1
|
+
{"version":3,"file":"showwhen-field-exists.js","sourceRoot":"","sources":["../../src/rules/showwhen-field-exists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AAErC,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAiB;IAC5D,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,oEAAoE;SAClF;QACD,QAAQ,EAAE;YACR,iBAAiB,EACf,qFAAqF;SACxF;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,kBAAkB,CAAC,IAAI;gBACrB,MAAM,iBAAiB,GAAG,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;gBAC1D,IAAI,CAAC,iBAAiB;oBAAE,OAAO;gBAE/B,MAAM,eAAe,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;gBAC5D,IAAI,CAAC,eAAe;oBAAE,OAAO;gBAE7B,wBAAwB;gBACxB,sEAAsE;gBACtE,wEAAwE;gBACxE,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;gBAC9B,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;gBACnC,IACE,SAAS,CAAC,IAAI,KAAK,cAAc,CAAC,gBAAgB;oBAClD,0FAA0F;oBAC1F,SAAS,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe,EACjD,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,sCAAsC;gBACtC,MAAM,aAAa,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;gBAEvD,uCAAuC;gBACvC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;oBACxC,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,iBAAiB,CAAC,IAAI;wBAC5B,SAAS,EAAE,mBAAmB;wBAC9B,IAAI,EAAE;4BACJ,eAAe;yBAChB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"showwhen-suggests-optional.d.ts","sourceRoot":"","sources":["../../src/rules/showwhen-suggests-optional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAC;AAUvE,eAAO,MAAM,wBAAwB;;
|
|
1
|
+
{"version":3,"file":"showwhen-suggests-optional.d.ts","sourceRoot":"","sources":["../../src/rules/showwhen-suggests-optional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAC;AAUvE,eAAO,MAAM,wBAAwB;;CAoCnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"showwhen-suggests-optional.js","sourceRoot":"","sources":["../../src/rules/showwhen-suggests-optional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAiB;IACjE,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,
|
|
1
|
+
{"version":3,"file":"showwhen-suggests-optional.js","sourceRoot":"","sources":["../../src/rules/showwhen-suggests-optional.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4CAA4C,IAAI,EAAE,CAC7D,CAAC;AAIF,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAiB;IACjE,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,kEAAkE;SAChF;QACD,QAAQ,EAAE;YACR,gBAAgB,EACd,iJAAiJ;SACpJ;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,kBAAkB,CAAC,IAAI;gBACrB,MAAM,iBAAiB,GAAG,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;gBAC1D,IAAI,CAAC,iBAAiB;oBAAE,OAAO;gBAE/B,yCAAyC;gBACzC,IAAI,kBAAkB,CAAC,IAAI,CAAC;oBAAE,OAAO;gBAErC,MAAM,SAAS,GACb,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC;gBAE7E,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,EAAE,IAAI,CAAC,GAAG;oBACd,SAAS,EAAE,kBAAkB;oBAC7B,IAAI,EAAE;wBACJ,KAAK,EAAE,SAAS;qBACjB;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { TSESTree } from "@typescript-eslint/utils";
|
|
|
6
6
|
* Information extracted from a decorator.
|
|
7
7
|
*/
|
|
8
8
|
export interface DecoratorInfo {
|
|
9
|
-
/** The decorator name (e.g., "
|
|
9
|
+
/** The decorator name (e.g., "Minimum", "Field", "EnumOptions") */
|
|
10
10
|
name: string;
|
|
11
11
|
/** The arguments passed to the decorator */
|
|
12
12
|
args: TSESTree.Expression[];
|
|
@@ -17,11 +17,13 @@ export interface DecoratorInfo {
|
|
|
17
17
|
* FormSpec decorator names that imply specific field types.
|
|
18
18
|
*/
|
|
19
19
|
export declare const DECORATOR_TYPE_HINTS: {
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
20
|
+
readonly Minimum: "number";
|
|
21
|
+
readonly Maximum: "number";
|
|
22
|
+
readonly ExclusiveMinimum: "number";
|
|
23
|
+
readonly ExclusiveMaximum: "number";
|
|
24
|
+
readonly MinLength: "string";
|
|
25
|
+
readonly MaxLength: "string";
|
|
26
|
+
readonly Pattern: "string";
|
|
25
27
|
readonly EnumOptions: "enum";
|
|
26
28
|
};
|
|
27
29
|
export type TypeHintDecorator = keyof typeof DECORATOR_TYPE_HINTS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorator-utils.d.ts","sourceRoot":"","sources":["../../src/utils/decorator-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAkB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"decorator-utils.d.ts","sourceRoot":"","sources":["../../src/utils/decorator-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAkB,MAAM,0BAA0B,CAAC;AAGpE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,IAAI,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC5B,kCAAkC;IAClC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;CASvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,mBAAmB,aAA4C,CAAC;AAE7E;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,GAAG,aAAa,GAAG,IAAI,CAyBpF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,kBAAkB,GAAG,aAAa,EAAE,CAexF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,CAAC,kBAAkB,EACjC,IAAI,EAAE,MAAM,GACX,aAAa,GAAG,IAAI,CAGtB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,CAqBxE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,EAAE,GAAG,IAAI,CAgC/E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAqBxE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,kBAAkB,GAAG,MAAM,GAAG,IAAI,CAQhF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,QAAQ,CAAC,gBAAgB,GAAG,QAAQ,CAAC,eAAe,GAC9D,GAAG,CAAC,MAAM,CAAC,CAWb"}
|
|
@@ -2,37 +2,24 @@
|
|
|
2
2
|
* Utility functions for working with decorator AST nodes.
|
|
3
3
|
*/
|
|
4
4
|
import { TSESTree, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
5
|
+
import { FORMSPEC_DECORATOR_NAMES } from "@formspec/core";
|
|
5
6
|
/**
|
|
6
7
|
* FormSpec decorator names that imply specific field types.
|
|
7
8
|
*/
|
|
8
9
|
export const DECORATOR_TYPE_HINTS = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
MaxItems: "array",
|
|
17
|
-
// Enum field decorators
|
|
10
|
+
Minimum: "number",
|
|
11
|
+
Maximum: "number",
|
|
12
|
+
ExclusiveMinimum: "number",
|
|
13
|
+
ExclusiveMaximum: "number",
|
|
14
|
+
MinLength: "string",
|
|
15
|
+
MaxLength: "string",
|
|
16
|
+
Pattern: "string",
|
|
18
17
|
EnumOptions: "enum",
|
|
19
18
|
};
|
|
20
19
|
/**
|
|
21
20
|
* All known FormSpec decorator names.
|
|
22
21
|
*/
|
|
23
|
-
export const FORMSPEC_DECORATORS = new Set(
|
|
24
|
-
"FormClass",
|
|
25
|
-
"Label",
|
|
26
|
-
"Optional",
|
|
27
|
-
"Placeholder",
|
|
28
|
-
"Min",
|
|
29
|
-
"Max",
|
|
30
|
-
"EnumOptions",
|
|
31
|
-
"Group",
|
|
32
|
-
"ShowWhen",
|
|
33
|
-
"MinItems",
|
|
34
|
-
"MaxItems",
|
|
35
|
-
]);
|
|
22
|
+
export const FORMSPEC_DECORATORS = new Set(FORMSPEC_DECORATOR_NAMES);
|
|
36
23
|
/**
|
|
37
24
|
* Extracts decorator information from a Decorator AST node.
|
|
38
25
|
*
|
|
@@ -122,6 +109,13 @@ export function getDecoratorLiteralArg(decorator) {
|
|
|
122
109
|
if (arg.type === AST_NODE_TYPES.Literal) {
|
|
123
110
|
return arg.value;
|
|
124
111
|
}
|
|
112
|
+
// Handle negative numbers: -5 is a UnaryExpression('-', Literal(5))
|
|
113
|
+
if (arg.type === AST_NODE_TYPES.UnaryExpression &&
|
|
114
|
+
arg.operator === "-" &&
|
|
115
|
+
arg.argument.type === AST_NODE_TYPES.Literal &&
|
|
116
|
+
typeof arg.argument.value === "number") {
|
|
117
|
+
return -arg.argument.value;
|
|
118
|
+
}
|
|
125
119
|
return null;
|
|
126
120
|
}
|
|
127
121
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorator-utils.js","sourceRoot":"","sources":["../../src/utils/decorator-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"decorator-utils.js","sourceRoot":"","sources":["../../src/utils/decorator-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAc1D;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,gBAAgB,EAAE,QAAQ;IAC1B,gBAAgB,EAAE,QAAQ;IAC1B,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,MAAM;CACX,CAAC;AAIX;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS,wBAAwB,CAAC,CAAC;AAE7E;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA6B;IAC5D,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC;IAElC,4CAA4C;IAC5C,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,cAAc,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU,EAAE,CAAC;YAC9C,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,IAAI,CAAC,SAAkC;gBAC7C,IAAI,EAAE,SAAS;aAChB,CAAC;QACJ,CAAC;IACH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AAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAiC;IAC/D,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;IACD,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACnF,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,SAA+D;IAE/D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,CAAC,kBAAkB,EAAE,CAAC;YACtD,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;YACrC,IAAI,IAAI,EAAE,CAAC;gBACT,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for extracting constraint tags from JSDoc comments.
|
|
3
|
+
*/
|
|
4
|
+
import { type TSESTree } from "@typescript-eslint/utils";
|
|
5
|
+
import type { SourceCode } from "@typescript-eslint/utils/ts-eslint";
|
|
6
|
+
/** A constraint extracted from a JSDoc comment tag. */
|
|
7
|
+
export interface JSDocConstraint {
|
|
8
|
+
/** The constraint name (e.g., "Minimum", "Maximum") */
|
|
9
|
+
name: string;
|
|
10
|
+
/** The parsed value */
|
|
11
|
+
value: number | string;
|
|
12
|
+
/** The comment node (for error reporting location) */
|
|
13
|
+
comment: TSESTree.Comment;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extracts constraint tags from JSDoc comments preceding a node.
|
|
17
|
+
*
|
|
18
|
+
* @param node - The AST node to check for preceding JSDoc comments
|
|
19
|
+
* @param sourceCode - The ESLint source code object
|
|
20
|
+
* @returns Array of parsed JSDoc constraints
|
|
21
|
+
*/
|
|
22
|
+
export declare function getJSDocConstraints(node: TSESTree.Node, sourceCode: SourceCode): JSDocConstraint[];
|
|
23
|
+
/**
|
|
24
|
+
* Finds a specific constraint by name in a JSDoc constraints array.
|
|
25
|
+
*
|
|
26
|
+
* @param constraints - The array of JSDoc constraints to search
|
|
27
|
+
* @param name - The constraint name to find
|
|
28
|
+
* @returns The matching constraint or null if not found
|
|
29
|
+
*/
|
|
30
|
+
export declare function findJSDocConstraint(constraints: JSDocConstraint[], name: string): JSDocConstraint | null;
|
|
31
|
+
//# sourceMappingURL=jsdoc-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsdoc-utils.d.ts","sourceRoot":"","sources":["../../src/utils/jsdoc-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAGrE,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,sDAAsD;IACtD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;CAC3B;AAiBD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,QAAQ,CAAC,IAAI,EACnB,UAAU,EAAE,UAAU,GACrB,eAAe,EAAE,CAsDnB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,eAAe,EAAE,EAC9B,IAAI,EAAE,MAAM,GACX,eAAe,GAAG,IAAI,CAExB"}
|