@trigen/oxlint-config 9.1.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -131,6 +131,11 @@ function hasInnerComments(sourceCode, range) {
|
|
|
131
131
|
&& comment.range[1] < range[1])
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
function shouldBeMultiline(sourceCode, range, items) {
|
|
135
|
+
return items.length > 1
|
|
136
|
+
&& !sourceCode.text.slice(range[0], range[1]).includes('\n')
|
|
137
|
+
}
|
|
138
|
+
|
|
134
139
|
function getFixedText(node, items, options, sourceCode, range) {
|
|
135
140
|
const text = sourceCode.text
|
|
136
141
|
const content = text.slice(range[0], range[1])
|
|
@@ -138,14 +143,16 @@ function getFixedText(node, items, options, sourceCode, range) {
|
|
|
138
143
|
.sort(compareItems)
|
|
139
144
|
.map(({ specifier }) => sourceCode.getText(specifier))
|
|
140
145
|
|
|
141
|
-
if (!content.includes('\n')) {
|
|
146
|
+
if (!content.includes('\n') && items.length < 2) {
|
|
142
147
|
return ` ${sortedSpecifiers.join(', ')} `
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
const linebreak = getLinebreak(text)
|
|
146
151
|
const firstSpecifier = items[0].specifier
|
|
147
|
-
const indent = getLineIndent(text, firstSpecifier.range[0])
|
|
148
152
|
const closingIndent = getLineIndent(text, node.range[0])
|
|
153
|
+
const indent = content.includes('\n')
|
|
154
|
+
? getLineIndent(text, firstSpecifier.range[0])
|
|
155
|
+
: `${closingIndent} `
|
|
149
156
|
|
|
150
157
|
return `${linebreak}${indent}${sortedSpecifiers.join(`,${linebreak}${indent}`)}${linebreak}${closingIndent}`
|
|
151
158
|
}
|
|
@@ -203,13 +210,18 @@ export default {
|
|
|
203
210
|
}
|
|
204
211
|
|
|
205
212
|
const unorderedPair = getFirstUnorderedPair(items)
|
|
213
|
+
const sourceCode = context.sourceCode
|
|
214
|
+
const range = getBracesRange(node, items, sourceCode)
|
|
215
|
+
const invalidMultiline = range && shouldBeMultiline(
|
|
216
|
+
sourceCode,
|
|
217
|
+
range,
|
|
218
|
+
items
|
|
219
|
+
)
|
|
206
220
|
|
|
207
|
-
if (!unorderedPair) {
|
|
221
|
+
if (!unorderedPair && !invalidMultiline) {
|
|
208
222
|
return
|
|
209
223
|
}
|
|
210
224
|
|
|
211
|
-
const sourceCode = context.sourceCode
|
|
212
|
-
const range = getBracesRange(node, items, sourceCode)
|
|
213
225
|
const fix = range && !hasInnerComments(sourceCode, range)
|
|
214
226
|
? fixer => fixer.replaceTextRange(
|
|
215
227
|
range,
|
|
@@ -219,11 +231,16 @@ export default {
|
|
|
219
231
|
const [
|
|
220
232
|
previousItem,
|
|
221
233
|
item
|
|
222
|
-
] = unorderedPair
|
|
234
|
+
] = unorderedPair ?? [
|
|
235
|
+
items[0],
|
|
236
|
+
items[1]
|
|
237
|
+
]
|
|
223
238
|
|
|
224
239
|
context.report({
|
|
225
240
|
node: item.specifier,
|
|
226
|
-
message:
|
|
241
|
+
message: unorderedPair
|
|
242
|
+
? getMessage(previousItem, item)
|
|
243
|
+
: 'Expected named imports to be multiline.',
|
|
227
244
|
fix
|
|
228
245
|
})
|
|
229
246
|
}
|
|
@@ -79,6 +79,17 @@ function getTypeSpecifierText(specifier, sourceCode) {
|
|
|
79
79
|
: `type ${text}`
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
function getLinebreak(text) {
|
|
83
|
+
return text.includes('\r\n') ? '\r\n' : '\n'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getLineIndent(text, index) {
|
|
87
|
+
const lineStart = text.lastIndexOf('\n', index - 1) + 1
|
|
88
|
+
const indentMatch = /^[ \t]*/.exec(text.slice(lineStart, index))
|
|
89
|
+
|
|
90
|
+
return indentMatch[0]
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
function getMergedText(typeNode, valueNode, sourceCode) {
|
|
83
94
|
const typeSpecifiers = typeNode.specifiers.map(specifier => getTypeSpecifierText(
|
|
84
95
|
specifier,
|
|
@@ -88,11 +99,15 @@ function getMergedText(typeNode, valueNode, sourceCode) {
|
|
|
88
99
|
specifier
|
|
89
100
|
))
|
|
90
101
|
const source = sourceCode.getText(valueNode.source)
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
const linebreak = getLinebreak(sourceCode.text)
|
|
103
|
+
const closingIndent = getLineIndent(sourceCode.text, valueNode.range[0])
|
|
104
|
+
const indent = `${closingIndent} `
|
|
105
|
+
const specifiers = [
|
|
93
106
|
...typeSpecifiers,
|
|
94
107
|
...valueSpecifiers
|
|
95
|
-
]
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
return `import {${linebreak}${indent}${specifiers.join(`,${linebreak}${indent}`)}${linebreak}${closingIndent}} from ${source}`
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
function getFixedText(node, sourceCode) {
|