Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

document/explain logic of ignoring --lines

Open
#1,276 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
cli, tooling

Research direction

Reproduce the issue with the supplied hello.java example and the two google-java-format commands. Trace the --lines option's range handling, then document why the first line is formatted and what behavior is intended, including whether a focused-line formatting result can be achieved.

Written by the indexing model from the issue text.

Description

as seen in #942 and #1000 (and others) use of --lines does not reliably work.

I'm trying to grok how/why....

As an example:

///usr/bin/env jbang "$0" "$@" ; exit $?


import static java.lang.System.*;

public class hello {

    public static void main(String... args) {
        out.println("Hello World");
    }
}

I want google java format to ignore the first line - reading other isseues I should --skip-* as much as possible ...

jbang com.google.googlejavaformat:google-java-format:1.28.0 --lines 2:9999 --skip-javadoc-formatting --skip-reflowing-long-strings --skip-sorting-imports --skip-removing-unused-imports hello.java

result in first line being formatted as: /// usr/bin/env jbang "$0" "$@" ; exit $?

why ?

If I add --lines 1000:9999 it works...but now the code is not formatted at all.

is this really the intended behavior of --lines ?

any way to have it not try include outside the lines requested?

Dominant language
Java
Stars
6.2k
Forks
936
Avg merge
6m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/google-java-format

All issues in google/google-java-format

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.