Skip to content

Commit

Permalink
fix: convert optionalityOrder to kebab case
Browse files Browse the repository at this point in the history
  • Loading branch information
chirokas authored Apr 1, 2024
1 parent e142c39 commit 7726294
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions docs/rules/sort-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Group = 'multiline' | CustomGroup

interface Options {
type?: 'alphabetical' | 'natural' | 'line-length'
optionalityOrder?: 'ignore' | 'optional-first' | 'required-first'
'optionality-order'?: 'ignore' | 'optional-first' | 'required-first'
order?: 'asc' | 'desc'
'ignore-case'?: boolean
groups?: (Group | Group[])[]
Expand All @@ -118,7 +118,7 @@ interface Options {
- `natural` - sort in natural order.
- `line-length` - sort by code line length.

### optionalityOrder
### optionality-order

<sub>(default: `'ignore'`)</sub>

Expand Down
18 changes: 9 additions & 9 deletions rules/sort-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Group<T extends string[]> = 'multiline' | 'unknown' | T[number]
type Options<T extends string[]> = [
Partial<{
'custom-groups': { [key: string]: string[] | string }
optionalityOrder: OptionalityOrder
'optionality-order': OptionalityOrder
groups: (Group<T>[] | Group<T>)[]
'partition-by-new-line': boolean
'ignore-pattern': string[]
Expand All @@ -51,7 +51,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
'custom-groups': {
type: 'object',
},
optionalityOrder: {
'optionality-order': {
enum: [
OptionalityOrder.ignore,
OptionalityOrder['optional-first'],
Expand Down Expand Up @@ -111,7 +111,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
TSInterfaceDeclaration: node => {
if (node.body.body.length > 1) {
let options = complete(context.options.at(0), {
optionalityOrder: OptionalityOrder.ignore,
'optionality-order': OptionalityOrder.ignore,
'partition-by-new-line': false,
type: SortType.alphabetical,
'ignore-case': false,
Expand Down Expand Up @@ -246,13 +246,15 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
)
}

let optionalityOrder = options['optionality-order']

let checkOrder = (
members: SortingNode[],
left: SortingNode,
right: SortingNode,
iteration: number,
) => {
if (options.optionalityOrder === OptionalityOrder.ignore) {
if (optionalityOrder === OptionalityOrder.ignore) {
return checkGroupSort(left, right)
}

Expand All @@ -270,8 +272,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
if (isMemberOptional(left.node) !== isMemberOptional(right.node)) {
return (
isMemberOptional(left.node) !==
(options.optionalityOrder ===
OptionalityOrder['optional-first'])
(optionalityOrder === OptionalityOrder['optional-first'])
)
}

Expand All @@ -291,7 +292,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
fix: fixer => {
let sortedNodes

if (options.optionalityOrder !== OptionalityOrder.ignore) {
if (optionalityOrder !== OptionalityOrder.ignore) {
let optionalNodes = nodes.filter(member =>
isMemberOptional(member.node),
)
Expand All @@ -300,8 +301,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
)

sortedNodes =
options.optionalityOrder ===
OptionalityOrder['optional-first']
optionalityOrder === OptionalityOrder['optional-first']
? [
...toSorted(optionalNodes),
...toSorted(requiredNodes),
Expand Down
48 changes: 24 additions & 24 deletions test/sort-interfaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
},
Expand Down Expand Up @@ -709,7 +709,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
errors: [
Expand Down Expand Up @@ -761,7 +761,7 @@ describe(RULE_NAME, () => {
callback: 'on*',
},
groups: ['unknown', 'callback'],
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
errors: [
Expand Down Expand Up @@ -814,7 +814,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
'partition-by-new-line': true,
},
],
Expand Down Expand Up @@ -859,7 +859,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
},
Expand Down Expand Up @@ -887,7 +887,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
errors: [
Expand Down Expand Up @@ -939,7 +939,7 @@ describe(RULE_NAME, () => {
callback: 'on*',
},
groups: ['unknown', 'callback'],
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
errors: [
Expand Down Expand Up @@ -992,7 +992,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
'partition-by-new-line': true,
},
],
Expand Down Expand Up @@ -1696,7 +1696,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
},
Expand Down Expand Up @@ -1724,7 +1724,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
errors: [
Expand Down Expand Up @@ -1776,7 +1776,7 @@ describe(RULE_NAME, () => {
callback: 'on*',
},
groups: ['unknown', 'callback'],
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
errors: [
Expand Down Expand Up @@ -1829,7 +1829,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
'partition-by-new-line': true,
},
],
Expand Down Expand Up @@ -1874,7 +1874,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
},
Expand Down Expand Up @@ -1902,7 +1902,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
errors: [
Expand Down Expand Up @@ -1954,7 +1954,7 @@ describe(RULE_NAME, () => {
callback: 'on*',
},
groups: ['unknown', 'callback'],
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
errors: [
Expand Down Expand Up @@ -2007,7 +2007,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
'partition-by-new-line': true,
},
],
Expand Down Expand Up @@ -2673,7 +2673,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
},
Expand Down Expand Up @@ -2701,7 +2701,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
errors: [
Expand Down Expand Up @@ -2753,7 +2753,7 @@ describe(RULE_NAME, () => {
callback: 'on*',
},
groups: ['unknown', 'callback'],
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
},
],
errors: [
Expand Down Expand Up @@ -2813,7 +2813,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['optional-first'],
'optionality-order': OptionalityOrder['optional-first'],
'partition-by-new-line': true,
},
],
Expand Down Expand Up @@ -2851,7 +2851,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
},
Expand Down Expand Up @@ -2879,7 +2879,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
errors: [
Expand Down Expand Up @@ -2931,7 +2931,7 @@ describe(RULE_NAME, () => {
callback: 'on*',
},
groups: ['unknown', 'callback'],
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
},
],
errors: [
Expand Down Expand Up @@ -2991,7 +2991,7 @@ describe(RULE_NAME, () => {
options: [
{
...options,
optionalityOrder: OptionalityOrder['required-first'],
'optionality-order': OptionalityOrder['required-first'],
'partition-by-new-line': true,
},
],
Expand Down

1 comment on commit 7726294

@bab2683
Copy link

@bab2683 bab2683 commented on 7726294 Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, do we know when this fix will be released?

Please sign in to comment.