Skip to content

Commit 000f2f4

Browse files
authored
feat(object-curly-spacing): support ImportAttribute (#862)
1 parent 46e43f5 commit 000f2f4

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

packages/eslint-plugin/rules/object-curly-spacing/object-curly-spacing._ts_.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ run<RuleOptions, MessageIds>({
315315
code: 'enum Foo {ONE, TWO,}',
316316
options: ['never'],
317317
},
318+
{
319+
code: `import pkgJson from 'package.json' with {type: 'json'}`,
320+
},
321+
{
322+
code: `export { name } from 'package.json' with { type: 'json' }`,
323+
options: ['always'],
324+
},
325+
{
326+
code: `export * from 'package.json' with {type: 'json'}`,
327+
options: ['never'],
328+
},
318329
],
319330

320331
invalid: [
@@ -467,5 +478,31 @@ run<RuleOptions, MessageIds>({
467478
{ messageId: 'requireSpaceBefore' },
468479
],
469480
},
481+
{
482+
code: `import pkgJson from 'package.json' with { type: 'json' }`,
483+
output: `import pkgJson from 'package.json' with {type: 'json'}`,
484+
errors: [
485+
{ messageId: 'unexpectedSpaceAfter' },
486+
{ messageId: 'unexpectedSpaceBefore' },
487+
],
488+
},
489+
{
490+
code: `export { name } from 'package.json' with {type: 'json'}`,
491+
output: `export { name } from 'package.json' with { type: 'json' }`,
492+
options: ['always'],
493+
errors: [
494+
{ messageId: 'requireSpaceAfter' },
495+
{ messageId: 'requireSpaceBefore' },
496+
],
497+
},
498+
{
499+
code: `export * from 'package.json' with { type: 'json' }`,
500+
output: `export * from 'package.json' with {type: 'json'}`,
501+
options: ['never'],
502+
errors: [
503+
{ messageId: 'unexpectedSpaceAfter' },
504+
{ messageId: 'unexpectedSpaceBefore' },
505+
],
506+
},
470507
],
471508
})

packages/eslint-plugin/rules/object-curly-spacing/object-curly-spacing.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
isClosingBraceToken,
77
isClosingBracketToken,
88
isNotCommaToken,
9+
isOpeningBraceToken,
910
isTokenOnSameLine,
1011
} from '#utils/ast'
1112
import { createRule } from '#utils/create-rule'
@@ -254,7 +255,7 @@ export default createRule<RuleOptions, MessageIds>({
254255

255256
const closeToken = sourceCode.getTokenAfter(properties.at(-1)!, isClosingBraceToken)!
256257

257-
const openingToken = sourceCode.getFirstToken(node)!
258+
const openingToken = sourceCode.getTokenBefore(properties[0], isOpeningBraceToken)!
258259

259260
validateBraceSpacing(node, openingToken, closeToken)
260261
}
@@ -308,9 +309,23 @@ export default createRule<RuleOptions, MessageIds>({
308309
checkForObjectLike(node, node.properties)
309310
},
310311
// import {y} from 'x';
311-
ImportDeclaration: checkForImport,
312+
ImportDeclaration(node) {
313+
checkForImport(node)
314+
315+
if (node.attributes)
316+
checkForObjectLike(node, node.attributes)
317+
},
312318
// export {name} from 'yo';
313-
ExportNamedDeclaration: checkForExport,
319+
ExportNamedDeclaration(node) {
320+
checkForExport(node)
321+
322+
if (node.attributes)
323+
checkForObjectLike(node, node.attributes)
324+
},
325+
ExportAllDeclaration(node) {
326+
if (node.attributes)
327+
checkForObjectLike(node, node.attributes)
328+
},
314329
TSMappedType(node) {
315330
const openingToken = sourceCode.getFirstToken(node)!
316331
const closeToken = sourceCode.getLastToken(node)!

0 commit comments

Comments
 (0)