Skip to content

Commit faaf3dd

Browse files
committed
[PLUTO-1431] Revive/go installation/running
1 parent faa8566 commit faaf3dd

File tree

21 files changed

+645
-9
lines changed

21 files changed

+645
-9
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: 15 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,10 @@ 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+
if err := createReviveConfigFile(patternsConfig, toolsConfigDir); err != nil {
687+
return fmt.Errorf("failed to create default Revive configuration: %w", err)
688+
}
674689
default:
675690
if meta, ok := domain.SupportedToolsMetadata[uuid]; ok {
676691
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
@@ -3,6 +3,7 @@ runtimes:
33
44
55
6+
67
tools:
78
89
@@ -11,3 +12,4 @@ tools:
1112
1213
1314
15+
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/run.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ function Normalize-Config {
7070

7171
$output
7272
}
73+
{ $_ -in @('mjs', 'js') } {
74+
# For JavaScript config files (like ESLint), sort the rule lines within the rules object
75+
$content = Get-Content $file
76+
$output = @()
77+
$inRules = $false
78+
$ruleLines = @()
79+
80+
foreach ($line in $content) {
81+
if ($line -match 'rules: \{') {
82+
$output += $line
83+
$inRules = $true
84+
} elseif ($inRules -and $line -match '^\s*\}') {
85+
# Sort collected rule lines and add them
86+
$output += ($ruleLines | Sort-Object)
87+
$ruleLines = @()
88+
$inRules = $false
89+
$output += $line
90+
} elseif ($inRules) {
91+
# Collect rule lines for sorting
92+
$ruleLines += $line
93+
} else {
94+
$output += $line
95+
}
96+
}
97+
$output
98+
}
7399
{ $_ -in @('rc', 'conf', 'ini', 'xml') } {
74100
Get-Content $file | ForEach-Object {
75101
if ($_ -match '^[^#].*=.*,') {

integration-tests/run.sh

100644100755
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ normalize_config() {
2323
# For YAML files, use yq to sort
2424
yq e '.' "$file" | sort
2525
;;
26+
mjs|js)
27+
# For JavaScript config files (like ESLint), sort the rule lines within the rules object
28+
awk '
29+
/rules: \{/ {
30+
print;
31+
inRules = 1;
32+
next
33+
}
34+
inRules && /^\s*\}/ {
35+
# Sort collected rules and print them
36+
n = asorti(rules, sortedIndices)
37+
for (i = 1; i <= n; i++) {
38+
print rules[sortedIndices[i]]
39+
}
40+
delete rules
41+
inRules = 0
42+
print
43+
next
44+
}
45+
inRules {
46+
# Collect rule lines for sorting
47+
rules[NR] = $0
48+
next
49+
}
50+
{ print }
51+
' "$file"
52+
;;
2653
rc|conf|ini)
2754
# For other config files, sort values after '=' and keep other lines
2855
awk -F'=' '

0 commit comments

Comments
 (0)