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

opt: show diff in optfmt linter #48651

Merged
merged 1 commit into from
May 13, 2020
Merged

Conversation

RaduBerinde
Copy link
Member

The optfmt linter only shows the problematic files. This can be inconvenient for
anyone who doesn't regularly touch .opt files and has optfmt set up in their
editor (or has no idea what it even is). This change improves optfmt -l to
include a diff which can be applied to fix the files. Sample output:

--- FAIL: TestLint (0.00s)
    --- FAIL: TestLint/TestOptfmt (0.20s)
        lint_test.go:340:
            --- /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/agg.opt
            +++ /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/agg.opt
            @@ -5,9 +5,8 @@

             # EliminateAggDistinct removes AggDistinct for aggregations where DISTINCT
             # never modifies the result; for example: min(DISTINCT x).
             [EliminateAggDistinct, Normalize]
            -(AggDistinct
            -$input:(Min | Max | BoolAnd | BoolOr))
            +(AggDistinct $input:(Min | Max | BoolAnd | BoolOr))
             =>
             $input

            --- /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/bool.opt
            +++ /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/bool.opt
            @@ -152,9 +152,10 @@
             # This transformation is useful for finding a conjunct that can be pushed down
             # in the query tree. For example, if the redundant conjunct A is fully bound by
             # one side of a join, it can be pushed through the join, even if B AND C cannot.
             [ExtractRedundantConjunct, Normalize]
            -(Or $left:^(Or)
            +(Or
            +    $left:^(Or)
                 $right:^(Or) &
                     (Succeeded
                         $conjunct:(FindRedundantConjunct $left $right)
                     )
FAIL
FAIL	github.com/cockroachdb/cockroach/pkg/testutils/lint	0.227s

Release note: None

The optfmt linter only shows the problematic files. This can be inconvenient for
anyone who doesn't regularly touch .opt files and has optfmt set up in their
editor (or has no idea what it even is). This change improves `optfmt -l` to
include a diff which can be applied to fix the files. Sample output:

```
--- FAIL: TestLint (0.00s)
    --- FAIL: TestLint/TestOptfmt (0.20s)
        lint_test.go:340:
            --- /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/agg.opt
            +++ /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/agg.opt
            @@ -5,9 +5,8 @@

             # EliminateAggDistinct removes AggDistinct for aggregations where DISTINCT
             # never modifies the result; for example: min(DISTINCT x).
             [EliminateAggDistinct, Normalize]
            -(AggDistinct
            -$input:(Min | Max | BoolAnd | BoolOr))
            +(AggDistinct $input:(Min | Max | BoolAnd | BoolOr))
             =>
             $input

            --- /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/bool.opt
            +++ /go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/norm/rules/bool.opt
            @@ -152,9 +152,10 @@
             # This transformation is useful for finding a conjunct that can be pushed down
             # in the query tree. For example, if the redundant conjunct A is fully bound by
             # one side of a join, it can be pushed through the join, even if B AND C cannot.
             [ExtractRedundantConjunct, Normalize]
            -(Or $left:^(Or)
            +(Or
            +    $left:^(Or)
                 $right:^(Or) &
                     (Succeeded
                         $conjunct:(FindRedundantConjunct $left $right)
                     )
FAIL
FAIL	github.com/cockroachdb/cockroach/pkg/testutils/lint	0.227s
```

Release note: None
@RaduBerinde RaduBerinde requested a review from maddyblue May 10, 2020 02:11
@RaduBerinde RaduBerinde requested a review from a team as a code owner May 10, 2020 02:11
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@blathers-crl
Copy link

blathers-crl bot commented May 10, 2020

❌ The GitHub CI (Cockroach) build has failed on 7743a098.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@RaduBerinde
Copy link
Member Author

bors r+

@RaduBerinde
Copy link
Member Author

bors r-

@RaduBerinde
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented May 13, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented May 13, 2020

Build succeeded

@craig craig bot merged commit 3531318 into cockroachdb:master May 13, 2020
@RaduBerinde RaduBerinde deleted the optfmt-diff branch May 13, 2020 16:15
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 this pull request may close these issues.

3 participants