Skip to content

Commit

Permalink
fix: split comment after and newlines fixes in two cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 committed Jan 12, 2025
1 parent dc00b27 commit 5200b6d
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 7 deletions.
55 changes: 55 additions & 0 deletions test/rules/sort-classes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4513,6 +4513,61 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): handles newlines and comment after fixes`,
rule,
{
invalid: [
{
output: [
dedent`
class Class {
a // Comment after
b() {}
c() {}
}
`,
dedent`
class Class {
a // Comment after
b() {}
c() {}
}
`,
],
errors: [
{
data: {
rightGroup: 'property',
leftGroup: 'method',
right: 'a',
left: 'b',
},
messageId: 'unexpectedClassesGroupOrder',
},
],
code: dedent`
class Class {
b() {}
a // Comment after
c() {}
}
`,
options: [
{
groups: ['property', 'method'],
newlinesBetween: 'always',
},
],
},
],
valid: [],
},
)
})

describe(`${ruleName}(${type}): sorts inline elements correctly`, () => {
Expand Down
49 changes: 49 additions & 0 deletions test/rules/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,55 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): handles newlines and comment after fixes`,
rule,
{
invalid: [
{
output: [
dedent`
import { a } from './a' // Comment after
import { b } from 'b'
import { c } from 'c'
`,
dedent`
import { a } from './a' // Comment after
import { b } from 'b'
import { c } from 'c'
`,
],
errors: [
{
data: {
rightGroup: 'unknown',
leftGroup: 'external',
right: './a',
left: 'b',
},
messageId: 'unexpectedImportsGroupOrder',
},
],
code: dedent`
import { b } from 'b'
import { a } from './a' // Comment after
import { c } from 'c'
`,
options: [
{
groups: ['unknown', 'external'],
newlinesBetween: 'always',
},
],
},
],
valid: [],
},
)
})

ruleTester.run(
Expand Down
55 changes: 55 additions & 0 deletions test/rules/sort-interfaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,61 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): handles newlines and comment after fixes`,
rule,
{
invalid: [
{
output: [
dedent`
interface Interface {
a: string // Comment after
b: () => void
c: () => void
};
`,
dedent`
interface Interface {
a: string // Comment after
b: () => void
c: () => void
};
`,
],
errors: [
{
data: {
rightGroup: 'property',
leftGroup: 'method',
right: 'a',
left: 'b',
},
messageId: 'unexpectedInterfacePropertiesGroupOrder',
},
],
code: dedent`
interface Interface {
b: () => void
a: string // Comment after
c: () => void
};
`,
options: [
{
groups: ['property', 'method'],
newlinesBetween: 'always',
},
],
},
],
valid: [],
},
)
})

ruleTester.run(
Expand Down
49 changes: 49 additions & 0 deletions test/rules/sort-modules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,55 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): handles newlines and comment after fixes`,
rule,
{
invalid: [
{
output: [
dedent`
function a() {} // Comment after
type B = string
type C = string
`,
dedent`
function a() {} // Comment after
type B = string
type C = string
`,
],
errors: [
{
data: {
rightGroup: 'function',
leftGroup: 'type',
right: 'a',
left: 'B',
},
messageId: 'unexpectedModulesGroupOrder',
},
],
options: [
{
groups: ['function', 'type'],
newlinesBetween: 'always',
},
],
code: dedent`
type B = string
function a() {} // Comment after
type C = string
`,
},
],
valid: [],
},
)
})

describe(`${ruleName}(${type}): sorts inline elements correctly`, () => {
Expand Down
55 changes: 55 additions & 0 deletions test/rules/sort-object-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,61 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): handles newlines and comment after fixes`,
rule,
{
invalid: [
{
output: [
dedent`
type Test = {
a: string // Comment after
b: () => void
c: () => void
};
`,
dedent`
type Test = {
a: string // Comment after
b: () => void
c: () => void
};
`,
],
errors: [
{
data: {
rightGroup: 'property',
leftGroup: 'method',
right: 'a',
left: 'b',
},
messageId: 'unexpectedObjectTypesGroupOrder',
},
],
code: dedent`
type Test = {
b: () => void
a: string // Comment after
c: () => void
};
`,
options: [
{
groups: ['property', 'method'],
newlinesBetween: 'always',
},
],
},
],
valid: [],
},
)
})

ruleTester.run(
Expand Down
55 changes: 55 additions & 0 deletions test/rules/sort-objects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,61 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): handles newlines and comment after fixes`,
rule,
{
invalid: [
{
output: [
dedent`
let obj = {
a, // Comment after
b() {},
c() {},
};
`,
dedent`
let obj = {
a, // Comment after
b() {},
c() {},
};
`,
],
errors: [
{
data: {
rightGroup: 'unknown',
leftGroup: 'method',
right: 'a',
left: 'b',
},
messageId: 'unexpectedObjectsGroupOrder',
},
],
code: dedent`
let obj = {
b() {},
a, // Comment after
c() {},
};
`,
options: [
{
groups: ['unknown', 'method'],
newlinesBetween: 'always',
},
],
},
],
valid: [],
},
)
})

ruleTester.run(
Expand Down
Loading

0 comments on commit 5200b6d

Please sign in to comment.