Skip to content

Bug: [no-array-constructor] Does not detect Array call with optional chaining #10933

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
JoshuaKGoldberg opened this issue Mar 10, 2025 · 2 comments · Fixed by #10963
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JoshuaKGoldberg
Copy link
Member

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.8.2&fileType=.ts&code=IIJxEME8AoEoG4BQjQUgfgHR3kA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQHYHsBaAQ2mmIE9CBjfXZAFzmof2nSnwDMvIAacNkgABBhQAOKatACW4hoRTwZuBgHoCJMpRp1GzVuwyREZNpEEBfEJaA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

Array();

Array?.();

ESLint Config

module.exports = {
  "rules": {
    "no-array-constructor": "off",
    "@typescript-eslint/no-array-constructor": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

Array?.() should be reported the same way Array() is.

Actual Result

No report.

Additional Info

Array?.() is reported in the core rule: https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgbm8tYXJyYXktY29uc3RydWN0b3I6IFwiZXJyb3JcIiovXG5cbkFycmF5KCk7XG5cbkFycmF5Py4oKTsiLCJvcHRpb25zIjp7InJ1bGVzIjp7fSwibGFuZ3VhZ2VPcHRpb25zIjp7InBhcnNlck9wdGlvbnMiOnsiZWNtYUZlYXR1cmVzIjp7fX19fX0=

💖

@JoshuaKGoldberg JoshuaKGoldberg 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 Mar 10, 2025
@bradzacher bradzacher 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 Mar 10, 2025
@developer-bandi
Copy link
Contributor

@JoshuaKGoldberg in our repo's no-array-constructor test file, similer cases are in valid case

'Array?.(0, 1, 2);',
'Array?.(x, y);',

Since both cases are throwing errors in upstream, should they be fixed the same?

Then logically, new Array, Array, Array? should all be the same.

Is this direction of fixing correct?

https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgbm8tYXJyYXktY29uc3RydWN0b3I6IFwiZXJyb3JcIiovXG5cbkFycmF5Py4oMCwgMSwgMik7XG5BcnJheT8uKHgsIHkpOyIsIm9wdGlvbnMiOnsicnVsZXMiOnt9LCJsYW5ndWFnZU9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hRmVhdHVyZXMiOnt9fX19fQ==

@JoshuaKGoldberg
Copy link
Member Author

Good spot, yup. Anything with optional chaining detected by the core rule but not in this extension rule should be.

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 8, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2025
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 locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants