Appearance
vue/sort-keys
以与组件顺序兼容的方式强制排序键
¥enforce sort-keys in a manner that is compatible with order-in-components
此规则与核心 sort-keys 规则几乎相同,但它不会在顶层组件属性上出错,从而允许使用 order-in-components
强制执行该顺序。
¥This rule is almost the same rule as core sort-keys rule but it will not error on top component properties allowing that order to be enforced with order-in-components
.
📖 规则详情
此规则强制许多字典属性按字母顺序排列,同时允许 order-in-components
、属性详细信息和其他类似字段不按字母顺序排列。
¥This rule forces many dictionary properties to be in alphabetical order while allowing order-in-components
, property details, and other similar fields not to be in alphabetical order.
🔧选项
¥🔧 Options
json
{
"vue/sort-keys": ["error", "asc", {
"caseSensitive": true,
"ignoreChildrenOf": ["model"],
"ignoreGrandchildrenOf": ["computed", "directives", "inject", "props", "watch"],
"minKeys": 2,
"natural": false
}]
}
第一个选项是 "asc"
或 "desc"
。
¥The 1st option is "asc"
or "desc"
.
"asc"
(默认) - 强制属性按升序排列。¥
"asc"
(default) - enforce properties to be in ascending order."desc"
- 强制属性按降序排列。¥
"desc"
- enforce properties to be in descending order.
第二个选项是一个具有 5 个属性的对象。
¥The 2nd option is an object which has 5 properties.
caseSensitive
- 如果true
,则强制属性区分大小写。默认值为true
。¥
caseSensitive
- iftrue
, enforce properties to be in case-sensitive order. Default istrue
.ignoreChildrenOf
- 要忽略子级的属性数组。默认值为["model"]
¥
ignoreChildrenOf
- an array of properties to ignore the children of. Default is["model"]
ignoreGrandchildrenOf
- 要忽略孙级排序顺序的属性数组。默认值为["computed", "directives", "inject", "props", "watch"]
¥
ignoreGrandchildrenOf
- an array of properties to ignore the grandchildren sort order. Default is["computed", "directives", "inject", "props", "watch"]
minKeys
- 指定对象应具有的最小键数,以便对象的未排序键产生错误。默认值为2
,这意味着默认情况下所有具有未排序键的对象都会导致 lint 错误。¥
minKeys
- Specifies the minimum number of keys that an object should have in order for the object's unsorted keys to produce an error. Default is2
, which means by default all objects with unsorted keys will result in lint errors.natural
- 如果true
,则强制属性按自然顺序排列。默认值为false
。自然顺序以人类排序的方式比较包含字母和数字组合的字符串。它基本上按数字排序,而不是按字母顺序排序。因此,在自然排序中,数字 10 位于数字 3 之后。¥
natural
- iftrue
, enforce properties to be in natural order. Default isfalse
. Natural Order compares strings containing combination of letters and numbers in the way a human being would sort. It basically sorts numerically, instead of sorting alphabetically. So the number 10 comes after the number 3 in Natural Sorting.
使用此规则时,你可以禁用正常的 sort-keys
规则。此规则将适用于纯 js 文件以及 Vue 组件脚本。
¥While using this rule, you may disable the normal sort-keys
rule. This rule will apply to plain js files as well as Vue component scripts.
📚扩展阅读
¥📚 Further Reading
🚀版本
¥🚀 Version
此规则在 eslint-plugin-vue v6.2.0 中引入
¥This rule was introduced in eslint-plugin-vue v6.2.0
🔍代码实现
¥🔍 Implementation