Redefine the behavior of `max_line_length` #280

Open
florianb opened this Issue Nov 8, 2016 · 4 comments

Projects

None yet

4 participants

@florianb
florianb commented Nov 8, 2016 edited

Currently the max_line_length-definition states:

Forces hard line wrapping after the amount of characters specified.

This Definition is not applicable

We had a recent discussion about the implementation of this property f.e. in sindresorhus/atom-editorconfig#133. It turned out that this definition seems not to be applicable for these reasons:

  • Hard wraps can't be implemented without knowledge of the context (current grammar). Which is impossible to achieve, because you'd need to correctly derive the language from the file ending (not possible) and you'd need to parse the AST (very expensive).
  • The definition does not specify when the setting should be applied (during save or while editing).
  • Even Soft Wrapping files is a far too invasive implementation for a reasonable amount of users.
  • There is no standard conform implementation of this property.

I therefore propose to change this property to

  • visually hint the user that lines are exceeding the max_line_length and/or
  • notify the the user about the violation of the max_line_length during save

@florianb florianb referenced this issue in sindresorhus/atom-editorconfig Nov 8, 2016
Closed

Improving implementation of `max_line_length` #143

@jedmao
Member
jedmao commented Nov 8, 2016

I absolutely agree with this request; however, my personal conviction is that this rule shouldn't exist. I would rather use a rulers rule to indicate a line is exceeding some length, but that's just me.

I think this max_line_length rule is more of a language-specific linting rule and shouldn't be the concern of EditorConfig. That's my $0.02.

@florianb
florianb commented Nov 9, 2016

I agree for the current implementation. In general i think the max_line_length has its origin in platform dependency. Given you have to access your files on terminals with limited dimension you'd like to define a maximum line length to avoid outraging lines.

I would leave it in general. But i would't vote for explicitly push the limit through rather than hinting the user that she's running into trouble.

@nfarina
nfarina commented Nov 11, 2016

Finally found this page after a lot of frustration with soft wrapping being re-enabled!

After reading the official docs on max_line_length, I think what this plugin is doing does makes sense in a way - it's true to the letter and spirit of the property. But it's also very confusing if you aren't expecting it. I think your idea of some sort of visual hint alerting the user would be a great solution.

If it helps, what I thought max_line_length did was to simply adjust the "preferred line length" in Atom - for instance moving the "wrap guide" line and wrapping there if I had turned on Soft Wraps myself.

@osdm
osdm commented Jan 4, 2017

Maybe there should be another property, like "enforce_max_line_length", with values like "warning", "hard_wrap" and "soft_wrap"?

@jedmao
Member
jedmao commented Jan 11, 2017

@osdm, are you suggesting you want to "enforce" a soft wrap? That's a user preference, so I don't think it has a place in EditorConfig, especially since it has zero to do with keeping things consistent in a project.

As for the "warning" value you suggested, see my comment above about a rulers setting that would allow you to essentially place a warning not to go past that ruler.

Enforcing a max line length is much more tricky, because there's really no automatic way to fix it w/o knowledge of the language being written. EditorConfig is language agnostic, so it will never have knowledge about the language being written. All that could be done is some sort of warning, which brings us right back to the rulers setting.

In conclusion, I think the rulers setting would cover all of these scenarios in the least invasive way. Furthermore, it would be a pretty simple rule to implement across editors, which you also have to consider.

@osdm
osdm commented Jan 11, 2017

@jedmao Not so many tools can display several vertical rulers and I highly doubt that they would want to add functionality only to conform to optional property. On the opposite side, max_line_length is already supported by a number of editors somehow, and it would be better not to create inconveniences for users and plugin authors by changing it.
What I suggest is to give a user a setting to express his desires about enforcing max_line_length explicitly. Does she want a warning if an editor can do it? Does she want a hard wrap if an editor can do it (I just implemented support for max_line_length as a hard wrap in ReSharper/Rider, so at least one editor can)? Does she want a soft wrap? I think that displaying a ruler goes without saying by default, I don't see how one can object to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment