Skip to content

Commit

Permalink
Linter update + add revive rules (#3127)
Browse files Browse the repository at this point in the history
* Linter update + add revive rules

Signed-off-by: Steve Coffman <steve@khanacademy.org>

* More revive lints

Signed-off-by: Steve Coffman <steve@khanacademy.org>

---------

Signed-off-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
StevenACoffman committed Jun 10, 2024
1 parent e6860c3 commit 6daceaf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
golangci-lint:
env:
GOLANGCI_LINT_VERSION: v1.59.0
GOLANGCI_LINT_VERSION: v1.59.1
strategy:
matrix:
go: ["1.21", "1.22"]
Expand Down
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ linters-settings:
rules:
- name: empty-lines
- name: use-any
- name: struct-tag
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: error-return
- name: error-naming
- name: exported
disabled: true
- name: if-return
- name: increment-decrement
- name: var-declaration
- name: package-comments
disabled: true
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: superfluous-else
- name: unused-parameter
disabled: true
- name: unreachable-code
- name: redefines-builtin-id
testifylint:
disable-all: true
enable:
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c *wsConnection) init() bool {
}
}

var initAckPayload *InitPayload = nil
var initAckPayload *InitPayload
if c.InitFunc != nil {
var ctx context.Context
ctx, initAckPayload, err = c.InitFunc(c.ctx, c.initPayload)
Expand Down
28 changes: 14 additions & 14 deletions internal/code/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ func goModuleRoot(dir string) (string, bool) {
// go.mod is not found in the tree, so the same sentinel value fits all the directories in a tree
goModuleRootCache[d] = result
} else {
if relPath, err := filepath.Rel(result.goModPath, d); err != nil {
relPath, err := filepath.Rel(result.goModPath, d)
if err != nil {
panic(err)
} else {
path := result.moduleName
relPath := filepath.ToSlash(relPath)
if !strings.HasSuffix(relPath, "/") {
path += "/"
}
path += relPath

goModuleRootCache[d] = goModuleSearchResult{
path: path,
goModPath: result.goModPath,
moduleName: result.moduleName,
}
}
path := result.moduleName
relPath = filepath.ToSlash(relPath)
if !strings.HasSuffix(relPath, "/") {
path += "/"
}
path += relPath

goModuleRootCache[d] = goModuleSearchResult{
path: path,
goModPath: result.goModPath,
moduleName: result.moduleName,
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ var generateCmd = &cli.Command{
}
}

if err = api.Generate(cfg); err != nil {
return err
}
return nil
return api.Generate(cfg)
},
}

Expand Down
19 changes: 9 additions & 10 deletions plugin/modelgen/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,17 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error {
getter += "\treturn interfaceSlice\n"
getter += "}"
return getter
} else {
getter := fmt.Sprintf("func (this %s) Get%s() %s { return ", templates.ToGo(model.Name), field.GoName, goType)

if interfaceFieldTypeIsPointer && !structFieldTypeIsPointer {
getter += "&"
} else if !interfaceFieldTypeIsPointer && structFieldTypeIsPointer {
getter += "*"
}
}
getter := fmt.Sprintf("func (this %s) Get%s() %s { return ", templates.ToGo(model.Name), field.GoName, goType)

getter += fmt.Sprintf("this.%s }", field.GoName)
return getter
if interfaceFieldTypeIsPointer && !structFieldTypeIsPointer {
getter += "&"
} else if !interfaceFieldTypeIsPointer && structFieldTypeIsPointer {
getter += "*"
}

getter += fmt.Sprintf("this.%s }", field.GoName)
return getter
}
funcMap := template.FuncMap{
"getInterfaceByName": getInterfaceByName,
Expand Down

0 comments on commit 6daceaf

Please sign in to comment.