-
-
Notifications
You must be signed in to change notification settings - Fork 51
feat: add pattern support to priority option in sort-attrs #408
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
Conversation
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.
Pull Request Overview
This PR adds pattern support to the priority option in the sort-attrs ESLint rule, addressing issue #404. The enhancement allows users to specify regular expression patterns to match attribute names in addition to exact string matches.
- Extends the priority option schema to accept objects with a
patternproperty containing regex patterns - Implements pattern matching logic using RegExp to evaluate attribute names against priority patterns
- Adds comprehensive test coverage for pattern-based priority sorting scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/eslint-plugin/lib/rules/sort-attrs.js | Core implementation adding pattern support with regex compilation and matching logic |
| packages/eslint-plugin/tests/rules/sort-attrs.test.js | Comprehensive test cases covering pattern matching scenarios for both valid and invalid cases |
| docs/rules/sort-attrs.md | Documentation updates explaining the new pattern syntax and providing usage examples |
| .cspell.json | Adds "describedby" to the spell check dictionary for test attributes |
| return { | ||
| ...item, | ||
| regex: new RegExp(item.pattern, "u"), |
Copilot
AI
Aug 11, 2025
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.
Creating RegExp objects during rule execution can impact performance. Consider validating and compiling patterns once during rule initialization or caching compiled regexes to avoid repeated compilation for the same patterns.
| return { | |
| ...item, | |
| regex: new RegExp(item.pattern, "u"), | |
| let regex = regexCache.get(item.pattern); | |
| if (!regex) { | |
| regex = new RegExp(item.pattern, "u"); | |
| regexCache.set(item.pattern, regex); | |
| } | |
| return { | |
| ...item, | |
| regex, |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #408 +/- ##
==========================================
- Coverage 98.56% 98.53% -0.03%
==========================================
Files 83 83
Lines 2716 2733 +17
Branches 756 763 +7
==========================================
+ Hits 2677 2693 +16
- Misses 39 40 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Checklist
sort-attrs#404Description