Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes overlapping errors between newlinesBetween and comment-after fixes #441

Merged
merged 11 commits into from
Jan 13, 2025
Merged
4 changes: 2 additions & 2 deletions rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateGeneratedGroupsConfiguration } from '../utils/validate-generated-groups-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import {
singleCustomGroupJsonSchema,
allSelectors,
Expand All @@ -39,6 +38,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
Copy link
Owner

Choose a reason for hiding this comment

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

Why not makeFixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@azat-io Renamed in ee1f5eb.

import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -338,7 +338,7 @@ export let sortArray = <MessageIds extends string>({

context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
18 changes: 9 additions & 9 deletions rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
sortNodesByDependencies,
} from '../utils/sort-nodes-by-dependencies'
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration'
import { makeOrderCommentsAfterAndNewlinesFixes } from '../utils/make-order-comments-after-and-newlines-fixes'
import { validateGeneratedGroupsConfiguration } from '../utils/validate-generated-groups-configuration'
import {
singleCustomGroupJsonSchema,
Expand All @@ -48,6 +47,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -651,21 +651,21 @@ export default createEslintRule<SortClassesOptions, MESSAGE_ID>({

for (let messageId of messageIds) {
context.report({
fix: (fixer: TSESLint.RuleFixer) =>
makeOrderCommentsAfterAndNewlinesFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
fixer,
nodes,
}),
data: {
nodeDependentOnRight: firstUnorderedNodeDependentOnRight?.name,
right: toSingleLine(right.name),
left: toSingleLine(left.name),
rightGroup: right.group,
leftGroup: left.group,
},
fix: (fixer: TSESLint.RuleFixer) =>
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
fixer,
nodes,
}),
node: right.node,
messageId,
})
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
Expand All @@ -28,6 +27,7 @@ import { getNodeDecorators } from '../utils/get-node-decorators'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -286,7 +286,7 @@ let sortDecorators = (
let rightNumber = getGroupNumber(options.groups, right)
context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
ignoreFirstNodeHighestBlockComment: true,
sourceCode,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
sortNodesByDependencies,
} from '../utils/sort-nodes-by-dependencies'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
import { hasPartitionComment } from '../utils/has-partition-comment'
Expand All @@ -28,6 +27,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getEnumMembers } from '../utils/get-enum-members'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -254,7 +254,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
getFirstUnorderedNodeDependentOn(right, sortingNodes)
context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
nodes: sortingNodes,
sourceCode,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
import { hasPartitionComment } from '../utils/has-partition-comment'
Expand All @@ -22,6 +21,7 @@ import { getCommentsBefore } from '../utils/get-comments-before'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
import { sortNodes } from '../utils/sort-nodes'
Expand Down Expand Up @@ -166,7 +166,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-heritage-clauses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
Expand All @@ -23,6 +22,7 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -177,7 +177,7 @@ let sortHeritageClauses = (
let rightNumber = getGroupNumber(options.groups, right)
context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
fixer,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration'
import { makeOrderCommentsAfterAndNewlinesFixes } from '../utils/make-order-comments-after-and-newlines-fixes'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { readClosestTsConfigByPath } from './sort-imports/read-closest-ts-config-by-path'
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
Expand All @@ -34,6 +33,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
import { isSortable } from '../utils/is-sortable'
Expand Down Expand Up @@ -571,7 +571,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
for (let messageId of messageIds) {
context.report({
fix: fixer =>
makeOrderCommentsAfterAndNewlinesFixes({
makeAllFixes({
options: {
...options,
customGroups: [],
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-jsx-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
Expand All @@ -22,6 +21,7 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
import { isSortable } from '../utils/is-sortable'
Expand Down Expand Up @@ -169,7 +169,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
let rightNumber = getGroupNumber(options.groups, right)
context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
fixer,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
import { hasPartitionComment } from '../utils/has-partition-comment'
Expand All @@ -22,6 +21,7 @@ import { getCommentsBefore } from '../utils/get-comments-before'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -177,7 +177,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
sortNodesByDependencies,
} from '../utils/sort-nodes-by-dependencies'
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration'
import { makeOrderCommentsAfterAndNewlinesFixes } from '../utils/make-order-comments-after-and-newlines-fixes'
import { validateGeneratedGroupsConfiguration } from '../utils/validate-generated-groups-configuration'
import {
singleCustomGroupJsonSchema,
Expand All @@ -52,6 +51,7 @@ import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getEnumMembers } from '../utils/get-enum-members'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -449,7 +449,7 @@ let analyzeModule = ({
leftGroup: left.group,
},
fix: (fixer: TSESLint.RuleFixer) =>
makeOrderCommentsAfterAndNewlinesFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-named-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
import { hasPartitionComment } from '../utils/has-partition-comment'
Expand All @@ -22,6 +21,7 @@ import { getCommentsBefore } from '../utils/get-comments-before'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
import { isSortable } from '../utils/is-sortable'
Expand Down Expand Up @@ -174,7 +174,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-named-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { makeOrderAndCommentsAfterFixes } from '../utils/make-order-and-comments-after-fixes'
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines'
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
import { hasPartitionComment } from '../utils/has-partition-comment'
Expand All @@ -22,6 +21,7 @@ import { getCommentsBefore } from '../utils/get-comments-before'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
import { isSortable } from '../utils/is-sortable'
Expand Down Expand Up @@ -183,7 +183,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

context.report({
fix: fixer =>
makeOrderAndCommentsAfterFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-object-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
orderJsonSchema,
} from '../utils/common-json-schemas'
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration'
import { makeOrderCommentsAfterAndNewlinesFixes } from '../utils/make-order-comments-after-and-newlines-fixes'
import {
singleCustomGroupJsonSchema,
allModifiers,
Expand All @@ -47,6 +46,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { toSingleLine } from '../utils/to-single-line'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
Expand Down Expand Up @@ -447,7 +447,7 @@ export let sortObjectTypeElements = <MessageIds extends string>({
for (let messageId of messageIds) {
context.report({
fix: fixer =>
makeOrderCommentsAfterAndNewlinesFixes({
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
Expand Down
18 changes: 9 additions & 9 deletions rules/sort-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
sortNodesByDependencies,
} from '../utils/sort-nodes-by-dependencies'
import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration'
import { makeOrderCommentsAfterAndNewlinesFixes } from '../utils/make-order-comments-after-and-newlines-fixes'
import { validateCustomSortConfiguration } from '../utils/validate-custom-sort-configuration'
import { getFirstNodeParentWithType } from './sort-objects/get-first-node-parent-with-type'
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
Expand All @@ -37,6 +36,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
import { rangeToDiff } from '../utils/range-to-diff'
import { getSettings } from '../utils/get-settings'
import { isSortable } from '../utils/is-sortable'
Expand Down Expand Up @@ -482,21 +482,21 @@ export default createEslintRule<Options, MESSAGE_ID>({

for (let messageId of messageIds) {
context.report({
fix: fixer =>
makeOrderCommentsAfterAndNewlinesFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
fixer,
nodes,
}),
data: {
nodeDependentOnRight: firstUnorderedNodeDependentOnRight?.name,
rightGroup: right.group,
leftGroup: left.group,
right: right.name,
left: left.name,
},
fix: fixer =>
makeAllFixes({
sortedNodes: sortedNodesExcludingEslintDisabled,
sourceCode,
options,
fixer,
nodes,
}),
node: right.node,
messageId,
})
Expand Down
Loading
Loading