No long lines #70
Replies: 8 comments
-
One idea is to insert But it might be better to let the user decide where to break the line. There might be multiple possible places that all result in a different result after running elm-format. See also this issue in elm-format: avh4/elm-format#324 |
Beta Was this translation helpful? Give feedback.
-
The problem I see with just inserting a lot of spaces is that it complicates figuring out if the line break was sufficient or if additional line breaks are needed to keep the line under the maximum character length. |
Beta Was this translation helpful? Give feedback.
-
Ah, gotcha. I guess it would be annoying if you had to run |
Beta Was this translation helpful? Give feedback.
-
I think it should be sufficient to report the long lines and not offer any fixes; this gives the developer the opportunity to identify a possible refactor, and lets them solve the complicated mess of where to insert the new line, how much to indent, and whether that's enough. That said, you still need some way to identify whether a long line can be fixed. If you're offering a fix, I see three problems that need to be solved:
|
Beta Was this translation helpful? Give feedback.
-
I am personally not fond of this behavior, as it makes certain things annoying (that bug me with Prettier for instance)
Most of these things I would do anyway myself when I feel like it is appropriate. But I see the value in enforcing it, to reduce the disparity in "code styles" in a team. Just like Richard in avh4/elm-format#324 (comment), I find that Anyway, that was my point of view. Here are some edge-cases that I see if you feel like writing this rule anyway. Module exposing lineI imagine that this rule will also report long import lines and the module X exposing
( thing1, thing2, loooooooooooooooooooooooooooooooooooongThing
, thing3
)
{-|
@docs thing1, thing2, loooooooooooooooooooooooooooooooooooongThing
@docs thing3
-}
import ... Here, regardless of how you will split the line containing the long thing, PerformanceOne thing to note is it's fine to have several round trips with
I don't put many comments in my source code, but this does happen yes. baseRegex =
"(" ++ "\d\d\d\d-\d\d\d\d-\d\d\d\d-\d\d\d\d" -- Credit card number
++ "|\d\d\d\d-\d\d\d\d-\d\d\d\d"
++ ")" could turn into baseRegex =
"("
++ "\d\d\d\d-\d\d\d\d-\d\d\d\d-\d\d\d\d"
-- Credit card number
++ "|\d\d\d\d-\d\d\d\d-\d\d\d\d"
++ ")" where the comment doesn't give the same meaning/explanation to the code Spacing issueAs for the spacing issue that was raised where we wondered by how much to indent when splitting a line, I'm sure you can store the start column from the parent expression and indent it by a bit more than that amount, when the parent is on the same line. |
Beta Was this translation helpful? Give feedback.
-
As far as I understood the proposal it would only complain about lines that can be made shorter by introducing line breaks (not ones where you’d have to “change the code”). |
Beta Was this translation helpful? Give feedback.
-
I meant about concatenation of code like this: Rule.error
{ message = "You have an error around module `" ++ moduleName ++ "` and function `" ++ functionName ++ "` on line " ++ String.fromInt line ++ "."
, details = [ "Bla" ]
} which would turn into Rule.error
{ message =
"You have an error around module `"
++ moduleName
++ "` and function `"
++ functionName
++ "` on line "
++ String.fromInt line
++ "."
, details = [ "Bla" ]
} |
Beta Was this translation helpful? Give feedback.
-
Ah, I see. That’s good, in my opinion. |
Beta Was this translation helpful? Give feedback.
-
What the rule should do:
This rule is a generalization of https://package.elm-lang.org/packages/r-k-b/no-long-import-lines/latest/
It will report an error for any line that exceeds a specified character length. An exception is made for lines that can't be shortened without making changes beyond just inserting whitespace.
Example of things the rule would report:
gets fixed to
which elm-format can then fix up.
Example of things the rule would not report:
The only place a line break can be introduced is here
= "
which don't make the line short enough to fit.When (not) to enable this rule:
If it turns out to be too difficult to implement. There are some edge cases that might be tricky. For example:
If we only apply a line break and a fixed amount of spacing to the long line, we'll end up with
which won't compile since the expression needs to be indented past the start of the pattern match.
I am looking for:
a = "some text" ++ {- a comment -} "more text"
will probably cause weird results. Does this seem like a big problem? Do people often place comments in lines of code?Beta Was this translation helpful? Give feedback.
All reactions