Skip to content

Commit 87a48ff

Browse files
refactor!(prefer-readonly-type): change checkImplicit option to be more expicit of what it does
BREAKING CHANGE: option checkImplicit changed to checkForImplicitMutableArrays
1 parent 0e2c490 commit 87a48ff

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/rules/prefer-readonly-type.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Options = AllowLocalMutationOption &
3939
IgnoreInterfaceOption &
4040
IgnorePatternOption & {
4141
readonly allowMutableReturnType: boolean;
42-
readonly checkImplicit: boolean;
42+
readonly checkForImplicitMutableArrays: boolean;
4343
readonly ignoreCollections: boolean;
4444
};
4545

@@ -56,7 +56,7 @@ const schema: JSONSchema4 = [
5656
allowMutableReturnType: {
5757
type: "boolean",
5858
},
59-
checkImplicit: {
59+
checkForImplicitMutableArrays: {
6060
type: "boolean",
6161
},
6262
ignoreCollections: {
@@ -70,7 +70,7 @@ const schema: JSONSchema4 = [
7070

7171
// The default options for the rule.
7272
const defaultOptions: Options = {
73-
checkImplicit: false,
73+
checkForImplicitMutableArrays: false,
7474
ignoreClass: false,
7575
ignoreInterface: false,
7676
ignoreCollections: false,
@@ -255,7 +255,7 @@ function checkProperty(
255255
/**
256256
* Check if the given TypeReference violates this rule.
257257
*/
258-
function checkImplicitType(
258+
function checkForImplicitMutableArray(
259259
node:
260260
| TSESTree.ArrowFunctionExpression
261261
| TSESTree.FunctionDeclaration
@@ -264,7 +264,7 @@ function checkImplicitType(
264264
context: RuleContext<keyof typeof errorMessages, Options>,
265265
options: Options
266266
): RuleResult<keyof typeof errorMessages, Options> {
267-
if (options.checkImplicit) {
267+
if (options.checkForImplicitMutableArrays) {
268268
type Declarator = {
269269
readonly id: TSESTree.Node;
270270
readonly init: TSESTree.Node | null;
@@ -324,17 +324,17 @@ export const rule = createRule<keyof typeof errorMessages, Options>(
324324
meta,
325325
defaultOptions,
326326
{
327-
ArrowFunctionExpression: checkImplicitType,
327+
ArrowFunctionExpression: checkForImplicitMutableArray,
328328
ClassProperty: checkProperty,
329-
FunctionDeclaration: checkImplicitType,
330-
FunctionExpression: checkImplicitType,
329+
FunctionDeclaration: checkForImplicitMutableArray,
330+
FunctionExpression: checkForImplicitMutableArray,
331331
TSArrayType: checkArrayOrTupleType,
332332
TSIndexSignature: checkProperty,
333333
TSParameterProperty: checkProperty,
334334
TSPropertySignature: checkProperty,
335335
TSTupleType: checkArrayOrTupleType,
336336
TSMappedType: checkMappedType,
337337
TSTypeReference: checkTypeReference,
338-
VariableDeclaration: checkImplicitType,
338+
VariableDeclaration: checkForImplicitMutableArray,
339339
}
340340
);

tests/rules/prefer-readonly-type/ts/invalid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ const tests: ReadonlyArray<InvalidTestCase> = [
507507
code: dedent`
508508
const foo = [1, 2, 3]
509509
function bar(param = [1, 2, 3]) {}`,
510-
optionsSet: [[{ checkImplicit: true }]],
510+
optionsSet: [[{ checkForImplicitMutableArrays: true }]],
511511
output: dedent`
512512
const foo: readonly unknown[] = [1, 2, 3]
513513
function bar(param: readonly unknown[] = [1, 2, 3]) {}`,

tests/rules/prefer-readonly-type/ts/valid.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const tests: ReadonlyArray<ValidTestCase> = [
142142
{
143143
code: dedent`
144144
const foo = [1, 2, 3] as const`,
145-
optionsSet: [[{ checkImplicit: true }]],
145+
optionsSet: [[{ checkForImplicitMutableArrays: true }]],
146146
},
147147
// Should not fail on implicit Array.
148148
{
@@ -357,7 +357,9 @@ const tests: ReadonlyArray<ValidTestCase> = [
357357
},
358358
{
359359
code: dedent`const Foo = []`,
360-
optionsSet: [[{ ignoreCollections: true, checkImplicit: true }]],
360+
optionsSet: [
361+
[{ ignoreCollections: true, checkForImplicitMutableArrays: true }],
362+
],
361363
},
362364
{
363365
code: dedent`type Foo = [string, string];`,
@@ -369,7 +371,9 @@ const tests: ReadonlyArray<ValidTestCase> = [
369371
},
370372
{
371373
code: dedent`const Foo = ['foo', 'bar'];`,
372-
optionsSet: [[{ ignoreCollections: true, checkImplicit: true }]],
374+
optionsSet: [
375+
[{ ignoreCollections: true, checkForImplicitMutableArrays: true }],
376+
],
373377
},
374378
{
375379
code: dedent`type Foo = Set<string, string>;`,

0 commit comments

Comments
 (0)