eslint-plugin-function 0.0.23 → 0.0.25

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +5 -16
  2. package/dist/index.js +156 -155
  3. package/package.json +20 -20
package/dist/index.d.ts CHANGED
@@ -1,17 +1,6 @@
1
- import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
1
+ import { CompatiblePlugin } from "@eslint-react/kit";
2
2
 
3
- declare const _default: {
4
- readonly meta: {
5
- readonly name: string;
6
- readonly version: string;
7
- };
8
- readonly rules: {
9
- readonly "function-definition": _typescript_eslint_utils_ts_eslint.RuleModule<"functionDefinition", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
10
- readonly "function-name": _typescript_eslint_utils_ts_eslint.RuleModule<"functionName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
11
- readonly "function-return-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"functionReturnBoolean", readonly [{
12
- readonly pattern?: string;
13
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
14
- };
15
- };
16
-
17
- export { _default as default };
3
+ //#region src/index.d.ts
4
+ declare const plugin: CompatiblePlugin;
5
+ //#endregion
6
+ export { plugin as default };
package/dist/index.js CHANGED
@@ -1,174 +1,175 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- import * as AST from '@eslint-react/ast';
3
- import * as ER from '@eslint-react/core';
4
- import '@eslint-react/eff';
5
- import { RegExp } from '@eslint-react/kit';
6
- import { getConstrainedTypeAtLocation } from '@typescript-eslint/type-utils';
7
- import { AST_NODE_TYPES } from '@typescript-eslint/types';
8
- import { unionConstituents } from 'ts-api-utils';
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ import * as AST from "@eslint-react/ast";
3
+ import * as ER from "@eslint-react/core";
4
+ import "@eslint-react/eff";
5
+ import { RegExp } from "@eslint-react/kit";
6
+ import { getConstrainedTypeAtLocation } from "@typescript-eslint/type-utils";
7
+ import { AST_NODE_TYPES } from "@typescript-eslint/types";
8
+ import { unionConstituents } from "ts-api-utils";
9
9
 
10
- // package.json
10
+ //#region package.json
11
11
  var name = "eslint-plugin-function";
12
- var version = "0.0.23";
12
+ var version = "0.0.25";
13
+
14
+ //#endregion
15
+ //#region src/utils/create-rule.ts
13
16
  function getDocsUrl() {
14
- return "TODO: add docs for local ESLint rules";
17
+ return "TODO: add docs for local ESLint rules";
15
18
  }
16
- var createRule = ESLintUtils.RuleCreator(getDocsUrl);
19
+ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
17
20
 
18
- // src/rules/function-definition.ts
19
- var RULE_NAME = "function-definition";
20
- var RULE_FEATURES = [];
21
+ //#endregion
22
+ //#region src/rules/function-definition.ts
23
+ const RULE_NAME$2 = "function-definition";
24
+ const RULE_FEATURES$2 = [];
21
25
  var function_definition_default = createRule({
22
- meta: {
23
- type: "problem",
24
- docs: {
25
- description: "Enforce a consistent function definition style.",
26
- [Symbol.for("rule_features")]: RULE_FEATURES
27
- },
28
- messages: {
29
- functionDefinition: ""
30
- },
31
- schema: []
32
- },
33
- name: RULE_NAME,
34
- create,
35
- defaultOptions: []
26
+ meta: {
27
+ type: "problem",
28
+ docs: {
29
+ description: "Enforce a consistent function definition style.",
30
+ [Symbol.for("rule_features")]: RULE_FEATURES$2
31
+ },
32
+ messages: { functionDefinition: "" },
33
+ schema: []
34
+ },
35
+ name: RULE_NAME$2,
36
+ create: create$2,
37
+ defaultOptions: []
36
38
  });
37
- function create(context) {
38
- return {};
39
+ function create$2(context) {
40
+ return {};
39
41
  }
40
42
 
41
- // src/rules/function-name.ts
42
- var RULE_NAME2 = "function-name";
43
- var RULE_FEATURES2 = [];
43
+ //#endregion
44
+ //#region src/rules/function-name.ts
45
+ const RULE_NAME$1 = "function-name";
46
+ const RULE_FEATURES$1 = [];
44
47
  var function_name_default = createRule({
45
- meta: {
46
- type: "problem",
47
- docs: {
48
- description: "Enforce a consistent function naming style.",
49
- [Symbol.for("rule_features")]: RULE_FEATURES2
50
- },
51
- messages: {
52
- functionName: ""
53
- },
54
- schema: []
55
- },
56
- name: RULE_NAME2,
57
- create: create2,
58
- defaultOptions: []
48
+ meta: {
49
+ type: "problem",
50
+ docs: {
51
+ description: "Enforce a consistent function naming style.",
52
+ [Symbol.for("rule_features")]: RULE_FEATURES$1
53
+ },
54
+ messages: { functionName: "" },
55
+ schema: []
56
+ },
57
+ name: RULE_NAME$1,
58
+ create: create$1,
59
+ defaultOptions: []
59
60
  });
60
- function create2(context) {
61
- return {};
61
+ function create$1(context) {
62
+ return {};
62
63
  }
63
- var RULE_NAME3 = "function-return-boolean";
64
- var RULE_FEATURES3 = [];
65
- var defaultPattern = "/^(is|has|should)/u";
66
- var defaultOptions = [
67
- {
68
- pattern: defaultPattern
69
- }
70
- ];
71
- var allowedVariants = [
72
- "never",
73
- "boolean",
74
- "falsy boolean",
75
- "truthy boolean"
64
+
65
+ //#endregion
66
+ //#region src/rules/function-return-boolean.ts
67
+ const RULE_NAME = "function-return-boolean";
68
+ const RULE_FEATURES = [];
69
+ const defaultPattern = "/^(is|has|should)/u";
70
+ const defaultOptions = [{ pattern: defaultPattern }];
71
+ const allowedVariants = [
72
+ "never",
73
+ "boolean",
74
+ "falsy boolean",
75
+ "truthy boolean"
76
76
  ];
77
77
  var function_return_boolean_default = createRule({
78
- meta: {
79
- type: "problem",
80
- docs: {
81
- description: `Enforce functions that match the pattern \`${defaultPattern}\` return a boolean.`,
82
- [Symbol.for("rule_features")]: RULE_FEATURES3
83
- },
84
- messages: {
85
- functionReturnBoolean: "The function '{{functionName}}' should return a boolean value (got {{variants}})."
86
- },
87
- schema: [{
88
- type: "object",
89
- additionalProperties: false,
90
- properties: {
91
- pattern: {
92
- type: "string",
93
- description: "The pattern to match function names against."
94
- }
95
- }
96
- }]
97
- },
98
- name: RULE_NAME3,
99
- create: create3,
100
- defaultOptions
78
+ meta: {
79
+ type: "problem",
80
+ docs: {
81
+ description: `Enforce functions that match the pattern \`${defaultPattern}\` return a boolean.`,
82
+ [Symbol.for("rule_features")]: RULE_FEATURES
83
+ },
84
+ messages: { functionReturnBoolean: "The function '{{functionName}}' should return a boolean value (got {{variants}})." },
85
+ schema: [{
86
+ type: "object",
87
+ additionalProperties: false,
88
+ properties: { pattern: {
89
+ type: "string",
90
+ description: "The pattern to match function names against."
91
+ } }
92
+ }]
93
+ },
94
+ name: RULE_NAME,
95
+ create,
96
+ defaultOptions
101
97
  });
102
- function create3(context, [opts]) {
103
- const services = ESLintUtils.getParserServices(context, false);
104
- const pattern = RegExp.toRegExp(opts?.pattern ?? defaultPattern);
105
- const functionEntries = [];
106
- function handleReturnExpression(context2, returnExpression, onViolation) {
107
- if (returnExpression == null) {
108
- onViolation(returnExpression, { variants: "nullish" });
109
- return;
110
- }
111
- const returnType = getConstrainedTypeAtLocation(services, returnExpression);
112
- const parts = [...ER.getTypeVariants(unionConstituents(returnType))];
113
- if (parts.every((part) => allowedVariants.some((allowed) => part === allowed))) return;
114
- onViolation(returnExpression, {
115
- variants: [...parts].map((part) => `'${part}'`).join(", ")
116
- });
117
- }
118
- return {
119
- [":function"](node) {
120
- const functionName = AST.getFunctionId(node)?.name;
121
- const isMatched = functionName != null && pattern.test(functionName);
122
- functionEntries.push({ functionName, functionNode: node, isMatched });
123
- },
124
- [":function:exit"]() {
125
- functionEntries.pop();
126
- },
127
- ["ArrowFunctionExpression"](node) {
128
- const { functionName, isMatched = false } = functionEntries.at(-1) ?? {};
129
- if (functionName == null || !isMatched) return;
130
- if (node.body.type === AST_NODE_TYPES.BlockStatement) return;
131
- handleReturnExpression(context, node.body, (expr, data) => {
132
- context.report({
133
- messageId: "functionReturnBoolean",
134
- node: expr ?? node,
135
- data: {
136
- ...data,
137
- functionName
138
- }
139
- });
140
- });
141
- },
142
- ["ReturnStatement"](node) {
143
- const { functionName, functionNode, isMatched = false } = functionEntries.at(-1) ?? {};
144
- if (functionName == null || functionNode == null || !isMatched) return;
145
- handleReturnExpression(context, node.argument, (expr, data) => {
146
- const functionName2 = AST.getFunctionId(functionNode)?.name;
147
- if (functionName2 == null) return;
148
- context.report({
149
- messageId: "functionReturnBoolean",
150
- node: expr ?? node.argument ?? node,
151
- data: {
152
- ...data,
153
- functionName: functionName2
154
- }
155
- });
156
- });
157
- }
158
- };
98
+ function create(context, [opts]) {
99
+ const services = ESLintUtils.getParserServices(context, false);
100
+ const pattern = RegExp.toRegExp(opts?.pattern ?? defaultPattern);
101
+ const functionEntries = [];
102
+ function handleReturnExpression(context$1, returnExpression, onViolation) {
103
+ if (returnExpression == null) {
104
+ onViolation(returnExpression, { variants: "nullish" });
105
+ return;
106
+ }
107
+ const returnType = getConstrainedTypeAtLocation(services, returnExpression);
108
+ const parts = [...ER.getTypeVariants(unionConstituents(returnType))];
109
+ if (parts.every((part) => allowedVariants.some((allowed) => part === allowed))) return;
110
+ onViolation(returnExpression, { variants: [...parts].map((part) => `'${part}'`).join(", ") });
111
+ }
112
+ return {
113
+ [":function"](node) {
114
+ const functionName = AST.getFunctionId(node)?.name;
115
+ const isMatched = functionName != null && pattern.test(functionName);
116
+ functionEntries.push({
117
+ functionName,
118
+ functionNode: node,
119
+ isMatched
120
+ });
121
+ },
122
+ [":function:exit"]() {
123
+ functionEntries.pop();
124
+ },
125
+ ["ArrowFunctionExpression"](node) {
126
+ const { functionName, isMatched = false } = functionEntries.at(-1) ?? {};
127
+ if (functionName == null || !isMatched) return;
128
+ if (node.body.type === AST_NODE_TYPES.BlockStatement) return;
129
+ handleReturnExpression(context, node.body, (expr, data) => {
130
+ context.report({
131
+ messageId: "functionReturnBoolean",
132
+ node: expr ?? node,
133
+ data: {
134
+ ...data,
135
+ functionName
136
+ }
137
+ });
138
+ });
139
+ },
140
+ ["ReturnStatement"](node) {
141
+ const { functionName, functionNode, isMatched = false } = functionEntries.at(-1) ?? {};
142
+ if (functionName == null || functionNode == null || !isMatched) return;
143
+ handleReturnExpression(context, node.argument, (expr, data) => {
144
+ const functionName$1 = AST.getFunctionId(functionNode)?.name;
145
+ if (functionName$1 == null) return;
146
+ context.report({
147
+ messageId: "functionReturnBoolean",
148
+ node: expr ?? node.argument ?? node,
149
+ data: {
150
+ ...data,
151
+ functionName: functionName$1
152
+ }
153
+ });
154
+ });
155
+ }
156
+ };
159
157
  }
160
158
 
161
- // src/index.ts
162
- var index_default = {
163
- meta: {
164
- name,
165
- version
166
- },
167
- rules: {
168
- "function-definition": function_definition_default,
169
- "function-name": function_name_default,
170
- "function-return-boolean": function_return_boolean_default
171
- }
159
+ //#endregion
160
+ //#region src/index.ts
161
+ const plugin = {
162
+ meta: {
163
+ name,
164
+ version
165
+ },
166
+ rules: {
167
+ "function-definition": function_definition_default,
168
+ "function-name": function_name_default,
169
+ "function-return-boolean": function_return_boolean_default
170
+ }
172
171
  };
172
+ var src_default = plugin;
173
173
 
174
- export { index_default as default };
174
+ //#endregion
175
+ export { src_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-function",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "private": false,
5
5
  "description": "(WIP) The ESLint plugin for function-related rules.",
6
6
  "license": "MIT",
@@ -18,45 +18,45 @@
18
18
  "package.json"
19
19
  ],
20
20
  "dependencies": {
21
- "@eslint-react/ast": "^2.0.0-beta.34",
22
- "@eslint-react/core": "^2.0.0-beta.34",
23
- "@eslint-react/eff": "^2.0.0-beta.34",
24
- "@eslint-react/kit": "^2.0.0-beta.34",
25
- "@typescript-eslint/scope-manager": "^8.40.0",
26
- "@typescript-eslint/type-utils": "^8.40.0",
27
- "@typescript-eslint/types": "^8.40.0",
28
- "@typescript-eslint/utils": "^8.40.0",
21
+ "@eslint-react/ast": "^2.0.0-beta.66",
22
+ "@eslint-react/core": "^2.0.0-beta.66",
23
+ "@eslint-react/eff": "^2.0.0-beta.66",
24
+ "@eslint-react/kit": "^2.0.0-beta.66",
25
+ "@typescript-eslint/scope-manager": "^8.42.0",
26
+ "@typescript-eslint/type-utils": "^8.42.0",
27
+ "@typescript-eslint/types": "^8.42.0",
28
+ "@typescript-eslint/utils": "^8.42.0",
29
29
  "string-ts": "^2.2.1",
30
30
  "ts-pattern": "^5.8.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@eslint/markdown": "^7.1.0",
33
+ "@eslint/markdown": "^7.2.0",
34
34
  "@tsconfig/node22": "^22.0.2",
35
35
  "@tsconfig/strictest": "^2.0.5",
36
- "@types/node": "^24.3.0",
37
- "@typescript-eslint/rule-tester": "^8.40.0",
38
- "dedent": "^1.6.0",
39
- "eslint": "^9.33.0",
36
+ "@types/node": "^24.3.1",
37
+ "@typescript-eslint/rule-tester": "^8.42.0",
38
+ "dedent": "^1.7.0",
39
+ "eslint": "^9.34.0",
40
40
  "eslint-config-flat-gitignore": "^2.1.0",
41
41
  "eslint-plugin-vitest": "^0.5.4",
42
42
  "jiti": "^2.5.1",
43
43
  "publint": "^0.3.12",
44
44
  "skott": "^0.35.4",
45
- "tsup": "^8.5.0",
46
- "typescript-eslint": "^8.40.0",
45
+ "tsdown": "^0.14.2",
46
+ "typescript-eslint": "^8.42.0",
47
47
  "vitest": "^3.2.4",
48
48
  "@local/configs": "0.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "eslint": "^9.25.0",
51
+ "eslint": "^9.34.0",
52
52
  "ts-api-utils": "^2.1.0",
53
- "typescript": "^5.8.3"
53
+ "typescript": "^5.9.2"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=20.10.0"
57
57
  },
58
58
  "scripts": {
59
- "build": "tsup",
59
+ "build": "tsdown",
60
60
  "build:pkgs": "pnpm -F \"./.pkgs/*\" run build",
61
61
  "format:check": "dprint check",
62
62
  "format:package-json": "pnpm m exec sort-package-json -q package.json && dprint fmt",
@@ -66,6 +66,6 @@
66
66
  "lint:es": "eslint . --max-warnings 10",
67
67
  "lint:publish": "publint",
68
68
  "lint:ts": "tsc --noEmit",
69
- "test": "vitest"
69
+ "test": "vitest run"
70
70
  }
71
71
  }