Generator-jhipster: Let choice of indentation level

Created on 8 Apr 2018  Â·  23Comments  Â·  Source: jhipster/generator-jhipster

Overview of the issue

In the developper world, there is a big conflict between those who want 2 levels of indentation, and those who want 4 levels of indentation.

Motivation of the use case

Historically, JHipster is writen with four spaces of indentation (see #634).

But in the Angular world, the style is more 2 spaces of indentation. As they say at https://github.com/angular/angular-cli/issues/6272 angular-cli generate 2 levels of indentation, and angular.io show examples written with 2 spaces of indentation. We could read lot of big war at https://github.com/angular/angular-cli/issues/, especially at https://github.com/angular/angular-cli/issues/1252). Therfore, 2 spaces of indentation is not an erronous question.

If angular-cli and all examples in Angular are written with 2 levels of indentation, we could ask why we couldn't generate a JHipster code with 2 levels of indentation. Maybe this question it's not a trivial question.

It's only a programmation style, and now it could be easy fixed. Thanks the introduction of Prettier, we maybe could let the programmer the choice during the generation step? This choice could be let thanks a new question, and the choice could be saved into the file .yo-rc.json. The default value could be 4 spaces for historical reasons.

If add a question during the generation is not a good option (already too much questions), we could let the user modify this option manually in .yo-rc.json. A comment could be let in .editorconfig and .prettierrc to explain that. So, during automatical upgrade or manual upgrade, JHipster generate the code we want.

What do you think about that?

Related issues
JHipster Version(s)

JHipster 5

JHipster configuration

Irrelevant

Entity configuration(s) entityName.json files generated in the .jhipster directory

Irrelevant

Browsers and Operating System

Irrelevant

Most helpful comment

@LoganDark Please don't make demands from the team. Remember that we work for free.

All 23 comments

Just to give you the historic background - as in the last 4 years things have evolved a lot, but that's not totally irrelevant.

I originally wanted to do:

  • 4 spaces in Java as it's the official standard (from Sun, not sure if it's really "official" anymore, but everybody does this)
  • 2 spaces in JavaScript as this is what most people do, and you need less indentation because of the "callback hell" in AngularJs (again, not relevant anymore)

But the issue is that I could configure it only in the .editorconfig (today we have indeed Prettier that could also help here), and not all text editor supports it (or have the plugin). So we still have people coding in basic text editors, where you tell it that your projects has 2 or 4 spaces indentation for the whole project.

And now you guess the issue: on all those "basic" text editors, doing a mix of 2/4 spaces is going to end very bad.

So the first question is: do we still care about those people? Not sure many people do this anymore, now we have Visual Studio Code for free - but I didn't check if it understands .editorconfig correctly.

@jdubois
Maybe if the default style is 4 spaces of indentation, we care of this people… We could believe that if a coder change .editorconfig, he knows how works .editorconfig. As Visual Studio Code is the free editor advise by Angular, maybe in .editorconfig and the README we could add a link to https://github.com/editorconfig/editorconfig-vscode~~ https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig and advise to search the correct plugin if the coder uses another editor.

Personnaly, I use Vim, so I'm among this people ;-)…

EDIT: As Visual Studio Code is the free editor advise by Angular, and as it doesn't understand it out of box, we may care about this persons at least in the README?

Oh yes, maybe you misunderstood me: I choose 4 spaces because I care about people not having advanced text editors.
Now, with Visual Studio Code and Atom, maybe it's time to change, and expect people to have something a bit advanced. It's also wrong to limit what we do because a handful of people want to use inferior tooling!

@jdubois
Sorry ! You were perfectly clear ;-).

So actually maybe we could let the user to have a choice for JavaScript and a different choice for Java? Why not, back and front could be two different worlds. A team for the back, a team for the front. But I believe by default we must let 4 spaces for the whole project. For small projects it's better to have style consistence in all the project! And for a beginner who doesn't know .editorconfig and havn't the plugin, it could be very painful to have code with no consistence…

@jdubois @JulioJu, first of all, I wouldn't offer it as a choice during generation as its quite cumbersome especially for Java, so here is what I think,

  1. Java code should remain at 4 space indentation as its normal in the Java world, and unless we have some sort of prettier support (btw the java plugin is out for prettier) there we don't want to spend time manually changing it
  2. For Typescript changing between 2 and 4 space is very easy thanks to prettier, so we can switch to use 2 space indentation in TS files easily but HTML files would need manual modification and hence is cumbersome for us, so lets stick to 4 here(unless @JulioJu you want to contribute manual formatting of all the html templates to use 2 spaces). If user wants 2 space they could just change the prettier config or editorconfig (most editors, IDE support editorconfig anyway)
  3. In our React support the front end code uses 2 spaces already and its quite elegant

So for me this is a wont fix item due to the effort involved

Why not tabs :trollface: ?

I think once we move to prettier for java we could add a JHipster --option to choose between 2/4 spaces globally or even tabs. As @jdubois said we should keep the same number of spaces everywhere to support simple editors.
Also when we say that java code always has 4 spaces indenting it's not actually true for everyone as the Google java style guide uses 2 spaces.

@deepu105 Can't we use prettier to format html files as well ?

@deepu105

If user wants 2 space they could just change the prettier config or editorconfig (most editors, IDE support editorconfig anyway)

  • Actually for force manual upgrade (jhipster --with-entities --force), files .editorconfig and .prettierrc are erased.
  • Maybe you could say we could don't use --force. But personally I use always manual force upgrade, because review changes with the JHipster diff tool is for me less clear than use other git diff tools (*Magit for Emacs or Vim, maybe Sourcetree for MS-Windows, etc).
  • ==> Maybe an other solution to resolve this problem is don't overwrite .editorconfig and .prettierrc when we use parameter --force. What do you think about that?

@PierreBesson actually we can't use prettier to format html. See https://github.com/prettier/prettier/issues/3301 or https://github.com/prettier/prettier/issues/1882. Maybe soon ? For beautify HTML files, there is https://github.com/beautify-web/js-beautify (I use it).

HTML files would need manual modification and hence is cumbersome for us, so lets stick to 4 here

@deepu105 maybe for HTML files we could investigate js-beautify ?

As @jdubois said we should keep the same number of spaces everywhere to support simple editors.

@PierreBesson. As @deepu105 said, React use 2 spaces for indentations. Therefore, now we could freely have different levels of indentation for the back and the front.

+1 for --option parameter.

Again, unless we have transform stream supporting all the remaining file types(Java, XML, HTML, SASS, CSS, Scala, YML) we cant offer a choice of indentation. It's a small price you pay for the stuff JHipster provides. Let's just say that we provide an opinionated code style :wink:

@JulioJu I don't understand your point about force update, the .prettierrc file is the first file written in memory and transform stream uses that to format TS files. I didn't find any problems when doing force update since I added tabWidth to the file as well. What problem do you see?

I've read through so many issues involving indentation levels it's not even funny. Please just do it already. There is literally no reason to be arguing. Some people prefer 4 spaces per level. Some people prefer tabs. You should _at least_ make it a config option to use a different amount of spaces or tabs.

@LoganDark supporting such trivial personal preferences are definitely not worth our time, we have much more important stuff to do, so no this will not be done

@LoganDark Please don't make demands from the team. Remember that we work for free.

I'm not making demands, I'm just saying that supporting that "trivial personal preference" is important to a lot of people. I understand you don't care.

No, it's again the project policies to do trivial things - it's more complex for users to understand the JHipster configuration than do it themselves.
See https://www.jhipster.tech/policies/
And they are voted by the team, so unless there's another vote we can't change this.

Sorry for wasting your time. I thought this was angular-cli.

@LoganDark
For TypeScript, css and scss, it's easy to customize it. For Angular, simply customize https://github.com/jhipster/generator-jhipster/blob/master/generators/client/templates/angular/.prettierrc.ejs and https://github.com/jhipster/generator-jhipster/blob/master/.editorconfig before generate your application. Then, to use your own JHipster customized, use https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md#set-npmyarn-to-use-the-cloned-project.

So it's very easy to have the indentation you want ;-) ! If you want you could have five spaces of indentation :-) ! Or five tabs ;-) !

Sorry we are fully community-driven, but follow some rules that are basically copied on the ASF - it's closer to us than Google.
I think the "no trivial configuration" rule is good, but discussing it is not a waste of time.

Just because you don't care much about indentation doesn't mean nobody else does. It definitely doesn't mean it doesn't matter at all.

If you're "community driven", then why don't you listen to the community? :p

No, you don't understand, please have a look at the link above on our policies

I'm locking this thread as I don't see any use of further discussion on this.

Also "community-driven" means something will be considered when the majority of the community wants it not when few people want it. Also, community-driven doesn't imply community decided. As project maintainers we still decide what will be done or not based whats good for the project and majority of the users.

@LoganDark I also suggest you consider changing your attitude when expecting something from an OSS project, where people work for free giving up their personal time for the benefit of strangers, so what we at least expect is respect for what we do.

Hi everyone, @LoganDark I'm sorry but I was on holidays (and I still am), and I didn't have access to my computer, so I answered you quickly, hoping that would read the link.

  • We are using 4-spaces indentation because of Policy 1 and 3. I understand this is different in Javascript land than in Java land, but this has been discussed before, and people having "simple" text editors can't have a mix of 2 and 4 spaces, so we have 4 spaces for everyone by default.
  • We are not giving the choice in the generator because of Policy 2
  • Those policies can't be changed by you because of Policy 0

I'm sorry, but the project has 100,000s of users, and we are less than 20 core members, all working for free. So we need to have those rules, in order to make some progress.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sdoxsee picture sdoxsee  Â·  4Comments

Steven-Garcia picture Steven-Garcia  Â·  3Comments

trajakovic picture trajakovic  Â·  4Comments

lsadehaan picture lsadehaan  Â·  3Comments

pascalgrimaud picture pascalgrimaud  Â·  4Comments