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
Add declaration-block-no-redundant-longhand-properties
autofix
#6580
Add declaration-block-no-redundant-longhand-properties
autofix
#6580
Conversation
🦋 Changeset detectedLatest commit: 3836097 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wrapped up a draft for a first pass on this feature. Broadly, I use a similar approach to @imvetri, except:
- instead of redefining the properties, I convert the existing
longhandSubPropertiesOfShorthandProperties
to contain an (ordered) array, and then recreatelonghandSubPropertiesOfShorthandProperties
by calling theSet
constructor - hopefully reduces code de-dup while requiring few code changes outside of this PR - then, I use the orders to "replace" the prop + values of the first node where a longhand declaration was used - adjusting @imvetri's original solution
- I added fixes to each test case, leaning on the MDN docs + CSS spec to make sure my order is correct
I'd like to get feedback on:
- broadly, does this approach make sense?
- how many more tests should I write (I am considering one per shorthand)
- how am I doing with naming? I found the existing code slightly confusing to read through, but also recognize that I've added some more complexity
- am I doing TS-related stuff properly?
This is certainly a complicated-ish PR and requires a bit of double-checking. I think this PR is ready to review, but I'll certainly do some more rigorous testing (likely adding more test cases) just in case.
I will still write more test cases, but would like some feedback before I wrap them up!
@@ -42,10 +43,13 @@ const rule = (primary, secondaryOptions) => { | |||
return; | |||
} | |||
|
|||
/** @type {Map<string, string[]>} */ | |||
/** @type {Map<string, import('stylelint').ShorthandProperties[]>} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure the previous type was slightly incorrect, but could be wrong!
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js
Show resolved
Hide resolved
@mattxwang Thanks for creating the pull request, and sorry for the late reply. The
So, is it possible to use |
…bPropertiesOfShorthandProperties` explicitly
Thanks for the suggestion @ybiquitous, that's a much cleaner way to approach this! I've reverted most of the changes regarding |
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
@@ -66,6 +66,8 @@ This rule complains when the following shorthand properties can be used: | |||
|
|||
Flexbox-related properties can be ignored using `ignoreShorthands: ["/flex/"]` (see below). | |||
|
|||
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix most of the problems reported by this rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor
You could add an unfixable: true,
test to illustrate that.
Resolved two quick merge conflicts:
Final question: would we prefer more test cases ( |
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
lib/rules/declaration-block-no-redundant-longhand-properties/index.js
Outdated
Show resolved
Hide resolved
The current cases look enough, thank you. If a problem is found, then let's add cases. |
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! LGTM 👍🏼
Closes #3304.
See my review comment below - I think this probably needs some reviewing!
In particular, this PR involved me writing a lot of manual code/is prone to error.