google / keep-sorted

keep-sorted is a language-agnostic formatter that sorts lines between two markers in a larger file.
Apache License 2.0
132 stars 15 forks source link

fix: Calculate the initial indent correctly in a couple edge cases. #45

Closed JeffFaer closed 3 weeks ago

JeffFaer commented 4 weeks ago
  1. When the first seen line is one of the group_prefixes.
  2. When the first seen line is another keep-sorted directive.

Idempotency output before this change:

$ go test ./...
?       github.com/google/keep-sorted   [no test files]
?       github.com/google/keep-sorted/cmd       [no test files]
--- FAIL: TestGoldens (0.66s)
    --- FAIL: TestGoldens/group (0.00s)
        --- FAIL: TestGoldens/group/group (0.66s)
            golden_test.go:105: keep-sorted diff on keep-sorted output (should be idempotent) (-want +got)
                  (
                        """
                        ... // 180 identical lines
                          case 5:
                          // keep-sorted-test end
                -           return 10
                          case 2:
                -           return 2;
                          case 4:
                +         case 6:
                +           return 10
                +           return 2;
                            return 4;
                -         case 6:
                            return 6;
                          // keep-sorted-test end
                        """
                  )
FAIL
FAIL    github.com/google/keep-sorted/goldens   0.686s
ok      github.com/google/keep-sorted/keepsorted        (cached)
FAIL

Also, check the git history to see how group.out evolved.