-
Notifications
You must be signed in to change notification settings - Fork 25
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
Line break removed when importOrderCombineTypeAndValueImports is used #54
Comments
Thanks, I'll look into this as soon as I get some spare time, but it might be a little while. |
@andidev I don't believe this plugin should remove (all) new-lines after the pragma-comment -- even though the original plugin does so. -- You wouldn't want us to move that comment away from top-of-file if your currently-first import gets sorted lower down. That said in #71 I've made significant changes to our handling of comments, so once that gets reviewed (and fixed if I made a mistake) your original bug report should no-longer be happening! |
well the pragma comment should of course not be sorted lower. however removing the blank string at top if any would not harm according to me but I get this might be a taste what you like or not. |
Hi @andidev! We've just released 4.0.0-alpha.4 which includes changes to the way we handle comments. We have a migration guide, but mostly we are becoming more opinionated on options to make the plugin easier to configure. We'd love if you were able to try it out and let us know what you think! |
Wow nice work, like the changes! However I cannot test this issue since Otherwise I tested it on our flow and typescript largest code bases and besides that it seem to work (however the imports where already sorted so not sure how much test branches this validates) |
@andidev yes, by default we will now combine type and value imports for versions of typescript that support that syntax. If you'd rather keep type imports separate, and sorted to their own section, you can use the |
@IanVS I think you misunderstood me. I know it is suppose to combine it by default but my problem is it does not combine it. Types and non types importer from same file is kept on separate rows. |
@andidev We have a test-case that verifies that we combine them here: prettier-plugin-sort-imports/tests/TypescriptModern/__snapshots__/ppsi.spec.ts.snap Lines 4 to 16 in eb1220a
If you want us to debug it further, I'd be happy to help -- please supply your sample code! (Ideally as a new ticket, with your prettier.config settings too) |
Oh okay, thanks for explaining! A new issue would be great if you don't mind. Also note, it only works when you use |
So it looks like it my error was a webstorm doing the sorting instead of prettier (even though prettier is configured). @IanVS /**
* @prettier
*/
import type { FooValue } from './foo';
import { fooValue } from './foo'; formats to: /**
* @prettier
*/
import { fooValue, type FooValue } from './foo'; @fbartho /**
* @prettier
*/
import { requireValue } from 'src/utils/require/requireValue';
import type { FooValue } from './foo';
import { fooValue } from './foo'; formats to: import { fooValue, type FooValue } from './foo';
/**
* @prettier
*/
import { requireValue } from 'src/utils/require/requireValue'; |
Currently, we require one blank line after comments at the top of the page in order to "detach" them from the following import statement. If you have a comment directly above an import, we treat it as a leading comment of that import, and it will move with the import if it gets sorted. Personally, I prefer having a blank line separating comments, pragma, or directives at the top of the page, but I realize not everyone might. Unfortunately in this case it's just something that we need to be opinionated about so that we can have predictable behavior. I believe the issue you first reported, about imports moving into the same line as the end of a comment block, is solved now, right? |
@IanVS its not solved. Its the first example I mentioned in my comment is this issue. |
/**
* @prettier
*/
import type { FooValue } from './foo';
import { fooValue } from './foo'; Reformatting to /**
* @prettier
*/
import { fooValue, type FooValue } from './foo'; Is not a bug, that's desired behavior. I can see why the second example you gave could be a problem, though. I think we can find a way to deal with that case. |
Ok, then it's just a strange behavior for a code formatter then. Because it formats a new line in case an import is merged to another if it's after the top comment. But in case the import sorted there is not merged with another import line it does not format a space. We formatted our whole code base and that is where I saw we sometimes got a new line after prettier comment and sometimes not. Just seemed strange. But it's an minor esthetic issue or maybe I am missing something so not gonna argue for it to be honest. Either way I appreciate the work on this import sorter! |
Thanks for your input, and I'm glad this is useful to you. We're going to try making a change so that comments above the first import never move, and I'll see what we can do about the addition of that extra newline as well. |
Fixes #81 - This also reverts my `alpha.4` behavior-change where top-of-file comments always got a newline injected below them. Now we neither inject nor delete 1 blank line below the last top-of-file-comment. - This reverts snapshot changes (around top-of-file blank-lines) as compared to our pre-4.0.0-alpha.4 behavior. - Fixes some cases where we would introduce a newline when combining type and value imports (reference #54) --------- Co-authored-by: Ian VanSchooten <ian.vanschooten@gmail.com>
@andidev would you mind trying 4.0.0-alpha.5? We made some changes to better preserve comments at the tops of files. |
@IanVS /**
* @prettier
*/
import { requireValue } from 'src/utils/require/requireValue';
import type { FooValue } from './foo';
import { fooValue } from './foo'; formats to /**
* @prettier
*/
import { fooValue, type FooValue } from './foo';
import { requireValue } from 'src/utils/require/requireValue'; but original issue seems to be solved actually and also formatting /**
* @prettier
*/
import type { FooValue } from './foo';
import { fooValue } from './foo'; mentioned earlier formats correctly now without a line break. |
This should address #54 (comment). Note, we don't currently have a way to _force_ or _remove_ a line at the top, under top-of-file comments, but I think this is okay. We preserve whatever the user had before, which seems fine. We can re-evaluate in the future if we hear from users.
Thanks, we had a bug, https://github.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0-alpha.6 should fix that for you now. Sorry for the back-and-forth, but thanks for testing out the alphas! |
nice just upgraded and tested it and cannot find any case yet causing empty lines or removed ones. |
Your Environment
Describe the bug
Sorting imports with option
importOrderCombineTypeAndValueImports: true
removes a line break at top of prettier anotation if the type import is defined above import line it is merged with.becomes:
Expected behavior
Expected a line break like this:
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
Contribute to @ianvs/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: