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

Bug: [ban-types] <rule don't work> #5898

Closed
4 tasks done
koyoter opened this issue Oct 28, 2022 · 2 comments
Closed
4 tasks done

Bug: [ban-types] <rule don't work> #5898

koyoter opened this issue Oct 28, 2022 · 2 comments
Labels
fix: user error issue was fixed by correcting the configuration / correcting the code package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended

Comments

@koyoter
Copy link

koyoter commented Oct 28, 2022

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=4.8.4&sourceType=script&code=MYGwhgzhAEBiD29oG8CwAoa0B2YC2ApgFzQQAuATgJbYDmA3BgL4YbDzbnQBm0AvDgIB3OIgAUASkbp2neCAIA6EPFpjui3ISmsZHLmX4om02RHlKVaslKA&eslintrc=N4KABGBEACAuCeAHApgZwMYCcCWjYFo0AbbAO1gHoAjAQ1PwRVUgC4wBtcCKZTTAe0yQANFwihu3SIzSswEyVIBi-fnMgARfqQDksMAFdUyMCv5gqydDSMns+7KkOlUNAGbIRYxZADyRABMAQQAFAEk5BUUpAFs0VwBzTzZIAFVjMAA5ZAB3ULCwMlRYZBoAr2jJSDdsAA8AdXsAC3VsvPDIb0kAX1FKqGBuuTcaImMusF6JyGRaktIAjWQRgyJYZjZYTANkb26uAF0QbqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

class Foo {
  name: string;
}

const f = new Foo();
console.log(f.name);

const t = {};
console.log(t);

ESLint Config

module.exports = {
  "@typescript-eslint/ban-types": [
    "error",
    {
      "types": {
        "Foo": "Don't use Foo because it is unsafe",
        "OldAPI": {
          "message": "Use NewAPI instead",
          "fixWith": "NewAPI"
        },
        "{}": false
      },
      "extendDefaults": true
    }
  ]
}

tsconfig

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

Expected Result

expected that the should report the error "Don't use Foo because it is unsafe".

Actual Result

no error.

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 5.41.0
@typescript-eslint/parser 5.41.0
TypeScript 4.8.4
ESLint 8.15.0
node web
@koyoter koyoter added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 28, 2022
@bradzacher
Copy link
Member

The rule is called ban-TYPES. In your example your usages of Foo is as a VALUE.

The rule does not match value usages. Please checkout the rule's documentation https://typescript-eslint.io/rules/ban-types/

Here are two other rules that may be of interest to you:
https://eslint.org/docs/latest/rules/no-restricted-globals
https://eslint.org/docs/latest/rules/no-restricted-imports

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2022
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended fix: user error issue was fixed by correcting the configuration / correcting the code and removed bug Something isn't working triage Waiting for maintainers to take a look labels Oct 28, 2022
@koyoter
Copy link
Author

koyoter commented Oct 31, 2022

Thank you. Much appreciated.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fix: user error issue was fixed by correcting the configuration / correcting the code package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants