Skip to content

Commit

Permalink
update editorconfig to version 3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
samtholiya committed Jan 19, 2025
1 parent b8f480f commit 1a88f87
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 29 deletions.
50 changes: 30 additions & 20 deletions cmd/validate_editorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ import (
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config"
er "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/error"
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/files"
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/outputformat"
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/utils"
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/validation"
"github.com/spf13/cobra"
)

var (
defaultConfigFilePath = ".editorconfig"
initEditorConfig bool
currentConfig *config.Config
cliConfig config.Config
configFilePath string
tmpExclude string
// defaultConfigFileNames determines the file names where the config is located
defaultConfigFileNames = []string{".editorconfig", ".editorconfig-checker.json", ".ecrc"}
initEditorConfig bool
currentConfig *config.Config
cliConfig config.Config
configFilePath string
tmpExclude string
format string
)

var editorConfigCmd *cobra.Command = &cobra.Command{
Expand All @@ -46,15 +49,14 @@ var editorConfigCmd *cobra.Command = &cobra.Command{
func initializeConfig(cmd *cobra.Command) {
replaceAtmosConfigInConfig(cmd, atmosConfig)

var configPaths = []string{}
if configFilePath == "" {
configFilePath = defaultConfigFilePath
configPaths = append(configPaths, defaultConfigFileNames[:]...)
} else {
configPaths = append(configPaths, configFilePath)
}

var err error
currentConfig, err = config.NewConfig(configFilePath)
if err != nil {
u.LogErrorAndExit(atmosConfig, err)
}
currentConfig = config.NewConfig(configPaths)

if initEditorConfig {
err := currentConfig.Save(version.Version)
Expand Down Expand Up @@ -89,7 +91,17 @@ func replaceAtmosConfigInConfig(cmd *cobra.Command, atmosConfig schema.AtmosConf
cliConfig.DryRun = atmosConfig.Validate.EditorConfig.DryRun
}
if !cmd.Flags().Changed("format") && atmosConfig.Validate.EditorConfig.Format != "" {
cliConfig.Format = atmosConfig.Validate.EditorConfig.Format
format := outputformat.OutputFormat(atmosConfig.Validate.EditorConfig.Format)
if ok := format.IsValid(); !ok {
u.LogErrorAndExit(atmosConfig, fmt.Errorf("%v is not a valid format choose from the following: %v", atmosConfig.Validate.EditorConfig.Format, outputformat.GetArgumentChoiceText()))
}
cliConfig.Format = format
} else if cmd.Flags().Changed("format") {
format := outputformat.OutputFormat(format)
if ok := format.IsValid(); !ok {
u.LogErrorAndExit(atmosConfig, fmt.Errorf("%v is not a valid format choose from the following: %v", atmosConfig.Validate.EditorConfig.Format, outputformat.GetArgumentChoiceText()))
}
cliConfig.Format = format
}
if !cmd.Flags().Changed("logs-level") && atmosConfig.Logs.Level == "trace" {
cliConfig.Verbose = true
Expand Down Expand Up @@ -124,7 +136,7 @@ func replaceAtmosConfigInConfig(cmd *cobra.Command, atmosConfig schema.AtmosConf
// runMainLogic contains the main logic
func runMainLogic() {
config := *currentConfig
u.LogDebug(atmosConfig, config.GetAsString())
u.LogDebug(atmosConfig, config.String())
u.LogTrace(atmosConfig, fmt.Sprintf("Exclude Regexp: %s", config.GetExcludesAsRegularExpression()))

if err := checkVersion(config); err != nil {
Expand All @@ -144,14 +156,12 @@ func runMainLogic() {
}

errors := validation.ProcessValidation(filePaths, config)
er.PrintErrors(errors, config)
u.LogDebug(atmosConfig, fmt.Sprintf("%d files checked", len(filePaths)))
errorCount := er.GetErrorCount(errors)

if errorCount != 0 {
er.PrintErrors(errors, config)
u.LogErrorAndExit(atmosConfig, fmt.Errorf("\n%d errors found", errorCount))
os.Exit(1)
}

u.LogDebug(atmosConfig, fmt.Sprintf("%d files checked", len(filePaths)))
u.PrintMessage("No errors found")
}

Expand All @@ -176,7 +186,7 @@ func addPersistentFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&cliConfig.IgnoreDefaults, "ignore-defaults", false, "Ignore default excludes")
cmd.PersistentFlags().BoolVar(&cliConfig.DryRun, "dry-run", false, "Show which files would be checked")
cmd.PersistentFlags().BoolVar(&cliConfig.ShowVersion, "version", false, "Print the version number")
cmd.PersistentFlags().StringVar(&cliConfig.Format, "format", "default", "Specify the output format: default, gcc")
cmd.PersistentFlags().StringVar(&format, "format", "default", "Specify the output format: default, gcc")
cmd.PersistentFlags().BoolVar(&cliConfig.NoColor, "no-color", false, "Don't print colors")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.TrimTrailingWhitespace, "disable-trim-trailing-whitespace", false, "Disable trailing whitespace check")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.EndOfLine, "disable-end-of-line", false, "Disable end-of-line check")
Expand Down
6 changes: 3 additions & 3 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/test-cases/validate-editorconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ tests:
- "editorconfig"
expect:
diff: []
stderr:
- "2 errors found"
stdout:
- "1 errors found"
exit_code: 1

0 comments on commit 1a88f87

Please sign in to comment.