@eslint-react/core 3.0.0-next.71 → 3.0.0-next.74
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/dist/index.js +159 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as ast from "@eslint-react/ast";
|
|
2
|
-
import { constFalse, dual, flip, getOrElseUpdate, identity } from "@eslint-react/eff";
|
|
3
2
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
4
3
|
import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
5
4
|
import { P, match } from "ts-pattern";
|
|
@@ -7,6 +6,165 @@ import { IdGenerator, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_J
|
|
|
7
6
|
import { resolve } from "@eslint-react/var";
|
|
8
7
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/utils";
|
|
9
8
|
|
|
9
|
+
//#region ../../.pkgs/eff/dist/index.js
|
|
10
|
+
/**
|
|
11
|
+
* Returns its argument.
|
|
12
|
+
*
|
|
13
|
+
* @param x - The value to return.
|
|
14
|
+
* @returns The input value unchanged.
|
|
15
|
+
*/
|
|
16
|
+
function identity(x) {
|
|
17
|
+
return x;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that can be used in a data-last (aka `pipe`able) or
|
|
21
|
+
* data-first style.
|
|
22
|
+
*
|
|
23
|
+
* The first parameter to `dual` is either the arity of the uncurried function
|
|
24
|
+
* or a predicate that determines if the function is being used in a data-first
|
|
25
|
+
* or data-last style.
|
|
26
|
+
*
|
|
27
|
+
* Using the arity is the most common use case, but there are some cases where
|
|
28
|
+
* you may want to use a predicate. For example, if you have a function that
|
|
29
|
+
* takes an optional argument, you can use a predicate to determine if the
|
|
30
|
+
* function is being used in a data-first or data-last style.
|
|
31
|
+
*
|
|
32
|
+
* You can pass either the arity of the uncurried function or a predicate
|
|
33
|
+
* which determines if the function is being used in a data-first or
|
|
34
|
+
* data-last style.
|
|
35
|
+
*
|
|
36
|
+
* **Example** (Using arity to determine data-first or data-last style)
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { dual, pipe } from "effect/Function"
|
|
40
|
+
*
|
|
41
|
+
* const sum = dual<
|
|
42
|
+
* (that: number) => (self: number) => number,
|
|
43
|
+
* (self: number, that: number) => number
|
|
44
|
+
* >(2, (self, that) => self + that)
|
|
45
|
+
*
|
|
46
|
+
* console.log(sum(2, 3)) // 5
|
|
47
|
+
* console.log(pipe(2, sum(3))) // 5
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* **Example** (Using call signatures to define the overloads)
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { dual, pipe } from "effect/Function"
|
|
54
|
+
*
|
|
55
|
+
* const sum: {
|
|
56
|
+
* (that: number): (self: number) => number
|
|
57
|
+
* (self: number, that: number): number
|
|
58
|
+
* } = dual(2, (self: number, that: number): number => self + that)
|
|
59
|
+
*
|
|
60
|
+
* console.log(sum(2, 3)) // 5
|
|
61
|
+
* console.log(pipe(2, sum(3))) // 5
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* **Example** (Using a predicate to determine data-first or data-last style)
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { dual, pipe } from "effect/Function"
|
|
68
|
+
*
|
|
69
|
+
* const sum = dual<
|
|
70
|
+
* (that: number) => (self: number) => number,
|
|
71
|
+
* (self: number, that: number) => number
|
|
72
|
+
* >(
|
|
73
|
+
* (args) => args.length === 2,
|
|
74
|
+
* (self, that) => self + that
|
|
75
|
+
* )
|
|
76
|
+
*
|
|
77
|
+
* console.log(sum(2, 3)) // 5
|
|
78
|
+
* console.log(pipe(2, sum(3))) // 5
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @param arity - The arity of the uncurried function or a predicate that determines if the function is being used in a data-first or data-last style.
|
|
82
|
+
* @param body - The function to be curried.
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
*/
|
|
85
|
+
const dual = function(arity, body) {
|
|
86
|
+
if (typeof arity === "function") return function() {
|
|
87
|
+
return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
|
|
88
|
+
};
|
|
89
|
+
switch (arity) {
|
|
90
|
+
case 0:
|
|
91
|
+
case 1: throw new RangeError(`Invalid arity ${arity}`);
|
|
92
|
+
case 2: return function(a, b) {
|
|
93
|
+
if (arguments.length >= 2) return body(a, b);
|
|
94
|
+
return function(self) {
|
|
95
|
+
return body(self, a);
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
case 3: return function(a, b, c) {
|
|
99
|
+
if (arguments.length >= 3) return body(a, b, c);
|
|
100
|
+
return function(self) {
|
|
101
|
+
return body(self, a, b);
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
default: return function() {
|
|
105
|
+
if (arguments.length >= arity) return body.apply(this, arguments);
|
|
106
|
+
const args = arguments;
|
|
107
|
+
return function(self) {
|
|
108
|
+
return body(self, ...args);
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Do nothing and return `false`.
|
|
115
|
+
*
|
|
116
|
+
* @returns false
|
|
117
|
+
*/
|
|
118
|
+
function constFalse() {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Reverses the order of arguments for a curried function.
|
|
123
|
+
*
|
|
124
|
+
* @param f - The function to flip.
|
|
125
|
+
* @returns A new function with the argument order reversed.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import * as assert from "node:assert"
|
|
129
|
+
* import { flip } from "effect/Function"
|
|
130
|
+
*
|
|
131
|
+
* const f = (a: number) => (b: string) => a - b.length
|
|
132
|
+
*
|
|
133
|
+
* assert.deepStrictEqual(flip(f)('aaa')(2), -1)
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @since 1.0.0
|
|
137
|
+
*/
|
|
138
|
+
const flip = (f) => (...b) => (...a) => f(...a)(...b);
|
|
139
|
+
/**
|
|
140
|
+
* Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.
|
|
141
|
+
* The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
|
|
142
|
+
*
|
|
143
|
+
* @param self - The first function to apply (or the composed function in data-last style).
|
|
144
|
+
* @param bc - The second function to apply.
|
|
145
|
+
* @returns A composed function that applies both functions in sequence.
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import * as assert from "node:assert"
|
|
149
|
+
* import { compose } from "effect/Function"
|
|
150
|
+
*
|
|
151
|
+
* const increment = (n: number) => n + 1;
|
|
152
|
+
* const square = (n: number) => n * n;
|
|
153
|
+
*
|
|
154
|
+
* assert.strictEqual(compose(increment, square)(2), 9);
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @since 1.0.0
|
|
158
|
+
*/
|
|
159
|
+
const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
|
|
160
|
+
function getOrElseUpdate(map, key, callback) {
|
|
161
|
+
if (map.has(key)) return map.get(key);
|
|
162
|
+
const value = callback();
|
|
163
|
+
map.set(key, value);
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
10
168
|
//#region src/api/find-import-source.ts
|
|
11
169
|
/**
|
|
12
170
|
* Get the arguments of a require expression
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.74",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"@typescript-eslint/types": "canary",
|
|
35
35
|
"@typescript-eslint/utils": "canary",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/ast": "3.0.0-next.
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@
|
|
37
|
+
"@eslint-react/ast": "3.0.0-next.74",
|
|
38
|
+
"@eslint-react/shared": "3.0.0-next.74",
|
|
39
|
+
"@eslint-react/var": "3.0.0-next.74",
|
|
40
|
+
"@local/eff": "3.0.0-beta.72"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsdown": "^0.21.0-beta.2",
|
|
44
44
|
"@local/configs": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"typescript": "
|
|
47
|
+
"eslint": "^10.0.0",
|
|
48
|
+
"typescript": "*"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=22.0.0"
|