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

import multiline optimization #13353

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

GlebDolzhikov
Copy link
Contributor

@GlebDolzhikov GlebDolzhikov commented Aug 24, 2022

Description

partly fixes #5995

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@GlebDolzhikov
Copy link
Contributor Author

@fisker @thorn0 please take a look

@fisker
Copy link
Member

fisker commented Sep 1, 2022

I(Personally) like things vertically one by one, I even use empty comment to prevent Prettier collapse to one line in some case. Same opinion here

@fisker
Copy link
Member

fisker commented Sep 1, 2022

Easier to reorder Alt + ↑, delete Ctrl + X

@thorn0
Copy link
Member

thorn0 commented Sep 1, 2022

Looks like a reasonable tradeoff to me.

Comment on lines +1519 to 1521
import { numberValue1 as numberValue8, numberValue2 as numberValue9 }
from "./ES6_ExportAllFromMulti";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure I prefer this over the original 🤔

Even where there is no as, new formatting makes a bit harder to scan through names. AFAIU, the main benefit we should expect from the change is the reduction of lines of code. But what does it improve in DX? Existing approach optimizes for cognitive ease and clean git diff – that will be a shame to lose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about as. The current formatting seems to work better for such imports.

As for clean diffs, I think the proposed formatting might be an improvement in that regard. Currently, the diff isn't clean when switching between the single-line and multi-line formatting happens. With the proposed formatting, that switching is seemingly going to happen less often, and the diff for switching single-line⇄double-line is quite clean, definitely cleaner than single⇄multi.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized I'm used to diff viewers that highlight in-line diffs like this:
image
And you're probably talking about raw unhighlighted output of git diff. That makes me wonder how many people view diffs without in-line highlighting and why they would do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what does it improve in DX?

Less scrolling through something that is edited mostly by tooling (auto-import, linters for sorting imports and removing unused ones), not manually? I wish we had some statistics on how many developers edit imports manually. That'd put this proposal in a good perspective. I guess these people are already in minority, but that's only a guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never need write code more than 200 lines. Split the file, if it's too long, that's what ES Module for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-import

I have these lines in my vscode settings

  "javascript.suggest.autoImports": false,
  "vetur.completion.autoImport": false,
  "volar.completion.autoImportComponent": false,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have these lines in my vscode settings

I'm surprised. To me, this is like formatting code manually instead of using Prettier. The only problem I ever had with auto-import has been fixed in TS 4.8. Do you think there are many people who share you preferences in this regard?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also didn't know that someone these days moves imports manually)

@shamseen
Copy link

partly fixes #5995

Hi @GlebDolzhikov, what parts of that issue aren't getting fixed? Also, will this be an opt-in feature? I think that's the best middle ground for an otherwise ... hotly debated proposal.


Will this be implemented? There was quite the pushback when someone stated it likely wouldn't be added. @thorn0 @fisker @kachkaev @thdomingues-dev

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

Successfully merging this pull request may close these issues.

Don’t multi-line imports (let them take less space) / Conflict with VSCode’s organizeImports
6 participants