Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule: prefer-readonly-return-types #317

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion .eslintrc.json
Expand Up @@ -39,6 +39,7 @@
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"import/no-relative-parent-imports": "error",
"functional/prefer-readonly-type": "off",
"node/no-unsupported-features/es-builtins": "off",
"node/no-unsupported-features/es-syntax": "off",
"promise/prefer-await-to-callbacks": "off",
Expand All @@ -57,7 +58,44 @@
{
"files": ["./src/**/*"],
"extends": ["plugin:eslint-plugin/recommended"],
"rules": {}
"rules": {
"functional/no-expression-statement": "error"
}
},
// Rule util file.
{
"files": ["./src/util/rule.ts"],
"rules": {
"@typescript-eslint/prefer-readonly-parameter-types": "warn"
}
},
// Typeguard files.
{
"files": ["./src/util/typeguard.ts"],
"rules": {
"jsdoc/require-jsdoc": "off"
}
},
// Test files.
{
"files": ["./tests/**/*"],
"rules": {
"jsdoc/require-jsdoc": "off"
}
},
// CZ Adapter files.
{
"files": ["./cz-adapter/**/*"],
"rules": {
"jsdoc/require-jsdoc": "off"
}
},
{
"files": ["**/*.md/**"],
"rules": {
"@typescript-eslint/array-type": "off",
"functional/no-mixed-type": "off"
}
},
// FIXME: This override is defined in the upsteam; it shouldn't need to be redefined here. Why?
{
Expand Down
13 changes: 7 additions & 6 deletions README.md
Expand Up @@ -186,12 +186,13 @@ The [below section](#supported-rules) gives details on which rules are enabled b

:see_no_evil: = `no-mutations` Ruleset.

| Name | Description | <span title="No Mutations">:see_no_evil:</span> | <span title="Lite">:hear_no_evil:</span> | <span title="Recommended">:speak_no_evil:</span> | :wrench: | :blue_heart: |
| -------------------------------------------------------------- | -------------------------------------------------------------------------- | :---------------------------------------------: | :--------------------------------------: | :----------------------------------------------: | :------: | :---------------: |
| [`immutable-data`](./docs/rules/immutable-data.md) | Disallow mutating objects and arrays | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :blue_heart: |
| [`no-let`](./docs/rules/no-let.md) | Disallow mutable variables | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| [`no-method-signature`](./docs/rules/no-method-signature.md) | Enforce property signatures with readonly modifiers over method signatures | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :thought_balloon: |
| [`prefer-readonly-type`](./docs/rules/prefer-readonly-type.md) | Use readonly types and readonly modifiers where possible | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :wrench: | :thought_balloon: |
| Name | Description | <span title="No Mutations">:see_no_evil:</span> | <span title="Lite">:hear_no_evil:</span> | <span title="Recommended">:speak_no_evil:</span> | :wrench: | :blue_heart: |
| ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | :---------------------------------------------: | :--------------------------------------: | :----------------------------------------------: | :------: | :---------------: |
| [`immutable-data`](./docs/rules/immutable-data.md) | Disallow mutating objects and arrays | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :blue_heart: |
| [`no-let`](./docs/rules/no-let.md) | Disallow mutable variables | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| [`no-method-signature`](./docs/rules/no-method-signature.md) | Enforce property signatures with readonly modifiers over method signatures | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :thought_balloon: |
| [`prefer-readonly-type`](./docs/rules/prefer-readonly-type.md) | Use readonly types and readonly modifiers where possible | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :wrench: | :thought_balloon: |
| [`prefer-readonly-return-types`](./docs/rules/prefer-readonly-return-types.md) | Enforce use of readonly types for function return values | | | | | :thought_balloon: |

### No Object-Orientation Rules

Expand Down
20 changes: 10 additions & 10 deletions cz-adapter/engine.ts
Expand Up @@ -5,16 +5,16 @@ import { rules } from "~/rules";

import type { Options } from "./options";

type Answers = {
readonly type: string;
readonly scope?: string;
readonly scopeRules?: string;
readonly subject: string;
readonly body?: string;
readonly isBreaking: boolean;
readonly isIssueAffected: boolean;
readonly issues?: string;
};
type Answers = Readonly<{
type: string;
scope?: string;
scopeRules?: string;
subject: string;
body?: string;
isBreaking: boolean;
isIssueAffected: boolean;
issues?: string;
}>;

type CZ = any;

Expand Down
17 changes: 9 additions & 8 deletions cz-adapter/options.ts
@@ -1,4 +1,5 @@
import { types as conventionalCommitTypes } from "conventional-commit-types";
import type { ReadonlyDeep } from "type-fest";

// Override the descriptions of some of the types.
const types = {
Expand Down Expand Up @@ -48,13 +49,13 @@ const types = {
},
};

const defaults: {
readonly defaultType: string | undefined;
readonly defaultScope: string | undefined;
readonly defaultSubject: string | undefined;
readonly defaultBody: string | undefined;
readonly defaultIssues: string | undefined;
} = {
const defaults: Readonly<{
defaultType: string | undefined;
defaultScope: string | undefined;
defaultSubject: string | undefined;
defaultBody: string | undefined;
defaultIssues: string | undefined;
}> = {
defaultType: process.env.CZ_TYPE,
defaultScope: process.env.CZ_SCOPE,
defaultSubject: process.env.CZ_SUBJECT,
Expand All @@ -71,6 +72,6 @@ const options = {
maxLineWidth: 100,
};

export type Options = typeof options;
export type Options = ReadonlyDeep<typeof options>;

export default options;
2 changes: 1 addition & 1 deletion docs/rules/functional-parameters.md
Expand Up @@ -112,7 +112,7 @@ Any function that take takes multiple parameter can be rewritten as a higher-ord

Example:

<!-- eslint-disable no-redeclare -->
<!-- eslint-disable @typescript-eslint/no-redeclare -->

```js
// This function
Expand Down