Skip to content

Commit

Permalink
Use consistent config names
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Mar 4, 2020
1 parent dc5abc7 commit 320b4e5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
6 changes: 3 additions & 3 deletions cmd/wsl/main.go
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/bombsimon/wsl/v2"
"github.com/bombsimon/wsl/v3"
)

// nolint: gocognit
Expand Down Expand Up @@ -36,8 +36,8 @@ func main() {
flag.BoolVar(&config.AllowCuddleDeclaration, "allow-cuddle-declarations", false, "Allow declarations to be cuddled")
flag.BoolVar(&config.AllowTrailingComment, "allow-trailing-comment", false, "Allow blocks to end with a comment")
flag.BoolVar(&config.AllowSeparatedLeadingComment, "allow-separated-leading-comment", false, "Allow empty newlines in leading comments")
flag.BoolVar(&config.MustCuddleErrCheckAndAssign, "enforce-err-cuddling", false, "Enforce cuddling of error checks with error var assignment")
flag.IntVar(&config.CaseForceTrailingWhitespaceLimit, "force-case-trailing-whitespace", 0, "Force newlines for case blocks > this number.")
flag.BoolVar(&config.ForceCuddleErrCheckAndAssign, "force-err-cuddling", false, "Force cuddling of error checks with error var assignment")
flag.IntVar(&config.ForceCaseTrailingWhitespaceLimit, "force-case-trailing-whitespace", 0, "Force newlines for case blocks > this number.")

flag.Parse()

Expand Down
9 changes: 5 additions & 4 deletions go.mod
@@ -1,11 +1,12 @@
module github.com/bombsimon/wsl/v2
module github.com/bombsimon/wsl/v3

go 1.12

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/stretchr/testify v1.5.1
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
15 changes: 9 additions & 6 deletions go.sum
@@ -1,21 +1,24 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
Expand Down
18 changes: 9 additions & 9 deletions wsl.go
Expand Up @@ -95,7 +95,7 @@ type Configuration struct {

// If the number of lines in a case block is equal to or lager than this
// number, the case *must* end white a newline.
CaseForceTrailingWhitespaceLimit int
ForceCaseTrailingWhitespaceLimit int

// AllowTrailingComment will allow blocks to end with comments.
AllowTrailingComment bool
Expand Down Expand Up @@ -133,7 +133,7 @@ type Configuration struct {
// mu.Unlock()
AllowCuddleWithRHS []string

// MustCuddleErrCheckAndAssign will cause an error when an If statement that
// ForceCuddleErrCheckAndAssign will cause an error when an If statement that
// checks an error variable doesn't cuddle with the assignment of that variable.
// This defaults to false but setting it to true will cause the following
// to generate an error:
Expand All @@ -143,9 +143,9 @@ type Configuration struct {
// if err != nil {
// return err
// }
MustCuddleErrCheckAndAssign bool
ForceCuddleErrCheckAndAssign bool

// When MustCuddleErrCheckAndAssign is enabled this is a list of names
// When ForceCuddleErrCheckAndAssign is enabled this is a list of names
// used for error variables to check for in the conditional.
// Defaults to just "err"
ErrorVariableNames []string
Expand All @@ -159,10 +159,10 @@ func DefaultConfig() Configuration {
AllowMultiLineAssignCuddle: true,
AllowTrailingComment: false,
AllowSeparatedLeadingComment: false,
CaseForceTrailingWhitespaceLimit: 0,
ForceCuddleErrCheckAndAssign: false,
ForceCaseTrailingWhitespaceLimit: 0,
AllowCuddleWithCalls: []string{"Lock", "RLock"},
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
MustCuddleErrCheckAndAssign: false,
ErrorVariableNames: []string{"err"},
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {

// If we're not cuddled and we don't need to enforce err-check cuddling
// then we can bail out here
if !cuddledWithLastStmt && !p.config.MustCuddleErrCheckAndAssign {
if !cuddledWithLastStmt && !p.config.ForceCuddleErrCheckAndAssign {
continue
}

Expand Down Expand Up @@ -1080,9 +1080,9 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, ne
hasTrailingWhitespace := p.nodeEnd(lastStatement)+caseTrailingCommentLines != blockEndLine

// If the force trailing limit is configured and we don't end with a newline.
if p.config.CaseForceTrailingWhitespaceLimit > 0 && !hasTrailingWhitespace {
if p.config.ForceCaseTrailingWhitespaceLimit > 0 && !hasTrailingWhitespace {
// Check if the block size is too big to miss the newline.
if blockSize >= p.config.CaseForceTrailingWhitespaceLimit {
if blockSize >= p.config.ForceCaseTrailingWhitespaceLimit {
p.addError(lastStatement.Pos(), reasonCaseBlockTooCuddly)
}
}
Expand Down
36 changes: 18 additions & 18 deletions wsl_test.go
Expand Up @@ -1423,7 +1423,7 @@ func TestWithConfig(t *testing.T) {
}
}`),
customConfig: &Configuration{
CaseForceTrailingWhitespaceLimit: 0,
ForceCaseTrailingWhitespaceLimit: 0,
AllowTrailingComment: false,
},
},
Expand Down Expand Up @@ -1471,7 +1471,7 @@ func TestWithConfig(t *testing.T) {
}
}`),
customConfig: &Configuration{
CaseForceTrailingWhitespaceLimit: 3,
ForceCaseTrailingWhitespaceLimit: 3,
AllowTrailingComment: true,
},
expectedErrorStrings: []string{
Expand All @@ -1483,8 +1483,8 @@ func TestWithConfig(t *testing.T) {
{
description: "must cuddle error checks with the error assignment",
customConfig: &Configuration{
MustCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
ForceCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
},
code: []byte(`package main
Expand All @@ -1502,9 +1502,9 @@ func TestWithConfig(t *testing.T) {
{
description: "must cuddle error checks with the error assignment multivalue",
customConfig: &Configuration{
AllowMultiLineAssignCuddle: true,
MustCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
AllowMultiLineAssignCuddle: true,
ForceCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
},
code: []byte(`package main
Expand All @@ -1522,8 +1522,8 @@ func TestWithConfig(t *testing.T) {
{
description: "must cuddle error checks with the error assignment only on assignment",
customConfig: &Configuration{
MustCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
ForceCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
},
code: []byte(`package main
Expand All @@ -1548,9 +1548,9 @@ func TestWithConfig(t *testing.T) {
{
description: "must cuddle error checks with the error assignment multivalue NoError",
customConfig: &Configuration{
AllowMultiLineAssignCuddle: true,
MustCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
AllowMultiLineAssignCuddle: true,
ForceCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
},
code: []byte(`package main
Expand All @@ -1567,9 +1567,9 @@ func TestWithConfig(t *testing.T) {
{
description: "must cuddle error checks with the error assignment known err",
customConfig: &Configuration{
AllowMultiLineAssignCuddle: true,
MustCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
AllowMultiLineAssignCuddle: true,
ForceCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
},
code: []byte(`package main
Expand All @@ -1587,9 +1587,9 @@ func TestWithConfig(t *testing.T) {
{
description: "err-check cuddle enforcement doesn't generate false-positives.",
customConfig: &Configuration{
AllowMultiLineAssignCuddle: true,
MustCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
AllowMultiLineAssignCuddle: true,
ForceCuddleErrCheckAndAssign: true,
ErrorVariableNames: []string{"err"},
},
code: []byte(`package main
Expand Down

0 comments on commit 320b4e5

Please sign in to comment.