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

[array-type] add ReadonlyArray option #635

Closed
a-tarasyuk opened this issue Jun 21, 2019 · 3 comments · Fixed by #654
Closed

[array-type] add ReadonlyArray option #635

a-tarasyuk opened this issue Jun 21, 2019 · 3 comments · Fixed by #654
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@a-tarasyuk
Copy link
Contributor

Repro

// "typescript/array-type": ["error", "array"]
const x: Array<number> = [1];
// fixes to
const x: number[] = [1];
// "typescript/array-type": ["error", "ReadonlyArray"]
const x: ReadonlyArray<number> = [1];
// fixes to
const x: readonly number[] = [1];
// "typescript/array-type": ["error", "array", "ReadonlyArray"]
const x: ReadonlyArray<number> = [1];
const y: Array<number> = [1];
// fixes to
const x: readonly number[] = [1];
const y: number[] = [1];

Versions

package version
@typescript-eslint/eslint-plugin 1.10.2
@typescript-eslint/parser 1.10.2
TypeScript 3.5.2
ESLint 5.16.0
node 8.15.0
npm 6.4.1
@a-tarasyuk a-tarasyuk added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jun 21, 2019
@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look labels Jun 21, 2019
@sindresorhus
Copy link

Related to #514

@a-tarasyuk
Copy link
Contributor Author

@sindresorhus @bradzacher maybe need to close this issue in favor to #514?

@bradzacher
Copy link
Member

No - the two are distinct rules.
This is an option for array-type which enforces you use ReadonlyArray instead of readonly array[].

#514 is a new rule which enforces that function arguments are readonly where appropriate, and return values are (optionally) not.

@bradzacher bradzacher added the has pr there is a PR raised to close this label Jun 27, 2019
bradzacher pushed a commit that referenced this issue Jul 22, 2019
BREAKING CHANGE: changes config structure

```ts
type ArrayOption = 'array' | 'generic' | 'array-simple';
type Options = [
  {
    // default case for all arrays
    default: ArrayOption,
    // optional override for readonly arrays
    readonly?: ArrayOption,
  },
];
```

Fixes #635
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants