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]: Missing rule for removing leading/trailing spaces in className #3574

Open
2 tasks done
Kyzegs opened this issue May 9, 2023 · 5 comments
Open
2 tasks done

Comments

@Kyzegs
Copy link

Kyzegs commented May 9, 2023

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

There is no rule for removing leading/trailing white space in className.

// Incorrect
<div className=" w-100 d-flex flex-row   justify-between   align-content-center   "></div>
// Correct
<div className="w-100 d-flex flex-row justify-between align-content-center"></div>

Expected Behavior

For there to be a rule for this.

eslint-plugin-react version

v7.32.2

eslint version

v17.0.2

node version

v16.17.0

@Kyzegs Kyzegs added the bug label May 9, 2023
@ljharb
Copy link
Member

ljharb commented May 9, 2023

I'm not sure why we'd want to special-case ``className` like that - in my experience it's usually set to the return of https://www.npmjs.com/package/classnames rather than manually typing strings anyways.

@Kyzegs
Copy link
Author

Kyzegs commented May 9, 2023

How do you mean special-case? It's just so that there are no excess spaces?

@ljharb
Copy link
Member

ljharb commented May 9, 2023

I mean that this wouldn’t be a generically applicable rule to any props with string values - so className would be a special case in that it would be hardcoded in the rule.

@Kyzegs
Copy link
Author

Kyzegs commented May 9, 2023

Ah, yeah! But I would say it makes most sense for className.

@ljharb
Copy link
Member

ljharb commented May 15, 2023

I agree - except that my experience tells me it's a best practice to use a utility and not to manually type out a space-separated string, and such a utility would have trimming built in already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants