Skip to content

Commit 8d4ad4f

Browse files
authored
fix: remove deprecated eslint source code api
1 parent db30f86 commit 8d4ad4f

18 files changed

+38
-61
lines changed

rules/sort-array-includes.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
3838
import { createEslintRule } from '../utils/create-eslint-rule'
3939
import { reportAllErrors } from '../utils/report-all-errors'
4040
import { shouldPartition } from '../utils/should-partition'
41-
import { getSourceCode } from '../utils/get-source-code'
4241
import { rangeToDiff } from '../utils/range-to-diff'
4342
import { getSettings } from '../utils/get-settings'
4443
import { isSortable } from '../utils/is-sortable'
@@ -169,7 +168,7 @@ export let sortArray = <MessageIds extends string>({
169168
return
170169
}
171170

172-
let sourceCode = getSourceCode(context)
171+
let { sourceCode, id } = context
173172
let settings = getSettings(context.settings)
174173

175174
let matchedContextOptions = getMatchingContextOptions({
@@ -189,7 +188,7 @@ export let sortArray = <MessageIds extends string>({
189188
validateNewlinesAndPartitionConfiguration(options)
190189

191190
let eslintDisabledLines = getEslintDisabledLines({
192-
ruleName: context.id,
191+
ruleName: id,
193192
sourceCode,
194193
})
195194

rules/sort-classes.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import { getDecoratorName } from '../utils/get-decorator-name'
4646
import { reportAllErrors } from '../utils/report-all-errors'
4747
import { shouldPartition } from '../utils/should-partition'
4848
import { getGroupNumber } from '../utils/get-group-number'
49-
import { getSourceCode } from '../utils/get-source-code'
5049
import { rangeToDiff } from '../utils/range-to-diff'
5150
import { getSettings } from '../utils/get-settings'
5251
import { isSortable } from '../utils/is-sortable'
@@ -127,9 +126,9 @@ export default createEslintRule<SortClassesOptions, MESSAGE_ID>({
127126
})
128127
validateNewlinesAndPartitionConfiguration(options)
129128

130-
let sourceCode = getSourceCode(context)
129+
let { sourceCode, id } = context
131130
let eslintDisabledLines = getEslintDisabledLines({
132-
ruleName: context.id,
131+
ruleName: id,
133132
sourceCode,
134133
})
135134
let className = node.parent.id?.name

rules/sort-decorators.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { getDecoratorName } from '../utils/get-decorator-name'
2626
import { createEslintRule } from '../utils/create-eslint-rule'
2727
import { reportAllErrors } from '../utils/report-all-errors'
2828
import { shouldPartition } from '../utils/should-partition'
29-
import { getSourceCode } from '../utils/get-source-code'
3029
import { rangeToDiff } from '../utils/range-to-diff'
3130
import { getSettings } from '../utils/get-settings'
3231
import { isSortable } from '../utils/is-sortable'
@@ -193,9 +192,9 @@ let sortDecorators = (
193192
if (!isSortable(decorators)) {
194193
return
195194
}
196-
let sourceCode = getSourceCode(context)
195+
let { sourceCode, id } = context
197196
let eslintDisabledLines = getEslintDisabledLines({
198-
ruleName: context.id,
197+
ruleName: id,
199198
sourceCode,
200199
})
201200

rules/sort-enums.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { createEslintRule } from '../utils/create-eslint-rule'
3535
import { reportAllErrors } from '../utils/report-all-errors'
3636
import { shouldPartition } from '../utils/should-partition'
3737
import { getEnumMembers } from '../utils/get-enum-members'
38-
import { getSourceCode } from '../utils/get-source-code'
3938
import { rangeToDiff } from '../utils/range-to-diff'
4039
import { getSettings } from '../utils/get-settings'
4140
import { isSortable } from '../utils/is-sortable'
@@ -93,9 +92,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
9392
})
9493
validateNewlinesAndPartitionConfiguration(options)
9594

96-
let sourceCode = getSourceCode(context)
95+
let { sourceCode, id } = context
9796
let eslintDisabledLines = getEslintDisabledLines({
98-
ruleName: context.id,
97+
ruleName: id,
9998
sourceCode,
10099
})
101100

rules/sort-exports.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
1717
import { createEslintRule } from '../utils/create-eslint-rule'
1818
import { reportAllErrors } from '../utils/report-all-errors'
1919
import { shouldPartition } from '../utils/should-partition'
20-
import { getSourceCode } from '../utils/get-source-code'
2120
import { rangeToDiff } from '../utils/range-to-diff'
2221
import { ORDER_ERROR } from '../utils/report-errors'
2322
import { getSettings } from '../utils/get-settings'
@@ -63,9 +62,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
6362
let options = complete(context.options.at(0), settings, defaultOptions)
6463
validateCustomSortConfiguration(options)
6564

66-
let sourceCode = getSourceCode(context)
65+
let { sourceCode, id } = context
6766
let eslintDisabledLines = getEslintDisabledLines({
68-
ruleName: context.id,
67+
ruleName: id,
6968
sourceCode,
7069
})
7170

rules/sort-heritage-clauses.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { GROUP_ORDER_ERROR, ORDER_ERROR } from '../utils/report-errors'
2121
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
2222
import { createEslintRule } from '../utils/create-eslint-rule'
2323
import { reportAllErrors } from '../utils/report-all-errors'
24-
import { getSourceCode } from '../utils/get-source-code'
2524
import { rangeToDiff } from '../utils/range-to-diff'
2625
import { getSettings } from '../utils/get-settings'
2726
import { isSortable } from '../utils/is-sortable'
@@ -113,9 +112,9 @@ let sortHeritageClauses = (
113112
if (!isSortable(heritageClauses)) {
114113
return
115114
}
116-
let sourceCode = getSourceCode(context)
115+
let { sourceCode, id } = context
117116
let eslintDisabledLines = getEslintDisabledLines({
118-
ruleName: context.id,
117+
ruleName: id,
119118
sourceCode,
120119
})
121120

rules/sort-imports.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
4242
import { createEslintRule } from '../utils/create-eslint-rule'
4343
import { reportAllErrors } from '../utils/report-all-errors'
4444
import { shouldPartition } from '../utils/should-partition'
45-
import { getSourceCode } from '../utils/get-source-code'
4645
import { rangeToDiff } from '../utils/range-to-diff'
4746
import { getSettings } from '../utils/get-settings'
4847
import { isSortable } from '../utils/is-sortable'
@@ -217,9 +216,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
217216
}
218217
}
219218

220-
let sourceCode = getSourceCode(context)
219+
let { sourceCode, filename, id } = context
221220
let eslintDisabledLines = getEslintDisabledLines({
222-
ruleName: context.id,
221+
ruleName: id,
223222
sourceCode,
224223
})
225224
let sortingNodes: SortImportsSortingNode[] = []
@@ -335,7 +334,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
335334

336335
let resolution = typescriptImport.resolveModuleName(
337336
value,
338-
context.filename,
337+
filename,
339338
tsConfigOutput.compilerOptions,
340339
typescriptImport.sys,
341340
tsConfigOutput.cache,

rules/sort-jsx-props.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
3434
import { createEslintRule } from '../utils/create-eslint-rule'
3535
import { reportAllErrors } from '../utils/report-all-errors'
3636
import { shouldPartition } from '../utils/should-partition'
37-
import { getSourceCode } from '../utils/get-source-code'
3837
import { rangeToDiff } from '../utils/range-to-diff'
3938
import { getSettings } from '../utils/get-settings'
4039
import { isSortable } from '../utils/is-sortable'
@@ -91,7 +90,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
9190
}
9291

9392
let settings = getSettings(context.settings)
94-
let sourceCode = getSourceCode(context)
93+
let { sourceCode, id } = context
9594
let matchedContextOptions = getMatchingContextOptions({
9695
nodeNames: node.openingElement.attributes
9796
.filter(
@@ -127,7 +126,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
127126
}
128127

129128
let eslintDisabledLines = getEslintDisabledLines({
130-
ruleName: context.id,
129+
ruleName: id,
131130
sourceCode,
132131
})
133132

rules/sort-maps.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { singleCustomGroupJsonSchema } from './sort-maps/types'
3131
import { createEslintRule } from '../utils/create-eslint-rule'
3232
import { reportAllErrors } from '../utils/report-all-errors'
3333
import { shouldPartition } from '../utils/should-partition'
34-
import { getSourceCode } from '../utils/get-source-code'
3534
import { rangeToDiff } from '../utils/range-to-diff'
3635
import { getSettings } from '../utils/get-settings'
3736
import { isSortable } from '../utils/is-sortable'
@@ -76,7 +75,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
7675
return
7776
}
7877

79-
let sourceCode = getSourceCode(context)
78+
let { sourceCode, id } = context
8079
let settings = getSettings(context.settings)
8180

8281
let matchedContextOptions = getMatchingContextOptions({
@@ -97,7 +96,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
9796
})
9897

9998
let eslintDisabledLines = getEslintDisabledLines({
100-
ruleName: context.id,
99+
ruleName: id,
101100
sourceCode,
102101
})
103102

rules/sort-modules.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import { reportAllErrors } from '../utils/report-all-errors'
4747
import { shouldPartition } from '../utils/should-partition'
4848
import { getGroupNumber } from '../utils/get-group-number'
4949
import { getEnumMembers } from '../utils/get-enum-members'
50-
import { getSourceCode } from '../utils/get-source-code'
5150
import { rangeToDiff } from '../utils/range-to-diff'
5251
import { getSettings } from '../utils/get-settings'
5352
import { isSortable } from '../utils/is-sortable'
@@ -138,9 +137,9 @@ export default createEslintRule<SortModulesOptions, MESSAGE_ID>({
138137
})
139138
validateNewlinesAndPartitionConfiguration(options)
140139

141-
let sourceCode = getSourceCode(context)
140+
let { sourceCode, id } = context
142141
let eslintDisabledLines = getEslintDisabledLines({
143-
ruleName: context.id,
142+
ruleName: id,
144143
sourceCode,
145144
})
146145

rules/sort-named-exports.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
1717
import { createEslintRule } from '../utils/create-eslint-rule'
1818
import { reportAllErrors } from '../utils/report-all-errors'
1919
import { shouldPartition } from '../utils/should-partition'
20-
import { getSourceCode } from '../utils/get-source-code'
2120
import { rangeToDiff } from '../utils/range-to-diff'
2221
import { ORDER_ERROR } from '../utils/report-errors'
2322
import { getSettings } from '../utils/get-settings'
@@ -68,9 +67,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
6867
let options = complete(context.options.at(0), settings, defaultOptions)
6968
validateCustomSortConfiguration(options)
7069

71-
let sourceCode = getSourceCode(context)
70+
let { sourceCode, id } = context
7271
let eslintDisabledLines = getEslintDisabledLines({
73-
ruleName: context.id,
72+
ruleName: id,
7473
sourceCode,
7574
})
7675

rules/sort-named-imports.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
1717
import { createEslintRule } from '../utils/create-eslint-rule'
1818
import { reportAllErrors } from '../utils/report-all-errors'
1919
import { shouldPartition } from '../utils/should-partition'
20-
import { getSourceCode } from '../utils/get-source-code'
2120
import { rangeToDiff } from '../utils/range-to-diff'
2221
import { ORDER_ERROR } from '../utils/report-errors'
2322
import { getSettings } from '../utils/get-settings'
@@ -71,9 +70,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
7170
let options = complete(context.options.at(0), settings, defaultOptions)
7271
validateCustomSortConfiguration(options)
7372

74-
let sourceCode = getSourceCode(context)
73+
let { sourceCode, id } = context
7574
let eslintDisabledLines = getEslintDisabledLines({
76-
ruleName: context.id,
75+
ruleName: id,
7776
sourceCode,
7877
})
7978

rules/sort-object-types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import { createEslintRule } from '../utils/create-eslint-rule'
4848
import { sortByJsonSchema } from './sort-object-types/types'
4949
import { reportAllErrors } from '../utils/report-all-errors'
5050
import { shouldPartition } from '../utils/should-partition'
51-
import { getSourceCode } from '../utils/get-source-code'
5251
import { rangeToDiff } from '../utils/range-to-diff'
5352
import { getSettings } from '../utils/get-settings'
5453
import { isSortable } from '../utils/is-sortable'
@@ -186,7 +185,7 @@ export let sortObjectTypeElements = <MessageIds extends string>({
186185
}
187186

188187
let settings = getSettings(context.settings)
189-
let sourceCode = getSourceCode(context)
188+
let { sourceCode, id } = context
190189
let matchedContextOptions = getMatchingContextOptions({
191190
nodeNames: elements.map(node =>
192191
getNodeName({ typeElement: node, sourceCode }),
@@ -218,7 +217,7 @@ export let sortObjectTypeElements = <MessageIds extends string>({
218217
}
219218

220219
let eslintDisabledLines = getEslintDisabledLines({
221-
ruleName: context.id,
220+
ruleName: id,
222221
sourceCode,
223222
})
224223

rules/sort-objects.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { TSESLint } from '@typescript-eslint/utils'
2+
13
import { TSESTree } from '@typescript-eslint/types'
24

35
import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies'
@@ -42,7 +44,6 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
4244
import { createEslintRule } from '../utils/create-eslint-rule'
4345
import { reportAllErrors } from '../utils/report-all-errors'
4446
import { shouldPartition } from '../utils/should-partition'
45-
import { getSourceCode } from '../utils/get-source-code'
4647
import { rangeToDiff } from '../utils/range-to-diff'
4748
import { getSettings } from '../utils/get-settings'
4849
import { isSortable } from '../utils/is-sortable'
@@ -87,7 +88,7 @@ let defaultOptions: Required<Options[0]> = {
8788
export default createEslintRule<Options, MESSAGE_ID>({
8889
create: context => {
8990
let settings = getSettings(context.settings)
90-
let sourceCode = getSourceCode(context)
91+
let { sourceCode, id } = context
9192

9293
let sortObject = (
9394
nodeObject: TSESTree.ObjectExpression | TSESTree.ObjectPattern,
@@ -181,7 +182,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
181182
}
182183

183184
let eslintDisabledLines = getEslintDisabledLines({
184-
ruleName: context.id,
185+
ruleName: id,
185186
sourceCode,
186187
})
187188

@@ -532,7 +533,7 @@ let getNodeName = ({
532533
sourceCode,
533534
property,
534535
}: {
535-
sourceCode: ReturnType<typeof getSourceCode>
536+
sourceCode: TSESLint.SourceCode
536537
property: TSESTree.Property
537538
}): string => {
538539
if (property.key.type === 'Identifier') {
@@ -547,7 +548,7 @@ let getNodeValue = ({
547548
sourceCode,
548549
property,
549550
}: {
550-
sourceCode: ReturnType<typeof getSourceCode>
551+
sourceCode: TSESLint.SourceCode
551552
property: TSESTree.Property
552553
}): string | null => {
553554
if (

rules/sort-switch-case.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { reportErrors, ORDER_ERROR, RIGHT, LEFT } from '../utils/report-errors'
1010
import { createNodeIndexMap } from '../utils/create-node-index-map'
1111
import { commonJsonSchemas } from '../utils/common-json-schemas'
1212
import { createEslintRule } from '../utils/create-eslint-rule'
13-
import { getSourceCode } from '../utils/get-source-code'
1413
import { rangeToDiff } from '../utils/range-to-diff'
1514
import { getSettings } from '../utils/get-settings'
1615
import { isSortable } from '../utils/is-sortable'
@@ -50,7 +49,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
5049
let options = complete(context.options.at(0), settings, defaultOptions)
5150
validateCustomSortConfiguration(options)
5251

53-
let sourceCode = getSourceCode(context)
52+
let { sourceCode } = context
5453
let isDiscriminantTrue =
5554
switchNode.discriminant.type === 'Literal' &&
5655
switchNode.discriminant.value === true

rules/sort-union-types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { sortNodesByGroups } from '../utils/sort-nodes-by-groups'
3232
import { createEslintRule } from '../utils/create-eslint-rule'
3333
import { reportAllErrors } from '../utils/report-all-errors'
3434
import { shouldPartition } from '../utils/should-partition'
35-
import { getSourceCode } from '../utils/get-source-code'
3635
import { rangeToDiff } from '../utils/range-to-diff'
3736
import { getSettings } from '../utils/get-settings'
3837
import { useGroups } from '../utils/use-groups'
@@ -173,9 +172,9 @@ export let sortUnionOrIntersectionTypes = <MessageIds extends string>({
173172
})
174173
validateNewlinesAndPartitionConfiguration(options)
175174

176-
let sourceCode = getSourceCode(context)
175+
let { sourceCode, id } = context
177176
let eslintDisabledLines = getEslintDisabledLines({
178-
ruleName: context.id,
177+
ruleName: id,
179178
sourceCode,
180179
})
181180

rules/sort-variable-declarations.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled'
1919
import { createEslintRule } from '../utils/create-eslint-rule'
2020
import { reportAllErrors } from '../utils/report-all-errors'
2121
import { shouldPartition } from '../utils/should-partition'
22-
import { getSourceCode } from '../utils/get-source-code'
2322
import { rangeToDiff } from '../utils/range-to-diff'
2423
import { getSettings } from '../utils/get-settings'
2524
import { isSortable } from '../utils/is-sortable'
@@ -62,9 +61,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
6261
let options = complete(context.options.at(0), settings, defaultOptions)
6362
validateCustomSortConfiguration(options)
6463

65-
let sourceCode = getSourceCode(context)
64+
let { sourceCode, id } = context
6665
let eslintDisabledLines = getEslintDisabledLines({
67-
ruleName: context.id,
66+
ruleName: id,
6867
sourceCode,
6968
})
7069

0 commit comments

Comments
 (0)