-
-
Notifications
You must be signed in to change notification settings - Fork 681
New Rule vue/sort-keys #997
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
49b4486
sort keys
055f26d
fix for eslint 6.7
6b5be10
Merge branch 'master' into vue-sort-keys
loren138 273c68a
ignore children/grandchildren
bd071ea
more finegrained parent analysis
50404e9
expand the test
3630bf4
Update docs/rules/sort-keys.md
loren138 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/sort-keys | ||
description: enforce sort-keys in a manner that is compatible with order-in-components | ||
--- | ||
# vue/sort-keys | ||
> enforce sort-keys within components after the top level details | ||
|
||
This rule is almost the same rule as core [sorts-keys] rule but it will not error on top component properties allowing that order to be enforced with `order-in-components`. | ||
|
||
## Options | ||
|
||
```json | ||
{ | ||
"sort-keys": ["error", "asc", { | ||
"caseSensitive": true, | ||
"ignoreChildrenOf": ["model"], | ||
"ignoreGrandchildrenOf": ["computed", "directives", "inject", "props", "watch"], | ||
"minKeys": 2, | ||
"natural": false | ||
}] | ||
} | ||
``` | ||
|
||
The 1st option is `"asc"` or `"desc"`. | ||
|
||
* `"asc"` (default) - enforce properties to be in ascending order. | ||
* `"desc"` - enforce properties to be in descending order. | ||
|
||
The 2nd option is an object which has 5 properties. | ||
|
||
* `caseSensitive` - if `true`, enforce properties to be in case-sensitive order. Default is `true`. | ||
* `ignoreChildrenOf` - an array of properties to ignore the children of. Default is `["model"]` | ||
* `ignoreGrandchildrenOf` - an array of properties to ignore the grandchildren sort order. Default is `["computed", "directives", "inject", "props", "watch"]` | ||
* `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 is `2`, which means by default all objects with unsorted keys will result in lint errors. | ||
* `natural` - if `true`, enforce properties to be in natural order. Default is `false`. 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. | ||
|
||
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. | ||
|
||
## :book: Rule Details | ||
|
||
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. | ||
|
||
<eslint-code-block fix :rules="{'vue/sort-keys': ['error']}"> | ||
|
||
```vue | ||
<script> | ||
/* ✓ GOOD */ | ||
export default { | ||
name: 'app', | ||
model: { | ||
prop: 'checked', | ||
event: 'change' | ||
}, | ||
props: { | ||
propA: { | ||
type: String, | ||
default: 'abc', | ||
}, | ||
propB: { | ||
type: String, | ||
default: 'abc', | ||
}, | ||
}, | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
<eslint-code-block fix :rules="{'vue/sort-keys': ['error']}"> | ||
|
||
```vue | ||
<script> | ||
/* ✗ BAD */ | ||
export default { | ||
name: 'app', | ||
model: { | ||
prop: 'checked', | ||
event: 'change' | ||
}, | ||
props: { | ||
propB: { | ||
type: String, | ||
default: 'abc', | ||
}, | ||
propA: { | ||
type: String, | ||
default: 'abc', | ||
}, | ||
}, | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :books: Further reading | ||
|
||
- [sorts-keys] | ||
|
||
[sort-keys]: https://eslint.org/docs/rules/sort-keys | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/sort-keys.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/sort-keys.js) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
EsLint 6.7.0 changes eslintignore parsing. The previous one seems to have ignored the whole folder which I'm now explicitly doing. Otherwise, you get errors about eslint-plugin-ignore not being installed when running
npm run lint
after a clean install.