-
-
Notifications
You must be signed in to change notification settings - Fork 976
Fix custom-property-pattern
false negatives for @property
preludes
#8468
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
Fix custom-property-pattern
false negatives for @property
preludes
#8468
Conversation
🦋 Changeset detectedLatest commit: 683a0ef 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 |
Try the Instant Preview in Online DemoInstall the Instant Preview to Your Local
|
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.
Hi. Thanks for the pull request. Can you add a test case for the new behavior?
…erty at-rule names and add test cases (closes stylelint#8430)
@property
preludes
@property
preludescustom-property-pattern
false negatives for @property
preludes
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.
Thank for the quick action! Additionally, can you check my reviews?
…ts (closes stylelint#8430) - Removed unnecessary typeof additions. - Use shared regex (atRuleRegexes.propertyName) to support both lower/upper cases. - Simplified error index calculation for @Property rules by using atRuleParamIndex utility. - Added an empty line in the @Property block for clarity. - Simplified test CSS for @Property rules (e.g. '@Property --foo-bar {}') to focus on core syntax. This refactor addresses reviewer suggestions and improves code clarity and maintainability.
…loses stylelint#8430) Forgot to remove the leftover typeof additions from the code. This change cleans up the code, ensuring we only use the shared utilities and simplify the @Property handling logic as suggested.
closes stylelint#8430) Removed the "extra" parameter from the complain function since it is no longer needed after simplifying the error location calculation. This further streamlines the code and improves clarity.
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.
@rohitgs28 Thanks for making @ybiquitous suggested changes.
I've requested a couple more minor ones related to our code conventions. Otherwise, looking good thank you.
@@ -70,19 +69,26 @@ const rule = (primary) => { | |||
|
|||
complain(0, prop, decl); | |||
}); | |||
root.walkAtRules(atRuleRegexes.propertyName, (atRule) => { |
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.
Done
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.
Thanks for making the changes.
One last one, then LGTM.
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.
LGTM, thank you!
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.
Thanks LGTM 👍
@rohitgs28 Thank you for your first contribution to Stylelint 🎉 |
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.16.0 | 16.17.0 | ## [v16.17.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16170---2025-03-26) It adds 1 new rule, support for `languageOptions` to 2 rules, 1 option to a rule, the `--compute-edit-info` CLI flag (along with support for `EditInfo` in 3 rules), and fixes 1 bug. `EditInfo` is useful for automated fixing tools and editor integrations. - Added: `layer-name-pattern` rule ([#8474](stylelint/stylelint#8474)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `--compute-edit-info` CLI flag ([#8473](stylelint/stylelint#8473)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `ignorePreludeOfAtRules: []` to `length-zero-no-unit` ([#8472](stylelint/stylelint#8472)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `at-rule-no-unknown` support for `languageOptions` ([#8475](stylelint/stylelint#8475)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `property-no-unknown` support for `languageOptions` ([#8476](stylelint/stylelint#8476)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `declaration-block-no-redundant-longhand-properties` support for computing `EditInfo` ([#8482](stylelint/stylelint#8482)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `function-url-quotes` support for computing `EditInfo` ([#8483](stylelint/stylelint#8483)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-attribute-quotes` support for computing `EditInfo` ([#8484](stylelint/stylelint#8484)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Fixed: `custom-property-pattern` false negatives for `@property` preludes ([#8468](stylelint/stylelint#8468)) ([@rohitgs28](https://github.com/rohitgs28)).
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.16.0 | 16.17.0 | ## [v16.17.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16170---2025-03-26) It adds 1 new rule, support for `languageOptions` to 2 rules, 1 option to a rule, the `--compute-edit-info` CLI flag (along with support for `EditInfo` in 3 rules), and fixes 1 bug. `EditInfo` is useful for automated fixing tools and editor integrations. - Added: `layer-name-pattern` rule ([#8474](stylelint/stylelint#8474)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `--compute-edit-info` CLI flag ([#8473](stylelint/stylelint#8473)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `ignorePreludeOfAtRules: []` to `length-zero-no-unit` ([#8472](stylelint/stylelint#8472)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `at-rule-no-unknown` support for `languageOptions` ([#8475](stylelint/stylelint#8475)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `property-no-unknown` support for `languageOptions` ([#8476](stylelint/stylelint#8476)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `declaration-block-no-redundant-longhand-properties` support for computing `EditInfo` ([#8482](stylelint/stylelint#8482)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `function-url-quotes` support for computing `EditInfo` ([#8483](stylelint/stylelint#8483)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Added: `selector-attribute-quotes` support for computing `EditInfo` ([#8484](stylelint/stylelint#8484)) ([@pamelalozano16](https://github.com/pamelalozano16)). - Fixed: `custom-property-pattern` false negatives for `@property` preludes ([#8468](stylelint/stylelint#8468)) ([@rohitgs28](https://github.com/rohitgs28)).
This PR fixes issue #8430, where the custom-property-pattern rule was not reporting the correct error location for custom property names declared via @Property at-rules.
Changes
In
lib/rules/custom-property-pattern/index.mjs
, the error location calculation for @Property at-rules has been adjusted. The fix computes the base error index using the at-rule’s source column plus an offset (and optionally adds an extra offset for property names ending with a hyphen) so that the reported start and end columns match the expected values.New test cases were added to
lib/rules/custom-property-pattern/__tests__/index.mjs
to ensure that:--foo-bar
) passes.--Foo-bar
with an uppercase letter or--foo-
for an incomplete name) are flagged with the correct error location.Testing
npm run build
.npm test
and confirmed that all tests pass and the error locations in @Property at-rules now match the expected snapshots.Closes #8430.
Please let me know if any further changes are required.