tsl-dx 0.8.0 → 0.10.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/dist/index.js +32 -191
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -66,124 +66,6 @@ function buildSuggestions$1(a, b) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region ../../.pkgs/eff/dist/index.js
|
|
71
|
-
/**
|
|
72
|
-
* Creates a function that can be used in a data-last (aka `pipe`able) or
|
|
73
|
-
* data-first style.
|
|
74
|
-
*
|
|
75
|
-
* The first parameter to `dual` is either the arity of the uncurried function
|
|
76
|
-
* or a predicate that determines if the function is being used in a data-first
|
|
77
|
-
* or data-last style.
|
|
78
|
-
*
|
|
79
|
-
* Using the arity is the most common use case, but there are some cases where
|
|
80
|
-
* you may want to use a predicate. For example, if you have a function that
|
|
81
|
-
* takes an optional argument, you can use a predicate to determine if the
|
|
82
|
-
* function is being used in a data-first or data-last style.
|
|
83
|
-
*
|
|
84
|
-
* You can pass either the arity of the uncurried function or a predicate
|
|
85
|
-
* which determines if the function is being used in a data-first or
|
|
86
|
-
* data-last style.
|
|
87
|
-
*
|
|
88
|
-
* **Example** (Using arity to determine data-first or data-last style)
|
|
89
|
-
*
|
|
90
|
-
* ```ts
|
|
91
|
-
* import { dual, pipe } from "effect/Function"
|
|
92
|
-
*
|
|
93
|
-
* const sum = dual<
|
|
94
|
-
* (that: number) => (self: number) => number,
|
|
95
|
-
* (self: number, that: number) => number
|
|
96
|
-
* >(2, (self, that) => self + that)
|
|
97
|
-
*
|
|
98
|
-
* console.log(sum(2, 3)) // 5
|
|
99
|
-
* console.log(pipe(2, sum(3))) // 5
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* **Example** (Using call signatures to define the overloads)
|
|
103
|
-
*
|
|
104
|
-
* ```ts
|
|
105
|
-
* import { dual, pipe } from "effect/Function"
|
|
106
|
-
*
|
|
107
|
-
* const sum: {
|
|
108
|
-
* (that: number): (self: number) => number
|
|
109
|
-
* (self: number, that: number): number
|
|
110
|
-
* } = dual(2, (self: number, that: number): number => self + that)
|
|
111
|
-
*
|
|
112
|
-
* console.log(sum(2, 3)) // 5
|
|
113
|
-
* console.log(pipe(2, sum(3))) // 5
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
* **Example** (Using a predicate to determine data-first or data-last style)
|
|
117
|
-
*
|
|
118
|
-
* ```ts
|
|
119
|
-
* import { dual, pipe } from "effect/Function"
|
|
120
|
-
*
|
|
121
|
-
* const sum = dual<
|
|
122
|
-
* (that: number) => (self: number) => number,
|
|
123
|
-
* (self: number, that: number) => number
|
|
124
|
-
* >(
|
|
125
|
-
* (args) => args.length === 2,
|
|
126
|
-
* (self, that) => self + that
|
|
127
|
-
* )
|
|
128
|
-
*
|
|
129
|
-
* console.log(sum(2, 3)) // 5
|
|
130
|
-
* console.log(pipe(2, sum(3))) // 5
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* @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.
|
|
134
|
-
* @param body - The function to be curried.
|
|
135
|
-
* @since 1.0.0
|
|
136
|
-
*/
|
|
137
|
-
const dual = function(arity, body) {
|
|
138
|
-
if (typeof arity === "function") return function() {
|
|
139
|
-
return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
|
|
140
|
-
};
|
|
141
|
-
switch (arity) {
|
|
142
|
-
case 0:
|
|
143
|
-
case 1: throw new RangeError(`Invalid arity ${arity}`);
|
|
144
|
-
case 2: return function(a, b) {
|
|
145
|
-
if (arguments.length >= 2) return body(a, b);
|
|
146
|
-
return function(self) {
|
|
147
|
-
return body(self, a);
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
case 3: return function(a, b, c) {
|
|
151
|
-
if (arguments.length >= 3) return body(a, b, c);
|
|
152
|
-
return function(self) {
|
|
153
|
-
return body(self, a, b);
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
default: return function() {
|
|
157
|
-
if (arguments.length >= arity) return body.apply(this, arguments);
|
|
158
|
-
const args = arguments;
|
|
159
|
-
return function(self) {
|
|
160
|
-
return body(self, ...args);
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* 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`.
|
|
167
|
-
* The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
|
|
168
|
-
*
|
|
169
|
-
* @param self - The first function to apply (or the composed function in data-last style).
|
|
170
|
-
* @param bc - The second function to apply.
|
|
171
|
-
* @returns A composed function that applies both functions in sequence.
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* import * as assert from "node:assert"
|
|
175
|
-
* import { compose } from "effect/Function"
|
|
176
|
-
*
|
|
177
|
-
* const increment = (n: number) => n + 1;
|
|
178
|
-
* const square = (n: number) => n * n;
|
|
179
|
-
*
|
|
180
|
-
* assert.strictEqual(compose(increment, square)(2), 9);
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* @since 1.0.0
|
|
184
|
-
*/
|
|
185
|
-
const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
|
|
186
|
-
|
|
187
69
|
//#endregion
|
|
188
70
|
//#region src/rules/no-duplicate-imports.ts
|
|
189
71
|
const messages$2 = { default: (p) => `Duplicate import from module ${p.source}.` };
|
|
@@ -220,7 +102,7 @@ const noDuplicateImports = defineRule(() => {
|
|
|
220
102
|
node,
|
|
221
103
|
source: node.moduleSpecifier.getText(),
|
|
222
104
|
kind: importKind,
|
|
223
|
-
defaultImport: node.importClause.name?.getText(),
|
|
105
|
+
defaultImport: node.importClause.name?.getText() ?? null,
|
|
224
106
|
bindings: match(node.importClause.namedBindings).with({ kind: ts.SyntaxKind.NamedImports }, (nb) => ({
|
|
225
107
|
kind: "named",
|
|
226
108
|
imports: nb.elements.map((el) => el.getText())
|
|
@@ -266,13 +148,6 @@ function buildSuggestions(existing, incoming) {
|
|
|
266
148
|
}];
|
|
267
149
|
}
|
|
268
150
|
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/utils/source-file.ts
|
|
271
|
-
function getLine(node) {
|
|
272
|
-
const sourceFile = node.getSourceFile();
|
|
273
|
-
return [sourceFile.getLineAndCharacterOfPosition(node.getStart()).line, sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line];
|
|
274
|
-
}
|
|
275
|
-
|
|
276
151
|
//#endregion
|
|
277
152
|
//#region src/rules/no-multiline-template-expression-without-auto-dedent.ts
|
|
278
153
|
const messages$1 = {
|
|
@@ -304,6 +179,10 @@ const messages$1 = {
|
|
|
304
179
|
const noMultilineTemplateExpressionWithoutAutoDedent = defineRule((options) => {
|
|
305
180
|
const dedentTagNames = options?.dedentTagNames ?? ["dedent"];
|
|
306
181
|
const dedentTagImportCallback = options?.dedentTagImportCallback ?? ((name) => `import ${name} from "dedent";\n`);
|
|
182
|
+
function getLine(node) {
|
|
183
|
+
const sourceFile = node.getSourceFile();
|
|
184
|
+
return [sourceFile.getLineAndCharacterOfPosition(node.getStart()).line, sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line];
|
|
185
|
+
}
|
|
307
186
|
return {
|
|
308
187
|
name: "dx/no-multiline-template-expression-without-auto-dedent",
|
|
309
188
|
visitor: { NoSubstitutionTemplateLiteral(ctx, node) {
|
|
@@ -333,9 +212,8 @@ const noMultilineTemplateExpressionWithoutAutoDedent = defineRule((options) => {
|
|
|
333
212
|
//#endregion
|
|
334
213
|
//#region src/rules/nullish.ts
|
|
335
214
|
const messages = {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
replaceWithExpression: (p) => `Replace with '${p.expr}'.`
|
|
215
|
+
default: (p) => `Use '${p.op}' for nullish comparison.`,
|
|
216
|
+
replace: (p) => `Replace with '${p.expr}'.`
|
|
339
217
|
};
|
|
340
218
|
/**
|
|
341
219
|
* Rule to enforce the use of `unit` instead of `undefined` and loose equality for nullish checks.
|
|
@@ -359,69 +237,32 @@ const nullish = defineRule((options) => ({
|
|
|
359
237
|
createData(ctx) {
|
|
360
238
|
return { runtimeLibrary: options?.runtimeLibrary ?? "@local/eff" };
|
|
361
239
|
},
|
|
362
|
-
visitor: {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
message: messages.useUnitForUndefined,
|
|
385
|
-
suggestions: [{
|
|
386
|
-
message: messages.replaceWithExpression({ expr: "unit" }),
|
|
387
|
-
changes: [{
|
|
388
|
-
start: 0,
|
|
389
|
-
end: 0,
|
|
390
|
-
newText: `import type { unit } from '${ctx.data.runtimeLibrary}';\n`
|
|
391
|
-
}, {
|
|
392
|
-
node,
|
|
393
|
-
newText: "unit"
|
|
394
|
-
}]
|
|
395
|
-
}]
|
|
396
|
-
});
|
|
397
|
-
},
|
|
398
|
-
BinaryExpression(ctx, node) {
|
|
399
|
-
const newOperatorText = match(node.operatorToken.kind).with(SyntaxKind.EqualsEqualsEqualsToken, () => "==").with(SyntaxKind.ExclamationEqualsEqualsToken, () => "!=").otherwise(() => null);
|
|
400
|
-
if (newOperatorText == null) return;
|
|
401
|
-
const offendingChild = [node.left, node.right].find((n) => {
|
|
402
|
-
switch (n.kind) {
|
|
403
|
-
case SyntaxKind.NullKeyword: return true;
|
|
404
|
-
case SyntaxKind.Identifier: return n.text === "unit" || n.text === "undefined";
|
|
405
|
-
default: return false;
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
if (offendingChild == null) return;
|
|
409
|
-
ctx.report({
|
|
410
|
-
message: messages.useLooseNullishComparison({ op: newOperatorText }),
|
|
411
|
-
node,
|
|
412
|
-
suggestions: [{
|
|
413
|
-
message: messages.replaceWithExpression({ expr: offendingChild === node.left ? `null ${newOperatorText} ${node.right.getText()}` : `${node.left.getText()} ${newOperatorText} null` }),
|
|
414
|
-
changes: [{
|
|
415
|
-
node: node.operatorToken,
|
|
416
|
-
newText: newOperatorText
|
|
417
|
-
}, {
|
|
418
|
-
node: offendingChild,
|
|
419
|
-
newText: "null"
|
|
420
|
-
}]
|
|
240
|
+
visitor: { BinaryExpression(ctx, node) {
|
|
241
|
+
const newOperatorText = match(node.operatorToken.kind).with(SyntaxKind.EqualsEqualsEqualsToken, () => "==").with(SyntaxKind.ExclamationEqualsEqualsToken, () => "!=").otherwise(() => null);
|
|
242
|
+
if (newOperatorText == null) return;
|
|
243
|
+
const offendingChild = [node.left, node.right].find((n) => {
|
|
244
|
+
switch (n.kind) {
|
|
245
|
+
case SyntaxKind.NullKeyword: return true;
|
|
246
|
+
case SyntaxKind.Identifier: return n.text === "unit" || n.text === "undefined";
|
|
247
|
+
default: return false;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (offendingChild == null) return;
|
|
251
|
+
ctx.report({
|
|
252
|
+
message: messages.default({ op: newOperatorText }),
|
|
253
|
+
node,
|
|
254
|
+
suggestions: [{
|
|
255
|
+
message: messages.replace({ expr: offendingChild === node.left ? `null ${newOperatorText} ${node.right.getText()}` : `${node.left.getText()} ${newOperatorText} null` }),
|
|
256
|
+
changes: [{
|
|
257
|
+
node: node.operatorToken,
|
|
258
|
+
newText: newOperatorText
|
|
259
|
+
}, {
|
|
260
|
+
node: offendingChild,
|
|
261
|
+
newText: "null"
|
|
421
262
|
}]
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
263
|
+
}]
|
|
264
|
+
});
|
|
265
|
+
} }
|
|
425
266
|
}));
|
|
426
267
|
|
|
427
268
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsl-dx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "A tsl plugin for better JavaScript/TypeScript DX.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tsl",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@liautaud/typezod": "^2.0.0",
|
|
28
|
-
"dedent": "^1.7.
|
|
29
|
-
"tsdown": "^0.
|
|
28
|
+
"dedent": "^1.7.2",
|
|
29
|
+
"tsdown": "^0.21.2",
|
|
30
30
|
"tsl": "^1.0.29",
|
|
31
|
-
"vitest": "^4.0
|
|
31
|
+
"vitest": "^4.1.0",
|
|
32
32
|
"@local/configs": "0.0.0",
|
|
33
33
|
"@local/eff": "0.2.9"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"tsl": "^1.0.
|
|
36
|
+
"tsl": "^1.0.29",
|
|
37
37
|
"typescript": "*"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|