rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huzongt...@apache.org
Subject [rocketmq-client-go] branch native updated: [ISSUE #88]use golangci to improve code quality (#83)
Date Thu, 04 Jul 2019 07:44:53 GMT
This is an automated email from the ASF dual-hosted git repository.

huzongtang pushed a commit to branch native
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-go.git


The following commit(s) were added to refs/heads/native by this push:
     new d347650  [ISSUE #88]use golangci to improve code quality (#83)
d347650 is described below

commit d347650a30e8463f74da5156b2ffb50997f30ec9
Author: xujianhai666 <52450794+xujianhai666@users.noreply.github.com>
AuthorDate: Thu Jul 4 15:44:48 2019 +0800

    [ISSUE #88]use golangci to improve code quality (#83)
    
    * fix address for issue
    
    * use golangci fix goalng usage problem
---
 .golangci.yml             | 172 ++++++++++++++++++++++++++++++++++++++++++++++
 README.md                 |   2 +-
 benchmark/consumer.go     |   8 +--
 benchmark/producer.go     |   4 +-
 utils/helper.go           |   6 +-
 utils/messagesysflag.go   |  18 ++---
 utils/ring_buffer_test.go |   1 -
 7 files changed, 191 insertions(+), 20 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 0000000..07d6b09
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,172 @@
+service:
+  # When updating this, also update bin/linters.sh accordingly
+  golangci-lint-version: 1.16.x # use the fixed version to not introduce new linters unexpectedly
+run:
+  # timeout for analysis, e.g. 30s, 5m, default is 1m
+  deadline: 20m
+
+  # which dirs to skip: they won't be analyzed;
+  # can use regexp here: generated.*, regexp is applied on full path;
+  # default value is empty list, but next dirs are always skipped independently
+  # from this option's value:
+  #   	vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
+
+linters:
+  enable-all: true
+  disable:
+    - depguard
+    - dupl
+    - gochecknoglobals
+    - gochecknoinits
+    - goconst
+    - gocyclo
+    - gosec
+    - nakedret
+    - prealloc
+    - scopelint
+  fast: false
+
+linters-settings:
+  errcheck:
+    # report about not checking of errors in type assetions: `a := b.(MyStruct)`;
+    # default is false: such cases aren't reported by default.
+    check-type-assertions: false
+
+    # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
+    # default is false: such cases aren't reported by default.
+    check-blank: false
+  govet:
+    # report about shadowed variables
+    check-shadowing: false
+  golint:
+    # minimal confidence for issues, default is 0.8
+    min-confidence: 0.0
+  gofmt:
+    # simplify code: gofmt with `-s` option, true by default
+    simplify: true
+  goimports:
+    # put imports beginning with prefix after 3rd-party packages;
+    # it's a comma-separated list of prefixes
+    local-prefixes: istio.io/
+  maligned:
+    # print struct with more effective memory layout or not, false by default
+    suggest-new: true
+  misspell:
+    # Correct spellings using locale preferences for US or UK.
+    # Default is to use a neutral variety of English.
+    # Setting locale to US will correct the British spelling of 'colour' to 'color'.
+    locale: US
+  lll:
+    # max line length, lines longer will be reported. Default is 120.
+    # '\t' is counted as 1 character by default, and can be changed with the tab-width option
+    line-length: 160
+    # tab width in spaces. Default to 1.
+    tab-width: 1
+  unused:
+    # treat code as a program (not a library) and report unused exported identifiers; default
is false.
+    # XXX: if you enable this setting, unused will report a lot of false-positives in text
editors:
+    # if it's called for subdir of a project it can't find funcs usages. All text editor
integrations
+    # with golangci-lint call it on a directory with the changed file.
+    check-exported: false
+  unparam:
+    # call graph construction algorithm (cha, rta). In general, use cha for libraries,
+    # and rta for programs with main packages. Default is cha.
+    algo: cha
+
+    # Inspect exported functions, default is false. Set to true if no external program/library
imports your code.
+    # XXX: if you enable this setting, unparam will report a lot of false-positives in text
editors:
+    # if it's called for subdir of a project it can't find external interfaces. All text
editor integrations
+    # with golangci-lint call it on a directory with the changed file.
+    check-exported: false
+  gocritic:
+    enabled-checks:
+      - appendCombine
+      - argOrder
+      - assignOp
+      - badCond
+      - boolExprSimplify
+      - builtinShadow
+      - captLocal
+      - caseOrder
+      - codegenComment
+      - commentedOutCode
+      - commentedOutImport
+      - defaultCaseOrder
+      - deprecatedComment
+      - docStub
+      - dupArg
+      - dupBranchBody
+      - dupCase
+      - dupSubExpr
+      - elseif
+      - emptyFallthrough
+      - equalFold
+      - flagDeref
+      - flagName
+      - hexLiteral
+      - indexAlloc
+      - initClause
+      - methodExprCall
+      - nilValReturn
+      - octalLiteral
+      - offBy1
+      - rangeExprCopy
+      - regexpMust
+      - sloppyLen
+      - stringXbytes
+      - switchTrue
+      - typeAssertChain
+      - typeSwitchVar
+      - typeUnparen
+      - underef
+      - unlambda
+      - unnecessaryBlock
+      - unslice
+      - valSwap
+      - weakCond
+      - yodaStyleExpr
+
+      # Unused
+      # - appendAssign
+      # - commentFormatting
+      # - emptyStringTest
+      # - exitAfterDefer
+      # - ifElseChain
+      # - hugeParam
+      # - importShadow
+      # - nestingReduce
+      # - paramTypeCombine
+      # - ptrToRefParam
+      # - rangeValCopy
+      # - singleCaseSwitch
+      # - sloppyReassign
+      # - unlabelStmt
+      # - unnamedResult
+      # - wrapperFunc
+
+issues:
+  # List of regexps of issue texts to exclude, empty list by default.
+  # But independently from this option we use default exclude patterns,
+  # it can be disabled by `exclude-use-default: false`. To list all
+  # excluded by default patterns execute `golangci-lint run --help`
+  exclude:
+    - composite literal uses unkeyed fields
+
+  exclude-rules:
+    # Exclude some linters from running on test files.
+    - path: _test\.go$|^tests/|^samples/
+      linters:
+        - errcheck
+        - maligned
+
+  # Independently from option `exclude` we use default exclude patterns,
+  # it can be disabled by this option. To list all
+  # excluded by default patterns execute `golangci-lint run --help`.
+  # Default value for this option is true.
+  exclude-use-default: true
+
+  # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
+  max-per-linter: 0
+
+  # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
+  max-same-issues: 0
diff --git a/README.md b/README.md
index 50c5bb0..0db29fa 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ in 2.0.0-alpha1, support:
 * Mailing Lists: <https://rocketmq.apache.org/about/contact/>
 * Home: <https://rocketmq.apache.org>
 * Docs: <https://rocketmq.apache.org/docs/quick-start/>
-* Issues: <https://github.com/apache/rocketmq-client-python/issues>
+* Issues: <https://github.com/apache/rocketmq-client-go/issues>
 * Ask: <https://stackoverflow.com/questions/tagged/rocketmq>
 * Slack: <https://rocketmq-community.slack.com/>
  
diff --git a/benchmark/consumer.go b/benchmark/consumer.go
index 31e7ea9..941713c 100644
--- a/benchmark/consumer.go
+++ b/benchmark/consumer.go
@@ -113,7 +113,7 @@ func init() {
 
 	flags.StringVar(&c.topic, "t", "BenchmarkTest", "topic")
 	flags.StringVar(&c.groupPrefix, "g", "benchmark_consumer", "group prefix")
-	flags.StringVar(&c.nameSrv, "n", "", "namesrv address list, seperated by comma")
+	flags.StringVar(&c.nameSrv, "n", "", "namesrv address list, separated by comma")
 	flags.BoolVar(&c.isPrefixEnable, "p", true, "group prefix is enable")
 	flags.StringVar(&c.filterType, "f", "", "filter type,options:TAG|SQL92, or empty")
 	flags.StringVar(&c.expression, "e", "*", "expression")
@@ -212,15 +212,15 @@ func (c *consumer) run(args []string) {
 
 	wg := sync.WaitGroup{}
 
+	wg.Add(1)
 	go func() {
-		wg.Add(1)
 		c.consumeMsg(&stati, exitChan)
 		wg.Done()
 	}()
 
 	// snapshot
+	wg.Add(1)
 	go func() {
-		wg.Add(1)
 		defer wg.Done()
 		ticker := time.NewTicker(time.Second)
 		for {
@@ -235,8 +235,8 @@ func (c *consumer) run(args []string) {
 	}()
 
 	// print statistic
+	wg.Add(1)
 	go func() {
-		wg.Add(1)
 		defer wg.Done()
 		ticker := time.NewTicker(time.Second * 10)
 		for {
diff --git a/benchmark/producer.go b/benchmark/producer.go
index 7ab3bdc..f3c1c60 100644
--- a/benchmark/producer.go
+++ b/benchmark/producer.go
@@ -221,8 +221,8 @@ func (bp *producer) run(args []string) {
 	}
 
 	// snapshot
+	wg.Add(1)
 	go func() {
-		wg.Add(1)
 		defer wg.Done()
 		ticker := time.NewTicker(time.Second)
 		for {
@@ -237,8 +237,8 @@ func (bp *producer) run(args []string) {
 	}()
 
 	// print statistic
+	wg.Add(1)
 	go func() {
-		wg.Add(1)
 		defer wg.Done()
 		ticker := time.NewTicker(time.Second * 10)
 		for {
diff --git a/utils/helper.go b/utils/helper.go
index c5495b0..d8797dd 100644
--- a/utils/helper.go
+++ b/utils/helper.go
@@ -57,8 +57,8 @@ func MessageClientID() string {
 
 func updateTimestamp() {
 	year, month := time.Now().Year(), time.Now().Month()
-	startTimestamp = int64(time.Date(year, month, 1, 0, 0, 0, 0, time.Local).Unix())
-	nextTimestamp = int64(time.Date(year, month, 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0).Unix())
+	startTimestamp = time.Date(year, month, 1, 0, 0, 0, 0, time.Local).Unix()
+	nextTimestamp = time.Date(year, month, 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0).Unix()
 }
 
 func GetAddressByBytes(data []byte) string {
@@ -78,5 +78,5 @@ func UnCompress(data []byte) []byte {
 }
 
 func IsArrayEmpty(i ...interface{}) bool {
-	return i == nil || len(i) == 0
+	return len(i) == 0
 }
diff --git a/utils/messagesysflag.go b/utils/messagesysflag.go
index 589490d..2410a5b 100644
--- a/utils/messagesysflag.go
+++ b/utils/messagesysflag.go
@@ -18,27 +18,27 @@ limitations under the License.
 package utils
 
 var (
-	COMPRESSED_FLAG = 0x1
+	CompressedFlag = 0x1
 
-	MULTI_TAGS_FLAG = 0x1 << 1
+	MultiTagsFlag = 0x1 << 1
 
-	TRANSACTION_NOT_TYPE = 0
+	TransactionNotType = 0
 
-	TRANSACTION_PREPARED_TYPE = 0x1 << 2
+	TransactionPreparedType = 0x1 << 2
 
-	TRANSACTION_COMMIT_TYPE = 0x2 << 2
+	TransactionCommitType = 0x2 << 2
 
-	TRANSACTION_ROLLBACK_TYPE = 0x3 << 2
+	TransactionRollbackType = 0x3 << 2
 )
 
 func GetTransactionValue(flag int) int {
-	return flag & TRANSACTION_ROLLBACK_TYPE
+	return flag & TransactionRollbackType
 }
 
 func ResetTransactionValue(flag int, typeFlag int) int {
-	return (flag & (^TRANSACTION_ROLLBACK_TYPE)) | typeFlag
+	return (flag & (^TransactionRollbackType)) | typeFlag
 }
 
 func ClearCompressedFlag(flag int) int {
-	return flag & (^COMPRESSED_FLAG)
+	return flag & (^CompressedFlag)
 }
diff --git a/utils/ring_buffer_test.go b/utils/ring_buffer_test.go
index 2d54a85..af35a69 100644
--- a/utils/ring_buffer_test.go
+++ b/utils/ring_buffer_test.go
@@ -111,7 +111,6 @@ func BenchmarkRingBySizeBufferMPMC(b *testing.B) {
 			for i := 0; i < b.N; i++ {
 				p := make([]byte, len(strconv.Itoa(i)))
 				q.ReadBySize(p, 1*time.Second)
-				fmt.Sprintf("%v", p)
 			}
 			wg.Done()
 		}()


Mime
View raw message