Skip to content

Enhancement: [ban-types] Rule does not trigger with comments inside type object #8735

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
yuki2006 opened this issue Mar 20, 2024 · 1 comment
Closed
4 tasks done
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule 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 working as intended Issues that are closed as they are working as intended

Comments

@yuki2006
Copy link

yuki2006 commented Mar 20, 2024

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/ban-types/

Description

https://typescript-eslint.io/play/#ts=5.4.2&fileType=.ts&code=C4TwDgpgBANg9gdwgJwPICMBWUC8UDeAUFFAPSlQAWcA5hIQL4DchhoksiKGmATLgWaEgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AIwEMnajTUMkRNGgB7aJHBgAviGlA&tsconfig=&tokens=false

I believe this behavior might be unintended, as the presence of comments should ideally not affect the linting rules for identifying empty object types. It would be beneficial for code quality and consistency if the ban-types rule could be enhanced to trigger an error regardless of the presence of comments within the type object.

I propose an enhancement to the ban-types rule to ensure it consistently identifies and flags empty object types, even when comments are present inside the type declaration. This change would help developers maintain higher code standards and avoid potential issues related to the use of empty object types in TypeScript.

Thank you for considering this enhancement to the ban-types rule. I believe it will make a valuable contribution to the robustness and consistency of TypeScript linting with ESLint.

Fail

type lowerObj = {
  // Expecting a lint error"
};

Pass

type lowerObj2 = {};

Additional Info

No response

@yuki2006 yuki2006 added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 20, 2024
@bradzacher
Copy link
Member

This is expected - the rule just matches on raw strings.
It's simplistic by design - it relies on a very fast heuristic to match banned names - specifically it removes the spaces from the found type name and the configured type name and it compares the two.

At this point in time we're not looking to do anything more complex than that.
Additionally we're considering splitting {} out into its own rule (#8700).
So I'm going to close this as working as intended.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed triage Waiting for team members to take a look labels Mar 20, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2024
@bradzacher bradzacher 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 14, 2025
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 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 working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants