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

Please allow overriding importAttributesKeyword with assert #180

Closed
ifeltsweet opened this issue Aug 12, 2024 · 7 comments
Closed

Please allow overriding importAttributesKeyword with assert #180

ifeltsweet opened this issue Aug 12, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@ifeltsweet
Copy link

Our build system requires output to be generated with assert instead of with on the import statements. Please allow us to override babel format option importAttributesKeyword.

@fbartho fbartho added the enhancement New feature or request label Aug 12, 2024
@IanVS
Copy link
Owner

IanVS commented Aug 12, 2024

Why does your build system enforce the use of a deprecated syntax?

@fbartho

This comment was marked as outdated.

@IanVS
Copy link
Owner

IanVS commented Aug 12, 2024

@fbartho that will allow parsing the deprecated syntax, but we don't allow changing the way that we re-generate it.

@vincerubinetti
Copy link

vincerubinetti commented Aug 12, 2024

Related issue on upstream repo, in case it's relevant/helpful:

trivago/prettier-plugin-sort-imports#270


Also, I'm not using the assert syntax, I'm using with { type: "json" }, and I'm finding that this plugin (removing just this plugin makes everything work) is breaking the parsing of some playwright tests I have:

SyntaxError: This experimental syntax requires enabling the parser plugin: "importAttributes". (3:53)
    at constructor (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:352:19)
    at TypeScriptParserMixin.raise (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:3250:19)
    at TypeScriptParserMixin.expectPlugin (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:3278:16)
    at TypeScriptParserMixin.expectImportAttributesPlugin (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:10704:12)
    at TypeScriptParserMixin.maybeParseImportAttributes (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:13783:16)
    at TypeScriptParserMixin.parseImportSourceAndAttributes (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:13696:10)
    at TypeScriptParserMixin.parseImportSpecifiersAndAfter (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:13690:17)
    at TypeScriptParserMixin.parseImport (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:13681:17)
    at TypeScriptParserMixin.parseImport (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:9048:26)
    at TypeScriptParserMixin.parseStatementContent (/Users/vincerubinetti/Desktop/molevolvr-new/app/node_modules/@babel/parser/lib/index.js:12328:27)

Any way to at least get this to not cause a critical error that completely halts all of prettier formatting?

EDIT: Nevermind, putting this in my prettier config seems to work: "importOrderParserPlugins": ["typescript", "importAssertions"]. I was already trying importAssertions as the error message said, but then I was getting a different error. I guess it was due to it not being able to understand the TS syntax in the file.

@fbartho
Copy link
Collaborator

fbartho commented Aug 12, 2024

Nevermind, putting this in my prettier config seems to work: "importOrderParserPlugins": ["typescript", "importAssertions"]. I was already trying importAssertions as the error message said, but then I was getting a different error. I guess it was due to it not being able to understand the TS syntax in the file.

Ah! That's good news!

I agree, I don't love the importOrderParserPlugins option. I think it's a bit clunky, and hard to prevent problems between different plugins clobbering each other -- but so far, this is a pinch point a bit outside the control of this plugin! (babel/prettier take the blame for the fundamental underlying issue there!)

@IanVS
Copy link
Owner

IanVS commented Aug 12, 2024

Hah, I guess you had the right suggestion after all, @fbartho!

Glad it sounds like everything's sorted out. Thanks ya'll.

@IanVS IanVS closed this as completed Aug 12, 2024
@vincerubinetti
Copy link

FYI I also ended up needing to add jsx along with typescript, since I'm using the same prettier config for my tests (pure ts) and my app source (TSX).

Also FYI, I tested the importOrderParserPlugins solution using assert instead of with (per OP's original request), and it seems to work fine.... however, either Prettier or this plugin seems to be automatically change assert to with, which may mess things up in OP's case. At least it's not a critical format-halting error though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants