editorconfig icon indicating copy to clipboard operation
editorconfig copied to clipboard

Support `continuation_indent_size`

Open cjbarth opened this issue 6 years ago • 12 comments

Some languages like Python and Java have style guidelines that warn when a continuation line has the same indentation as the following lines. An EditorConfig file has no way to specify what the continuation indent should be, thus causing an EditorConfig-formatted file to actually break style guidelines. For example, if EditorConfig were set with indent_size=4, you'd get this:

def printer(arg1, \
    arg2):
    print(arg1 + arg1)

which breaks with PEP8.

What you really want is:

def printer(arg1, \
        arg2):
    print(arg1 + arg1)

So, if there was a rule continuation_indent_size=4, that could be accomplished. Or, if desired, a keyword like 'hanging', align or auto could be supported which might yield:

def printer(arg1, \
            arg2):
    print(arg1 + arg1)

Further adding weight to this need is https://github.com/editorconfig/editorconfig-jetbrains/issues/57 wherein this proposed rule is already at least partially supported. Documenting it and making it an official rule with an official EditorConfig description seems like a logical descriptive thing to do.

cjbarth avatar Nov 12 '19 19:11 cjbarth

Hi @cjbarth,

thanks for getting in touch. Having an additional indentation after a line-continuation-character is in my opinion a context-aware behavior. Editorconfig does not specify that the editor should add an additional indentation after line-continuation that's currently the job of the syntax-aware plugin.

For the case of editorconfig/editorconfig-jetbrains#57 i guess the behavior of the plugin might be extended, also influencing the continuation_indent_size as well. Other editors i have seen don't provide a functionality like that, the given language-plugin "just" adds a single indent in the cases i am aware of.

florianb avatar Nov 13 '19 08:11 florianb

IntelliJ IDEA currently supports it as ij_continuation_indent_size. ij_ prefix was added to emphasize that the property is non-standard, IntelliJ IDEA-specific. If another IDE/editor will support something like that, I guess it will come up with some property of its own. Naturally they will not be interoperable but I guess the idea is to standardize only properties which can be supported even by a very basic text editor.

rvishnyakov avatar Nov 13 '19 10:11 rvishnyakov

Vim does this in cindent mode - see http://vimdoc.sourceforge.net/htmldoc/indent.html and search for cino=+10.

I think it's worth standardizing this property for those editors that support it. I also think we need more information about how different editors behave in order to make the property as useful as possible.

I also think, given this and at least one other recent issue, that we need somebody from IntelliJ to join the EC team! :)

cxw42 avatar Nov 13 '19 11:11 cxw42

Are there cases where the continuation-indent is different from the regular indent?

florianb avatar Nov 13 '19 11:11 florianb

@florianb Of course. There are many cases when, for e.g., parameters within a function declaration are indented differently from statements in function body. Users even ask for more granular continuation definition like different indents for function parameters vs expressions and etc. Although I think the latter perhaps is too much for the .editorconfig standard.

rvishnyakov avatar Nov 13 '19 11:11 rvishnyakov

This setting is already enlisted as an example for a domain-specific setting (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties). Since it depends on editor-support and is not language-agnostic i'd suggest to move that issue to https://github.com/editorconfig/editorconfig-jetbrains - it should implement the domain-specific setting.

florianb avatar Nov 13 '19 11:11 florianb

We hopefully will come to a point in editorconfig where we're able to handle domain-specific properties better.

florianb avatar Nov 13 '19 11:11 florianb

Currently supporting an organization where people work with at least three different full-fledged IDEs (with differing indent_style-settings for starters :facepalm:) i am now in the process of implementing a default .editorconfig-file to start working towards a common baseline. For this reason i am glad that the editorconfig initiative exists and these days i really begin to wonder why our industry has not come up it 20 years earlier... but better late than never i guess.

Reading through https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#ideas-for-domain-specific-properties i was almost a bit sad discovering that this one is "not intended to be implemented by EditorConfig.", which sounds pretty definite and final in my ears.

Having an additional indentation after a line-continuation-character is in my opinion a context-aware behavior.

@florianb While there is some truth to this statement (e.g. continuation amidst method signature declaration vs. continuation in a scope body) i don't see why this is an argument for not implementing it.

Since it depends on editor-support and is not language-agnostic

It's true that there are languages where this is simply not applicable, but what i can say that this is not a java or python-only thing, e.g. also applies to PHP and JSON. Furthermore Netbeans IDE also has formatting settings for continuation_indent_size – and it seems to be only this one (not broken down by context), same as for IntelliJ, which currently generates ij_continuation_indent_size as its own custom namespaced version (which unfortunately this way will never get picked up by the other devs in our org using Netbeans or Eclipse).

So i guess i'd just wanted to chime in and show my strong support to consider this as a real good candidate for a new setting to be officially included, as it would immediately generate a lot of benefit for many developers. If there's a strong reason for not including, kindly help me and others understand why that is the case. Cheers!

Philzen avatar May 03 '21 00:05 Philzen

Hi @Philzen - thank you for adding you opinion to this thread.

I just want to clarify my opinion on this - i am by no means against extending EditorConfig. But for the core features i have currently the standpoint that any core rule should be context-free so that an user can rely on the knowledge that every core rule is applicable by any editor you're using with that EditorConfig file.

that this [..] also applies to PHP and JSON

I can't follow that argument - i am sorry. How is a plugin supposed to know you're having a "continuing" line with the single knowledge the prepending line contains text (or not)?

But i also agree with you - i would really really appreciate to have the possibility to offer a standard for all these great features offered by ides, linters and fixers in a single well defined standard. And we already discussed that. Unfortunately it is a question of resources and responsibility. We are already receiving a lot of issues about EditorConfig implementations even though the standardized feature-set is very limited.

It turned out that it seems we wouldn't be able to maintain standardized extended rule set in representation of all those tool developing parties. I would like to remind at this point that nobody of us gets paid for working on EditorConfig and that alone on GitHub millions of references to EditorConfig exist.

So at the current point - and again this is only my opinion - i recommend to create an .editorconfig including overlapping custom rules of you vendor's tools. In a corporate environment it should be possible to maintain and distribute it in a central way. With the current features of EditorConfig this might be still a littlebit clumsy but i hope #236 will ease that pain.

Even though this answer might not satisfy your needs i hope it helps you to understand parts of the reasoning and my opinion. Stay safe.

florianb avatar May 03 '21 09:05 florianb

Just wanting to pitch in; I really like this proposal and it is most defiantly needed. I think this also matches some people choice for 'tab for indentation, space for alignment' where you end up with 'no perfectly simple' indentation. Which matches the 'hanging' indent mentioned by OP.

E.g. it is often nice to be able to say:

myecho "some arg" \
       "some other arg"

In sometimes also referred to 'smart-tabs' in some IDE's

oliv3r avatar Oct 13 '21 17:10 oliv3r

First just a big thanks to @florianb and everyone else, .editorconfig fills a very important need in the development community and I'm grateful that you took it on.

I'm here as well after some quick googling because I too am hoping to have this particular line continuation indent size configured in a standardised way. My fear is that if it's not standardised in editorconfig, implementers will start to use the intellij parameter as a de facto standard, since there doesn't seem to be any other better choice. I think that would be worse than having a standardised definition that wasn't universally implemented well.

pgalbraith avatar Apr 13 '22 14:04 pgalbraith

Thank you very much @pgalbraith – you are absolutely right. I wish i would have more time to roll out my ideas about that topic. Because i really see the requirement of using the file format as a tool-independent carrier of possible text-affecting settings.

One of the major pain points in that regard is that as soon as we start to standardize f.e. extended rules the amount of work on our side will raise in a uncontrollable way. I remember that we have discussed this in the past.

While i have ideas to offer a process of standardizing core/extended rules for processors/checkers it was hard to bring them up in the last few years due to the pandemic and its consequences.

florianb avatar May 04 '22 07:05 florianb