Skip to content

Commit

Permalink
Fix legacy linting issues. Solve issue #24 (#28)
Browse files Browse the repository at this point in the history
* fix(fix-legacy-linting-issues): Disable long line reporting and exhaustiveness checking

* fix(fix-legacy-linting-issues): fix format linting issue

Update codec.go

* fix(fix-legacy-linting-issues): modify statements

Update codec.go

Update codec.go

modify statement

* fix(fix-legacy-linting-issues): fix declaration shadowing


* fix(fix-legacy-linting-issues): rewirte single type-switch

Update codec.go

* fix(fix-legacy-linting-issues): fix unused code

fix unused

fix(fix-legacy-linting-issues): fix unused code

Update jsoncolor.go

* fix(fix-legacy-linting-issues): Rewrite syntaxError, Remove init function and global variable "syntaxErrorMsgOffset"

* fix(fix-legacy-linting-issues): Display line number in golangci-lint action output

* fix(fix-legacy-linting-issues): golangci-lint exti when failed

* fix(fix-legacy-linting-issues): fix naked return

* fix(fix-legacy-linting-issues): fix redefines builtin function

* fix(fix-legacy-linting-issues): Use errors.As to check for specific errors

* fix(fix-legacy-linting-issues): Use errors.Is to check for a specific error

* fix(fix-legacy-linting-issues): fix indent-error-flow

* fix(fix-legacy-linting-issues): No value of int64 less than MinInt64 or greater than MaxInt64

* fix(fix-legacy-linting-issues): unnecessary conversion (unconvert)

* fix(fix-legacy-linting-issues): Error return value is not checked

* fix(fix-legacy-linting-issues): Implicit memory aliasing in for loop

* fix(fix-legacy-linting-issues): fix gofumpt linting issue

* fix(fix-legacy-linting-issues): Fix duplicate line

* fix(fix-legacy-linting-issues): Remove deprecated and unused funtion

* fix(fix-legacy-linting-issues): Fix function "appendStructFields" is too long

* - Cleaned up some typos.
- Consolidated use of err/err2 names for multiple error variables.

* fix(fix-legacy-linting-issues): Remove all unused code

* fix(fix-legacy-linting-issues): Rename function name to make it more clearer

* Rename function name

---------

Co-authored-by: neilotoole <neilotoole@apache.org>
  • Loading branch information
dreamjz and neilotoole authored Nov 15, 2023
1 parent 6780a26 commit 1637fae
Show file tree
Hide file tree
Showing 19 changed files with 499 additions and 659 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# We're explicitly setting the exit code to 0 because we don't want the CI to fail
# if there are linting errors right now (because there's a bunch of linting errors!)
# Ultimately we want to set the exit code to 1.
args: --issues-exit-code=0
args: --issues-exit-code=1 --out-format=colored-line-number

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ linters:
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
- exhaustive # checks exhaustiveness of enum switch statements
#- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
Expand All @@ -231,7 +231,7 @@ linters:
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- lll # reports long lines
#- lll # reports long lines
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- nakedret # finds naked returns in functions greater than a specified function length
Expand Down
20 changes: 7 additions & 13 deletions cmd/jc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//
// Examples:
//
// $ cat example.json | jc
// $ cat example.json | jc -c false

// $ cat example.json | jc
// $ cat example.json | jc -c false
package main

import (
Expand Down Expand Up @@ -45,9 +44,8 @@ Example Usage:
$ jc -c -p=false -i ./testdata/sakila_actor.json
# Pipe a JSON input file to jc, outputting to a specified file; and DO NOT prettify
$ cat ./testdata/sakila_actor.json | jc -p=false -o /tmp/out.json
`
fmt.Fprintf(os.Stderr, msg)
$ cat ./testdata/sakila_actor.json | jc -p=false -o /tmp/out.json`
fmt.Fprintln(os.Stderr, msg)
}

func main() {
Expand Down Expand Up @@ -124,7 +122,7 @@ func doMain() error {

var enc *json.Encoder

if flagColorize != nil && *flagColorize == true && json.IsColorTerminal(out) {
if flagColorize != nil && *flagColorize && json.IsColorTerminal(out) {
out = colorable.NewColorable(out.(*os.File)) // colorable is needed for Windows
enc = json.NewEncoder(out)
clrs := json.DefaultColors()
Expand All @@ -136,14 +134,10 @@ func doMain() error {
enc = json.NewEncoder(out)
}

if flagPretty != nil && *flagPretty == true {
if flagPretty != nil && *flagPretty {
// Pretty-print, i.e. set indent
enc.SetIndent("", " ")
}

if err = enc.Encode(jsn); err != nil {
return err
}

return nil
return enc.Encode(jsn)
}
Loading

0 comments on commit 1637fae

Please sign in to comment.