-
Notifications
You must be signed in to change notification settings - Fork 2
/
analysis_configuration.go
39 lines (31 loc) · 1.35 KB
/
analysis_configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package codacytool
import (
"encoding/json"
"os"
"path/filepath"
"github.com/sirupsen/logrus"
)
const defaultAnalysisConfigurationFile = ".codacyrc"
// AnalysisConfiguration represents the files to analyse and the tools to analyze them with, as obtained via the .codacyrc file.
type AnalysisConfiguration struct {
Files *[]string `json:"files"`
Tools *[]ToolDefinition `json:"tools"`
}
// loadAnalysisConfiguration loads the analysis configuration from the default file.
// If the file does not exist, an empty AnalysisConfiguration is returned.
// Tools should know how to deal with the absence of these values.
// If the file exists but is invalid, the execution is aborted.
func loadAnalysisConfiguration(runConfiguration RunConfiguration) (AnalysisConfiguration, error) {
fileLocation := filepath.Join(runConfiguration.ToolConfigurationDir, defaultAnalysisConfigurationFile)
analysisConfiguration := AnalysisConfiguration{}
fileContent, err := os.ReadFile(fileLocation)
if err != nil {
logrus.Infof("Failed to read analysis configuration file: %s\n%s", fileLocation, err.Error())
return analysisConfiguration, nil
}
err = json.Unmarshal(fileContent, &analysisConfiguration)
if err != nil {
logrus.Infof("Failed to parse analysis configuration file content: %s\n%s", string(fileContent), err.Error())
}
return analysisConfiguration, err
}