eslint-plugin-function 0.0.21 → 0.0.23

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/README.md +1 -1
  2. package/dist/index.js +6 -94
  3. package/package.json +20 -19
package/README.md CHANGED
@@ -19,8 +19,8 @@ npm install --save-dev eslint-plugin-function
19
19
 
20
20
  // @ts-check
21
21
  import eslintJs from "@eslint/js";
22
- import tseslint from "typescript-eslint";
23
22
  import pluginFunction from "eslint-plugin-function";
23
+ import tseslint from "typescript-eslint";
24
24
 
25
25
  export default tseslint.config({
26
26
  files: ["**/*.ts", "**/*.tsx"],
package/dist/index.js CHANGED
@@ -1,107 +1,19 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
- import { unionConstituents, isTypeFlagSet, isTrueLiteralType, isFalseLiteralType } from 'ts-api-utils';
3
- import { match, isMatching, P } from 'ts-pattern';
4
- import ts from 'typescript';
5
2
  import * as AST from '@eslint-react/ast';
3
+ import * as ER from '@eslint-react/core';
6
4
  import '@eslint-react/eff';
5
+ import { RegExp } from '@eslint-react/kit';
7
6
  import { getConstrainedTypeAtLocation } from '@typescript-eslint/type-utils';
8
7
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
8
+ import { unionConstituents } from 'ts-api-utils';
9
9
 
10
10
  // package.json
11
11
  var name = "eslint-plugin-function";
12
- var version = "0.0.21";
12
+ var version = "0.0.23";
13
13
  function getDocsUrl() {
14
14
  return "TODO: add docs for local ESLint rules";
15
15
  }
16
16
  var createRule = ESLintUtils.RuleCreator(getDocsUrl);
17
- var tsHelpers = {
18
- isAnyType: (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any),
19
- isBigIntType: (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike),
20
- isBooleanType: (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike),
21
- isEnumType: (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike),
22
- isFalsyBigIntType: (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type),
23
- isFalsyNumberType: (type) => type.isNumberLiteral() && type.value === 0,
24
- isFalsyStringType: (type) => type.isStringLiteral() && type.value === "",
25
- isNeverType: (type) => isTypeFlagSet(type, ts.TypeFlags.Never),
26
- isNullishType: (type) => isTypeFlagSet(
27
- type,
28
- ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike
29
- ),
30
- isNumberType: (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike),
31
- isObjectType: (type) => !isTypeFlagSet(
32
- type,
33
- ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.TypeParameter | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never
34
- ),
35
- isStringType: (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike),
36
- isTruthyBigIntType: (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type),
37
- isTruthyNumberType: (type) => type.isNumberLiteral() && type.value !== 0,
38
- isTruthyStringType: (type) => type.isStringLiteral() && type.value !== "",
39
- isUnknownType: (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown)
40
- };
41
-
42
- // src/utils/inspect-variant-types.ts
43
- function inspectVariantTypes(types) {
44
- const variantTypes = /* @__PURE__ */ new Set();
45
- if (types.some(tsHelpers.isUnknownType)) {
46
- variantTypes.add("unknown");
47
- return variantTypes;
48
- }
49
- if (types.some(tsHelpers.isNullishType)) {
50
- variantTypes.add("nullish");
51
- }
52
- const booleans = types.filter(tsHelpers.isBooleanType);
53
- switch (true) {
54
- case (booleans.length === 1 && booleans[0] != null): {
55
- const first = booleans[0];
56
- if (isTrueLiteralType(first)) {
57
- variantTypes.add("truthy boolean");
58
- } else if (isFalseLiteralType(first)) {
59
- variantTypes.add("falsy boolean");
60
- }
61
- break;
62
- }
63
- case booleans.length === 2: {
64
- variantTypes.add("boolean");
65
- break;
66
- }
67
- }
68
- const strings = types.filter(tsHelpers.isStringType);
69
- if (strings.length > 0) {
70
- const evaluated = match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType), () => "truthy string").when((types2) => types2.every(tsHelpers.isFalsyStringType), () => "falsy string").otherwise(() => "string");
71
- variantTypes.add(evaluated);
72
- }
73
- const bigints = types.filter(tsHelpers.isBigIntType);
74
- if (bigints.length > 0) {
75
- const evaluated = match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType), () => "truthy bigint").when((types2) => types2.every(tsHelpers.isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
76
- variantTypes.add(evaluated);
77
- }
78
- const numbers = types.filter(tsHelpers.isNumberType);
79
- if (numbers.length > 0) {
80
- const evaluated = match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType), () => "truthy number").when((types2) => types2.every(tsHelpers.isFalsyNumberType), () => "falsy number").otherwise(() => "number");
81
- variantTypes.add(evaluated);
82
- }
83
- if (types.some(tsHelpers.isEnumType)) {
84
- variantTypes.add("enum");
85
- }
86
- if (types.some(tsHelpers.isObjectType)) {
87
- variantTypes.add("object");
88
- }
89
- if (types.some(tsHelpers.isAnyType)) {
90
- variantTypes.add("any");
91
- }
92
- if (types.some(tsHelpers.isNeverType)) {
93
- variantTypes.add("never");
94
- }
95
- return variantTypes;
96
- }
97
-
98
- // src/utils/regexp.ts
99
- var RE_REGEXP_STR = /^\/(.+)\/([A-Za-z]*)$/u;
100
- function toRegExp(string) {
101
- const [, pattern, flags = "u"] = RE_REGEXP_STR.exec(string) ?? [];
102
- if (pattern) return new RegExp(pattern, flags);
103
- return { test: (s) => s === string };
104
- }
105
17
 
106
18
  // src/rules/function-definition.ts
107
19
  var RULE_NAME = "function-definition";
@@ -189,7 +101,7 @@ var function_return_boolean_default = createRule({
189
101
  });
190
102
  function create3(context, [opts]) {
191
103
  const services = ESLintUtils.getParserServices(context, false);
192
- const pattern = toRegExp(opts?.pattern ?? defaultPattern);
104
+ const pattern = RegExp.toRegExp(opts?.pattern ?? defaultPattern);
193
105
  const functionEntries = [];
194
106
  function handleReturnExpression(context2, returnExpression, onViolation) {
195
107
  if (returnExpression == null) {
@@ -197,7 +109,7 @@ function create3(context, [opts]) {
197
109
  return;
198
110
  }
199
111
  const returnType = getConstrainedTypeAtLocation(services, returnExpression);
200
- const parts = [...inspectVariantTypes(unionConstituents(returnType))];
112
+ const parts = [...ER.getTypeVariants(unionConstituents(returnType))];
201
113
  if (parts.every((part) => allowedVariants.some((allowed) => part === allowed))) return;
202
114
  onViolation(returnExpression, {
203
115
  variants: [...parts].map((part) => `'${part}'`).join(", ")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-function",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "private": false,
5
5
  "description": "(WIP) The ESLint plugin for function-related rules.",
6
6
  "license": "MIT",
@@ -18,32 +18,33 @@
18
18
  "package.json"
19
19
  ],
20
20
  "dependencies": {
21
- "@eslint-react/ast": "^2.0.0-next.4",
22
- "@eslint-react/eff": "^2.0.0-next.4",
23
- "@eslint-react/kit": "^2.0.0-next.4",
24
- "@typescript-eslint/scope-manager": "^8.30.1",
25
- "@typescript-eslint/type-utils": "^8.30.1",
26
- "@typescript-eslint/types": "^8.30.1",
27
- "@typescript-eslint/utils": "^8.30.1",
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",
28
29
  "string-ts": "^2.2.1",
29
- "ts-pattern": "^5.7.0"
30
+ "ts-pattern": "^5.8.0"
30
31
  },
31
32
  "devDependencies": {
32
- "@eslint/markdown": "^6.4.0",
33
- "@tsconfig/node22": "^22.0.1",
33
+ "@eslint/markdown": "^7.1.0",
34
+ "@tsconfig/node22": "^22.0.2",
34
35
  "@tsconfig/strictest": "^2.0.5",
35
- "@types/node": "^22.14.1",
36
- "@typescript-eslint/rule-tester": "^8.30.1",
37
- "dedent": "^1.5.3",
38
- "eslint": "^9.25.0",
36
+ "@types/node": "^24.3.0",
37
+ "@typescript-eslint/rule-tester": "^8.40.0",
38
+ "dedent": "^1.6.0",
39
+ "eslint": "^9.33.0",
39
40
  "eslint-config-flat-gitignore": "^2.1.0",
40
41
  "eslint-plugin-vitest": "^0.5.4",
41
- "jiti": "^2.4.2",
42
+ "jiti": "^2.5.1",
42
43
  "publint": "^0.3.12",
43
44
  "skott": "^0.35.4",
44
- "tsup": "^8.4.0",
45
- "typescript-eslint": "^8.30.1",
46
- "vitest": "^3.1.1",
45
+ "tsup": "^8.5.0",
46
+ "typescript-eslint": "^8.40.0",
47
+ "vitest": "^3.2.4",
47
48
  "@local/configs": "0.0.0"
48
49
  },
49
50
  "peerDependencies": {