@redmix/eslint-plugin 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Redmix
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.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # ESLint Plugin
2
+
3
+ Custom ESLint plugins used for standalone RedwoodJS ESLint lint rules.
4
+ These rules are ment to be consumed via the larger
5
+ [`@redwoodjs/eslint-config`](https://github.com/redwoodjs/redwood/tree/main/packages/eslint-config).
6
+
7
+ ## Contributing
8
+
9
+ This package doesn't depend on other Redwood Framework packages.
10
+ To contribute, you should be familiar with the ESLint package.
11
+ Keep in mind that any rules added should not conflict with code formatting
12
+ tools (e.g.
13
+ [Prettier](https://prettier.io/docs/en/integrating-with-linters.html)).
@@ -0,0 +1,23 @@
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const meta: {
3
+ name: string;
4
+ version: any;
5
+ };
6
+ export declare const rules: {
7
+ 'process-env-computed': ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
8
+ 'service-type-annotations': ESLintUtils.RuleModule<"needsType", [], unknown, ESLintUtils.RuleListener>;
9
+ 'unsupported-route-components': ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
10
+ };
11
+ declare const plugin: {
12
+ meta: {
13
+ name: string;
14
+ version: any;
15
+ };
16
+ rules: {
17
+ 'process-env-computed': ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
18
+ 'service-type-annotations': ESLintUtils.RuleModule<"needsType", [], unknown, ESLintUtils.RuleListener>;
19
+ 'unsupported-route-components': ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
20
+ };
21
+ };
22
+ export default plugin;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAM3D,eAAO,MAAM,IAAI;;;CAGhB,CAAA;AAED,eAAO,MAAM,KAAK;;;;CAIwC,CAAA;AAE1D,QAAA,MAAM,MAAM;;;;;;;;;;CAAkB,CAAA;AAE9B,eAAe,MAAM,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ default: () => index_default,
22
+ meta: () => meta,
23
+ rules: () => rules
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_process_env_computed = require("./process-env-computed.js");
27
+ var import_service_type_annotations = require("./service-type-annotations.js");
28
+ var import_unsupported_route_components = require("./unsupported-route-components.js");
29
+ const meta = {
30
+ name: "@redmix/eslint-plugin",
31
+ version: require("../package.json").version
32
+ };
33
+ const rules = {
34
+ "process-env-computed": import_process_env_computed.processEnvComputedRule,
35
+ "service-type-annotations": import_service_type_annotations.serviceTypeAnnotations,
36
+ "unsupported-route-components": import_unsupported_route_components.unsupportedRouteComponents
37
+ };
38
+ const plugin = { meta, rules };
39
+ var index_default = plugin;
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ meta,
43
+ rules
44
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const processEnvComputedRule: ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=process-env-computed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-env-computed.d.ts","sourceRoot":"","sources":["../src/process-env-computed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAA;AAoCtE,eAAO,MAAM,sBAAsB,6EA8BjC,CAAA"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var process_env_computed_exports = {};
20
+ __export(process_env_computed_exports, {
21
+ processEnvComputedRule: () => processEnvComputedRule
22
+ });
23
+ module.exports = __toCommonJS(process_env_computed_exports);
24
+ var import_utils = require("@typescript-eslint/utils");
25
+ const createRule = import_utils.ESLintUtils.RuleCreator.withoutDocs;
26
+ function isProcessEnv(node) {
27
+ return node.type === import_utils.AST_NODE_TYPES.MemberExpression && hasName(node.object, "process") && hasName(node.property, "env");
28
+ }
29
+ function hasName(node, name) {
30
+ return node.type === import_utils.AST_NODE_TYPES.Identifier && node.name === name;
31
+ }
32
+ function isTestFile(filename) {
33
+ return filename.endsWith(".test.ts") || filename.endsWith(".test.js") || filename.endsWith(".test.tsx") || filename.endsWith(".test.jsx") || filename.endsWith(".test.mts") || filename.endsWith(".test.mjs") || filename.endsWith(".test.cjs") || filename.endsWith(".spec.ts") || filename.endsWith(".spec.js") || filename.endsWith(".spec.tsx") || filename.endsWith(".spec.jsx") || filename.endsWith(".spec.mts") || filename.endsWith(".spec.mjs") || filename.endsWith(".spec.cjs") || filename.includes("/__tests__/");
34
+ }
35
+ const processEnvComputedRule = createRule({
36
+ meta: {
37
+ type: "problem",
38
+ docs: {
39
+ description: "Find computed member access on process.env"
40
+ },
41
+ messages: {
42
+ unexpected: "Accessing process.env via array syntax will break in production. Use dot notation e.g. process.env.MY_ENV_VAR instead"
43
+ },
44
+ schema: []
45
+ // No additional configuration needed
46
+ },
47
+ defaultOptions: [],
48
+ create(context) {
49
+ return {
50
+ MemberExpression: function(node) {
51
+ const matches = isProcessEnv(node.object) && node.computed && !isTestFile(context.filename);
52
+ if (matches) {
53
+ context.report({
54
+ messageId: "unexpected",
55
+ node
56
+ });
57
+ }
58
+ }
59
+ };
60
+ }
61
+ });
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ processEnvComputedRule
65
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const serviceTypeAnnotations: ESLintUtils.RuleModule<"needsType", [], unknown, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=service-type-annotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-type-annotations.d.ts","sourceRoot":"","sources":["../src/service-type-annotations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAkB,MAAM,0BAA0B,CAAA;AAOtE,eAAO,MAAM,sBAAsB,4EA0JjC,CAAA"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var service_type_annotations_exports = {};
20
+ __export(service_type_annotations_exports, {
21
+ serviceTypeAnnotations: () => serviceTypeAnnotations
22
+ });
23
+ module.exports = __toCommonJS(service_type_annotations_exports);
24
+ var import_node_path = require("node:path");
25
+ var import_utils = require("@typescript-eslint/utils");
26
+ const createRule = import_utils.ESLintUtils.RuleCreator.withoutDocs;
27
+ const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
28
+ const serviceTypeAnnotations = createRule({
29
+ meta: {
30
+ docs: {
31
+ description: "Sets the types on a query/mutation resolver function to the correct type"
32
+ },
33
+ messages: {
34
+ needsType: "The query/mutation function ({{name}}) needs a type annotation of {{typeName}}."
35
+ },
36
+ fixable: "code",
37
+ type: "suggestion",
38
+ schema: []
39
+ },
40
+ defaultOptions: [],
41
+ create(context) {
42
+ const thisFilename = (0, import_node_path.basename)(context.filename);
43
+ const sansTS = thisFilename.replace(".ts", "");
44
+ const thisFileCorrespondingImport = `types/${sansTS}`;
45
+ let importForThisFile = null;
46
+ return {
47
+ // Make sure we have a reference to the import for the relative file
48
+ // which includes definitions for this service
49
+ ImportDeclaration(node) {
50
+ importForThisFile ||= node.source.value === thisFileCorrespondingImport ? node : null;
51
+ },
52
+ // Then start looking at every exported fn/const
53
+ ExportNamedDeclaration(node) {
54
+ if (!node.declaration || node.declaration.type !== import_utils.AST_NODE_TYPES.VariableDeclaration) {
55
+ return;
56
+ }
57
+ node.declaration.declarations.forEach((vd) => {
58
+ if (vd.type === import_utils.AST_NODE_TYPES.VariableDeclarator && vd.id.type === import_utils.AST_NODE_TYPES.Identifier) {
59
+ if (vd.id.name.startsWith("_")) {
60
+ return;
61
+ }
62
+ const isGlobalOrMutationResolver = /^[a-z]/.test(vd.id.name);
63
+ const suffix = isGlobalOrMutationResolver ? "Resolver" : "TypeResolvers";
64
+ const typeName = capitalizeFirstLetter(vd.id.name) + suffix;
65
+ if (isGlobalOrMutationResolver && vd.init?.type !== import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
66
+ return;
67
+ }
68
+ const tsID = vd.id;
69
+ if (!tsID.typeAnnotation) {
70
+ context.report({
71
+ messageId: "needsType",
72
+ node: vd.id,
73
+ data: {
74
+ name: vd.id.name,
75
+ typeName
76
+ },
77
+ *fix(fixer) {
78
+ yield fixer.insertTextAfter(vd.id, `: ${typeName}`);
79
+ if (!importForThisFile) {
80
+ yield fixer.insertTextBeforeRange(
81
+ [0, 0],
82
+ `import type { ${typeName} } from "${thisFileCorrespondingImport}"
83
+ `
84
+ );
85
+ } else {
86
+ const lastImportSpecifier = importForThisFile.specifiers[importForThisFile.specifiers.length - 1];
87
+ yield fixer.insertTextAfter(
88
+ lastImportSpecifier,
89
+ `, ${typeName}`
90
+ );
91
+ }
92
+ }
93
+ });
94
+ return;
95
+ }
96
+ if (tsID.typeAnnotation.typeAnnotation) {
97
+ const type = tsID.typeAnnotation.typeAnnotation;
98
+ if (!("typeName" in type)) {
99
+ return;
100
+ }
101
+ const isCorrectType = type.typeName?.type === import_utils.AST_NODE_TYPES.Identifier && type.typeName?.name === typeName;
102
+ if (isCorrectType) {
103
+ return;
104
+ }
105
+ context.report({
106
+ messageId: "needsType",
107
+ node: vd.id,
108
+ data: {
109
+ name: vd.id.name,
110
+ typeName
111
+ },
112
+ *fix(fixer) {
113
+ yield fixer.removeRange([type.range[0] - 2, type.range[1]]);
114
+ yield fixer.insertTextAfter(vd.id, `: ${typeName}`);
115
+ if (!importForThisFile) {
116
+ yield fixer.insertTextBeforeRange(
117
+ [0, 0],
118
+ `import type { ${typeName} } from "${thisFileCorrespondingImport}"
119
+ `
120
+ );
121
+ } else {
122
+ const lastImportSpecifier = importForThisFile.specifiers[importForThisFile.specifiers.length - 1];
123
+ yield fixer.insertTextAfter(
124
+ lastImportSpecifier,
125
+ `, ${typeName}`
126
+ );
127
+ }
128
+ }
129
+ });
130
+ }
131
+ }
132
+ });
133
+ }
134
+ };
135
+ }
136
+ });
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ serviceTypeAnnotations
140
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const unsupportedRouteComponents: ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=unsupported-route-components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsupported-route-components.d.ts","sourceRoot":"","sources":["../src/unsupported-route-components.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAiCtE,eAAO,MAAM,0BAA0B,6EA8CrC,CAAA"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var unsupported_route_components_exports = {};
20
+ __export(unsupported_route_components_exports, {
21
+ unsupportedRouteComponents: () => unsupportedRouteComponents
22
+ });
23
+ module.exports = __toCommonJS(unsupported_route_components_exports);
24
+ var import_utils = require("@typescript-eslint/utils");
25
+ const createRule = import_utils.ESLintUtils.RuleCreator.withoutDocs;
26
+ function isAllowedElement(name) {
27
+ const allowedElements = ["Router", "Route", "Set", "PrivateSet", "Private"];
28
+ return allowedElements.includes(name);
29
+ }
30
+ function checkNodes(nodesToCheck, context) {
31
+ if (nodesToCheck.type === import_utils.AST_NODE_TYPES.JSXElement) {
32
+ const name = nodesToCheck.openingElement.name.type === import_utils.AST_NODE_TYPES.JSXIdentifier ? nodesToCheck.openingElement.name.name : null;
33
+ if (name && !isAllowedElement(name)) {
34
+ context.report({
35
+ node: nodesToCheck,
36
+ messageId: "unexpected",
37
+ data: { name }
38
+ });
39
+ }
40
+ if (nodesToCheck.children) {
41
+ nodesToCheck.children.forEach((node) => checkNodes(node, context));
42
+ }
43
+ }
44
+ }
45
+ const unsupportedRouteComponents = createRule({
46
+ meta: {
47
+ type: "problem",
48
+ docs: {
49
+ description: "Find unsupported route components"
50
+ },
51
+ messages: {
52
+ unexpected: "Unexpected JSX element <{{name}}>. Only <Router>, <Route>, <Set>, <PrivateSet> and <Private> are allowed in the Routes component."
53
+ },
54
+ schema: []
55
+ },
56
+ defaultOptions: [],
57
+ create(context) {
58
+ return {
59
+ VariableDeclaration(node) {
60
+ if (isRoutesRenderBlock(node.declarations[0])) {
61
+ const routesDeclaration = node.declarations[0].init;
62
+ if (routesDeclaration?.type === import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
63
+ if (routesDeclaration.body.type === import_utils.AST_NODE_TYPES.JSXElement) {
64
+ checkNodes(routesDeclaration.body, context);
65
+ } else if (routesDeclaration.body.type === import_utils.AST_NODE_TYPES.BlockStatement) {
66
+ if (routesDeclaration.body.body[0].type === import_utils.AST_NODE_TYPES.ReturnStatement && routesDeclaration.body.body[0].argument?.type === import_utils.AST_NODE_TYPES.JSXElement) {
67
+ const routesReturnStatement = routesDeclaration.body.body[0].argument;
68
+ checkNodes(routesReturnStatement, context);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ };
75
+ }
76
+ });
77
+ function isRoutesRenderBlock(node) {
78
+ return node?.type === import_utils.AST_NODE_TYPES.VariableDeclarator && node?.id.type === import_utils.AST_NODE_TYPES.Identifier && node?.id.name === "Routes";
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ unsupportedRouteComponents
83
+ });
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@redmix/eslint-plugin",
3
+ "version": "0.0.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/redmix-run/redmix.git",
7
+ "directory": "packages/eslint-plugin"
8
+ },
9
+ "license": "MIT",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsx ./build.mts && yarn build:types",
17
+ "build:pack": "yarn pack -o redmix-eslint-plugin.tgz",
18
+ "build:types": "tsc --build --verbose",
19
+ "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
20
+ "prepublishOnly": "NODE_ENV=production yarn build",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest watch"
23
+ },
24
+ "dependencies": {
25
+ "@typescript-eslint/utils": "8.19.1",
26
+ "eslint": "8.57.1"
27
+ },
28
+ "devDependencies": {
29
+ "@redmix/framework-tools": "0.0.1",
30
+ "@types/eslint": "8.56.12",
31
+ "@types/estree": "1.0.6",
32
+ "@typescript-eslint/parser": "8.19.1",
33
+ "@typescript-eslint/rule-tester": "8.19.1",
34
+ "tsx": "4.19.3",
35
+ "typescript": "5.6.2",
36
+ "vitest": "2.1.9"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "gitHead": "688027c97502c500ebbede9cdc7cc51545a8dcf3"
42
+ }