Skip to content

An option to squash consequtive newlines. #68

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

Closed
phadej opened this issue Mar 7, 2025 · 2 comments · Fixed by #70
Closed

An option to squash consequtive newlines. #68

phadej opened this issue Mar 7, 2025 · 2 comments · Fixed by #70

Comments

@phadej
Copy link
Contributor

phadej commented Mar 7, 2025

When editing files I sometimes end up wth something like

foo : Bool
foo = true









bar : Bool
Bar = false

and while this an extreme example, it would be great if fix-whitespace had an option to disallow (and fix) more then 2 (or configurable amount) of consequtive newline characters.

EDIT: I can write a patch if this feature is ok to have.

@ulysses4ever
Copy link
Contributor

I've found myself wanting it often. Students do this all the time.

It's a pity that it's not entirely trivial because of the configurable amount of new lines in a row. But I agree that this configuration is desirable.

phadej added a commit to phadej/fix-whitespace that referenced this issue Mar 7, 2025
Resolves agda#68

Add an option to check for maximum count of consecutive empty lines.
If zero, unlimited cmount is allowed. If 1, there cannot be empty lines,
if 2 there can be one empty line, and so on.

I fail with naming, having value 1 to disallow any empty lines makes
sense, but it's not "maximum amount of empty lines",
it's more of "fail if there is that much empty lines".
phadej added a commit to phadej/fix-whitespace that referenced this issue Mar 7, 2025
Resolves agda#68

Add an option to check for maximum count of consecutive empty lines.
If zero, unlimited cmount is allowed. If 1, there cannot be empty lines,
if 2 there can be one empty line, and so on.

I fail with naming, having value 1 to disallow any empty lines makes
sense, but it's not "maximum amount of empty lines",
it's more of "fail if there is that much empty lines".
@phadej
Copy link
Contributor Author

phadej commented Mar 7, 2025

I made a PoC.

I tried it on GHC codebase, there are 796 files in compiler/. Out of these:

% fix-whitespace compiler/**/*.hs --check -n 4
[ Violation detected ] compiler/GHC/ByteCode/Linker.hs
[ Violation detected ] compiler/GHC/CmmToAsm/X86/Instr.hs
[ Violation detected ] compiler/GHC/StgToCmm/Prof.hs
[ Violation detected ] compiler/GHC/StgToJS/Monad.hs
[polinukli] /code/ghc wip/fix-whitespace % fix-whitespace compiler/**/*.hs --check -n 3 2>&1 | wc
     24     120    1291
[polinukli] /code/ghc wip/fix-whitespace % fix-whitespace compiler/**/*.hs --check -n 2 2>&1 | wc
    150     750    8241

So it feels that if this functionality is enabled by default, then 3 (i.e. allowing 2 empty lines) is not too controversial. Allowing only one empty line (with --consecutive 2) is already quite intrusive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants