Skip to content

feat: add no-important rule#124

Merged
nzakas merged 3 commits into
eslint:mainfrom
thecalamiity:no-important
May 6, 2025
Merged

feat: add no-important rule#124
nzakas merged 3 commits into
eslint:mainfrom
thecalamiity:no-important

Conversation

@thecalamiity

@thecalamiity thecalamiity commented May 3, 2025

Copy link
Copy Markdown
Contributor

Prerequisites checklist

What is the purpose of this pull request?

This pull request introduces a new rule, no-important, which disallows the use of the !important flag in declarations.

What changes did you make? (Give an overview)

  • Implemented the no-important rule to detect and warn when !important is used.
  • Added documentation for the rule
  • Added tests

Related Issues

Closes #20, Closes #23

Is there anything you'd like reviewers to focus on?

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good. Just a few suggestions to clean things up.

Comment thread docs/rules/no-important.md Outdated
Comment thread docs/rules/no-important.md Outdated
Comment thread src/rules/no-important.js
Comment thread src/rules/no-important.js Outdated

@lumirlumir lumirlumir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, it looks good to me!

I've left a few comments for minor changes.

Comment on lines +9 to +12
- It breaks the natural cascade of CSS
- It makes debugging more difficult
- It can lead to specificity wars where developers keep adding more `!important` declarations to override each other
- It makes the code harder to maintain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- It breaks the natural cascade of CSS
- It makes debugging more difficult
- It can lead to specificity wars where developers keep adding more `!important` declarations to override each other
- It makes the code harder to maintain
- It breaks the natural cascade of CSS.
- It makes debugging more difficult.
- It can lead to specificity wars where developers keep adding more `!important` declarations to override each other.
- It makes the code harder to maintain.

I believe adding a period would be appropriate, as it is a complete sentence and the items below also end with periods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I actually think both shouldn't end with periods since they are really phrases, not complete sentences?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that would be fine too.

Comment thread src/rules/no-important.js Outdated
Comment thread src/rules/no-important.js
},

messages: {
unexpectedImportant: "Unexpected !important flag found.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unexpectedImportant: "Unexpected !important flag found.",
unexpectedImportant: "Unexpected `!important` flag found.",

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the messages from other rules don't seem to wrap code snippets with backticks. So to maintain consistency I didn't implement this change. What do you think @nzakas?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that makes sense for the internal CSS rules.

It might be better to open a separate PR to wrap code snippets in backticks, in order to follow the convention used in ESLint's internal rules.

Before proceeding, I'd like to hear thoughts from the ESLint team.

// @eslint/eslint-team

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't wrap code inside of messages in backticks. These are rarely if ever rendered using Markdown. Sometimes we use quotes around syntax, and in this case, I think it's fine in the original form.

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would like @lumirlumir to verify before merging.

@lumirlumir lumirlumir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@nzakas nzakas merged commit af043db into eslint:main May 6, 2025
22 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Complete in Triage May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

New Rule: no-important

4 participants