@reticlehq/core 1.3.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.
@@ -0,0 +1 @@
1
+ export { default, requireSignalOnMutation, rules } from '@reticlehq/eslint-plugin';
package/dist/eslint.js ADDED
@@ -0,0 +1,134 @@
1
+ // ../eslint-plugin/dist/require-signal-on-mutation.js
2
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
3
+
4
+ // ../eslint-plugin/dist/constants.js
5
+ var RULE_NAME = "require-signal-on-mutation";
6
+ var MessageId = {
7
+ MUTATION_WITHOUT_SIGNAL: "mutationWithoutSignal"
8
+ };
9
+ var MUTATION_WITHOUT_SIGNAL_MESSAGE = "store mutation without a mapped Reticle signal";
10
+ var DEFAULT_SIGNAL_CALLEES = ["reticleSignal", "signal"];
11
+ var DEFAULT_MUTATORS = [];
12
+ var PLUGIN_NAME = "reticle";
13
+ var DOCS_URL_ROOT = "https://github.com/reticlehq/reticle/blob/main/packages/eslint-plugin/README.md";
14
+
15
+ // ../eslint-plugin/dist/options.js
16
+ var OPTIONS_SCHEMA = [
17
+ {
18
+ type: "object",
19
+ properties: {
20
+ mutators: {
21
+ type: "array",
22
+ items: { type: "string" }
23
+ },
24
+ signalCallee: {
25
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
26
+ }
27
+ },
28
+ additionalProperties: false
29
+ }
30
+ ];
31
+ function toNonEmptySet(values) {
32
+ return new Set(values.filter((v) => v.length > 0));
33
+ }
34
+ function normalizeOptions(raw) {
35
+ const mutatorList = raw?.mutators ?? DEFAULT_MUTATORS;
36
+ const rawSignal = raw?.signalCallee;
37
+ let signalList;
38
+ if (rawSignal === void 0) {
39
+ signalList = DEFAULT_SIGNAL_CALLEES;
40
+ } else if (typeof rawSignal === "string") {
41
+ signalList = [rawSignal];
42
+ } else {
43
+ signalList = rawSignal;
44
+ }
45
+ return {
46
+ mutators: toNonEmptySet(mutatorList),
47
+ signalCallees: toNonEmptySet(signalList)
48
+ };
49
+ }
50
+
51
+ // ../eslint-plugin/dist/require-signal-on-mutation.js
52
+ var createRule = ESLintUtils.RuleCreator((name) => `${DOCS_URL_ROOT}#${name}`);
53
+ function calleeName(node) {
54
+ const callee = node.callee;
55
+ if (callee.type === AST_NODE_TYPES.Identifier) {
56
+ return callee.name;
57
+ }
58
+ if (callee.type === AST_NODE_TYPES.MemberExpression && callee.computed === false && callee.property.type === AST_NODE_TYPES.Identifier) {
59
+ return callee.property.name;
60
+ }
61
+ return null;
62
+ }
63
+ var requireSignalOnMutation = createRule({
64
+ name: "require-signal-on-mutation",
65
+ meta: {
66
+ type: "problem",
67
+ docs: {
68
+ description: "Require an Reticle signal alongside any user-visible store mutation so the signal layer cannot drift."
69
+ },
70
+ schema: OPTIONS_SCHEMA,
71
+ messages: {
72
+ [MessageId.MUTATION_WITHOUT_SIGNAL]: MUTATION_WITHOUT_SIGNAL_MESSAGE
73
+ }
74
+ },
75
+ defaultOptions: [{}],
76
+ create(context) {
77
+ const { mutators, signalCallees } = normalizeOptions(context.options[0]);
78
+ const stack = [];
79
+ function enterFn() {
80
+ stack.push({ calledSignal: false, mutatorNode: null });
81
+ }
82
+ function exitFn() {
83
+ const frame = stack.pop();
84
+ if (frame === void 0)
85
+ return;
86
+ if (frame.mutatorNode !== null && frame.calledSignal === false) {
87
+ context.report({
88
+ node: frame.mutatorNode,
89
+ messageId: MessageId.MUTATION_WITHOUT_SIGNAL
90
+ });
91
+ }
92
+ }
93
+ return {
94
+ FunctionDeclaration: enterFn,
95
+ "FunctionDeclaration:exit": exitFn,
96
+ FunctionExpression: enterFn,
97
+ "FunctionExpression:exit": exitFn,
98
+ ArrowFunctionExpression: enterFn,
99
+ "ArrowFunctionExpression:exit": exitFn,
100
+ CallExpression(node) {
101
+ const frame = stack.at(-1);
102
+ if (frame === void 0)
103
+ return;
104
+ const name = calleeName(node);
105
+ if (name === null)
106
+ return;
107
+ if (mutators.has(name) && frame.mutatorNode === null) {
108
+ frame.mutatorNode = node;
109
+ }
110
+ if (signalCallees.has(name)) {
111
+ frame.calledSignal = true;
112
+ }
113
+ }
114
+ };
115
+ }
116
+ });
117
+
118
+ // ../eslint-plugin/dist/index.js
119
+ var rules = { [RULE_NAME]: requireSignalOnMutation };
120
+ var plugin = {
121
+ meta: { name: PLUGIN_NAME },
122
+ rules,
123
+ configs: {}
124
+ };
125
+ plugin.configs.recommended = {
126
+ plugins: { [PLUGIN_NAME]: plugin },
127
+ rules: { [`${PLUGIN_NAME}/${RULE_NAME}`]: "warn" }
128
+ };
129
+ var dist_default = plugin;
130
+ export {
131
+ dist_default as default,
132
+ requireSignalOnMutation,
133
+ rules
134
+ };
@@ -0,0 +1,2 @@
1
+ export * from '@reticlehq/browser';
2
+ export { hasHoverHandlers, identify, install, installRenderMeter, readState } from '@reticlehq/react';