Skip to content

Commit

Permalink
Merge pull request #11 from forivall/feat/override-ignore
Browse files Browse the repository at this point in the history
feat: allow ignoring in an override
  • Loading branch information
forivall committed Jan 8, 2024
2 parents c9d7ee3 + 3e42af5 commit 0e3ab49
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
58 changes: 58 additions & 0 deletions __tests__/lib/rules/sort-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,33 @@ const test = {
},
],
},
{
code: 'var obj = {a:1, b:{y:1, $:1, a:1}, c:1}',
options: [
'asc',
{
overrides: [
{
properties: ['b'],
ignore: true,
},
],
},
],
},
{
code: 'var obj = {a:1, b:{y:1, $:1}, c:1}',
options: [
'asc',
{
overrides: [
{
order: ['y', '$'],
},
],
},
],
},

// shorthand first
{
Expand Down Expand Up @@ -1040,6 +1067,37 @@ const test = {
errors: ["CUSTOM_MESSAGE 'y' should be before '$'."],
output: 'var obj = {a:1, b:{y:1, $:1, a:1}, c:1}',
},
{
code: 'var obj = {a:1, b:{y:1, $:1, a:1}, c:1}',
options: [
'asc',
{
overrides: [
{
order: ['y', '$'],
},
],
},
],
errors: ["Expected object keys to be in ascending order. '$' should be before 'y'."],
output: 'var obj = {a:1, b:{$:1, y:1, a:1}, c:1}',
},
{
code: 'var obj = {a:1, c:1, b:{y:1, $:1, a:1}}',
options: [
'asc',
{
overrides: [
{
properties: ['b'],
ignore: true,
},
],
},
],
errors: ["Expected object keys to be in ascending order. 'b' should be before 'c'."],
output: 'var obj = {a:1, b:{y:1, $:1, a:1}, c:1}',
},

// ALL_CAPS first
{
Expand Down
18 changes: 16 additions & 2 deletions lib/rules/sort-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ module.exports = {
type: 'array',
items: {
type: 'object',
required: ['order'],
properties: {
message: { type: 'string' },
order: {
Expand All @@ -371,7 +370,22 @@ module.exports = {
minLength: 1,
items: { type: 'string' },
},
sort: {
properties: {
ignore: {
type: 'boolean',
},
},
},
},
$anyOf: [
{
required: ['order'],
},
{
required: ['properties', 'ignore'],
},
],
},
default: [],
},
Expand Down Expand Up @@ -500,7 +514,7 @@ module.exports = {
SpreadElement,

Property(node) {
if (node.parent.type === 'ObjectPattern' || stack.ignore) {
if (node.parent.type === 'ObjectPattern' || stack.ignore || (stack.override && stack.override.ignore)) {
return
}

Expand Down

0 comments on commit 0e3ab49

Please sign in to comment.