Skip to content
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

Need an option to delete consecutive empty lines #5829

Open
3 tasks done
stevewgr opened this issue Apr 29, 2024 · 1 comment
Open
3 tasks done

Need an option to delete consecutive empty lines #5829

stevewgr opened this issue Apr 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@stevewgr
Copy link

stevewgr commented Apr 29, 2024

Search before asking

  • I searched the issues and found no similar issues.

Description

As a user I would like to specify the maximum amount of empty lines allowed to keep so that empty lines will be removed. As an example, clang-format have this as one of the first features: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#maxemptylinestokeep

Use case

I guess the use case should be pretty obvious and it is common in most formatters I've used for other languages in the past.
Additionally apart from making the code more consistent, it will solve an issue I'm having with mssql-scripter that sometimes produce empty line at the end of the file before the last GO statement, bloating the diffs in PRs unecessarily: ko4life-net/ko-db@7b7ed20

I couldn't find any option to format GO statement either, althougt I've tried modifying the code here:

class FileSegment(BaseFileSegment):
    """A segment representing a whole file or script.

    We override default as T-SQL allows concept of several
    batches of commands separated by GO as well as usual
    semicolon-separated statement lines.

    This is also the default "root" segment of the dialect,
    and so is usually instantiated directly. It therefore
    has no match_grammar.
    """

    match_grammar = Sequence(
        AnyNumberOf(Ref("BatchDelimiterGrammar")),
        Delimited(
            Ref("BatchSegment"),
            delimiter=AnyNumberOf(
                Sequence(
                    Ref("DelimiterGrammar", optional=True), Ref("BatchDelimiterGrammar")
                ),
                min_times=1,
            ),
-            allow_gaps=True,
-            allow_trailing=True,
+            allow_gaps=False,
+            allow_trailing=False,
        ),
    )

If no one have the patience to work on this, I'm happy to help, but I'll need some guidance where to start looking at considering I've just started using the project. Thanks.

Dialect

tsql

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

@stevewgr stevewgr added the enhancement New feature or request label Apr 29, 2024
@fmms
Copy link
Contributor

fmms commented Apr 29, 2024

@stevewgr i think this a duplicate:

I am very much looking forward to have this ;)

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

No branches or pull requests

2 participants