@gost-kit/eslint-plugin 0.0.0-stage → 0.1.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/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/RULES.md +249 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -0
- package/dist/lib/common-source.d.ts +2 -0
- package/dist/lib/common-source.js +39 -0
- package/dist/lib/component-refs.d.ts +5 -0
- package/dist/lib/component-refs.js +58 -0
- package/dist/lib/dispatch-type.d.ts +2 -0
- package/dist/lib/dispatch-type.js +103 -0
- package/dist/lib/handler-body.d.ts +2 -0
- package/dist/lib/handler-body.js +32 -0
- package/dist/lib/member-key.d.ts +2 -0
- package/dist/lib/member-key.js +13 -0
- package/dist/lib/optional-call.d.ts +2 -0
- package/dist/lib/optional-call.js +55 -0
- package/dist/lib/raw-state.d.ts +2 -0
- package/dist/lib/raw-state.js +27 -0
- package/dist/lib/reactive-context.d.ts +6 -0
- package/dist/lib/reactive-context.js +48 -0
- package/dist/lib/rune-callee.d.ts +2 -0
- package/dist/lib/rune-callee.js +19 -0
- package/dist/lib/selector-fix.d.ts +2 -0
- package/dist/lib/selector-fix.js +122 -0
- package/dist/lib/store-state.d.ts +2 -0
- package/dist/lib/store-state.js +57 -0
- package/dist/lib/svelte-scripts.d.ts +5 -0
- package/dist/lib/svelte-scripts.js +25 -0
- package/dist/lib/ui-handlers.d.ts +10 -0
- package/dist/lib/ui-handlers.js +84 -0
- package/dist/lib/value-variable.d.ts +2 -0
- package/dist/lib/value-variable.js +25 -0
- package/dist/rules/no-component-state.d.ts +2 -0
- package/dist/rules/no-component-state.js +46 -0
- package/dist/rules/require-feature-state-selector.d.ts +2 -0
- package/dist/rules/require-feature-state-selector.js +58 -0
- package/dist/rules/single-intent-dispatch.d.ts +2 -0
- package/dist/rules/single-intent-dispatch.js +89 -0
- package/package.json +55 -4
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, ESLintUtils, } from '@typescript-eslint/utils';
|
|
2
|
+
import { isOptionalCall } from '../lib/optional-call.js';
|
|
3
|
+
import { createDispatchCheck } from '../lib/dispatch-type.js';
|
|
4
|
+
import { createUiHandlerCollector } from '../lib/ui-handlers.js';
|
|
5
|
+
import { visitHandlerBody } from '../lib/handler-body.js';
|
|
6
|
+
import { scriptHasAttribute, svelteScripts } from '../lib/svelte-scripts.js';
|
|
7
|
+
export const singleIntentDispatch = ESLintUtils.RuleCreator.withoutDocs({
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'suggestion',
|
|
10
|
+
docs: { description: 'Forward one intent in business UI callbacks.' },
|
|
11
|
+
schema: [],
|
|
12
|
+
messages: {
|
|
13
|
+
multipleDispatch: 'Forward one intent action; move business transitions to the reducer.',
|
|
14
|
+
conditionalDispatch: 'Move business decisions to the reducer and browser event handling to a UI-Kit component.',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
defaultOptions: [],
|
|
18
|
+
create(context) {
|
|
19
|
+
const source = context.sourceCode;
|
|
20
|
+
const scripts = svelteScripts(source)?.filter((script) => {
|
|
21
|
+
return (scriptHasAttribute(script, 'lang', 'ts') &&
|
|
22
|
+
!scriptHasAttribute(script, 'module') &&
|
|
23
|
+
!scriptHasAttribute(script, 'context', 'module'));
|
|
24
|
+
});
|
|
25
|
+
if (!scripts?.length) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
const isDispatch = createDispatchCheck(ESLintUtils.getParserServices(context));
|
|
29
|
+
const collector = createUiHandlerCollector(source, scripts);
|
|
30
|
+
return {
|
|
31
|
+
SvelteAttribute: collector.attribute,
|
|
32
|
+
SvelteShorthandAttribute: collector.shorthand,
|
|
33
|
+
SvelteDirective: collector.directive,
|
|
34
|
+
'Program:exit'() {
|
|
35
|
+
collector.handlers.forEach((handler) => {
|
|
36
|
+
let calls = 0;
|
|
37
|
+
let condition;
|
|
38
|
+
if (!handler.body) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const inspect = (node) => {
|
|
42
|
+
if (node.type === AST_NODE_TYPES.CallExpression &&
|
|
43
|
+
isDispatch(node.callee)) {
|
|
44
|
+
calls += 1;
|
|
45
|
+
if (isOptionalCall(node)) {
|
|
46
|
+
condition ??= node;
|
|
47
|
+
}
|
|
48
|
+
// A Dispatch default argument runs conditionally at invocation,
|
|
49
|
+
// even though its AssignmentPattern is not a logical expression.
|
|
50
|
+
condition ??= source.getAncestors(node).find((ancestor) => {
|
|
51
|
+
return (ancestor.type === AST_NODE_TYPES.AssignmentPattern &&
|
|
52
|
+
handler.params.some((parameter) => {
|
|
53
|
+
return (ancestor.range[0] >= parameter.range[0] &&
|
|
54
|
+
ancestor.range[1] <= parameter.range[1]);
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (node.type === AST_NODE_TYPES.IfStatement ||
|
|
59
|
+
node.type === AST_NODE_TYPES.SwitchStatement ||
|
|
60
|
+
node.type === AST_NODE_TYPES.ForStatement ||
|
|
61
|
+
node.type === AST_NODE_TYPES.ForInStatement ||
|
|
62
|
+
node.type === AST_NODE_TYPES.ForOfStatement ||
|
|
63
|
+
node.type === AST_NODE_TYPES.WhileStatement ||
|
|
64
|
+
node.type === AST_NODE_TYPES.DoWhileStatement ||
|
|
65
|
+
node.type === AST_NODE_TYPES.ConditionalExpression ||
|
|
66
|
+
node.type === AST_NODE_TYPES.LogicalExpression ||
|
|
67
|
+
(node.type === AST_NODE_TYPES.AssignmentExpression &&
|
|
68
|
+
['??=', '&&=', '||='].includes(node.operator))) {
|
|
69
|
+
condition ??= node;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
handler.params.forEach((parameter) => {
|
|
73
|
+
visitHandlerBody(parameter, source, inspect);
|
|
74
|
+
});
|
|
75
|
+
visitHandlerBody(handler.body, source, inspect);
|
|
76
|
+
if (calls > 1) {
|
|
77
|
+
context.report({ node: handler, messageId: 'multipleDispatch' });
|
|
78
|
+
}
|
|
79
|
+
else if (calls === 1 && condition) {
|
|
80
|
+
context.report({
|
|
81
|
+
node: condition,
|
|
82
|
+
messageId: 'conditionalDispatch',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gost-kit/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "GOST architecture rules for agent-assisted frontend development.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "^26.0.0"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"CHANGELOG.md",
|
|
13
|
+
"RULES.md"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "npm run clean && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
24
|
+
"check": "tsc -p tsconfig.json",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"prepack": "npm run build",
|
|
27
|
+
"clean": "node --input-type=module -e \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true });\""
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/antonsmolko/gost-kit.git",
|
|
32
|
+
"directory": "packages/eslint-plugin"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "26.6.5",
|
|
39
|
+
"typescript": "5.9.3",
|
|
40
|
+
"tsc-alias": "1.9.9",
|
|
41
|
+
"vitest": "5.0.5",
|
|
42
|
+
"eslint": "10.14.0",
|
|
43
|
+
"svelte-eslint-parser": "1.10.1",
|
|
44
|
+
"typescript-eslint": "8.72.1",
|
|
45
|
+
"svelte": "5.57.2",
|
|
46
|
+
"@gost-kit/common": "0.2.1",
|
|
47
|
+
"@gost-kit/svelte": "0.1.1",
|
|
48
|
+
"@typescript-eslint/rule-tester": "8.72.1"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@typescript-eslint/utils": "8.72.1"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"eslint": "^10.14.0",
|
|
55
|
+
"typescript": "^5.9.3"
|
|
56
|
+
}
|
|
57
|
+
}
|