@trigen/oxlint-config 9.1.0 → 9.2.0

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trigen/oxlint-config",
3
3
  "type": "module",
4
- "version": "9.1.0",
4
+ "version": "9.2.0",
5
5
  "description": "Trigen's Oxlint config.",
6
6
  "author": "dangreen",
7
7
  "license": "MIT",
@@ -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: getMessage(previousItem, item),
241
+ message: unorderedPair
242
+ ? getMessage(previousItem, item)
243
+ : 'Expected named imports to be multiline.',
227
244
  fix
228
245
  })
229
246
  }