ci: Use golang-ci linter
This commit is contained in:
parent
a85a609bbe
commit
44c364e364
|
@ -0,0 +1,22 @@
|
|||
on: [push, pull_request]
|
||||
name: Lint
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.21'
|
||||
cache: false
|
||||
- name: Install PAM
|
||||
run: sudo apt install -y libpam-dev
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.54
|
|
@ -0,0 +1,61 @@
|
|||
# This is for linting. To run it, please use:
|
||||
# golangci-lint run ${MODULE}/... [--fix]
|
||||
|
||||
linters:
|
||||
# linters to run in addition to default ones
|
||||
enable:
|
||||
- dupl
|
||||
- durationcheck
|
||||
- errname
|
||||
- errorlint
|
||||
- exportloopref
|
||||
- forbidigo
|
||||
- forcetypeassert
|
||||
- gci
|
||||
- godot
|
||||
- gofmt
|
||||
- gosec
|
||||
- misspell
|
||||
- nakedret
|
||||
- nolintlint
|
||||
- revive
|
||||
- thelper
|
||||
- tparallel
|
||||
- unconvert
|
||||
- unparam
|
||||
- whitespace
|
||||
|
||||
run:
|
||||
timeout: 5m
|
||||
|
||||
# Get all linter issues, even if duplicated
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
fix: false # we don’t want this in CI
|
||||
exclude:
|
||||
# EXC0001 errcheck: most errors are in defer calls, which are safe to ignore and idiomatic Go (would be good to only ignore defer ones though)
|
||||
- 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv|w\.Stop). is not checked'
|
||||
# EXC0008 gosec: duplicated of errcheck
|
||||
- (G104|G307)
|
||||
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
|
||||
- Potential file inclusion via variable
|
||||
# We want named parameters even if unused, as they help better document the function
|
||||
- unused-parameter
|
||||
# Sometimes it is more readable it do a `if err:=a(); err != nil` tha simpy `return a()`
|
||||
- if-return
|
||||
|
||||
nolintlint:
|
||||
require-explanation: true
|
||||
require-specific: true
|
||||
|
||||
linters-settings:
|
||||
# Forbid the usage of deprecated ioutil and debug prints
|
||||
forbidigo:
|
||||
forbid:
|
||||
- ioutil\.
|
||||
- ^print.*$
|
||||
# Never have naked return ever
|
||||
nakedret:
|
||||
max-func-lines: 1
|
|
@ -94,6 +94,7 @@ func cbPAMConv(s C.int, msg *C.char, c C.uintptr_t) (*C.char, C.int) {
|
|||
var err error
|
||||
v := cgo.Handle(c).Value()
|
||||
style := Style(s)
|
||||
var handler ConversationHandler
|
||||
switch cb := v.(type) {
|
||||
case BinaryConversationHandler:
|
||||
if style == BinaryPrompt {
|
||||
|
@ -102,15 +103,18 @@ func cbPAMConv(s C.int, msg *C.char, c C.uintptr_t) (*C.char, C.int) {
|
|||
return nil, C.PAM_CONV_ERR
|
||||
}
|
||||
return (*C.char)(C.CBytes(bytes)), C.PAM_SUCCESS
|
||||
} else {
|
||||
r, err = cb.RespondPAM(style, C.GoString(msg))
|
||||
}
|
||||
handler = cb
|
||||
case ConversationHandler:
|
||||
if style == BinaryPrompt {
|
||||
return nil, C.PAM_AUTHINFO_UNAVAIL
|
||||
}
|
||||
r, err = cb.RespondPAM(style, C.GoString(msg))
|
||||
handler = cb
|
||||
}
|
||||
if handler == nil {
|
||||
return nil, C.PAM_CONV_ERR
|
||||
}
|
||||
r, err = handler.RespondPAM(style, C.GoString(msg))
|
||||
if err != nil {
|
||||
return nil, C.PAM_CONV_ERR
|
||||
}
|
||||
|
@ -118,6 +122,8 @@ func cbPAMConv(s C.int, msg *C.char, c C.uintptr_t) (*C.char, C.int) {
|
|||
}
|
||||
|
||||
// Transaction is the application's handle for a PAM transaction.
|
||||
//
|
||||
//nolint:errname
|
||||
type Transaction struct {
|
||||
handle *C.pam_handle_t
|
||||
conv *C.struct_pam_conv
|
||||
|
@ -195,7 +201,7 @@ func start(service, user string, handler ConversationHandler, confDir string) (*
|
|||
}
|
||||
|
||||
func (t *Transaction) Error() string {
|
||||
return C.GoString(C.pam_strerror(t.handle, C.int(t.status)))
|
||||
return C.GoString(C.pam_strerror(t.handle, t.status))
|
||||
}
|
||||
|
||||
// Item is a an PAM information type.
|
||||
|
|
Loading…
Reference in New Issue