Skip to content

Commit 5e83261

Browse files
authored
[PLUTO-1431] Revive/go installation/running (#144)
* [PLUTO-1431] Fix it test sorting
1 parent faa8566 commit 5e83261

File tree

23 files changed

+1178
-124
lines changed

23 files changed

+1178
-124
lines changed

.codacy/codacy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
runtimes:
22
3+
34
45
56
@@ -10,5 +11,6 @@ tools:
1011
1112
1213
14+
1315
1416

cmd/analyze.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"codacy/cli-v2/plugins"
77
"codacy/cli-v2/tools"
88
"codacy/cli-v2/tools/lizard"
9+
reviveTool "codacy/cli-v2/tools/revive"
910
"encoding/json"
1011
"fmt"
1112
"io"
@@ -412,6 +413,16 @@ func runEnigmaAnalysis(workDirectory string, pathsToCheck []string, outputFile s
412413
return tools.RunEnigma(workDirectory, enigma.InstallDir, enigma.Binaries["codacy-enigma-cli"], pathsToCheck, outputFile, outputFormat)
413414
}
414415

416+
func runReviveAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error {
417+
revive := config.Config.Tools()["revive"]
418+
if revive == nil {
419+
log.Fatal("Revive tool configuration not found")
420+
}
421+
reviveBinary := revive.Binaries["revive"]
422+
423+
return reviveTool.RunRevive(workDirectory, reviveBinary, pathsToCheck, outputFile, outputFormat)
424+
}
425+
415426
var analyzeCmd = &cobra.Command{
416427
Use: "analyze",
417428
Short: "Runs all configured linters.",
@@ -522,6 +533,8 @@ func runTool(workDirectory string, toolName string, args []string, outputFile st
522533
return runLizardAnalysis(workDirectory, args, outputFile, outputFormat)
523534
case "codacy-enigma-cli":
524535
return runEnigmaAnalysis(workDirectory, args, outputFile, outputFormat)
536+
case "revive":
537+
return runReviveAnalysis(workDirectory, args, outputFile, outputFormat)
525538
default:
526539
return fmt.Errorf("unsupported tool: %s", toolName)
527540
}

cmd/configsetup/setup.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"codacy/cli-v2/tools"
1616
"codacy/cli-v2/tools/lizard"
1717
"codacy/cli-v2/tools/pylint"
18+
reviveTool "codacy/cli-v2/tools/revive"
1819
"codacy/cli-v2/utils"
1920
)
2021

@@ -374,6 +375,11 @@ func createToolFileConfigurations(tool domain.Tool, patternConfiguration []domai
374375
return fmt.Errorf("failed to create Lizard config: %v", err)
375376
}
376377
fmt.Println("Lizard configuration created based on Codacy settings")
378+
case domain.Revive:
379+
if err := createReviveConfigFile(patternConfiguration, toolsConfigDir); err != nil {
380+
return fmt.Errorf("failed to write revive config: %v", err)
381+
}
382+
fmt.Println("Revive configuration created based on Codacy settings")
377383
}
378384
return nil
379385
}
@@ -466,6 +472,11 @@ func createLizardConfigFile(toolsConfigDir string, patternConfiguration []domain
466472
return nil
467473
}
468474

475+
func createReviveConfigFile(config []domain.PatternConfiguration, toolsConfigDir string) error {
476+
reviveConfigurationString := reviveTool.GenerateReviveConfig(config)
477+
return os.WriteFile(filepath.Join(toolsConfigDir, "revive.toml"), []byte(reviveConfigurationString), utils.DefaultFilePerms)
478+
}
479+
469480
// buildDefaultConfigurationFiles creates default configuration files for all tools
470481
func BuildDefaultConfigurationFiles(toolsConfigDir string, flags domain.InitFlags) error {
471482
// Get all supported tool UUIDs
@@ -671,6 +682,8 @@ func createToolConfigurationFile(uuid string, patternsConfig []domain.PatternCon
671682
return createSemgrepConfigFile(patternsConfig, toolsConfigDir)
672683
case domain.Lizard:
673684
return createLizardConfigFile(toolsConfigDir, patternsConfig)
685+
case domain.Revive:
686+
return createReviveConfigFile(patternsConfig, toolsConfigDir)
674687
default:
675688
if meta, ok := domain.SupportedToolsMetadata[uuid]; ok {
676689
return fmt.Errorf("configuration creation not implemented for tool %s", meta.Name)

config/tools-installer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string
167167
// Execute the installation command using the package manager
168168
cmd := exec.Command(packageManagerBinary, strings.Split(installCmd, " ")...)
169169

170+
// Special handling for Go tools: set GOBIN so the binary is installed in the tool's install directory
171+
if toolInfo.Runtime == "go" {
172+
env := os.Environ()
173+
env = append(env, "GOBIN="+toolInfo.InstallDir)
174+
cmd.Env = env
175+
}
176+
170177
// Special handling for ESLint installation in Linux (WSL) environment
171178
if toolInfo.Name == "eslint" && runtime.GOOS == "linux" {
172179
// Get node binary directory to add to PATH

domain/tool.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
DartAnalyzer string = "d203d615-6cf1-41f9-be5f-e2f660f7850f"
2828
Semgrep string = "6792c561-236d-41b7-ba5e-9d6bee0d548b"
2929
Lizard string = "76348462-84b3-409a-90d3-955e90abfb87"
30+
Revive string = "bd81d1f4-1406-402d-9181-1274ee09f1aa"
3031
)
3132

3233
type ToolInfo struct {
@@ -45,4 +46,5 @@ var SupportedToolsMetadata = map[string]ToolInfo{
4546
DartAnalyzer: {Name: "dartanalyzer", Priority: 0},
4647
Lizard: {Name: "lizard", Priority: 0},
4748
Semgrep: {Name: "semgrep", Priority: 0},
49+
Revive: {Name: "revive", Priority: 0},
4850
}

integration-tests/init-without-token/expected/codacy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
runtimes:
22
3+
34
45
56
@@ -9,5 +10,6 @@ tools:
910
1011
1112
13+
1214
1315

integration-tests/init-without-token/expected/tools-configs/eslint.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default [
99
"no-class-assign": ["error"],
1010
"no-compare-neg-zero": ["error"],
1111
"no-cond-assign": ["error", "except-parens"],
12-
"no-const-assign": ["error"],
1312
"no-constant-condition": ["error", {"checkLoops": true}],
13+
"no-const-assign": ["error"],
1414
"no-control-regex": ["error"],
1515
"no-debugger": ["error"],
1616
"no-delete-var": ["error"],
@@ -31,7 +31,7 @@ export default [
3131
"no-import-assign": ["error"],
3232
"no-inner-declarations": ["error", "functions"],
3333
"no-invalid-regexp": ["error"],
34-
"no-irregular-whitespace": ["error", {"skipStrings": true, "skipJSXText": false, "skipRegExps": false, "skipComments": false, "skipTemplates": false}],
34+
"no-irregular-whitespace": ["error", {"skipComments": false, "skipJSXText": false, "skipRegExps": false, "skipStrings": true, "skipTemplates": false}],
3535
"no-loss-of-precision": ["error"],
3636
"no-misleading-character-class": ["error"],
3737
"no-mixed-spaces-and-tabs": ["error"],
@@ -60,7 +60,7 @@ export default [
6060
"no-useless-escape": ["error"],
6161
"no-with": ["error"],
6262
"require-yield": ["error"],
63-
"use-isnan": ["error", {"enforceForSwitchCase": true, "enforceForIndexOf": false}],
63+
"use-isnan": ["error", {"enforceForIndexOf": false, "enforceForSwitchCase": true}],
6464
"valid-typeof": ["error", {"requireStringLiterals": false}],
6565
}
6666
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
patterns:
22
Lizard_ccn-medium:
33
category: Complexity
4-
description: Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 8.
4+
description: Checks if the cyclomatic complexity of a function or logic block exceeds the medium threshold (default is 8).
55
explanation: |-
66
# Medium Cyclomatic Complexity control
77
@@ -11,20 +11,20 @@ patterns:
1111
severityLevel: Warning
1212
threshold: 8
1313
timeToFix: 5
14-
title: Medium Cyclomatic Complexity control
14+
title: Enforce Medium Cyclomatic Complexity Threshold
1515
Lizard_file-nloc-medium:
1616
category: Complexity
17-
description: Check the number of lines of code (without comments) in a file. If the threshold is not met, raise a Medium issue. The default threshold is 500.
17+
description: This rule checks if the number of lines of code (excluding comments) in a file exceeds a medium threshold, typically 500 lines.
1818
explanation: ""
1919
id: Lizard_file-nloc-medium
2020
level: Warning
2121
severityLevel: Warning
2222
threshold: 500
2323
timeToFix: 5
24-
title: Medium File NLOC control - Number of Lines of Code (without comments)
24+
title: Enforce Medium File Length Limit Based on Number of Lines of Code
2525
Lizard_nloc-medium:
2626
category: Complexity
27-
description: Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
27+
description: Checks if the number of lines of code (excluding comments) in a function exceeds a medium threshold (default 50 lines).
2828
explanation: |-
2929
# Medium NLOC control - Number of Lines of Code (without comments)
3030
@@ -34,10 +34,10 @@ patterns:
3434
severityLevel: Warning
3535
threshold: 50
3636
timeToFix: 5
37-
title: Medium NLOC control - Number of Lines of Code (without comments)
37+
title: Enforce Medium Number of Lines of Code (NLOC) Limit
3838
Lizard_parameter-count-medium:
3939
category: Complexity
40-
description: Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 8.
40+
description: This rule checks the number of parameters passed to a function and raises an issue if it exceeds a medium threshold, which by default is 8 parameters.
4141
explanation: |-
4242
# Medium Parameter count control
4343
@@ -47,4 +47,4 @@ patterns:
4747
severityLevel: Warning
4848
threshold: 8
4949
timeToFix: 5
50-
title: Medium Parameter count control
50+
title: Enforce Medium Parameter Count Limit
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[revive]
2+
ignoreGeneratedHeader = true
3+
severity = "warning"
4+
confidence = 0.8
5+
errorCode = 0
6+
warningCode = 0
7+
8+
rules = ["blank-imports", "context-as-argument", "context-keys-type", "dot-imports", "empty-block", "error-naming", "error-return", "error-strings", "errorf", "exported", "increment-decrement", "indent-error-flow", "package-comments", "range", "receiver-naming", "redefines-builtin-id", "superfluous-else", "time-naming", "unexported-return", "unreachable-code", "unused-parameter", "var-declaration", "var-naming"]
9+
10+
[rule.blank-imports]
11+
12+
[rule.context-as-argument]
13+
14+
[rule.context-keys-type]
15+
16+
[rule.dot-imports]
17+
18+
[rule.empty-block]
19+
20+
[rule.error-naming]
21+
22+
[rule.error-return]
23+
24+
[rule.error-strings]
25+
26+
[rule.errorf]
27+
28+
[rule.exported]
29+
30+
[rule.increment-decrement]
31+
32+
[rule.indent-error-flow]
33+
34+
[rule.package-comments]
35+
36+
[rule.range]
37+
38+
[rule.receiver-naming]
39+
40+
[rule.redefines-builtin-id]
41+
42+
[rule.superfluous-else]
43+
arguments = [""]
44+
45+
[rule.time-naming]
46+
47+
[rule.unexported-return]
48+
49+
[rule.unreachable-code]
50+
51+
[rule.unused-parameter]
52+
53+
[rule.var-declaration]
54+
55+
[rule.var-naming]
56+

integration-tests/init-without-token/expected/tools-configs/ruleset.xml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<ruleset name="Codacy PMD Ruleset"
3-
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
3+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
66
<description>Codacy PMD Ruleset</description>
77
<rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts"/>
88
<rule ref="category/apex/design.xml/ExcessiveClassLength"/>
@@ -13,8 +13,8 @@
1313
<rule ref="category/apex/security.xml/ApexDangerousMethods"/>
1414
<rule ref="category/apex/security.xml/ApexInsecureEndpoint"/>
1515
<rule ref="category/apex/security.xml/ApexOpenRedirect"/>
16-
<rule ref="category/apex/security.xml/ApexSOQLInjection"/>
1716
<rule ref="category/apex/security.xml/ApexSharingViolations"/>
17+
<rule ref="category/apex/security.xml/ApexSOQLInjection"/>
1818
<rule ref="category/apex/security.xml/ApexSuggestUsingNamedCred"/>
1919
<rule ref="category/apex/security.xml/ApexXSSFromEscapeFalse"/>
2020
<rule ref="category/apex/security.xml/ApexXSSFromURLParam"/>
@@ -23,12 +23,12 @@
2323
<rule ref="category/ecmascript/bestpractices.xml/UseBaseWithParseInt"/>
2424
<rule ref="category/ecmascript/codestyle.xml/AssignmentInOperand">
2525
<properties>
26-
<property name="allowWhile" value="false"/>
27-
<property name="allowIf" value="false"/>
28-
<property name="allowTernaryResults" value="false"/>
29-
<property name="allowTernary" value="false"/>
3026
<property name="allowFor" value="false"/>
27+
<property name="allowIf" value="false"/>
3128
<property name="allowIncrementDecrement" value="false"/>
29+
<property name="allowTernary" value="false"/>
30+
<property name="allowTernaryResults" value="false"/>
31+
<property name="allowWhile" value="false"/>
3232
</properties>
3333
</rule>
3434
<rule ref="category/ecmascript/codestyle.xml/UnnecessaryBlock"/>
@@ -49,13 +49,13 @@
4949
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
5050
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
5151
<properties>
52-
<property name="testClassPattern" value="^Test.*$|^[A-Z][a-zA-Z0-9]*Test(s|Case)?$"/>
5352
<property name="abstractClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
54-
<property name="classPattern" value="[A-Z][a-zA-Z0-9]*"/>
55-
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
5653
<property name="annotationPattern" value="[A-Z][a-zA-Z0-9]*"/>
54+
<property name="classPattern" value="[A-Z][a-zA-Z0-9]*"/>
5755
<property name="enumPattern" value="[A-Z][a-zA-Z0-9]*"/>
5856
<property name="interfacePattern" value="[A-Z][a-zA-Z0-9]*"/>
57+
<property name="testClassPattern" value="^Test.*$|^[A-Z][a-zA-Z0-9]*Test(s|Case)?$"/>
58+
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
5959
</properties>
6060
</rule>
6161
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
@@ -64,11 +64,11 @@
6464
<rule ref="category/java/codestyle.xml/MethodNamingConventions">
6565
<properties>
6666
<property name="junit3TestPattern" value="test[A-Z0-9][a-zA-Z0-9]*"/>
67+
<property name="junit4TestPattern" value="[a-z][a-zA-Z0-9]*"/>
6768
<property name="junit5TestPattern" value="[a-z][a-zA-Z0-9]*"/>
68-
<property name="staticPattern" value="[a-z][a-zA-Z0-9]*"/>
6969
<property name="methodPattern" value="[a-z][a-zA-Z0-9]*"/>
70-
<property name="junit4TestPattern" value="[a-z][a-zA-Z0-9]*"/>
7170
<property name="nativePattern" value="[a-z][a-zA-Z0-9]*"/>
71+
<property name="staticPattern" value="[a-z][a-zA-Z0-9]*"/>
7272
</properties>
7373
</rule>
7474
<rule ref="category/java/codestyle.xml/NoPackage"/>
@@ -104,9 +104,9 @@
104104
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
105105
<rule ref="category/java/errorprone.xml/EmptyFinalizer"/>
106106
<rule ref="category/java/errorprone.xml/EqualsNull"/>
107+
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
107108
<rule ref="category/java/errorprone.xml/JUnitSpelling"/>
108109
<rule ref="category/java/errorprone.xml/JUnitStaticSuite"/>
109-
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
110110
<rule ref="category/java/errorprone.xml/MethodWithSameNameAsEnclosingClass"/>
111111
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
112112
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass">
@@ -152,8 +152,8 @@
152152
<property name="maxmethods" value="1"/>
153153
</properties>
154154
</rule>
155-
<rule ref="category/plsql/errorprone.xml/TO_DATEWithoutDateFormat"/>
156155
<rule ref="category/plsql/errorprone.xml/TO_DATE_TO_CHAR"/>
156+
<rule ref="category/plsql/errorprone.xml/TO_DATEWithoutDateFormat"/>
157157
<rule ref="category/plsql/errorprone.xml/TO_TIMESTAMPWithoutDateFormat"/>
158158
<rule ref="category/pom/errorprone.xml/InvalidDependencyTypes">
159159
<properties>

0 commit comments

Comments
 (0)