sort-vue-attributes
Enforce sorted attributes in Vue elements.
Ensuring a consistent order of attributes in Vue elements is essential for readability and maintainability.
This rule enforces attribute sorting, making the structure of Vue components more predictable and easier to manage. By adopting this rule, developers can maintain a high standard of code organization and clarity in their Vue projects.
Try it out
Options
This rule accepts an options object with the following properties:
type
default:'alphabetical'
Specifies the sorting method.
'alphabetical'
— Sort items alphabetically (e.g., “a” < “b” < “c”).'natural'
— Sort items in a natural order (e.g., “item2” < “item10”).'line-length'
— Sort items by the length of the code line (shorter lines first).
order
default:'asc'
Determines whether the sorted items should be in ascending or descending order.
'asc'
— Sort items in ascending order (A to Z, 1 to 9).'desc'
— Sort items in descending order (Z to A, 9 to 1).
ignoreCase
default:true
Controls whether sorting should be case-sensitive or not.
true
— Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same).false
— Consider case when sorting (e.g., “A” comes before “a”).
groups
default:[]
Allows you to specify a list of Vue attribute groups for sorting. Groups help organize attributes into categories, making your components more readable and maintainable. Multiple groups can be combined to achieve the desired sorting order.
There are predefined groups: 'multiline'
, 'shorthand'
.
Predefined Groups:
'multiline'
— Attributes with multiline values, such as event handlers or functions.'shorthand'
— Shorthand attributes, which are used without a value, typically for boolean props.'unknown'
— Vue attributes that don’t fit into any other group.
customGroups
default:{}
You can define your own groups for Vue attributes using custom glob patterns for matching.
Example:
{
groups: [
'multiline',
'unknown',
'shorthand',
+ 'callback',
],
+ customGroups: {
+ callback: 'on*'
+ }
}
matcher
default:'minimatch'
Determines the matcher used for patterns in the customGroups
option.
'minimatch'
— Use the minimatch library for pattern matching.'regex'
— Use regular expressions for pattern matching.
Usage
In order to start using this rule, you need to install additional dependency:
Version
This rule was introduced in v2.0.0.