🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Is it possible to not add line breaks every 500 characters? #4106

Open

Description

@ghnp5

google/closure-compiler intentionally adds a line break after every 500 characters.

Is there a way to prevent this behavior, and not add these line breaks, or could this be added as an option, please?

Activity

  1. niloc132 commented on Aug 4, 2023

    @niloc132
    Contributor

    It looks like there is a setter for this on CompilerOptions (if you have your own subclass of either CommandLineRunner or AbstractCommandLineRunner, or if you directly create your own Compiler instance), but this isn't presently exposed via command line flags.

    // The number of characters after which we insert a line break in the code
    static final int DEFAULT_LINE_LENGTH_THRESHOLD = 500;

    int lineLengthThreshold = DEFAULT_LINE_LENGTH_THRESHOLD;

    public void setLineLengthThreshold(int lineLengthThreshold) {
    this.lineLengthThreshold = lineLengthThreshold;
    }

  2. concavelenz commented on Aug 4, 2023

    @concavelenz
    Contributor

    Yes, setting it to 0 will tell it not to break at all.

  3. ghnp5 commented on Aug 4, 2023

    @ghnp5
    Author

    Yes, setting it to 0 will tell it not to break at all.

    How do I set it to 0? (I use the command line)

  4. brad4d commented on Sep 1, 2023

    @brad4d
    Contributor

    It seems we haven't exposed a command-line option for setting this value.

    Here's the file where one would add that and an example option to copy.

    https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/CommandLineRunner.java#L217

    If you'd like to submit a PR, we'll be happy to review and merge it.

    Or you could just change the constant value in your download of our sources and rebuild.

  5. kittenswolf commented on Feb 5, 2026

    @kittenswolf

    I noticed that the closure compiler FAQ regarding newlines is incorrect:

    Removing the line breaks has no effect on a script's semantics.

    Unfortunately, when the newline is placed here: "value"in[newline]var - it breaks when the newline is removed. Still holding out for an exposed option to disable the newlines 😅

  6. lauraharker commented on Feb 9, 2026

    @lauraharker
    Contributor

    Unfortunately, when the newline is placed here: "value"in[newline]var - it breaks when the newline is removed.

    What sort of breakage do you mean?

    I tried reproducing in the Chrome console, but simply adding a new line after the in keyword still parses fine -

    var x = {};
    "foo" in
    x
    

    If the compiler is outputting code that doesn't parse, that's definitely a bug.

  7. niloc132 commented on Feb 9, 2026

    @niloc132
    Contributor

    @lauraharker I believe you are reading @kittenswolf's comment backwards. The original documentation reads

    Removing the line breaks has no effect on a script's semantics.

    so a user should be able to remove, not add, a newline, from the closure-generated output, and still see valid JS.

    The counterexample is that closure is apparently generating

    ...
    "foo" in
    x
    ...

    This code parses, but when that newline is removed the resulting JS is

    ...
    "foo" inx
    ...

    which will definitely have an impact on the script's semantics.

    Perhaps a regression occurred, or the documentation should indicate that in some cases the newline can't be removed, or must be replaced with a space?

  8. lauraharker commented on Feb 9, 2026

    @lauraharker
    Contributor

    Ah, thanks for the correction @niloc132 .

    I think the intent of that documentation was to say "the goal of adding these line breaks isn't preserving semantics", which is true, but "removing the line breaks has no effect on a script's semantics" is definitely incorrect.

    I can update that document.

    @kittenswolf as Bradford said in #4106 (comment), I think we'd still accept a PR if you want to contribute an option to not add the line breaks.

  9. brad4d commented on Feb 9, 2026

    @brad4d
    Contributor

    @niloc132 thanks for clarifying. It certainly isn't safe to remove a newline without replacing it with some other whitespace. I'm sure the author of the original documentation was thinking of "removing" a newline the same way the author of a text document would. If you remove the newline, you actually replace it with a space to keep word boundaries.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions