Skip to content

Bug: [array-type] the config simple-array should be disallowed by the schema #6852

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

Closed
4 tasks done
Gotos opened this issue Apr 6, 2023 · 3 comments · Fixed by #6947
Closed
4 tasks done

Bug: [array-type] the config simple-array should be disallowed by the schema #6852

Gotos opened this issue Apr 6, 2023 · 3 comments · Fixed by #6947
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@Gotos
Copy link

Gotos commented Apr 6, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.0.2&sourceType=module&code=MYewdgzgLgBAhgLhgCmgJwJZgOYwD4xgCuAtgEYCmaAlANoC6MAvDAwNwBQoksZSx5Kg2at6nbtBjAkAQTRo4ATwA86LLgIDKaAHwj2XcJIAms+UuVaqeluyA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AQ2mncNqNPRgA2pERcA9tEgAaTJAAmiAGbsE+QZGSUAtsSS1O3QpAC+AXXBgTIE0A

Repro Code

const a: (string | number)[] = [];
const b: number[] = [];
const c: Array<string | number> = [];
const d: Array<number> = [];

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  "rules": {
    "@typescript-eslint/array-type": ["error", {"default": "simple-array"}]
  }
};

tsconfig

No response

Expected Result

The constants a and d should fail the 'array-simple' rule and thus cause the following errors:

a: Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>'
d: Array type using 'Array<number>' is forbidden for simple types. Use 'number[]' instead.

Actual Result

All four constants fail the rule and cause errors. This means for example that neither number[] nor Array<number> is allowed, making it impossible to annotate array types without causing eslint error, if the "array-type" rule is configured with "simple-array".

Additional Info

No response

@Gotos Gotos added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 6, 2023
@armano2 armano2 added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Apr 6, 2023
@bradzacher
Copy link
Member

This is working as expected - you've misconfigured the rule with simple-array - but the option is actually array-simple.

The actual bug here is that the config schema doesn't reject the invalid config string.

@bradzacher bradzacher changed the title Bug: [array-type] 'array-simple' always claims array type needs to change Bug: [array-type] the config simple-array should be disallowed by the schema Apr 12, 2023
@bradzacher bradzacher added the good first issue Good for newcomers label Apr 12, 2023
@domdomegg
Copy link
Contributor

I'm going to try to pick this one up. Also including in the scope of this the other validation of the array-type rule in general (#6892).

@bradzacher
Copy link
Member

I had #6896 ready last night but I didn't push it because in fixing it I got side-tracked looking into fixing something tangentially related in json-schema-to-typescript.
Both PRs work together, @domdomegg - mine fixes the minimal schemas that need fixing and yours adds tests and tweaks other schemas, so no need to abandon or anything.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
4 participants