Skip to content

Commit

Permalink
Update editorconfig to version 3.1.2 (#955)
Browse files Browse the repository at this point in the history
* update editorconfig to version 3.1.2

issue: https://linear.app/cloudposse/issue/DEV-2952/update-editorconfig-library-version-to-312

* update help with the flags

* update help, test cases and go.mod

* fix No errors found message

* fix the help command path

* fix snapshots
  • Loading branch information
samtholiya authored Jan 19, 2025
1 parent b8f480f commit 07c9e71
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 48 deletions.
54 changes: 32 additions & 22 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 @@ -34,9 +37,9 @@ var editorConfigCmd *cobra.Command = &cobra.Command{
initializeConfig(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
if cliConfig.Help {
cmd.Help()
os.Exit(0)
handleHelpRequest(cmd, args)
if len(args) > 0 {
showUsageAndExit(cmd, args)
}
runMainLogic()
},
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)
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.

36 changes: 22 additions & 14 deletions go.sum

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

2 changes: 1 addition & 1 deletion internal/tui/templates/base_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The '--' (double-dash) can be used to signify the end of Atmos-specific options
and the beginning of additional native arguments and flags for the specific command being run.
Example:
atmos {{.CommandPath}} {{if gt (len .Commands) 0}}[subcommand]{{end}} <component> -s <stack> -- <native-flags>`
{{.CommandPath}} {{if gt (len .Commands) 0}}[subcommand]{{end}} <component> -s <stack> -- <native-flags>`
case Footer:
return `{{if .HasAvailableSubCommands}}
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/TestCLICommands_atmos_--help.stdout.golden

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

Empty file.

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.

Empty file.
Loading

0 comments on commit 07c9e71

Please sign in to comment.