SonarSource / sonar-go-archived

SonarGo: Go Analyzer for SonarQube
https://docs.sonarqube.org/display/PLUG/SonarGo
Other
120 stars 24 forks source link

Exception when analyzing gometalinter #339

Closed rucciva closed 5 years ago

rucciva commented 6 years ago

Sonarqube version: 7.3 SonarGo version: 1.1.0 Gometalinter version: gopkg.in/alecthomas/gometalinter.v2 Gometalinter output:

gometalinter --vendor ./... | tee -a gometalinter-report.out
cmd/provision/main.go:212:13:warning: ineffectual assignment to err (ineffassign)
repository/myredcass/myredcass.go:907:4:warning: ineffectual assignment to err (ineffassign)
repository/myredcass/mysql.go:607:8:warning: ineffectual assignment to err (ineffassign)
repository/myredcass/myredcass.go:584::warning: cyclomatic complexity 23 of function (*Myredcass).CreateSubscription() is high (> 10) (gocyclo)
repository/myredcass/balance-syncer_test.go:126::warning: cyclomatic complexity 18 of function testBalanceSyncerSync() is high (> 10) (gocyclo)
repository/myredcass/balance-syncer.go:376::warning: cyclomatic complexity 15 of function (*BalanceSyncer).sync() is high (> 10) (gocyclo)
cmd/consumption/main_test.go:324::warning: cyclomatic complexity 15 of function testSuccessFlow() is high (> 10) (gocyclo)
util/time-cycle.go:83::warning: cyclomatic complexity 13 of function GetTimeCycleGroup() is high (> 10) (gocyclo)
cmd/provision/main.go:856::warning: cyclomatic complexity 13 of function putBalanceIncrement() is high (> 10) (gocyclo)
application/wso2/wso2_test.go:88::warning: cyclomatic complexity 13 of function TestPreSubscriptionBuildSubscription() is high (> 10) (gocyclo)
cmd/provision/main_test.go:1913::warning: cyclomatic complexity 13 of function testDuplicationSubBalanceIncs() is high (> 10) (gocyclo)
cmd/provision/main.go:954::warning: cyclomatic complexity 13 of function putBalanceDecrement() is high (> 10) (gocyclo)
cmd/provision/main_test.go:1625::warning: cyclomatic complexity 12 of function testIncGetIncGetSubBalance() is high (> 10) (gocyclo)
cmd/provision/main.go:451::warning: cyclomatic complexity 12 of function patchAPIPlan() is high (> 10) (gocyclo)
util/converter.go:45::warning: cyclomatic complexity 12 of function GetMapIntValue() is high (> 10) (gocyclo)
util/converter.go:15::warning: cyclomatic complexity 12 of function GetMapFloatValue() is high (> 10) (gocyclo)
application/wso2/wso2_test.go:9::warning: cyclomatic complexity 12 of function TestPreTxBuildPre() is high (> 10) (gocyclo)
cmd/provision/main_test.go:1291::warning: cyclomatic complexity 11 of function testIncIncGetMainBalance() is high (> 10) (gocyclo)
repository/myredcass/myredcass.go:525::warning: cyclomatic complexity 11 of function (*Myredcass).prepareSubscriptionInfo() is high (> 10) (gocyclo)
cmd/consumption/main.go:204::warning: cyclomatic complexity 11 of function applyExternalRateIfAny() is high (> 10) (gocyclo)
cmd/consumption/main_test.go:476::warning: cyclomatic complexity 11 of function TestPropagateError() is high (> 10) (gocyclo)
repository/myredcass/myredcass_test.go:713::warning: cyclomatic complexity 11 of function testProvisionToInactivePlan() is high (> 10) (gocyclo)
repository/myredcass/trx-creator_test.go:114::warning: cyclomatic complexity 11 of function testNormalRefund() is high (> 10) (gocyclo)
helper/testing_helper.go:16:6:warning: exported type TData should have comment or be unexported (golint)
helper/testing_helper.go:22:1:warning: exported function AssertPublisher should have comment or be unexported (golint)
helper/testing_helper.go:37:1:warning: exported function AssertAPI should have comment or be unexported (golint)
helper/testing_helper.go:52:1:warning: exported function AssertPlan should have comment or be unexported (golint)
helper/testing_helper.go:89:1:warning: exported function AssertRate should have comment or be unexported (golint)
helper/testing_helper.go:115:1:warning: exported function AssertRates should have comment or be unexported (golint)
helper/testing_helper.go:131:1:warning: exported function AssertSubscriber should have comment or be unexported (golint)
helper/testing_helper.go:146:1:warning: exported function AssertSubscription should have comment or be unexported (golint)
helper/testing_helper.go:177:1:warning: exported function AssertMainBalance should have comment or be unexported (golint)
helper/testing_helper.go:189:1:warning: exported function AssertSubBalance should have comment or be unexported (golint)
helper/testing_helper.go:205:1:warning: exported function GeneratePublisher should have comment or be unexported (golint)
helper/testing_helper.go:223:1:warning: exported function GenerateSubscriber should have comment or be unexported (golint)
helper/testing_helper.go:241:1:warning: exported function GenerateAPI should have comment or be unexported (golint)
helper/testing_helper.go:263:1:warning: exported function GenerateResources should have comment or be unexported (golint)
helper/testing_helper.go:276:1:warning: exported function GenerateRates should have comment or be unexported (golint)
helper/testing_helper.go:295:1:warning: exported function GetAPIResources should have comment or be unexported (golint)
helper/testing_helper.go:303:1:warning: exported function GetRates should have comment or be unexported (golint)
helper/testing_helper.go:311:1:warning: exported function GeneratePlan should have comment or be unexported (golint)
helper/testing_helper.go:344:1:warning: exported function GenerateSubscription should have comment or be unexported (golint)
helper/testing_helper.go:376:1:warning: exported function RatesToSubscriptionRates should have comment or be unexported (golint)
helper/testing_helper.go:386:1:warning: exported function PlanToMap should have comment or be unexported (golint)
../../../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: error return value not checked (undeclared name: cgoLookupHost) (errcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: error return value not checked (undeclared name: cgoLookupIP) (errcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: error return value not checked (undeclared name: cgoLookupPort) (errcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: error return value not checked (undeclared name: cgoLookupCNAME) (errcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: error return value not checked (undeclared name: cgoLookupPTR) (errcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: unused variable or constant undeclared name: cgoLookupHost (varcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: unused variable or constant undeclared name: cgoLookupIP (varcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: unused variable or constant undeclared name: cgoLookupPort (varcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: unused variable or constant undeclared name: cgoLookupCNAME (varcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: unused variable or constant undeclared name: cgoLookupPTR (varcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: undeclared name: cgoLookupHost (unconvert)
../../../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: undeclared name: cgoLookupIP (unconvert)
../../../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: undeclared name: cgoLookupPort (unconvert)
../../../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: undeclared name: cgoLookupCNAME (unconvert)
../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: undeclared name: cgoLookupPTR (unconvert)
../../../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: undeclared name: cgoLookupHost (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: undeclared name: cgoLookupIP (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: undeclared name: cgoLookupPort (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: undeclared name: cgoLookupCNAME (interfacer)
../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: undeclared name: cgoLookupPTR (interfacer)
cmd/balance-syncer/main.go:31:1:warning: kafkaTopics is unused (deadcode)
cmd/consumption/main.go:27:1:warning: errInvalidRequest is unused (deadcode)
cmd/consumption/main.go:27:1:warning: errTransactionUnrated is unused (deadcode)
repository/myredcass/balance-syncer.go:51:1:warning: minInconsistentPostponedChanSize is unused (deadcode)
repository/myredcass/mysql-query.go:3:1:warning: myQFetchAPIResByAPI is unused (deadcode)
repository/myredcass/mysql-query.go:3:1:warning: myQSaveSubscription is unused (deadcode)
repository/myredcass/mysql-query.go:3:1:warning: myQDeleteSubscriptionByIDAndAppAndPlan is unused (deadcode)
repository/myredcass/mysql-query.go:3:1:warning: myQUpdateSubscriberAffectedBySavingSubscription is unused (deadcode)
cmd/consumption/main.go:145::warning: declaration of "err" shadows declaration at cmd/consumption/main.go:143 (vetshadow)
cmd/consumption/main.go:268::warning: declaration of "err" shadows declaration at cmd/consumption/main.go:235 (vetshadow)
cmd/consumption/main_test.go:425::warning: declaration of "client" shadows declaration at cmd/consumption/main_test.go:25 (vetshadow)
cmd/provision/main.go:537::warning: declaration of "err" shadows declaration at cmd/provision/main.go:523 (vetshadow)
cmd/provision/main.go:886::warning: declaration of "err" shadows declaration at cmd/provision/main.go:873 (vetshadow)
cmd/provision/main.go:984::warning: declaration of "err" shadows declaration at cmd/provision/main.go:971 (vetshadow)
repository/myredcass/balance-syncer.go:224::warning: declaration of "err" shadows declaration at repository/myredcass/balance-syncer.go:214 (vetshadow)
repository/myredcass/balance-syncer.go:227::warning: declaration of "err" shadows declaration at repository/myredcass/balance-syncer.go:214 (vetshadow)
repository/myredcass/balance-syncer.go:245::warning: declaration of "err" shadows declaration at repository/myredcass/balance-syncer.go:236 (vetshadow)
repository/myredcass/balance-syncer.go:418::warning: declaration of "err" shadows declaration at repository/myredcass/balance-syncer.go:376 (vetshadow)
repository/myredcass/myredcass_test.go:38::warning: declaration of "err" shadows declaration at repository/myredcass/myredcass_test.go:35 (vetshadow)
../../../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: unused struct field undeclared name: cgoLookupHost (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: unused struct field undeclared name: cgoLookupIP (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: unused struct field undeclared name: cgoLookupPort (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: unused struct field undeclared name: cgoLookupCNAME (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: unused struct field undeclared name: cgoLookupPTR (structcheck)
../../../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: undeclared name: cgoLookupHost (maligned)
../../../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: undeclared name: cgoLookupIP (maligned)
../../../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: undeclared name: cgoLookupPort (maligned)
../../../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: undeclared name: cgoLookupCNAME (maligned)
../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: undeclared name: cgoLookupPTR (maligned)

Sonar Scanner Config:

sonar.projectName=some/project/version-7.3
sonar.projectKey=some:project:version-7.3
sonar.host.url=https://some-host.com
sonar.login=somerandomtoken12346
sonar.projectVersion=115
sonar.scm.provider=git 
sonar.sources=.
sonar.exclusions=**/vendor/**,**/*_test.go

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**

sonar.go.coverage.reportPaths=coverage.out
sonar.go.gometalinter.reportPaths=gometalinter-report.out

Exception:

...
05:04:36.628 INFO: GoMetaLinterReportSensor: Importing /go/src/somehost.com/some/project/gometalinter-report.out
05:04:36.746 INFO: ------------------------------------------------------------------------
05:04:36.747 INFO: EXECUTION FAILURE
05:04:36.747 INFO: ------------------------------------------------------------------------
05:04:36.748 INFO: Total time: 18.261s
05:04:36.862 INFO: Final Memory: 13M/402M
05:04:36.863 INFO: ------------------------------------------------------------------------
05:04:36.863 ERROR: Error during SonarQube Scanner execution
java.lang.NullPointerException
    at org.sonar.api.batch.fs.internal.RelativePathPredicate.apply(RelativePathPredicate.java:46)
    at org.sonar.api.batch.fs.internal.OrPredicate.apply(OrPredicate.java:60)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
    at java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:294)
    at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206)
    at java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
    at java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
    at org.sonar.api.batch.fs.internal.DefaultFileSystem.inputFile(DefaultFileSystem.java:117)
    at org.sonar.go.plugin.externalreport.AbstractReportSensor.getInputFile(AbstractReportSensor.java:126)
    at org.sonar.go.plugin.externalreport.AbstractReportSensor.addLineIssue(AbstractReportSensor.java:135)
    at org.sonar.go.plugin.externalreport.AbstractReportSensor.importReport(AbstractReportSensor.java:94)
    at org.sonar.go.plugin.externalreport.AbstractReportSensor.execute(AbstractReportSensor.java:79)
    at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:62)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:166)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:300)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:295)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:269)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
    at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
vilchik-elena commented 6 years ago

@rucciva Thanks! I was able to reproduce

Problem is in paths going up (e.g. ../../../../../usr/local/go/src/net/lookup_unix.go:190:23:warning: undeclared name: cgoLookupPTR (maligned))

As a workaround you can remove such paths from your report

vilchik-elena commented 6 years ago

To fix problem inside SonarGo we can ignore paths starting with .. or try to resolve relative paths before passing them to predicate. The main fix should be done in SQ: https://jira.sonarsource.com/browse/SONAR-11225

rucciva commented 6 years ago

Yup, removing .. works. Thanks @vilchik-elena

Nerzal commented 5 years ago

Heyho,

i guess this can be closed.

gometalinter is DEPRECATED and the project will be archived on 2019-04-07

https://github.com/alecthomas/gometalinter

The new standard is https://github.com/golangci/golangci-lint