@barnum/eslint-plugin 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robert Balicki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ declare const plugin: {
2
+ rules: {
3
+ "exported-handler": import("eslint").Rule.RuleModule;
4
+ };
5
+ };
6
+ export default plugin;
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import exportedHandler from "./rules/exported-handler.js";
2
+ const plugin = {
3
+ rules: {
4
+ "exported-handler": exportedHandler,
5
+ },
6
+ };
7
+ export default plugin;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from "eslint";
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,147 @@
1
+ const HANDLER_FACTORIES = new Set([
2
+ "createHandler",
3
+ "createHandlerWithConfig",
4
+ ]);
5
+ const rule = {
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Require createHandler/createHandlerWithConfig calls to be exported with a name matching the exportName argument",
10
+ },
11
+ messages: {
12
+ unexported: "createHandler/createHandlerWithConfig must be exported. The runtime resolves handlers by module path + export name.",
13
+ nameMismatch: "Export name '{{ exportName }}' does not match the exportName argument '{{ argName }}'. The runtime uses the exportName argument to locate the handler at {{ module }}:{{ argName }}.",
14
+ defaultMissingArg: "Default exports should omit the exportName argument or pass 'default'. Got '{{ argName }}'.",
15
+ moduleExports: "module.exports assignment is not supported. Use ES module export syntax.",
16
+ },
17
+ schema: [],
18
+ },
19
+ create(context) {
20
+ function getCalleeHandlerName(node) {
21
+ if (node.type === "CallExpression" &&
22
+ node.callee?.type === "Identifier" &&
23
+ node.callee.name &&
24
+ HANDLER_FACTORIES.has(node.callee.name)) {
25
+ return node.callee.name;
26
+ }
27
+ return undefined;
28
+ }
29
+ function getExportNameArg(node) {
30
+ // Second argument is the exportName string
31
+ const arg = node.arguments[1];
32
+ if (!arg)
33
+ return null;
34
+ if (arg.type === "Literal" && typeof arg.value === "string") {
35
+ return arg.value;
36
+ }
37
+ // Non-string-literal second arg — can't statically verify
38
+ return null;
39
+ }
40
+ return {
41
+ // Catch module.exports.foo = createHandler(...)
42
+ AssignmentExpression(node) {
43
+ if (node.right.type === "CallExpression" &&
44
+ getCalleeHandlerName(node.right)) {
45
+ if (node.left.type === "MemberExpression" &&
46
+ node.left.object.type === "MemberExpression" &&
47
+ node.left.object.object.type === "Identifier" &&
48
+ node.left.object.object.name === "module" &&
49
+ node.left.object.property.type === "Identifier" &&
50
+ node.left.object.property.name === "exports") {
51
+ context.report({ node, messageId: "moduleExports" });
52
+ return;
53
+ }
54
+ if (node.left.type === "MemberExpression" &&
55
+ node.left.object.type === "Identifier" &&
56
+ node.left.object.name === "exports") {
57
+ context.report({ node, messageId: "moduleExports" });
58
+ return;
59
+ }
60
+ }
61
+ },
62
+ // Catch all CallExpressions to createHandler/createHandlerWithConfig
63
+ CallExpression(node) {
64
+ if (!getCalleeHandlerName(node))
65
+ return;
66
+ // Walk up to find if this is in an export context
67
+ const parent = node.parent;
68
+ if (!parent) {
69
+ context.report({ node, messageId: "unexported" });
70
+ return;
71
+ }
72
+ // Already reported by AssignmentExpression handler
73
+ if (parent.type === "AssignmentExpression") {
74
+ return;
75
+ }
76
+ // Case 1: export default createHandler(...)
77
+ if (parent.type === "ExportDefaultDeclaration") {
78
+ const argName = getExportNameArg(node);
79
+ if (argName !== null && argName !== "default") {
80
+ context.report({
81
+ node,
82
+ messageId: "defaultMissingArg",
83
+ data: { argName },
84
+ });
85
+ }
86
+ return;
87
+ }
88
+ // Case 2: export const foo = createHandler({...}, "foo")
89
+ // The CallExpression is inside a VariableDeclarator
90
+ if (parent.type === "VariableDeclarator") {
91
+ const declaration = parent.parent;
92
+ if (!declaration || declaration.type !== "VariableDeclaration") {
93
+ context.report({ node, messageId: "unexported" });
94
+ return;
95
+ }
96
+ const exportNode = declaration.parent;
97
+ if (!exportNode ||
98
+ exportNode.type !== "ExportNamedDeclaration") {
99
+ context.report({ node, messageId: "unexported" });
100
+ return;
101
+ }
102
+ // It's exported — now check name match
103
+ if (parent.id.type !== "Identifier") {
104
+ // Destructuring pattern — weird but report
105
+ context.report({ node, messageId: "unexported" });
106
+ return;
107
+ }
108
+ const exportName = parent.id.name;
109
+ const argName = getExportNameArg(node);
110
+ // If no second arg, the runtime uses "default" — that won't match
111
+ // a named export unless the export is literally named "default"
112
+ if (argName === null && node.arguments.length < 2) {
113
+ // No exportName arg provided — runtime defaults to "default"
114
+ // but this is a named export, so it won't resolve
115
+ if (exportName !== "default") {
116
+ context.report({
117
+ node,
118
+ messageId: "nameMismatch",
119
+ data: {
120
+ exportName,
121
+ argName: "default",
122
+ module: "<this file>",
123
+ },
124
+ });
125
+ }
126
+ return;
127
+ }
128
+ if (argName !== null && argName !== exportName) {
129
+ context.report({
130
+ node,
131
+ messageId: "nameMismatch",
132
+ data: {
133
+ exportName,
134
+ argName,
135
+ module: "<this file>",
136
+ },
137
+ });
138
+ }
139
+ return;
140
+ }
141
+ // Any other position — not exported
142
+ context.report({ node, messageId: "unexported" });
143
+ },
144
+ };
145
+ },
146
+ };
147
+ export default rule;
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@barnum/eslint-plugin",
3
+ "version": "0.1.0",
4
+ "description": "ESLint rules for Barnum workflows",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "peerDependencies": {
15
+ "eslint": ">=9.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^25.5.0",
19
+ "eslint": "^9.27.0",
20
+ "typescript": "^6.0.3",
21
+ "vitest": "^3.0.0"
22
+ },
23
+ "files": [
24
+ "dist/**/*"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.build.json",
28
+ "test": "vitest run",
29
+ "typecheck": "tsc --noEmit"
30
+ }
31
+ }