Skip to content

Commit 6be5862

Browse files
feat!: remove assumeTypes option
1 parent e6e0823 commit 6be5862

File tree

11 files changed

+40
-272
lines changed

11 files changed

+40
-272
lines changed

docs/rules/immutable-data.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ This rule accepts an options object of the following type:
5959

6060
```ts
6161
type Options = {
62-
assumeTypes:
63-
| boolean
64-
| {
65-
forArrays: boolean;
66-
forObjects: boolean;
67-
};
6862
ignoreClasses: boolean | "fieldsOnly";
6963
ignoreImmediateMutation: boolean;
7064
ignorePattern?: string[] | string;
@@ -76,7 +70,6 @@ type Options = {
7670

7771
```ts
7872
type Options = {
79-
assumeTypes: true;
8073
ignoreClasses: false;
8174
ignoreImmediateMutation: true;
8275
};
@@ -92,25 +85,6 @@ const liteOptions = {
9285
};
9386
```
9487

95-
### `assumeTypes`
96-
97-
The rule takes advantage of TypeScript's typing engine to check if mutation is taking place.
98-
If you are not using TypeScript, type checking cannot be performed; hence this option exists.
99-
100-
This option will make the rule assume the type of the nodes it is checking are of type Array/Object.
101-
However this may result in some false positives being picked up.
102-
103-
Disabling this option can result in false negatives, for example:
104-
105-
```js
106-
// When this option is DISABLED (and type info is not available).
107-
const x = [0, 1, 2];
108-
x.push(3); // This will NOT be flagged.
109-
// This is due to the fact that without a typing engine, we cannot tell that x is an array.
110-
```
111-
112-
Note: This option will have no effect if the TypeScript typing engine is available (i.e. you are using TypeScript and have configured ESLint correctly).
113-
11488
### `ignoreImmediateMutation`
11589

11690
If true, immediate mutation of objects before they are assigned to a variable is allowed.

docs/rules/prefer-tacit.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,16 @@ This rule accepts an options object of the following type:
4545

4646
```ts
4747
type Options = {
48-
assumeTypes: boolean;
4948
ignorePattern?: string[] | string;
5049
};
5150
```
5251

5352
### Default Options
5453

5554
```ts
56-
const defaults = {
57-
assumeTypes: false,
58-
};
59-
```
60-
61-
### `assumeTypes`
62-
63-
The rule takes advantage of TypeScript's typing engine to check if callback wrapper is in fact safe to remove.
64-
65-
This option will make the rule assume that the function only accepts the arguments given to it in the wrapper.
66-
However this may result in some false positives being picked up.
67-
68-
<!-- eslint-disable functional/prefer-tacit -->
69-
70-
```js
71-
const foo = (x) => f(x); // If `f` only accepts one parameter then this is violation of the rule.
72-
const bar = foo(1, 2, 3); // But if `f` accepts more than one parameter then it isn't.
55+
const defaults = {};
7356
```
7457

75-
Note: Enabling this option is the only way to get this rule to report violations in an environment without TypeScript's typing engine available (e.g. In Vanilla JS).
76-
7758
### `ignorePattern`
7859

7960
See the [ignorePattern](./options/ignore-pattern.md) docs.

src/configs/all.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const config: Linter.Config = {
3636
[`functional/${noTryStatements.name}`]: "error",
3737
[`functional/${preferImmutableTypes.name}`]: "error",
3838
[`functional/${preferPropertySignatures.name}`]: "error",
39-
[`functional/${preferTacit.name}`]: ["warn", { assumeTypes: true }],
39+
[`functional/${preferTacit.name}`]: "warn",
4040
[`functional/${readonlyType.name}`]: "error",
4141
[`functional/${typeDeclarationImmutability.name}`]: "error",
4242
},

src/configs/stylistic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as readonlyType from "~/rules/readonly-type";
77
const config: Linter.Config = {
88
rules: {
99
[`functional/${preferPropertySignatures.name}`]: "error",
10-
[`functional/${preferTacit.name}`]: ["warn", { assumeTypes: true }],
10+
[`functional/${preferTacit.name}`]: "warn",
1111
[`functional/${readonlyType.name}`]: "error",
1212
},
1313
};

src/rules/immutable-data.ts

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ type Options = [
4949
IgnoreClassesOption &
5050
IgnorePatternOption & {
5151
ignoreImmediateMutation: boolean;
52-
assumeTypes:
53-
| boolean
54-
| {
55-
forArrays: boolean;
56-
forObjects: boolean;
57-
};
5852
},
5953
];
6054

@@ -72,25 +66,6 @@ const schema: JSONSchema4[] = [
7266
ignoreImmediateMutation: {
7367
type: "boolean",
7468
},
75-
assumeTypes: {
76-
oneOf: [
77-
{
78-
type: "boolean",
79-
},
80-
{
81-
type: "object",
82-
properties: {
83-
forArrays: {
84-
type: "boolean",
85-
},
86-
forObjects: {
87-
type: "boolean",
88-
},
89-
},
90-
additionalProperties: false,
91-
},
92-
],
93-
},
9469
} satisfies JSONSchema4ObjectSchema["properties"],
9570
),
9671
additionalProperties: false,
@@ -104,10 +79,6 @@ const defaultOptions: Options = [
10479
{
10580
ignoreClasses: false,
10681
ignoreImmediateMutation: true,
107-
assumeTypes: {
108-
forArrays: true,
109-
forObjects: true,
110-
},
11182
},
11283
];
11384

@@ -286,18 +257,13 @@ function checkUpdateExpression(
286257
function isInChainCallAndFollowsNew(
287258
node: TSESTree.MemberExpression,
288259
context: Readonly<RuleContext<keyof typeof errorMessages, Options>>,
289-
assumeArrayTypes: boolean,
290260
): boolean {
291261
return (
292262
// Check for: [0, 1, 2]
293263
isArrayExpression(node.object) ||
294264
// Check for: new Array()
295265
(isNewExpression(node.object) &&
296-
isArrayConstructorType(
297-
getTypeOfNode(node.object.callee, context),
298-
assumeArrayTypes,
299-
node.object.callee,
300-
)) ||
266+
isArrayConstructorType(getTypeOfNode(node.object.callee, context))) ||
301267
(isCallExpression(node.object) &&
302268
isMemberExpression(node.object.callee) &&
303269
isIdentifier(node.object.callee.property) &&
@@ -307,8 +273,6 @@ function isInChainCallAndFollowsNew(
307273
) &&
308274
isArrayConstructorType(
309275
getTypeOfNode(node.object.callee.object, context),
310-
assumeArrayTypes,
311-
node.object.callee.object,
312276
)) ||
313277
// Check for: array.slice(0)
314278
arrayNewObjectReturningMethods.some(
@@ -346,37 +310,21 @@ function checkCallExpression(
346310
};
347311
}
348312

349-
const { assumeTypes, ignoreImmediateMutation } = optionsObject;
350-
351-
const assumeTypesForArrays =
352-
assumeTypes === true ||
353-
(assumeTypes !== false && assumeTypes.forArrays === true);
313+
const { ignoreImmediateMutation } = optionsObject;
354314

355315
// Array mutation?
356316
if (
357317
arrayMutatorMethods.has(node.callee.property.name) &&
358318
(!ignoreImmediateMutation ||
359-
!isInChainCallAndFollowsNew(
360-
node.callee,
361-
context,
362-
assumeTypesForArrays,
363-
)) &&
364-
isArrayType(
365-
getTypeOfNode(node.callee.object, context),
366-
assumeTypesForArrays,
367-
node.callee.object,
368-
)
319+
!isInChainCallAndFollowsNew(node.callee, context)) &&
320+
isArrayType(getTypeOfNode(node.callee.object, context))
369321
) {
370322
return {
371323
context,
372324
descriptors: [{ node, messageId: "array" }],
373325
};
374326
}
375327

376-
const assumeTypesForObjects =
377-
assumeTypes === true ||
378-
(assumeTypes !== false && assumeTypes.forObjects === true);
379-
380328
// Non-array object mutation (ex. Object.assign on identifier)?
381329
if (
382330
objectConstructorMutatorFunctions.has(node.callee.property.name) &&
@@ -390,11 +338,7 @@ function checkCallExpression(
390338
ignorePattern,
391339
ignoreAccessorPattern,
392340
) &&
393-
isObjectConstructorType(
394-
getTypeOfNode(node.callee.object, context),
395-
assumeTypesForObjects,
396-
node.callee.object,
397-
)
341+
isObjectConstructorType(getTypeOfNode(node.callee.object, context))
398342
) {
399343
return {
400344
context,

src/rules/prefer-tacit.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { TSESTree } from "@typescript-eslint/utils";
2-
import {
3-
type JSONSchema4,
4-
type JSONSchema4ObjectSchema,
5-
} from "@typescript-eslint/utils/json-schema";
2+
import { type JSONSchema4 } from "@typescript-eslint/utils/json-schema";
63
import {
74
type RuleFix,
85
type RuleFixer,
96
type RuleContext,
107
type ReportDescriptor,
118
type ReportSuggestionArray,
129
} from "@typescript-eslint/utils/ts-eslint";
13-
import { deepmerge } from "deepmerge-ts";
1410
import * as semver from "semver";
1511
import { type Type } from "typescript";
1612

@@ -42,35 +38,23 @@ export const name = "prefer-tacit" as const;
4238
/**
4339
* The options this rule can take.
4440
*/
45-
type Options = [
46-
IgnorePatternOption & {
47-
assumeTypes: boolean;
48-
},
49-
];
41+
type Options = [IgnorePatternOption];
5042

5143
/**
5244
* The schema for the rule options.
5345
*/
5446
const schema: JSONSchema4[] = [
5547
{
5648
type: "object",
57-
properties: deepmerge(ignorePatternOptionSchema, {
58-
assumeTypes: {
59-
type: "boolean",
60-
},
61-
} satisfies JSONSchema4ObjectSchema["properties"]),
49+
properties: ignorePatternOptionSchema,
6250
additionalProperties: false,
6351
},
6452
];
6553

6654
/**
6755
* The default options for the rule.
6856
*/
69-
const defaultOptions: Options = [
70-
{
71-
assumeTypes: false,
72-
},
73-
];
57+
const defaultOptions: Options = [{}];
7458

7559
/**
7660
* The possible error messages.
@@ -213,8 +197,6 @@ function getCallDescriptors(
213197
options: Options,
214198
caller: TSESTree.CallExpression,
215199
): Array<ReportDescriptor<keyof typeof errorMessages>> {
216-
const [{ assumeTypes }] = options;
217-
218200
if (
219201
node.params.length === caller.arguments.length &&
220202
node.params.every((param, index) => {
@@ -227,14 +209,8 @@ function getCallDescriptors(
227209
})
228210
) {
229211
const calleeType = getTypeOfNode(caller.callee, context);
230-
const assumingTypes =
231-
(calleeType === null || (calleeType.symbol as unknown) === undefined) &&
232-
assumeTypes;
233212

234-
if (
235-
assumingTypes ||
236-
(calleeType !== null && isCallerViolation(caller, calleeType, context))
237-
) {
213+
if (calleeType !== null && isCallerViolation(caller, calleeType, context)) {
238214
return [
239215
{
240216
node,

0 commit comments

Comments
 (0)