-
Notifications
You must be signed in to change notification settings - Fork 26
[bug] Line length checking is not accurate #86
Comments
Ex. 1
Ex. 2
|
Ex 1 can be solved with your smart proposition which i'm feeling more on board with now even tho it make me feel uneasy still. The alternative to the hack would be to have more context, maybe context could contain a hashmap of span -> info and info could hold a needed to break flag |
Example 2 happens because I'm going to take care of this in a few days but in the meanwhile if someone wants to do it, say so and I'll let you, I welcome PRs! When i start working on this I'll say so |
If ex. 2 is indeed a Typst term, then the slash must be forward, not backward. |
Edited, thank you :) |
One reason I'm hesitant to take the provided solution is this: |
The question is hard, because:
But regardless, as I said, the KISS principle is good as it can improve readability. There is already a nice example typst/typst#311 (comment):
Specifically, I already mentioned (somewhere) that I want text to be as packed as possible, like any Markdown file should be. Another example is (AGPL) license file: https://www.gnu.org/licenses/agpl-3.0.txt. So, f(arg)[too long][short][too long again][ long but
can be broken cause spaced ] (limit is 50 columns) ...is what I would say, if I didn't think for a while. To eliminate multistep formatting that in nested cases can slow down the formatting time (maybe not), A more general rule should be applied. Like a rule priority. Something like this:
Hmm... I don't know how it could be implemented, but there is still 2 steps in my rules. Ok, I'll finish the idea. After first 2 rules we will get: f(arg)[too long][short][too long again][
long but can be broken cause spaced
] Of course somewhere between the rules we have to add 1 indent, because 1st line ends with
But it doesn't exceed, so we finished formatting. |
Here are similar examples (limit: #f(arg)[too long][short][too long again][ long but can be broken cause spaced]
#f(arg)[too long][short][too long again][ long abc long abc long long long long long long long long long abc long long long long long long long long long]
// According to my rules:
#f(arg)[too long][short][too long again][
long but can be broken cause spaced]
#f(arg)[too long][short][too long again][
long abc long abc long long long long long long
long long long abc long long long long long long
long long long]
// But this kinda looks better, especially if the content is very long:
#f(arg)[too long][short][too long again][ long but
can be broken cause spaced]
#f(arg)[too long][short][too long again][ long abc
long abc long long long long long long long long
long abc long long long long long long long long
long] So maybe change rules to this:
I think the rules are more of a flowchart written linear (in one line), so maybe it's easier to follow a flowchart (with nested if statements and things like that). |
Here are all 4 variants: Whitespace after [ and before ]
#f(arg)[too long][short][too long again][ long but can be broken cause spaced ]
#f(arg)[too long][short][too long again][ long abc long abc long long long long long long long long long abc long long long long long long long long long ] #f(arg)[too long][short][too long again][
long but can be broken cause spaced
]
#f(arg)[too long][short][too long again][
long abc long abc long long long long long long
long long long abc long long long long long long
long long long
] Whitespace only after [
#f(arg)[too long][short][too long again][ long but can be broken cause spaced]
#f(arg)[too long][short][too long again][ long abc long abc long long long long long long long long long abc long long long long long long long long long] #f(arg)[too long][short][too long again][ long but
can be broken cause spaced]
#f(arg)[too long][short][too long again][ long abc
long abc long long long long long long long long
long abc long long long long long long long long
long] Whitespace only before ]
#f(arg)[too long][short][too long again][long but can be broken cause spaced ]
#f(arg)[too long][short][too long again][long abc long abc long long long long long long long long long abc long long long long long long long long long ] #f(arg)[too long][short][too long again][long but
can be broken cause spaced ]
#f(arg)[too long][short][too long again][long abc
long abc long long long long long long long long
long abc long long long long long long long long
long ] No whitespaces
#f(arg)[too long][short][too long again][long but can be broken cause spaced]
#f(arg)[too long][short][too long again][long abc long abc long long long long long long long long long abc long long long long long long long long long] #f(arg)[too long][short][too long again][long but
can be broken cause spaced]
#f(arg)[too long][short][too long again][long abc
long abc long long long long long long long long
long abc long long long long long long long long
long] |
Here are all 4 variants if 2nd to last argument exceeds the limit: Whitespace after [ and before ]
#f(arg)[too long][short][ long but can be broken cause spaced ][too long again]
#f(arg)[too long][short][ long abc long abc long long long long long long long long long abc long long long long long long long long long ][too long again] #f(arg)[too long][short][
long but can be broken cause spaced
][too long again]
#f(arg)[too long][short][
long abc long abc long long long long long long
long long long abc long long long long long long
long long long
][too long again] Whitespace only after [
#f(arg)[too long][short][ long but can be broken cause spaced][too long again]
#f(arg)[too long][short][ long abc long abc long long long long long long long long long abc long long long long long long long long long][too long again] #f(arg)[too long][short][ long but can be broken
cause spaced][too long again]
#f(arg)[too long][short][ long abc long abc long
long long long long long long long long abc long
long long long long long long long long][too
long again] Whitespace only before ]
#f(arg)[too long][short][long but can be broken cause spaced ][too long again]
#f(arg)[too long][short][long abc long abc long long long long long long long long long abc long long long long long long long long long ][too long again] #f(arg)[too long][short][long but can be broken
cause spaced ][too long again]
#f(arg)[too long][short][long abc long abc long
long long long long long long long long abc long
long long long long long long long long ][too
long again] No whitespaces
#f(arg)[too long][short][long but can be broken cause spaced][too long again]
#f(arg)[too long][short][long abc long abc long long long long long long long long long abc long long long long long long long long long][too long again] #f(arg)[too long][short][long but can be broken
cause spaced][too long again]
#f(arg)[too long][short][long abc long abc long
long long long long long long long long abc long
long long long long long long long long][too
long again] One thing that could be a problem is something like this: #f(arg)[too long][short][long abc long abc long
long long long long long long long long abc long
long long long long long long long long][too
long again] Maybe an easier approach is to only format things until the #f(arg)[too long][short][long abc long abc long
long long long long long long long long abc long
long long long long long long long long][too long again] This way we can reapply rules to the last still exceeding the limit line. I But this again makes formatting in multiple steps. But since Rust's binaries are |
So, I don't think perf would be an issue, what I'm unsure about |
in |
This is a sub-issue from #82 (see examples there). In a9e6249 line length can exceed the configured line limit. Specifically, if the text (
content
block) is used, then it can be chopped into smaller lines which won't alter the output.The text was updated successfully, but these errors were encountered: