Skip to content

Commit

Permalink
fix: use alphabetical as the default sort type in schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
haocheng6 authored Jul 21, 2023
1 parent e472451 commit 3b9366e
Show file tree
Hide file tree
Showing 26 changed files with 336 additions and 22 deletions.
2 changes: 1 addition & 1 deletion rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
'ignore-case': {
type: 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
'ignore-case': {
type: 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-jsx-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-map-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-named-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-named-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-object-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-union-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
SortType.natural,
SortType['line-length'],
],
default: SortType.natural,
default: SortType.alphabetical,
},
order: {
enum: [SortOrder.asc, SortOrder.desc],
Expand Down
11 changes: 11 additions & 0 deletions test/sort-array-includes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,17 @@ describe(RULE_NAME, () => {
'Tomomi Masaoka',
].includes(enforcer)
`,
{
code: dedent`
[
'img1.png',
'img10.png',
'img12.png',
'img2.png',
].includes(filename)
`,
options: [{}],
},
],
invalid: [
{
Expand Down
82 changes: 82 additions & 0 deletions test/sort-classes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,4 +945,86 @@ describe(RULE_NAME, () => {
})
})
})

describe(`${RULE_NAME}: misc`, () => {
it(`${RULE_NAME}: sets alphabetical asc sorting as default`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
{
code: dedent`
class Calculator {
static log(x) {
return 0;
}
static log10(x) {
return 0;
}
static log1p(x) {
return 0;
}
static log2(x) {
return 0;
}
}
`,
options: [{}],
},
],
invalid: [
{
code: dedent`
class Calculator {
static log(x) {
return 0;
}
static log1p(x) {
return 0;
}
static log10(x) {
return 0;
}
static log2(x) {
return 0;
}
}
`,
output: dedent`
class Calculator {
static log(x) {
return 0;
}
static log10(x) {
return 0;
}
static log1p(x) {
return 0;
}
static log2(x) {
return 0;
}
}
`,
errors: [
{
messageId: 'unexpectedClassesOrder',
data: {
left: 'log1p',
right: 'log10',
},
},
],
},
],
})
})
})
})
11 changes: 11 additions & 0 deletions test/sort-enums.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,17 @@ describe(RULE_NAME, () => {
'Ushio Kofune' = 'Ushio Kofune',
}
`,
{
code: dedent`
enum NumberBase {
BASE_10 = 10,
BASE_16 = 16,
BASE_2 = 2,
BASE_8 = 8
}
`,
options: [{}],
},
],
invalid: [
{
Expand Down
54 changes: 54 additions & 0 deletions test/sort-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,60 @@ describe(RULE_NAME, () => {
})

describe('misc', () => {
it(`${RULE_NAME}: sets alphabetical asc sorting as default`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
dedent`
export { Hizuru } from '~/higotoshima/hizuru'
export { Mio } from '~/higotoshima/mio'
export { Shinpei } from '~/higotoshima/shinpei'
export { Ushio } from '~/higotoshima/ushio'
`,
{
code: dedent`
export { log } from './log'
export { log10 } from './log10'
export { log1p } from './log1p'
export { log2 } from './log2'
`,
options: [{}],
},
],
invalid: [
{
code: dedent`
export { Shinpei } from '~/higotoshima/shinpei'
export { Mio } from '~/higotoshima/mio'
export { Ushio } from '~/higotoshima/ushio'
export { Hizuru } from '~/higotoshima/hizuru'
`,
output: dedent`
export { Hizuru } from '~/higotoshima/hizuru'
export { Mio } from '~/higotoshima/mio'
export { Shinpei } from '~/higotoshima/shinpei'
export { Ushio } from '~/higotoshima/ushio'
`,
errors: [
{
messageId: 'unexpectedExportsOrder',
data: {
left: '~/higotoshima/shinpei',
right: '~/higotoshima/mio',
},
},
{
messageId: 'unexpectedExportsOrder',
data: {
left: '~/higotoshima/ushio',
right: '~/higotoshima/hizuru',
},
},
],
},
],
})
})

it(`${RULE_NAME}: ignores exported variables or functions`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
Expand Down
9 changes: 9 additions & 0 deletions test/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,15 @@ describe(RULE_NAME, () => {
import Shinpei from '~/higotoshima/shinpei'
import Ushio from '~/higotoshima/ushio'
`,
{
code: dedent`
import { log } from './log'
import { log10 } from './log10'
import { log1p } from './log1p'
import { log2 } from './log2'
`,
options: [{}],
},
],
invalid: [
{
Expand Down
17 changes: 14 additions & 3 deletions test/sort-interfaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1590,11 +1590,22 @@ describe(RULE_NAME, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
dedent`
interface DeathNoteValue {
causeOfDeath: string
name: string
interface DeathNoteValue {
causeOfDeath: string
name: string
}
`,
{
code: dedent`
interface Calculator {
log: (x: number) => number,
log10: (x: number) => number,
log1p: (x: number) => number,
log2: (x: number) => number,
}
`,
options: [{}],
},
],
invalid: [
{
Expand Down
12 changes: 12 additions & 0 deletions test/sort-jsx-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,18 @@ describe(RULE_NAME, () => {
/>
)
`,
{
code: dedent`
const content = (
<AppBar
link1="http://www.example.com"
link10="http://www.example.com"
link2="http://www.example.com"
/>
)
`,
options: [{}],
},
],
invalid: [
{
Expand Down
21 changes: 16 additions & 5 deletions test/sort-map-elements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,25 @@ describe(RULE_NAME, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
dedent`
new Map([
['CNY', 'Renminbi'],
['EUR', 'Euro'],
['GBP', 'Sterling'],
['RUB', 'Russian ruble'],
['USD', 'United States dollar'],
])
`,
{
code: dedent`
new Map([
['CNY', 'Renminbi'],
['EUR', 'Euro'],
['GBP', 'Sterling'],
['RUB', 'Russian ruble'],
['USD', 'United States dollar'],
['img1.png', 'http://www.example.com/img1.png'],
['img10.png', 'http://www.example.com/img10.png'],
['img12.png', 'http://www.example.com/img12.png'],
['img2.png', 'http://www.example.com/img2.png']
])
`,
options: [{}],
},
],
invalid: [
{
Expand Down
Loading

0 comments on commit 3b9366e

Please sign in to comment.