Skip to content

Commit

Permalink
feat!: rename many of the options
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Oct 4, 2022
1 parent 0753450 commit 0bc49c3
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 350 deletions.
8 changes: 4 additions & 4 deletions docs/rules/immutable-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Options = {
forArrays: boolean;
forObjects: boolean;
}
ignoreClass: boolean | "fieldsOnly";
ignoreClasses: boolean | "fieldsOnly";
ignoreImmediateMutation: boolean;
ignorePattern?: string[] | string;
ignoreAccessorPattern?: string[] | string;
Expand All @@ -75,7 +75,7 @@ type Options = {
```ts
type Options = {
assumeTypes: true;
ignoreClass: false;
ignoreClasses: false;
ignoreImmediateMutation: true;
};
```
Expand All @@ -86,7 +86,7 @@ type Options = {

```ts
const liteOptions = {
ignoreClass: "fieldsOnly",
ignoreClasses: "fieldsOnly",
}
```

Expand Down Expand Up @@ -121,7 +121,7 @@ const original = ["foo", "bar", "baz"];
const sorted = [...original].sort((a, b) => a.localeCompare(b)); // This is OK with ignoreImmediateMutation.
```

### `ignoreClass`
### `ignoreClasses`

Ignore mutations inside classes.

Expand Down
10 changes: 6 additions & 4 deletions docs/rules/no-let.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This rule accepts an options object of the following type:

```ts
type Options = {
allowLocalMutation: boolean;
allowInFunctions: boolean;
ignorePattern?: string[] | string;
}
```
Expand All @@ -63,7 +63,7 @@ type Options = {
```ts
const defaults = {
allowInForLoopInit: false,
allowLocalMutation: false
allowInFunctions: false
}
```

Expand Down Expand Up @@ -112,9 +112,11 @@ for (let [index, element] of array.entries()) {
}
```

### `allowLocalMutation`
### `allowInFunctions`

See the [allowLocalMutation](./options/allow-local-mutation.md) docs.
If true, the rule will not flag any statements that are inside of function bodies.

See the [allowLocalMutation](./options/allow-local-mutation.md) docs for more information.

### `ignorePattern`

Expand Down
10 changes: 5 additions & 5 deletions docs/rules/no-return-void.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This rule accepts an options object of the following type:
type Options = {
allowNull: boolean;
allowUndefined: boolean;
ignoreImplicit: boolean;
ignoreInferredTypes: boolean;
}
```
Expand All @@ -51,18 +51,18 @@ type Options = {
const defaults = {
allowNull: true,
allowUndefined: true,
ignoreImplicit: false,
ignoreInferredTypes: false,
}
```

### allowNull
### `allowNull`

If true allow returning null.

### allowUndefined
### `allowUndefined`

If true allow returning undefined.

### ignoreImplicit
### `ignoreInferredTypes`

If true ignore functions that don't explicitly specify a return type.
45 changes: 31 additions & 14 deletions docs/rules/prefer-immutable-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,30 @@ This rule accepts an options object of the following type:
type Options = {
enforcement: "None" | "ReadonlyShallow" | "ReadonlyDeep" | "Immutable";
ignoreInferredTypes: boolean;
ignoreClasses: boolean | "fieldsOnly";
ignorePattern?: string[] | string;

parameters?: {
// The same properties as above or just an enforcement value.
enforcement: "None" | "ReadonlyShallow" | "ReadonlyDeep" | "Immutable";
ignoreInferredTypes: boolean;
ignoreClasses: boolean | "fieldsOnly";
ignorePattern?: string[] | string;
};

returnTypes?: {
// The same properties as above or just an enforcement value.
enforcement: "None" | "ReadonlyShallow" | "ReadonlyDeep" | "Immutable";
ignoreInferredTypes: boolean;
ignoreClasses: boolean | "fieldsOnly";
ignorePattern?: string[] | string;
};

variables?: {
// The same properties as above or just an enforcement value.
enforcement: "None" | "ReadonlyShallow" | "ReadonlyDeep" | "Immutable";
allowInFunctions: boolean;
ignoreInferredTypes: boolean;
ignoreClasses: boolean | "fieldsOnly";
ignorePattern?: string[] | string;
};

allowLocalMutation: boolean;
ignoreClass: boolean | "fieldsOnly";
ignorePattern?: string[] | string;
}
```
Expand All @@ -166,7 +176,7 @@ type Options = {
const defaults = {
enforcement: "Immutable",
allowLocalMutation: false,
ignoreClass: false,
ignoreClasses: false,
ignoreInferredTypes: false,
}
```
Expand All @@ -179,7 +189,9 @@ const defaults = {
const recommendedOptions = {
enforcement: "None",
ignoreInferredTypes: true,
parameters: "ReadonlyDeep",
parameters: {
enforcement: "ReadonlyDeep",
},
},
```

Expand All @@ -189,7 +201,9 @@ const recommendedOptions = {
const liteOptions = {
enforcement: "None",
ignoreInferredTypes: true,
parameters: "ReadonlyShallow",
parameters: {
enforcement: "ReadonlyShallow",
},
},
```

Expand Down Expand Up @@ -239,6 +253,10 @@ type. This may be desirable in cases where an external dependency specifies a
callback with mutable parameters, and manually annotating the callback's
parameters is undesirable.

### `ignoreClasses`

A boolean to specify if checking classes should be ignored. `false` by default.

<!--tabs-->

#### ❌ Incorrect
Expand Down Expand Up @@ -301,13 +319,12 @@ export const acceptsCallback: AcceptsCallback;

Override the options specifically for the given type of types.

### `ignoreClass`

A boolean to specify if checking classes should be ignored. `false` by default.
#### `variables.ignoreInFunctions`

### `allowLocalMutation`
If true, the rule will not flag any variables that are inside of function bodies.

See the [allowLocalMutation](./options/allow-local-mutation.md) docs.
See the [allowLocalMutation](./options/allow-local-mutation.md) docs for more information.

### `ignorePattern`

Expand Down
86 changes: 34 additions & 52 deletions src/common/ignore-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,12 @@ import {
isThisExpression,
} from "~/util/typeguard";

/**
* The option to allow local mutations.
*/
export type AllowLocalMutationOption = {
readonly allowLocalMutation: boolean;
};

/**
* The schema for the option to allow local mutations.
*/
export const allowLocalMutationOptionSchema: JSONSchema4["properties"] = {
allowLocalMutation: {
type: "boolean",
},
};

/**
* The option to ignore patterns.
*/
export type IgnorePatternOption = {
readonly ignorePattern?: ReadonlyArray<string> | string;
};
export type IgnorePatternOption = Readonly<{
ignorePattern?: ReadonlyArray<string> | string;
}>;

/**
* The schema for the option to ignore patterns.
Expand All @@ -52,9 +36,9 @@ export const ignorePatternOptionSchema: JSONSchema4["properties"] = {
/**
* The option to ignore accessor patterns.
*/
export type IgnoreAccessorPatternOption = {
readonly ignoreAccessorPattern?: ReadonlyArray<string> | string;
};
export type IgnoreAccessorPatternOption = Readonly<{
ignoreAccessorPattern?: ReadonlyArray<string> | string;
}>;

/**
* The schema for the option to ignore accessor patterns.
Expand All @@ -71,15 +55,15 @@ export const ignoreAccessorPatternOptionSchema: JSONSchema4["properties"] = {
/**
* The option to ignore classes.
*/
export type IgnoreClassOption = {
readonly ignoreClass: boolean | "fieldsOnly";
};
export type IgnoreClassesOption = Readonly<{
ignoreClasses: boolean | "fieldsOnly";
}>;

/**
* The schema for the option to ignore classes.
*/
export const ignoreClassOptionSchema: JSONSchema4["properties"] = {
ignoreClass: {
export const ignoreClassesOptionSchema: JSONSchema4["properties"] = {
ignoreClasses: {
oneOf: [
{
type: "boolean",
Expand All @@ -95,25 +79,25 @@ export const ignoreClassOptionSchema: JSONSchema4["properties"] = {
/**
* The option to ignore interfaces.
*/
export type IgnoreInterfaceOption = {
readonly ignoreInterface: boolean;
};
export type IgnoreInterfacesOption = Readonly<{
ignoreInterfaces: boolean;
}>;

/**
* The schema for the option to ignore interfaces.
*/
export const ignoreInterfaceOptionSchema: JSONSchema4["properties"] = {
ignoreInterface: {
export const ignoreInterfacesOptionSchema: JSONSchema4["properties"] = {
ignoreInterfaces: {
type: "boolean",
},
};

/**
* The option to ignore prefix selector.
*/
export type IgnorePrefixSelectorOption = {
readonly ignorePrefixSelector?: ReadonlyArray<string> | string;
};
export type IgnorePrefixSelectorOption = Readonly<{
ignorePrefixSelector?: ReadonlyArray<string> | string;
}>;

/**
* The schema for the option to ignore prefix selector.
Expand Down Expand Up @@ -213,29 +197,29 @@ function shouldIgnoreViaAccessorPattern(
/**
* Should the given node be allowed base off the following rule options?
*
* - AllowLocalMutationOption.
* - AllowInFunctionOption.
*/
export function shouldIgnoreLocalMutation(
export function shouldIgnoreInFunction(
node: ReadonlyDeep<TSESTree.Node>,
context: ReadonlyDeep<TSESLint.RuleContext<string, BaseOptions>>,
{ allowLocalMutation }: Partial<AllowLocalMutationOption>
allowInFunction: boolean | undefined
): boolean {
return allowLocalMutation === true && inFunctionBody(node);
return allowInFunction === true && inFunctionBody(node);
}

/**
* Should the given node be allowed base off the following rule options?
*
* - IgnoreClassOption.
* - IgnoreClassesOption.
*/
export function shouldIgnoreClass(
export function shouldIgnoreClasses(
node: ReadonlyDeep<TSESTree.Node>,
context: ReadonlyDeep<TSESLint.RuleContext<string, BaseOptions>>,
{ ignoreClass }: Partial<IgnoreClassOption>
ignoreClasses: Partial<IgnoreClassesOption>["ignoreClasses"]
): boolean {
return (
(ignoreClass === true && inClass(node)) ||
(ignoreClass === "fieldsOnly" &&
(ignoreClasses === true && inClass(node)) ||
(ignoreClasses === "fieldsOnly" &&
(isPropertyDefinition(node) ||
(isAssignmentExpression(node) &&
inClass(node) &&
Expand All @@ -247,14 +231,14 @@ export function shouldIgnoreClass(
/**
* Should the given node be allowed base off the following rule options?
*
* - IgnoreInterfaceOption.
* - IgnoreInterfacesOption.
*/
export function shouldIgnoreInterface(
export function shouldIgnoreInterfaces(
node: ReadonlyDeep<TSESTree.Node>,
context: ReadonlyDeep<TSESLint.RuleContext<string, BaseOptions>>,
{ ignoreInterface }: Partial<IgnoreInterfaceOption>
ignoreInterfaces: Partial<IgnoreInterfacesOption>["ignoreInterfaces"]
): boolean {
return ignoreInterface === true && inInterface(node);
return ignoreInterfaces === true && inInterface(node);
}

/**
Expand All @@ -266,10 +250,8 @@ export function shouldIgnoreInterface(
export function shouldIgnorePattern(
node: ReadonlyDeep<TSESTree.Node>,
context: ReadonlyDeep<TSESLint.RuleContext<string, BaseOptions>>,
{
ignorePattern,
ignoreAccessorPattern,
}: Partial<IgnoreAccessorPatternOption & IgnorePatternOption>
ignorePattern: Partial<IgnorePatternOption>["ignorePattern"],
ignoreAccessorPattern?: Partial<IgnoreAccessorPatternOption>["ignoreAccessorPattern"]
): boolean {
const texts = getNodeIdentifierTexts(node, context);

Expand Down
6 changes: 4 additions & 2 deletions src/configs/lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const overrides: Linter.Config = {
],
[`functional/${immutableData.name}`]: [
"error",
{ ignoreClass: "fieldsOnly" },
{ ignoreClasses: "fieldsOnly" },
],
[`functional/${noConditionalStatements.name}`]: "off",
[`functional/${noExpressionStatements.name}`]: "off",
Expand All @@ -28,7 +28,9 @@ const overrides: Linter.Config = {
{
enforcement: "None",
ignoreInferredTypes: true,
parameters: "ReadonlyShallow",
parameters: {
enforcement: "ReadonlyShallow",
},
},
],
},
Expand Down
4 changes: 3 additions & 1 deletion src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const overrides: Linter.Config = {
{
enforcement: "None",
ignoreInferredTypes: true,
parameters: "ReadonlyDeep",
parameters: {
enforcement: "ReadonlyDeep",
},
},
],
[`functional/${typeDeclarationImmutability.name}`]: [
Expand Down
Loading

0 comments on commit 0bc49c3

Please sign in to comment.