Skip to content

Commit

Permalink
fix: prohibit nonsensical configurations using the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius authored and ljharb committed Jan 26, 2025
1 parent 4f145a2 commit 9900388
Showing 1 changed file with 80 additions and 28 deletions.
108 changes: 80 additions & 28 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,12 @@ module.exports = {
properties: {
groups: {
type: 'array',
// Verified manually in the convertGroupsToRanks function
},
pathGroupsExcludedImportTypes: {
type: 'array',
uniqueItems: true,
items: { enum: types },
},
distinctGroup: {
type: 'boolean',
Expand Down Expand Up @@ -918,27 +921,28 @@ module.exports = {
},
named: {
default: false,
oneOf: [{
type: 'boolean',
}, {
type: 'object',
properties: {
enabled: { type: 'boolean' },
import: { type: 'boolean' },
export: { type: 'boolean' },
require: { type: 'boolean' },
cjsExports: { type: 'boolean' },
types: {
type: 'string',
enum: [
'mixed',
'types-first',
'types-last',
],
oneOf: [
{ type: 'boolean' },
{
type: 'object',
properties: {
enabled: { type: 'boolean' },
import: { type: 'boolean' },
export: { type: 'boolean' },
require: { type: 'boolean' },
cjsExports: { type: 'boolean' },
types: {
type: 'string',
enum: [
'mixed',
'types-first',
'types-last',
],
},
},
additionalProperties: false,
},
additionalProperties: false,
}],
],
},
alphabetize: {
type: 'object',
Expand All @@ -965,24 +969,72 @@ module.exports = {
},
additionalProperties: false,
dependencies: {
sortTypesGroup: {
oneOf: [
{
// When sortTypesGroup is true, groups must NOT be an array that does not contain 'type'
properties: {
sortTypesGroup: { enum: [true] },
groups: {
not: {
type: 'array',
uniqueItems: true,
items: {
oneOf: [
{ enum: types.filter((t) => t !== 'type') },
{
type: 'array',
uniqueItems: true,
items: { enum: types.filter((t) => t !== 'type') },
},
],
},
},
},
},
required: ['groups'],
},
{
properties: {
sortTypesGroup: { enum: [false] },
}
},
],
},
'newlines-between-types': {
properties: {
sortTypesGroup: { enum: [true] },
},
required: ['sortTypesGroup'],
},
consolidateIslands: {
anyOf: [{
properties: {
'newlines-between': { enum: ['always-and-inside-groups'] },
oneOf: [
{
properties: {
consolidateIslands: { enum: ['inside-groups'] },
},
anyOf: [
{
properties: {
'newlines-between': { enum: ['always-and-inside-groups'] },
},
required: ['newlines-between'],
},
{
properties: {
'newlines-between-types': { enum: ['always-and-inside-groups'] },
},
required: ['newlines-between-types'],
},
],
},
required: ['newlines-between'],
}, {
properties: {
'newlines-between-types': { enum: ['always-and-inside-groups'] },
{
properties: {
consolidateIslands: { enum: ['never'] },
},
},
required: ['newlines-between-types'],
}] },
],
},
},
},
],
Expand Down

0 comments on commit 9900388

Please sign in to comment.