Skip to content

Commit 0d715f5

Browse files
samtholiyaaknysh
andauthored
Support the --config flag as an array of strings for atmos validate editorconfig (#1173)
* update config to be an array of string for editorconfig * update test case * fix test coverage * Update pkg/schema/schema.go Co-authored-by: Andriy Knysh <[email protected]> * Update cmd/validate_editorconfig.go Co-authored-by: Andriy Knysh <[email protected]> * fix tests * updated website * screengrabs updated * updates * updates --------- Co-authored-by: Andriy Knysh <[email protected]> Co-authored-by: aknysh <[email protected]>
1 parent 1283f07 commit 0d715f5

7 files changed

+54
-38
lines changed

Diff for: cmd/validate_editorconfig.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
initEditorConfig bool
2525
currentConfig *config.Config
2626
cliConfig config.Config
27-
configFilePath string
27+
configFilePaths []string
2828
tmpExclude string
2929
format string
3030
)
@@ -50,10 +50,10 @@ func initializeConfig(cmd *cobra.Command) {
5050
replaceAtmosConfigInConfig(cmd, atmosConfig)
5151

5252
configPaths := []string{}
53-
if configFilePath == "" {
54-
configPaths = append(configPaths, defaultConfigFileNames[:]...)
53+
if len(configFilePaths) == 0 {
54+
configPaths = append(configPaths, defaultConfigFileNames...)
5555
} else {
56-
configPaths = append(configPaths, configFilePath)
56+
configPaths = append(configPaths, configFilePaths...)
5757
}
5858

5959
currentConfig = config.NewConfig(configPaths)
@@ -75,8 +75,8 @@ func initializeConfig(cmd *cobra.Command) {
7575
}
7676

7777
func replaceAtmosConfigInConfig(cmd *cobra.Command, atmosConfig schema.AtmosConfiguration) {
78-
if !cmd.Flags().Changed("config") && atmosConfig.Validate.EditorConfig.ConfigFilePath != "" {
79-
configFilePath = atmosConfig.Validate.EditorConfig.ConfigFilePath
78+
if !cmd.Flags().Changed("config") && len(atmosConfig.Validate.EditorConfig.ConfigFilePaths) > 0 {
79+
configFilePaths = atmosConfig.Validate.EditorConfig.ConfigFilePaths
8080
}
8181
if !cmd.Flags().Changed("exclude") && len(atmosConfig.Validate.EditorConfig.Exclude) > 0 {
8282
tmpExclude = strings.Join(atmosConfig.Validate.EditorConfig.Exclude, ",")
@@ -179,9 +179,9 @@ func checkVersion(config config.Config) error {
179179

180180
// addPersistentFlags adds flags to the root command
181181
func addPersistentFlags(cmd *cobra.Command) {
182-
cmd.PersistentFlags().StringVar(&configFilePath, "config", "", "Path to the configuration file")
182+
cmd.PersistentFlags().StringSliceVar(&configFilePaths, "config", defaultConfigFileNames, "Paths to the configuration files")
183183
cmd.PersistentFlags().StringVar(&tmpExclude, "exclude", "", "Regex to exclude files from checking")
184-
cmd.PersistentFlags().BoolVar(&initEditorConfig, "init", false, "creates an initial configuration")
184+
cmd.PersistentFlags().BoolVar(&initEditorConfig, "init", false, "Create an initial configuration")
185185

186186
cmd.PersistentFlags().BoolVar(&cliConfig.IgnoreDefaults, "ignore-defaults", false, "Ignore default excludes")
187187
cmd.PersistentFlags().BoolVar(&cliConfig.DryRun, "dry-run", false, "Show which files would be checked")

Diff for: cmd/validate_editorconfig_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cmd
2+
3+
import "testing"
4+
5+
func TestInitConfig(t *testing.T) {
6+
// TODO: We need to enhance testing coverage.
7+
// The reason we are skipping this part is because there is already a validate-editorconfig.yaml
8+
// that tests the editorconfig command.
9+
// We have a ticket to address coverage of such test cases here:
10+
// https://linear.app/cloudposse/issue/DEV-3094/update-the-testclicommands
11+
initializeConfig(editorConfigCmd)
12+
}

Diff for: pkg/schema/schema.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ type Validate struct {
170170
}
171171

172172
type EditorConfig struct {
173-
IgnoreDefaults bool `yaml:"ignore_defaults,omitempty" json:"ignore_defaults,omitempty" mapstructure:"ignore_defaults"`
174-
DryRun bool `yaml:"dry_run,omitempty" json:"dry_run,omitempty" mapstructure:"dry_run"`
175-
Format string `yaml:"format,omitempty" json:"format,omitempty" mapstructure:"format"`
176-
Color bool `yaml:"color,omitempty" json:"color,omitempty" mapstructure:"color"`
177-
ConfigFilePath string `yaml:"config_file_path,omitempty" json:"config_file_path,omitempty" mapstructure:"config_file_path"`
178-
Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty" mapstructure:"exclude"`
179-
Init bool `yaml:"init,omitempty" json:"init,omitempty" mapstructure:"init"`
173+
IgnoreDefaults bool `yaml:"ignore_defaults,omitempty" json:"ignore_defaults,omitempty" mapstructure:"ignore_defaults"`
174+
DryRun bool `yaml:"dry_run,omitempty" json:"dry_run,omitempty" mapstructure:"dry_run"`
175+
Format string `yaml:"format,omitempty" json:"format,omitempty" mapstructure:"format"`
176+
Color bool `yaml:"color,omitempty" json:"color,omitempty" mapstructure:"color"`
177+
ConfigFilePaths []string `yaml:"config_file_paths,omitempty" json:"config_file_paths,omitempty" mapstructure:"config_file_paths"`
178+
Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty" mapstructure:"exclude"`
179+
Init bool `yaml:"init,omitempty" json:"init,omitempty" mapstructure:"init"`
180180

181181
DisableEndOfLine bool `yaml:"disable_end_of_line,omitempty" json:"disable_end_of_line,omitempty" mapstructure:"disable_end_of_line"`
182182
DisableInsertFinalNewline bool `yaml:"disable_insert_final_newline,omitempty" json:"disable_insert_final_newline,omitempty" mapstructure:"disable_insert_final_newline"`

Diff for: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_help.stdout.golden

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: website/docs/cli/commands/validate/validate-editorconfig.mdx

+18-18
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ Run `atmos validate editorconfig --help` to see all the available options
3131

3232
```shell
3333
atmos validate editorconfig
34-
atmos validate editorconfig --logs-level trace
34+
atmos validate editorconfig --logs-level Trace
3535
atmos validate editorconfig --no-color
3636
atmos validate editorconfig --dry-run
3737
```
3838

3939
## Flags
4040

41-
| Flag | Description | Alias | Required |
42-
|:---------------------------------------|:----------------------------------------------------------------------|:------|:---------|
43-
|`--config string` |Path to the configuration file | |no |
44-
|`--disable-end-of-line` |Disable end-of-line check (default "false") | |no |
45-
|`--disable-indent-size` |Disable indent size check (default "false") | |no |
46-
|`--disable-indentation` |Disable indentation check (default "false")||no|
47-
|`--disable-insert-final-newline` |Disable final newline check (default "false")||no|
48-
|`--disable-max-line-length` |Disable max line length check (default "false")||no|
49-
|`--disable-trim-trailing-whitespace` |Disable trailing whitespace check (default "false")||no|
50-
|`--dry-run` |Show which files would be checked (default "false")||no|
51-
|`--exclude string` |Regex to exclude files from checking||no|
52-
|`--format string` |Specify the output format: default, gcc (default "default")||no|
53-
|`--help` |help for editorconfig (default "false")||no|
54-
|`--ignore-defaults` |Ignore default excludes (default "false")||no|
55-
|`--init` |creates an initial configuration (default "false")||no|
56-
|`--no-color` |Don't print colors (default "false")||no|
57-
|`--version` |Print the version number (default "false")||no|
41+
| Flag | Description | Alias | Required |
42+
|:-------------------------------------|:----------------------------------------------------------------------------------------------|:------|:---------|
43+
| `--config` | Path to the configuration file (e.g., `.editorconfig`, `.editorconfig-checker.json`, `.ecrc`) | | no |
44+
| `--disable-end-of-line` | Disable end-of-line check (default `false`) | | no |
45+
| `--disable-indent-size` | Disable indent size check (default `false`) | | no |
46+
| `--disable-indentation` | Disable indentation check (default `false`) | | no |
47+
| `--disable-insert-final-newline` | Disable final newline check (default `false`) | | no |
48+
| `--disable-max-line-length` | Disable max line length check (default `false`) | | no |
49+
| `--disable-trim-trailing-whitespace` | Disable trailing whitespace check (default `false`) | | no |
50+
| `--dry-run` | Show which files would be checked (default `false`) | | no |
51+
| `--exclude` | Regex to exclude files from checking | | no |
52+
| `--format` | Specify the output format: default, gcc (default `default`) | | no |
53+
| `--help` | help for editorconfig | | no |
54+
| `--ignore-defaults` | Ignore default excludes (default `false`) | | no |
55+
| `--init` | Create an initial configuration (default `false`) | | no |
56+
| `--no-color` | Don't print colors (default `false`) | | no |
57+
| `--version` | Print the version number (default `false`) | | no |

Diff for: website/src/components/Screengrabs/atmos-validate-editorconfig--help.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)