eslint-plugin-ts-data-forge 0.2.0 → 0.3.0
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/README.md +16 -14
- package/dist/plugin.d.mts +2 -0
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +1 -0
- package/dist/plugin.mjs.map +1 -1
- package/dist/rule-types.d.mts +16 -1
- package/dist/rule-types.d.mts.map +1 -1
- package/dist/rules/import-utils.mjs.map +1 -1
- package/dist/rules/prefer-arr-is-bounded-length-array.mjs +1 -1
- package/dist/rules/prefer-arr-is-bounded-length-array.mjs.map +1 -1
- package/dist/rules/prefer-arr-is-fixed-length-array.mjs +1 -1
- package/dist/rules/prefer-arr-is-fixed-length-array.mjs.map +1 -1
- package/dist/rules/prefer-arr-is-max-length-array.mjs +1 -1
- package/dist/rules/prefer-arr-is-max-length-array.mjs.map +1 -1
- package/dist/rules/prefer-arr-is-min-length-array.mjs +1 -1
- package/dist/rules/prefer-arr-is-min-length-array.mjs.map +1 -1
- package/dist/rules/prefer-arr-sum.mjs +2 -2
- package/dist/rules/prefer-arr-sum.mjs.map +1 -1
- package/dist/rules/prefer-canonical-array-slicing.mjs.map +1 -1
- package/dist/rules/prefer-canonical-length-cast.d.mts +6 -0
- package/dist/rules/prefer-canonical-length-cast.d.mts.map +1 -0
- package/dist/rules/prefer-canonical-length-cast.mjs +155 -0
- package/dist/rules/prefer-canonical-length-cast.mjs.map +1 -0
- package/dist/rules/prefer-canonical-length-guard.d.mts.map +1 -1
- package/dist/rules/prefer-canonical-length-guard.mjs +12 -8
- package/dist/rules/prefer-canonical-length-guard.mjs.map +1 -1
- package/dist/rules/prefer-range-for-loop.mjs +1 -1
- package/dist/rules/prefer-range-for-loop.mjs.map +1 -1
- package/dist/rules/rules.d.mts +1 -0
- package/dist/rules/rules.d.mts.map +1 -1
- package/dist/rules/rules.mjs +2 -0
- package/dist/rules/rules.mjs.map +1 -1
- package/package.json +3 -3
- package/src/plugin.mts +1 -0
- package/src/rule-types.mts +17 -1
- package/src/rules/import-utils.mts +0 -1
- package/src/rules/prefer-arr-is-bounded-length-array.mts +1 -1
- package/src/rules/prefer-arr-is-bounded-length-array.test.mts +5 -5
- package/src/rules/prefer-arr-is-fixed-length-array.mts +1 -1
- package/src/rules/prefer-arr-is-fixed-length-array.test.mts +11 -11
- package/src/rules/prefer-arr-is-max-length-array.mts +1 -1
- package/src/rules/prefer-arr-is-max-length-array.test.mts +8 -8
- package/src/rules/prefer-arr-is-min-length-array.mts +1 -1
- package/src/rules/prefer-arr-is-min-length-array.test.mts +9 -9
- package/src/rules/prefer-arr-sum.mts +2 -2
- package/src/rules/prefer-canonical-array-slicing.mts +0 -2
- package/src/rules/prefer-canonical-length-cast.mts +290 -0
- package/src/rules/prefer-canonical-length-cast.test.mts +305 -0
- package/src/rules/prefer-canonical-length-guard.mts +40 -21
- package/src/rules/prefer-canonical-length-guard.test.mts +32 -32
- package/src/rules/prefer-range-for-loop.mts +1 -1
- package/src/rules/rules.mts +2 -0
package/dist/rules/rules.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { preferArrIsArray } from './prefer-arr-is-array.mjs';
|
|
|
3
3
|
import { preferArrSum } from './prefer-arr-sum.mjs';
|
|
4
4
|
import { preferAsInt } from './prefer-as-int.mjs';
|
|
5
5
|
import { preferCanonicalArraySlicing } from './prefer-canonical-array-slicing.mjs';
|
|
6
|
+
import { preferCanonicalLengthCast } from './prefer-canonical-length-cast.mjs';
|
|
6
7
|
import { preferCanonicalLengthGuard } from './prefer-canonical-length-guard.mjs';
|
|
7
8
|
import { preferComparisonOverNullishGuard } from './prefer-comparison-over-nullish-guard.mjs';
|
|
8
9
|
import { preferIsNonNullObject } from './prefer-is-non-null-object.mjs';
|
|
@@ -14,6 +15,7 @@ import { preferRangeForLoop } from './prefer-range-for-loop.mjs';
|
|
|
14
15
|
const tsDataForgeRules = {
|
|
15
16
|
"prefer-canonical-array-slicing": preferCanonicalArraySlicing,
|
|
16
17
|
"prefer-canonical-length-guard": preferCanonicalLengthGuard,
|
|
18
|
+
"prefer-canonical-length-cast": preferCanonicalLengthCast,
|
|
17
19
|
"prefer-arr-is-array": preferArrIsArray,
|
|
18
20
|
"prefer-arr-sum": preferArrSum,
|
|
19
21
|
"prefer-as-int": preferAsInt,
|
package/dist/rules/rules.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.mjs","sources":["../../src/rules/rules.mts"],"sourcesContent":["import { type ESLintPlugin } from '../types.mjs';\nimport { noUnnecessaryTypeGuard } from './no-unnecessary-type-guard.mjs';\nimport { preferArrIsArray } from './prefer-arr-is-array.mjs';\nimport { preferArrSum } from './prefer-arr-sum.mjs';\nimport { preferAsInt } from './prefer-as-int.mjs';\nimport { preferCanonicalArraySlicing } from './prefer-canonical-array-slicing.mjs';\nimport { preferCanonicalLengthGuard } from './prefer-canonical-length-guard.mjs';\nimport { preferComparisonOverNullishGuard } from './prefer-comparison-over-nullish-guard.mjs';\nimport { preferIsNonNullObject } from './prefer-is-non-null-object.mjs';\nimport { preferIsRecordAndHasKey } from './prefer-is-record-and-has-key.mjs';\nimport { preferNumSafeParseFloat } from './prefer-num-safe-parse-float.mjs';\nimport { preferNumSafeParseInt } from './prefer-num-safe-parse-int.mjs';\nimport { preferRangeForLoop } from './prefer-range-for-loop.mjs';\n\nexport const tsDataForgeRules = {\n 'prefer-canonical-array-slicing': preferCanonicalArraySlicing,\n 'prefer-canonical-length-guard': preferCanonicalLengthGuard,\n 'prefer-arr-is-array': preferArrIsArray,\n 'prefer-arr-sum': preferArrSum,\n 'prefer-as-int': preferAsInt,\n 'prefer-is-non-null-object': preferIsNonNullObject,\n 'prefer-range-for-loop': preferRangeForLoop,\n 'prefer-is-record-and-has-key': preferIsRecordAndHasKey,\n 'prefer-num-safe-parse-int': preferNumSafeParseInt,\n 'prefer-num-safe-parse-float': preferNumSafeParseFloat,\n 'no-unnecessary-type-guard': noUnnecessaryTypeGuard,\n 'prefer-comparison-over-nullish-guard': preferComparisonOverNullishGuard,\n} as const satisfies ESLintPlugin['rules'];\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.mjs","sources":["../../src/rules/rules.mts"],"sourcesContent":["import { type ESLintPlugin } from '../types.mjs';\nimport { noUnnecessaryTypeGuard } from './no-unnecessary-type-guard.mjs';\nimport { preferArrIsArray } from './prefer-arr-is-array.mjs';\nimport { preferArrSum } from './prefer-arr-sum.mjs';\nimport { preferAsInt } from './prefer-as-int.mjs';\nimport { preferCanonicalArraySlicing } from './prefer-canonical-array-slicing.mjs';\nimport { preferCanonicalLengthCast } from './prefer-canonical-length-cast.mjs';\nimport { preferCanonicalLengthGuard } from './prefer-canonical-length-guard.mjs';\nimport { preferComparisonOverNullishGuard } from './prefer-comparison-over-nullish-guard.mjs';\nimport { preferIsNonNullObject } from './prefer-is-non-null-object.mjs';\nimport { preferIsRecordAndHasKey } from './prefer-is-record-and-has-key.mjs';\nimport { preferNumSafeParseFloat } from './prefer-num-safe-parse-float.mjs';\nimport { preferNumSafeParseInt } from './prefer-num-safe-parse-int.mjs';\nimport { preferRangeForLoop } from './prefer-range-for-loop.mjs';\n\nexport const tsDataForgeRules = {\n 'prefer-canonical-array-slicing': preferCanonicalArraySlicing,\n 'prefer-canonical-length-guard': preferCanonicalLengthGuard,\n 'prefer-canonical-length-cast': preferCanonicalLengthCast,\n 'prefer-arr-is-array': preferArrIsArray,\n 'prefer-arr-sum': preferArrSum,\n 'prefer-as-int': preferAsInt,\n 'prefer-is-non-null-object': preferIsNonNullObject,\n 'prefer-range-for-loop': preferRangeForLoop,\n 'prefer-is-record-and-has-key': preferIsRecordAndHasKey,\n 'prefer-num-safe-parse-int': preferNumSafeParseInt,\n 'prefer-num-safe-parse-float': preferNumSafeParseFloat,\n 'no-unnecessary-type-guard': noUnnecessaryTypeGuard,\n 'prefer-comparison-over-nullish-guard': preferComparisonOverNullishGuard,\n} as const satisfies ESLintPlugin['rules'];\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAeO,MAAM,gBAAA,GAAmB;AAAA,EAC9B,gCAAA,EAAkC,2BAAA;AAAA,EAClC,+BAAA,EAAiC,0BAAA;AAAA,EACjC,8BAAA,EAAgC,yBAAA;AAAA,EAChC,qBAAA,EAAuB,gBAAA;AAAA,EACvB,gBAAA,EAAkB,YAAA;AAAA,EAClB,eAAA,EAAiB,WAAA;AAAA,EACjB,2BAAA,EAA6B,qBAAA;AAAA,EAC7B,uBAAA,EAAyB,kBAAA;AAAA,EACzB,8BAAA,EAAgC,uBAAA;AAAA,EAChC,2BAAA,EAA6B,qBAAA;AAAA,EAC7B,6BAAA,EAA+B,uBAAA;AAAA,EAC/B,2BAAA,EAA6B,sBAAA;AAAA,EAC7B,sCAAA,EAAwC;AAC1C;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-ts-data-forge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ESLint rules that steer code toward ts-data-forge idioms.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@typescript-eslint/utils": "8.64.0",
|
|
38
|
-
"ts-type-forge": "
|
|
39
|
-
"ts-data-forge": "
|
|
38
|
+
"ts-type-forge": "^9.1.1",
|
|
39
|
+
"ts-data-forge": "14.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@typescript-eslint/parser": "8.64.0",
|
package/src/plugin.mts
CHANGED
|
@@ -9,6 +9,7 @@ import { type ESLintFlatConfig, type ESLintPlugin } from './types.mjs';
|
|
|
9
9
|
*/
|
|
10
10
|
const recommendedRules = {
|
|
11
11
|
'ts-data-forge/prefer-canonical-array-slicing': 'error',
|
|
12
|
+
'ts-data-forge/prefer-canonical-length-cast': 'error',
|
|
12
13
|
'ts-data-forge/prefer-canonical-length-guard': 'error',
|
|
13
14
|
'ts-data-forge/prefer-arr-is-array': 'error',
|
|
14
15
|
'ts-data-forge/prefer-arr-sum': 'error',
|
package/src/rule-types.mts
CHANGED
|
@@ -43,7 +43,7 @@ namespace PreferCanonicalArraySlicing {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* @description Normalize array-length checks to their canonical `Arr` guard: `xs.length <op> n` becomes the matching `Arr.is*` guard, and degenerate
|
|
46
|
+
* @description Normalize array-length checks to their canonical `Arr` guard: `xs.length <op> n` becomes the matching `Arr.is*` guard, and a degenerate guard becomes the named one for its family (`Arr.isFixedLengthArray(0, xs)` → `Arr.isEmpty`, `Arr.isFixedLengthTuple(0, xs)` → `Arr.isEmptyTuple`).
|
|
47
47
|
*
|
|
48
48
|
* ```md
|
|
49
49
|
* | key | value |
|
|
@@ -57,6 +57,21 @@ namespace PreferCanonicalLengthGuard {
|
|
|
57
57
|
export type RuleEntry = Linter.StringSeverity;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @description Normalize an `Arr` length cast whose bounds are degenerate (e.g. `Arr.asMinLengthArray(1, xs)`, `Arr.asFixedLengthTuple(0, xs)`) to the cast that names that constraint directly, staying within the branded `*Array` or structural `*Tuple` family.
|
|
62
|
+
*
|
|
63
|
+
* ```md
|
|
64
|
+
* | key | value |
|
|
65
|
+
* | :--------- | :--------- |
|
|
66
|
+
* | type | suggestion |
|
|
67
|
+
* | deprecated | false |
|
|
68
|
+
* | fixable | code |
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
namespace PreferCanonicalLengthCast {
|
|
72
|
+
export type RuleEntry = Linter.StringSeverity;
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
/**
|
|
61
76
|
* @description Replace `Array.isArray` with `Arr.isArray` from ts-data-forge.
|
|
62
77
|
*
|
|
@@ -238,6 +253,7 @@ namespace PreferComparisonOverNullishGuard {
|
|
|
238
253
|
export type EslintTsDataForgeRules = Readonly<{
|
|
239
254
|
'ts-data-forge/prefer-canonical-array-slicing': PreferCanonicalArraySlicing.RuleEntry;
|
|
240
255
|
'ts-data-forge/prefer-canonical-length-guard': PreferCanonicalLengthGuard.RuleEntry;
|
|
256
|
+
'ts-data-forge/prefer-canonical-length-cast': PreferCanonicalLengthCast.RuleEntry;
|
|
241
257
|
'ts-data-forge/prefer-arr-is-array': PreferArrIsArray.RuleEntry;
|
|
242
258
|
'ts-data-forge/prefer-arr-sum': PreferArrSum.RuleEntry;
|
|
243
259
|
'ts-data-forge/prefer-as-int': PreferAsInt.RuleEntry;
|
|
@@ -125,7 +125,7 @@ export const preferArrIsBoundedLengthArray: TSESLint.RuleModule<
|
|
|
125
125
|
max: maxText,
|
|
126
126
|
},
|
|
127
127
|
fix: (fixer) => {
|
|
128
|
-
const replacement = `Arr.isBoundedLengthArray(${
|
|
128
|
+
const replacement = `Arr.isBoundedLengthArray(${minText}, ${maxText}, ${arrayText})`;
|
|
129
129
|
|
|
130
130
|
const importFixes =
|
|
131
131
|
index === 0 && !hasArrImport
|
|
@@ -85,7 +85,7 @@ describe('prefer-arr-is-bounded-length-array', () => {
|
|
|
85
85
|
output: dedent`
|
|
86
86
|
import { Arr } from 'ts-data-forge';
|
|
87
87
|
const xs: readonly number[] = [1, 2, 3];
|
|
88
|
-
const ok = Arr.isBoundedLengthArray(
|
|
88
|
+
const ok = Arr.isBoundedLengthArray(1, 5, xs);
|
|
89
89
|
`,
|
|
90
90
|
errors: [{ messageId: 'useIsBoundedLengthArray' }],
|
|
91
91
|
},
|
|
@@ -98,7 +98,7 @@ describe('prefer-arr-is-bounded-length-array', () => {
|
|
|
98
98
|
output: dedent`
|
|
99
99
|
import { Arr } from 'ts-data-forge';
|
|
100
100
|
const xs: readonly number[] = [1, 2, 3];
|
|
101
|
-
const ok = Arr.isBoundedLengthArray(
|
|
101
|
+
const ok = Arr.isBoundedLengthArray(1, 5, xs);
|
|
102
102
|
`,
|
|
103
103
|
errors: [{ messageId: 'useIsBoundedLengthArray' }],
|
|
104
104
|
},
|
|
@@ -111,7 +111,7 @@ describe('prefer-arr-is-bounded-length-array', () => {
|
|
|
111
111
|
output: dedent`
|
|
112
112
|
import { Arr } from 'ts-data-forge';
|
|
113
113
|
const xs: readonly number[] = [1, 2, 3];
|
|
114
|
-
const ok = Arr.isBoundedLengthArray(
|
|
114
|
+
const ok = Arr.isBoundedLengthArray(1, 5, xs);
|
|
115
115
|
`,
|
|
116
116
|
errors: [{ messageId: 'useIsBoundedLengthArray' }],
|
|
117
117
|
},
|
|
@@ -128,7 +128,7 @@ describe('prefer-arr-is-bounded-length-array', () => {
|
|
|
128
128
|
const xs = [1, 2, 3];
|
|
129
129
|
const lo = 1;
|
|
130
130
|
const hi = 5;
|
|
131
|
-
const ok = Arr.isBoundedLengthArray(
|
|
131
|
+
const ok = Arr.isBoundedLengthArray(lo, hi, xs);
|
|
132
132
|
`,
|
|
133
133
|
errors: [{ messageId: 'useIsBoundedLengthArray' }],
|
|
134
134
|
},
|
|
@@ -144,7 +144,7 @@ describe('prefer-arr-is-bounded-length-array', () => {
|
|
|
144
144
|
import { Arr } from 'ts-data-forge';
|
|
145
145
|
|
|
146
146
|
const xs = [1, 2, 3];
|
|
147
|
-
const ok = Arr.isBoundedLengthArray(
|
|
147
|
+
const ok = Arr.isBoundedLengthArray(1, 5, xs);
|
|
148
148
|
`,
|
|
149
149
|
errors: [{ messageId: 'useIsBoundedLengthArray' }],
|
|
150
150
|
},
|
|
@@ -122,7 +122,7 @@ export const preferArrIsFixedLengthArray: TSESLint.RuleModule<
|
|
|
122
122
|
length: lengthText,
|
|
123
123
|
},
|
|
124
124
|
fix: (fixer) => {
|
|
125
|
-
const baseCall = `Arr.isFixedLengthArray(${
|
|
125
|
+
const baseCall = `Arr.isFixedLengthArray(${lengthText}, ${arrayText})`;
|
|
126
126
|
|
|
127
127
|
const replacement = isNegated ? `!${baseCall}` : baseCall;
|
|
128
128
|
|
|
@@ -76,7 +76,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
76
76
|
output: dedent`
|
|
77
77
|
import { Arr } from 'ts-data-forge';
|
|
78
78
|
const xs: readonly number[] = [1, 2, 3];
|
|
79
|
-
const ok = Arr.isFixedLengthArray(
|
|
79
|
+
const ok = Arr.isFixedLengthArray(3, xs);
|
|
80
80
|
`,
|
|
81
81
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
82
82
|
},
|
|
@@ -89,7 +89,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
89
89
|
output: dedent`
|
|
90
90
|
import { Arr } from 'ts-data-forge';
|
|
91
91
|
const xs: readonly number[] = [1, 2, 3];
|
|
92
|
-
const ok = Arr.isFixedLengthArray(
|
|
92
|
+
const ok = Arr.isFixedLengthArray(3, xs);
|
|
93
93
|
`,
|
|
94
94
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
95
95
|
},
|
|
@@ -102,7 +102,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
102
102
|
output: dedent`
|
|
103
103
|
import { Arr } from 'ts-data-forge';
|
|
104
104
|
const xs = [1, 2, 3];
|
|
105
|
-
const ok = Arr.isFixedLengthArray(
|
|
105
|
+
const ok = Arr.isFixedLengthArray(3, xs);
|
|
106
106
|
`,
|
|
107
107
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
108
108
|
},
|
|
@@ -115,7 +115,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
115
115
|
output: dedent`
|
|
116
116
|
import { Arr } from 'ts-data-forge';
|
|
117
117
|
const xs = [1, 2, 3] as const;
|
|
118
|
-
const ok = Arr.isFixedLengthArray(
|
|
118
|
+
const ok = Arr.isFixedLengthArray(3, xs);
|
|
119
119
|
`,
|
|
120
120
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
121
121
|
},
|
|
@@ -130,7 +130,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
130
130
|
import { Arr } from 'ts-data-forge';
|
|
131
131
|
const xs = [1, 2, 3];
|
|
132
132
|
const n = 3;
|
|
133
|
-
const ok = Arr.isFixedLengthArray(
|
|
133
|
+
const ok = Arr.isFixedLengthArray(n, xs);
|
|
134
134
|
`,
|
|
135
135
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
136
136
|
},
|
|
@@ -146,7 +146,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
146
146
|
import { Arr } from 'ts-data-forge';
|
|
147
147
|
|
|
148
148
|
const xs = [1, 2, 3];
|
|
149
|
-
const ok = Arr.isFixedLengthArray(
|
|
149
|
+
const ok = Arr.isFixedLengthArray(3, xs);
|
|
150
150
|
`,
|
|
151
151
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
152
152
|
},
|
|
@@ -162,8 +162,8 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
162
162
|
import { Arr } from 'ts-data-forge';
|
|
163
163
|
const xs = [1, 2, 3];
|
|
164
164
|
const ys = [4, 5];
|
|
165
|
-
const ok1 = Arr.isFixedLengthArray(
|
|
166
|
-
const ok2 = Arr.isFixedLengthArray(
|
|
165
|
+
const ok1 = Arr.isFixedLengthArray(3, xs);
|
|
166
|
+
const ok2 = Arr.isFixedLengthArray(2, ys);
|
|
167
167
|
`,
|
|
168
168
|
errors: [
|
|
169
169
|
{ messageId: 'useIsFixedLengthArray' },
|
|
@@ -179,7 +179,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
179
179
|
output: dedent`
|
|
180
180
|
import { Arr } from 'ts-data-forge';
|
|
181
181
|
const xs: readonly number[] = [1, 2, 3];
|
|
182
|
-
const ok = !Arr.isFixedLengthArray(
|
|
182
|
+
const ok = !Arr.isFixedLengthArray(3, xs);
|
|
183
183
|
`,
|
|
184
184
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
185
185
|
},
|
|
@@ -192,7 +192,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
192
192
|
output: dedent`
|
|
193
193
|
import { Arr } from 'ts-data-forge';
|
|
194
194
|
const xs: readonly number[] = [1, 2, 3];
|
|
195
|
-
const ok = !Arr.isFixedLengthArray(
|
|
195
|
+
const ok = !Arr.isFixedLengthArray(3, xs);
|
|
196
196
|
`,
|
|
197
197
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
198
198
|
},
|
|
@@ -205,7 +205,7 @@ describe('prefer-arr-is-fixed-length-array', () => {
|
|
|
205
205
|
output: dedent`
|
|
206
206
|
import { Arr } from 'ts-data-forge';
|
|
207
207
|
const xs = [1, 2, 3];
|
|
208
|
-
const ok = !Arr.isFixedLengthArray(
|
|
208
|
+
const ok = !Arr.isFixedLengthArray(5, xs);
|
|
209
209
|
`,
|
|
210
210
|
errors: [{ messageId: 'useIsFixedLengthArray' }],
|
|
211
211
|
},
|
|
@@ -123,7 +123,7 @@ export const preferArrIsMaxLengthArray: TSESLint.RuleModule<
|
|
|
123
123
|
length: lengthText,
|
|
124
124
|
},
|
|
125
125
|
fix: (fixer) => {
|
|
126
|
-
const replacement = `Arr.isMaxLengthArray(${
|
|
126
|
+
const replacement = `Arr.isMaxLengthArray(${lengthText}, ${arrayText})`;
|
|
127
127
|
|
|
128
128
|
const importFixes =
|
|
129
129
|
index === 0 && !hasArrImport
|
|
@@ -89,7 +89,7 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
89
89
|
output: dedent`
|
|
90
90
|
import { Arr } from 'ts-data-forge';
|
|
91
91
|
const xs: readonly number[] = [1, 2, 3];
|
|
92
|
-
const ok = Arr.isMaxLengthArray(
|
|
92
|
+
const ok = Arr.isMaxLengthArray(3, xs);
|
|
93
93
|
`,
|
|
94
94
|
errors: [{ messageId: 'useIsMaxLengthArray' }],
|
|
95
95
|
},
|
|
@@ -102,7 +102,7 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
102
102
|
output: dedent`
|
|
103
103
|
import { Arr } from 'ts-data-forge';
|
|
104
104
|
const xs: readonly number[] = [1, 2, 3];
|
|
105
|
-
const ok = Arr.isMaxLengthArray(
|
|
105
|
+
const ok = Arr.isMaxLengthArray(3, xs);
|
|
106
106
|
`,
|
|
107
107
|
errors: [{ messageId: 'useIsMaxLengthArray' }],
|
|
108
108
|
},
|
|
@@ -115,7 +115,7 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
115
115
|
output: dedent`
|
|
116
116
|
import { Arr } from 'ts-data-forge';
|
|
117
117
|
const xs = [1, 2, 3];
|
|
118
|
-
const ok = Arr.isMaxLengthArray(
|
|
118
|
+
const ok = Arr.isMaxLengthArray(1, xs);
|
|
119
119
|
`,
|
|
120
120
|
errors: [{ messageId: 'useIsMaxLengthArray' }],
|
|
121
121
|
},
|
|
@@ -128,7 +128,7 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
128
128
|
output: dedent`
|
|
129
129
|
import { Arr } from 'ts-data-forge';
|
|
130
130
|
const xs = [1, 2, 3] as const;
|
|
131
|
-
const ok = Arr.isMaxLengthArray(
|
|
131
|
+
const ok = Arr.isMaxLengthArray(2, xs);
|
|
132
132
|
`,
|
|
133
133
|
errors: [{ messageId: 'useIsMaxLengthArray' }],
|
|
134
134
|
},
|
|
@@ -143,7 +143,7 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
143
143
|
import { Arr } from 'ts-data-forge';
|
|
144
144
|
const xs = [1, 2, 3];
|
|
145
145
|
const n = 2;
|
|
146
|
-
const ok = Arr.isMaxLengthArray(
|
|
146
|
+
const ok = Arr.isMaxLengthArray(n, xs);
|
|
147
147
|
`,
|
|
148
148
|
errors: [{ messageId: 'useIsMaxLengthArray' }],
|
|
149
149
|
},
|
|
@@ -159,7 +159,7 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
159
159
|
import { Arr } from 'ts-data-forge';
|
|
160
160
|
|
|
161
161
|
const xs = [1, 2, 3];
|
|
162
|
-
const ok = Arr.isMaxLengthArray(
|
|
162
|
+
const ok = Arr.isMaxLengthArray(1, xs);
|
|
163
163
|
`,
|
|
164
164
|
errors: [{ messageId: 'useIsMaxLengthArray' }],
|
|
165
165
|
},
|
|
@@ -175,8 +175,8 @@ describe('prefer-arr-is-max-length-array', () => {
|
|
|
175
175
|
import { Arr } from 'ts-data-forge';
|
|
176
176
|
const xs = [1, 2, 3];
|
|
177
177
|
const ys = [4, 5];
|
|
178
|
-
const ok1 = Arr.isMaxLengthArray(
|
|
179
|
-
const ok2 = Arr.isMaxLengthArray(
|
|
178
|
+
const ok1 = Arr.isMaxLengthArray(2, xs);
|
|
179
|
+
const ok2 = Arr.isMaxLengthArray(1, ys);
|
|
180
180
|
`,
|
|
181
181
|
errors: [
|
|
182
182
|
{ messageId: 'useIsMaxLengthArray' },
|
|
@@ -123,7 +123,7 @@ export const preferArrIsMinLengthArray: TSESLint.RuleModule<
|
|
|
123
123
|
length: lengthText,
|
|
124
124
|
},
|
|
125
125
|
fix: (fixer) => {
|
|
126
|
-
const replacement = `Arr.isMinLengthArray(${
|
|
126
|
+
const replacement = `Arr.isMinLengthArray(${lengthText}, ${arrayText})`;
|
|
127
127
|
|
|
128
128
|
const importFixes =
|
|
129
129
|
index === 0 && !hasArrImport
|
|
@@ -90,7 +90,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
90
90
|
output: dedent`
|
|
91
91
|
import { Arr } from 'ts-data-forge';
|
|
92
92
|
const xs: readonly number[] = [1, 2, 3];
|
|
93
|
-
const ok = Arr.isMinLengthArray(
|
|
93
|
+
const ok = Arr.isMinLengthArray(3, xs);
|
|
94
94
|
`,
|
|
95
95
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
96
96
|
},
|
|
@@ -103,7 +103,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
103
103
|
output: dedent`
|
|
104
104
|
import { Arr } from 'ts-data-forge';
|
|
105
105
|
const xs: readonly number[] = [1, 2, 3];
|
|
106
|
-
const ok = Arr.isMinLengthArray(
|
|
106
|
+
const ok = Arr.isMinLengthArray(3, xs);
|
|
107
107
|
`,
|
|
108
108
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
109
109
|
},
|
|
@@ -116,7 +116,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
116
116
|
output: dedent`
|
|
117
117
|
import { Arr } from 'ts-data-forge';
|
|
118
118
|
const xs = [1, 2, 3];
|
|
119
|
-
const ok = Arr.isMinLengthArray(
|
|
119
|
+
const ok = Arr.isMinLengthArray(1, xs);
|
|
120
120
|
`,
|
|
121
121
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
122
122
|
},
|
|
@@ -129,7 +129,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
129
129
|
output: dedent`
|
|
130
130
|
import { Arr } from 'ts-data-forge';
|
|
131
131
|
const xs = [1, 2, 3] as const;
|
|
132
|
-
const ok = Arr.isMinLengthArray(
|
|
132
|
+
const ok = Arr.isMinLengthArray(2, xs);
|
|
133
133
|
`,
|
|
134
134
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
135
135
|
},
|
|
@@ -144,7 +144,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
144
144
|
import { Arr } from 'ts-data-forge';
|
|
145
145
|
const xs = [1, 2, 3];
|
|
146
146
|
const n = 2;
|
|
147
|
-
const ok = Arr.isMinLengthArray(
|
|
147
|
+
const ok = Arr.isMinLengthArray(n, xs);
|
|
148
148
|
`,
|
|
149
149
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
150
150
|
},
|
|
@@ -160,7 +160,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
160
160
|
import { Arr } from 'ts-data-forge';
|
|
161
161
|
|
|
162
162
|
const xs = [1, 2, 3];
|
|
163
|
-
const ok = Arr.isMinLengthArray(
|
|
163
|
+
const ok = Arr.isMinLengthArray(1, xs);
|
|
164
164
|
`,
|
|
165
165
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
166
166
|
},
|
|
@@ -176,8 +176,8 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
176
176
|
import { Arr } from 'ts-data-forge';
|
|
177
177
|
const xs = [1, 2, 3];
|
|
178
178
|
const ys = [4, 5];
|
|
179
|
-
const ok1 = Arr.isMinLengthArray(
|
|
180
|
-
const ok2 = Arr.isMinLengthArray(
|
|
179
|
+
const ok1 = Arr.isMinLengthArray(2, xs);
|
|
180
|
+
const ok2 = Arr.isMinLengthArray(1, ys);
|
|
181
181
|
`,
|
|
182
182
|
errors: [
|
|
183
183
|
{ messageId: 'useIsMinLengthArray' },
|
|
@@ -193,7 +193,7 @@ describe('prefer-arr-is-min-length-array', () => {
|
|
|
193
193
|
output: dedent`
|
|
194
194
|
import { Arr } from 'ts-data-forge';
|
|
195
195
|
const xs = [1, 2, 3];
|
|
196
|
-
const ok = Arr.isMinLengthArray(
|
|
196
|
+
const ok = Arr.isMinLengthArray(1, xs);
|
|
197
197
|
`,
|
|
198
198
|
errors: [{ messageId: 'useIsMinLengthArray' }],
|
|
199
199
|
},
|
|
@@ -61,7 +61,7 @@ export const preferArrSum: TSESLint.RuleModule<MessageIds, Options> = {
|
|
|
61
61
|
const arrayExpression = node.callee.object;
|
|
62
62
|
|
|
63
63
|
// Check if we have 2 arguments: reducer function and initial value 0
|
|
64
|
-
if (!Arr.isFixedLengthTuple(node.arguments
|
|
64
|
+
if (!Arr.isFixedLengthTuple(2, node.arguments)) return;
|
|
65
65
|
|
|
66
66
|
const reducer = node.arguments[0];
|
|
67
67
|
|
|
@@ -78,7 +78,7 @@ export const preferArrSum: TSESLint.RuleModule<MessageIds, Options> = {
|
|
|
78
78
|
// Check if reducer is an arrow function with 2 parameters
|
|
79
79
|
if (
|
|
80
80
|
reducer.type !== AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
81
|
-
!Arr.isFixedLengthTuple(reducer.params
|
|
81
|
+
!Arr.isFixedLengthTuple(2, reducer.params)
|
|
82
82
|
) {
|
|
83
83
|
return;
|
|
84
84
|
}
|