eslint-plugin-ts-std-forge 0.1.14 → 0.1.15
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/package.json +5 -5
- package/src/rules/prefer-is-non-null-object.test.mts +30 -13
- package/src/rules/prefer-is-record-and-has-key.test.mts +16 -7
- package/src/rules/prefer-safe-array-is-array.test.mts +13 -6
- package/src/rules/prefer-safe-number-parse-integer.test.mts +14 -6
- package/src/rules/prefer-safe-number-parse.test.mts +15 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-ts-std-forge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ESLint rules that steer code toward ts-std-forge idioms.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@typescript-eslint/utils": "^8.72.0",
|
|
38
|
-
"eslint-rule-forge": "^0.
|
|
38
|
+
"eslint-rule-forge": "^0.4.0",
|
|
39
39
|
"ts-std-forge": "0.5.2",
|
|
40
40
|
"ts-type-forge": "~9.2.2"
|
|
41
41
|
},
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@typescript-eslint/parser": "8.72.0",
|
|
44
44
|
"@typescript-eslint/rule-tester": "8.72.0",
|
|
45
45
|
"dedent": "1.7.2",
|
|
46
|
-
"eslint-config-typed": "
|
|
47
|
-
"eslint-plugin-ts-fortress": "1.3.
|
|
48
|
-
"eslint-plugin-ts-type-forge": "0.8.
|
|
46
|
+
"eslint-config-typed": "7.1.0",
|
|
47
|
+
"eslint-plugin-ts-fortress": "1.3.10",
|
|
48
|
+
"eslint-plugin-ts-type-forge": "0.8.15",
|
|
49
49
|
"prettier": "3.9.10",
|
|
50
50
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
51
51
|
"prettier-plugin-packagejson": "3.0.2",
|
|
@@ -180,14 +180,24 @@ describe('prefer-is-non-null-object in other forms', () => {
|
|
|
180
180
|
const y = a && typeof u === 'object' && u !== null;
|
|
181
181
|
const z = a && u !== null && (typeof u === 'object') && b;
|
|
182
182
|
`,
|
|
183
|
-
output:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
output: [
|
|
184
|
+
dedent`
|
|
185
|
+
import { isNonNullObject } from 'ts-std-forge';
|
|
186
|
+
declare const a: boolean;
|
|
187
|
+
declare const b: boolean;
|
|
188
|
+
const x = isNonNullObject(u) && 'k' in u;
|
|
189
|
+
const y = a && typeof u === 'object' && u !== null;
|
|
190
|
+
const z = a && u !== null && (typeof u === 'object') && b;
|
|
191
|
+
`,
|
|
192
|
+
dedent`
|
|
193
|
+
import { isNonNullObject } from 'ts-std-forge';
|
|
194
|
+
declare const a: boolean;
|
|
195
|
+
declare const b: boolean;
|
|
196
|
+
const x = isNonNullObject(u) && 'k' in u;
|
|
197
|
+
const y = a && isNonNullObject(u);
|
|
198
|
+
const z = a && isNonNullObject(u) && b;
|
|
199
|
+
`,
|
|
200
|
+
],
|
|
191
201
|
errors: [
|
|
192
202
|
{ messageId: 'useIsNonNullObject' },
|
|
193
203
|
{ messageId: 'useIsNonNullObject' },
|
|
@@ -200,11 +210,18 @@ describe('prefer-is-non-null-object in other forms', () => {
|
|
|
200
210
|
declare const v: unknown;
|
|
201
211
|
const ok = typeof u === 'object' && u !== null && v !== null && typeof v === 'object';
|
|
202
212
|
`,
|
|
203
|
-
output:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
output: [
|
|
214
|
+
dedent`
|
|
215
|
+
import { isNonNullObject } from 'ts-std-forge';
|
|
216
|
+
declare const v: unknown;
|
|
217
|
+
const ok = isNonNullObject(u) && v !== null && typeof v === 'object';
|
|
218
|
+
`,
|
|
219
|
+
dedent`
|
|
220
|
+
import { isNonNullObject } from 'ts-std-forge';
|
|
221
|
+
declare const v: unknown;
|
|
222
|
+
const ok = isNonNullObject(u) && isNonNullObject(v);
|
|
223
|
+
`,
|
|
224
|
+
],
|
|
208
225
|
errors: [
|
|
209
226
|
{ messageId: 'useIsNonNullObject' },
|
|
210
227
|
{ messageId: 'useIsNonNullObject' },
|
|
@@ -85,13 +85,22 @@ describe('prefer-is-record-and-has-key', () => {
|
|
|
85
85
|
const a = Object.hasOwn(rec, 'a');
|
|
86
86
|
const b = Object.hasOwn(unk, 'b');
|
|
87
87
|
`,
|
|
88
|
-
output:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
output: [
|
|
89
|
+
dedent`
|
|
90
|
+
import { hasKey } from 'ts-std-forge';
|
|
91
|
+
declare const rec: Record<string, unknown>;
|
|
92
|
+
declare const unk: unknown;
|
|
93
|
+
const a = hasKey(rec, 'a');
|
|
94
|
+
const b = Object.hasOwn(unk, 'b');
|
|
95
|
+
`,
|
|
96
|
+
dedent`
|
|
97
|
+
import { hasKey, isRecord } from 'ts-std-forge';
|
|
98
|
+
declare const rec: Record<string, unknown>;
|
|
99
|
+
declare const unk: unknown;
|
|
100
|
+
const a = hasKey(rec, 'a');
|
|
101
|
+
const b = (isRecord(unk) && hasKey(unk, 'b'));
|
|
102
|
+
`,
|
|
103
|
+
],
|
|
95
104
|
errors: [
|
|
96
105
|
{ messageId: 'useHasKey' },
|
|
97
106
|
{ messageId: 'useIsRecordAndHasKey' },
|
|
@@ -67,16 +67,23 @@ ruleTester.run('prefer-safe-array-is-array', preferSafeArrayIsArray, {
|
|
|
67
67
|
errors: [{ messageId: 'useIsArray' }],
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
|
-
name: 'Replace multiple Array.isArray calls, importing
|
|
70
|
+
name: 'Replace multiple Array.isArray calls, each fix importing',
|
|
71
71
|
code: dedent`
|
|
72
72
|
const result1 = Array.isArray(value1);
|
|
73
73
|
const result2 = Array.isArray(value2);
|
|
74
74
|
`,
|
|
75
|
-
output:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
output: [
|
|
76
|
+
dedent`
|
|
77
|
+
import { SafeArray } from 'ts-std-forge';
|
|
78
|
+
const result1 = SafeArray.isArray(value1);
|
|
79
|
+
const result2 = Array.isArray(value2);
|
|
80
|
+
`,
|
|
81
|
+
dedent`
|
|
82
|
+
import { SafeArray } from 'ts-std-forge';
|
|
83
|
+
const result1 = SafeArray.isArray(value1);
|
|
84
|
+
const result2 = SafeArray.isArray(value2);
|
|
85
|
+
`,
|
|
86
|
+
],
|
|
80
87
|
errors: [{ messageId: 'useIsArray' }, { messageId: 'useIsArray' }],
|
|
81
88
|
},
|
|
82
89
|
],
|
|
@@ -147,12 +147,20 @@ describe('prefer-safe-number-parse-integer through type wrappers', () => {
|
|
|
147
147
|
const a = (parseInt as typeof parseInt)(s);
|
|
148
148
|
const b = (Number as NumberConstructor)!.parseInt(s, 10);
|
|
149
149
|
`,
|
|
150
|
-
output:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
output: [
|
|
151
|
+
dedent`
|
|
152
|
+
import { Result, SafeNumber } from 'ts-std-forge';
|
|
153
|
+
declare const s: string;
|
|
154
|
+
const a = Result.unwrapOkOr(SafeNumber.parseInteger(s), Number.NaN);
|
|
155
|
+
const b = (Number as NumberConstructor)!.parseInt(s, 10);
|
|
156
|
+
`,
|
|
157
|
+
dedent`
|
|
158
|
+
import { Result, SafeNumber } from 'ts-std-forge';
|
|
159
|
+
declare const s: string;
|
|
160
|
+
const a = Result.unwrapOkOr(SafeNumber.parseInteger(s), Number.NaN);
|
|
161
|
+
const b = Result.unwrapOkOr(SafeNumber.parseInteger(s), Number.NaN);
|
|
162
|
+
`,
|
|
163
|
+
],
|
|
156
164
|
errors: [
|
|
157
165
|
{ messageId: 'useSafeParseInt' },
|
|
158
166
|
{ messageId: 'useSafeParseInt' },
|
|
@@ -118,8 +118,7 @@ describe('prefer-safe-number-parse', () => {
|
|
|
118
118
|
const n = parseFloat(s);
|
|
119
119
|
`,
|
|
120
120
|
output: dedent`
|
|
121
|
-
import { SafeNumber } from 'ts-std-forge';
|
|
122
|
-
import { Result } from 'ts-std-forge';
|
|
121
|
+
import { Result, SafeNumber } from 'ts-std-forge';
|
|
123
122
|
declare const s: string;
|
|
124
123
|
const n = Result.unwrapOkOr(SafeNumber.parse(s), Number.NaN);
|
|
125
124
|
`,
|
|
@@ -189,12 +188,20 @@ describe('prefer-safe-number-parse through type wrappers', () => {
|
|
|
189
188
|
const a = (Number as NumberConstructor)(s);
|
|
190
189
|
const b = Number!.parseFloat(s);
|
|
191
190
|
`,
|
|
192
|
-
output:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
output: [
|
|
192
|
+
dedent`
|
|
193
|
+
import { Result, SafeNumber } from 'ts-std-forge';
|
|
194
|
+
declare const s: string;
|
|
195
|
+
const a = Result.unwrapOkOr(SafeNumber.parse(s), Number.NaN);
|
|
196
|
+
const b = Number!.parseFloat(s);
|
|
197
|
+
`,
|
|
198
|
+
dedent`
|
|
199
|
+
import { Result, SafeNumber } from 'ts-std-forge';
|
|
200
|
+
declare const s: string;
|
|
201
|
+
const a = Result.unwrapOkOr(SafeNumber.parse(s), Number.NaN);
|
|
202
|
+
const b = Result.unwrapOkOr(SafeNumber.parse(s), Number.NaN);
|
|
203
|
+
`,
|
|
204
|
+
],
|
|
198
205
|
errors: [
|
|
199
206
|
{ messageId: 'useSafeParseFloat' },
|
|
200
207
|
{ messageId: 'useSafeParseFloat' },
|