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

Decide on indentation in sharness and cleanup existing files #4002

Closed
Kubuxu opened this issue Jun 21, 2017 · 12 comments
Closed

Decide on indentation in sharness and cleanup existing files #4002

Kubuxu opened this issue Jun 21, 2017 · 12 comments
Labels
help wanted Seeking public contribution on this issue
Milestone

Comments

@Kubuxu
Copy link
Member

Kubuxu commented Jun 21, 2017

Indentation in sharness files is a mess. Most of the files are using tabs (3000 lines), we have about 500 lines of double space in the front and 500 of 4 spaces in the front, there are 7k lines total.

We should decide on indentation style, clean it up and set up tooling to control it.

@whyrusleeping whyrusleeping added the help wanted Seeking public contribution on this issue label Aug 31, 2017
@whyrusleeping whyrusleeping added this to the Ipfs 0.4.12 milestone Aug 31, 2017
@kevina
Copy link
Contributor

kevina commented Sep 6, 2017

Using tabs in go code is fine as that is the standard, but using tabs in shell files is a royal PITA for me (I use emacs). I would be much happier if we use 4 spaces.

@kevina
Copy link
Contributor

kevina commented Sep 6, 2017

The standard for go is to use tab for indention and spaces for alignment. This makes a lot of sense. For example, it allows me to set the tab width to 4 without any ill effects. For go code, it also well supported in Emacs as it has a very good go mode and what ever it doesn't get right gofmt will fix for you.

As far as I know this is not the case for shell files. By default emacs will indent using 4 spaces but then replace 8 spaces with a tab character. The replacing of 8 spaces with a tab character is all around bad so I (as I am sure lots of other people have) disabled this by setting indent-tabs-mode to nil.

I do not think it is possible to get emacs to use tabs just for indention for shell files. I can set sh-basic-offset to 8 and then indent-tabs-mode to t to get close, but what is really going on is emacs is indenting with 8 spaces and then replacing the spaces with tab. This could mess up alignment if the tab width is set to something other than 8.

Indenting within quotes for example:

test_expect_success "ipfs version succeeds" '
	ipfs version >version.txt
'

Is even more of a pain as emacs does not see that as shell code but rather simply text within quotes. So to use tabs I have to use the Ctrl-q <tab> sequence. This is a manual process that I put off while actively writing new tests. Also manually inserting spaces is far easier than tabs. For one thing it is easier to type (keep in mind that just <tab> never inserts a literal tab characters in emacs) and also because I can quickly fix things up afterwards using the indent-rigidly command.

Using 4 spaces (or maybe just 2) will make things easier for me as I am fighting emacs less. I am not totally against using tabs, it just that it is not well supported, at least for emacs, and for me.

If people know of a better shell mode for emacs that addresses my concerns I will withdraw my objection to using tabs for indention.

@vyzo
Copy link
Contributor

vyzo commented Sep 7, 2017

fwiw I also use emacs with indent-tabs-mode set to nil, so I'd rather not have to deal with tabs in shell scripts. So can we please use spaces?

@magik6k
Copy link
Member

magik6k commented Sep 7, 2017

I'm okay with spaces, PR uses tabs as it was easier to convert to, especially given that some files used 4 different indentation conventions.

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 7, 2017

Someone has any objections against adding a header for vim to set indentation style correctly? For example of such header see cjdns: https://github.com/cjdelisle/cjdns/blob/master/client/Configurator.c

Maybe something like that exists for emacs too?

@Stebalien
Copy link
Member

Someone has any objections against adding a header for vim to set indentation style correctly?

I'd rather not start adding headers to every file. Emacs allows per-directory variables (in a .dir-locals.el file) but I don't think VIM does.

We could also use editorconfig.org but neither Vim nor Emacs have support out of the box.

@whyrusleeping
Copy link
Member

I'm fine with whatever as long as we have a script to enforce it

@magik6k
Copy link
Member

magik6k commented Sep 7, 2017

So would everyone by happy with using 2 spaces?

@kevina
Copy link
Contributor

kevina commented Sep 7, 2017

4 spaces is more standard and the default for Emacs, but I am okay with 2 also, it is easy enough to configure Emacs to use alternative setting for a directory. See, https://www.emacswiki.org/emacs/DirectoryVariables

@chriscool
Copy link
Contributor

I do not think it is possible to get emacs to use tabs just for indention for shell files. I can set sh-basic-offset to 8 and then indent-tabs-mode to t to get close, but what is really going on is emacs is indenting with 8 spaces and then replacing the spaces with tab. This could mess up alignment if the tab width is set to something other than 8.

Yeah, but that's what Emacs users working on Git and Sharness (including me) do and it works quite well in practice. Also Sharness and Git will probably never change the way shell script are indented, so there will be a mismatch if it is changed for go-ipfs or even all the IPFS related projects.

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 25, 2017

What caused me to create this issue was inconsistency. I am not for or against any style. I just want it to be consistent.

@kevina
Copy link
Contributor

kevina commented Sep 25, 2017

I will repeat my objection to the use of tabs in text files unless it is done in the manner in go, that is tab for indention and spaces for alignment. It is unfortunate that this manor of indention is still widely used in practice.

I still think 4 spaces is best. I am okay with 2 spaces. And if we decide to use tabs, I won't object again, but will often be mumbling to myself when ever I have to deal with it. :)

I do agree that we should be consistent with all IPFS projects though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Seeking public contribution on this issue
Projects
None yet
Development

No branches or pull requests

7 participants