Skip to content

[RFC] Indent with tabs#1026

Merged
jlongster merged 1 commit intoprettier:masterfrom
arijs:indent-tabs-refactor
Apr 7, 2017
Merged

[RFC] Indent with tabs#1026
jlongster merged 1 commit intoprettier:masterfrom
arijs:indent-tabs-refactor

Conversation

@rhengles
Copy link
Copy Markdown
Contributor

@rhengles rhengles commented Mar 16, 2017

I'm really sorry for having to create another PR, don't want to spam this project, but Github doesn't allow me to reopen the previous PR #920 because the branch has been rebased while the PR was closed.

Comment thread src/doc-printer.js
indent: ind.indent,
align: {
spaces: ind.align.spaces + n,
tabs: ind.align.tabs + (n ? 1 : 0)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vjeux :

Question to you, if you have nested ternaries and other indentation, you're going to have <tab><space><tab><space>. Isn't it an issue in practice?

When printing code indented with tabs, my current solution replaces all calls to align() with exactly one tab - doesn't matter how many spaces it was aligned with, unless it was zero, then it prints zero tabs also.

Copy link
Copy Markdown
Contributor

@vjeux vjeux Mar 16, 2017

Choose a reason for hiding this comment

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

What happens for code like

function f() {
  a
    ? function() {
      a
        ? function() {
            a;
          }
        : c;
      }
    : c;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm especially curious if you have tab width = 3.

The inner one is

<indent><indent><2 space><indent><2 space><indent>

If you do tabWidth = 3 then you have

tab(3) tab(3) space(2) tab(3) space(2) tab(3)

if you output it like this, then the tab after the spaces is going to be width = 1 in order to align, which is incorrect.

What you are doing instead is

tab(3) tab(3) tab(3) space(2) space(2)

which seems to be correct!

@rhengles rhengles mentioned this pull request Mar 16, 2017
@vjeux
Copy link
Copy Markdown
Contributor

vjeux commented Mar 16, 2017

@jlongster I actually think that the solution we sketched out isn't going to work well for nested spaces that are "fixed". It seems also like a good thing to have two different apis for fixed and variable indentation.

Could you review this pull request again? Thanks!

@rhengles rhengles force-pushed the indent-tabs-refactor branch 7 times, most recently from d82126e to 01e10cb Compare March 20, 2017 18:41
@jlongster
Copy link
Copy Markdown
Member

I will review this soon, sorry. It's a bigger thing to talk about so after I go through all the small issues/PRs I end up not having time to tackle this :) I will try to look at this later tonight or tomorrow morning.

It sounds like we're converging on a solution and this is looking good. I'm not stuck on the approach I was suggesting before.

@rhengles rhengles force-pushed the indent-tabs-refactor branch 3 times, most recently from f255266 to 49c30eb Compare March 27, 2017 20:00
@jlongster
Copy link
Copy Markdown
Member

I am so sorry I neglected this. A few things came up the last few weeks and I had to focus on client or other work. I'll be looking through prettier again over the next few days, and I'll look at this issue later tonight and review it. (It's probably ready, but I'll take one pass at it)

@rhengles
Copy link
Copy Markdown
Contributor Author

rhengles commented Apr 6, 2017

I will push now a rebase on top of the recent PRs. 👍

@rhengles rhengles force-pushed the indent-tabs-refactor branch from 49c30eb to f3d3baa Compare April 6, 2017 02:03
Comment thread src/doc-printer.js Outdated
break;
case "indent":
cmds.push([ind + doc.n, mode, doc.contents]);
cmds.push([indent(ind), mode, doc.contents]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a little confusing to name these functions indent and align, the same as the "commands". Can you possibly rename these? At first I thought it was calling the command and was very confused. Maybe something like makeIndent?

@jlongster
Copy link
Copy Markdown
Member

Alright, thanks for describing the reasons for this algorithm and being patient. This looks good to me. I made one small comment where I think there could be some clarification, but otherwise this is fine.

Refactored option to indent with tabs
@rhengles rhengles force-pushed the indent-tabs-refactor branch from f3d3baa to ed3a482 Compare April 6, 2017 03:50
@rhengles
Copy link
Copy Markdown
Contributor Author

rhengles commented Apr 6, 2017

@jlongster Fixed! Thank you very much! 😃 Please forgive me for my exaggerated enthusiasm sometimes... 😄

@jlongster
Copy link
Copy Markdown
Member

That was quick! No worries at all, I took it as just being thorough. Let's merge this and see if any problems come up!

@jlongster jlongster merged commit 170e4d5 into prettier:master Apr 7, 2017
This was referenced Apr 7, 2017
@respectTheCode
Copy link
Copy Markdown

are there plans to do a release with this?

@jlongster
Copy link
Copy Markdown
Member

@respectTheCode Definitely, not sure exactly when though. In the next few days at the latest.

@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 21, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants