Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editorconfig validation #896

Merged
merged 55 commits into from
Jan 18, 2025

Conversation

samtholiya
Copy link
Collaborator

@samtholiya samtholiya commented Dec 27, 2024

what

  • Added functionality to atmos validate to validate against the .editorconfig file if it is defined.
  • Integrated the editorconfig-checker library to perform the validation.
  • Modified the validation process to support OPA/JSON schema validation alongside the new .editorconfig validation.

why

  • The change ensures that the .editorconfig file is validated, which helps maintain consistency in code formatting across teams.
  • By incorporating editorconfig-checker, the validation process becomes more comprehensive, ensuring that both OPA/JSON schemas and editor configuration are correct.
  • This update was made to improve development workflow by catching formatting issues early during the validation process.

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added EditorConfig validation command to Atmos CLI.
    • Introduced configuration options for EditorConfig checking.
    • Enhanced project-wide code style validation capabilities.
  • Documentation

    • Added comprehensive documentation for EditorConfig validation.
    • Created new CLI command reference for atmos validate editorconfig.
  • Configuration

    • Updated atmos.yaml with new validation settings.
    • Added .editorconfig file for consistent code formatting.
    • Introduced new vendor.yaml for managing vendor components.
    • Added example configurations for testing purposes.
  • Testing

    • Implemented test cases for EditorConfig validation functionality.
    • Added new error messages for validation feedback.

@samtholiya samtholiya requested a review from a team as a code owner December 27, 2024 11:29
@mergify mergify bot added the triage Needs triage label Dec 27, 2024
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

📝 Walkthrough

Walkthrough

This pull request introduces comprehensive EditorConfig validation functionality to the Atmos CLI. The changes span multiple files, adding a new command atmos validate editorconfig that checks project files against defined coding style rules. The implementation includes configuration schema updates, documentation, test cases, and a new validation mechanism using the editorconfig-checker library.

Changes

File Change Summary
go.mod Added dependencies for EditorConfig validation
pkg/schema/schema.go Added Validate struct with EditorConfig validation settings
atmos.yaml Added new validate.editorconfig configuration section
cmd/validate_editorconfig.go Implemented new CLI command for EditorConfig validation
website/docs/* Added documentation for EditorConfig validation feature
examples/quick-start-simple/.editorconfig Introduced new EditorConfig file for coding style guidelines
tests/fixtures/scenarios/editorconfig/*.editorconfig Added test configurations and README for validation scenarios
tests/test-cases/validate-editorconfig.yaml Introduced test cases for validating editorconfig functionality

Assessment against linked issues

Objective Addressed Explanation
Implement atmos validate editorconfig
Validate against .editorconfig file
Use github.com/editorconfig-checker/editorconfig-checker

Possibly related PRs

Suggested reviewers

  • osterman
  • aknysh
  • Gowiem

With the strength of our collective effort, we have forged a robust validation mechanism! The EditorConfig checker shall bring order and consistency to our codebase, ensuring our files march in perfect formation. 🛡️


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
cmd/editor_config.go (2)

37-57: Initialization flow is well-structured.
Merging cliConfig into currentConfig is clear. Consider logging the final config path for troubleshooting.

🧰 Tools
🪛 golangci-lint (1.62.2)

46-46: printf: non-constant format string in call to github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Error

(govet)


113-137: Persistent flags are well-defined.
The scope of each flag is clear. If more flags appear, ensure new ones align with this pattern for consistency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa75c6 and 342dae4.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • cmd/editor_config.go (1 hunks)
  • go.mod (3 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

46-46: printf: non-constant format string in call to github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Error

(govet)


62-62: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Debug

(govet)


77-77: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


83-83: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)


93-93: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


103-103: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (5)
cmd/editor_config.go (3)

25-35: Command registration approach looks straightforward.
Nicely integrates with Cobra for CLI usage.


59-98: Validation logic is robust.
Checks file existence, handles dry-run, and reports errors smoothly. Good job!

🧰 Tools
🪛 golangci-lint (1.62.2)

62-62: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Debug

(govet)


77-77: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


83-83: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)


93-93: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


100-111: Early termination flags are polite and clear.
Helps users see version or usage right away. Nicely done.

🧰 Tools
🪛 golangci-lint (1.62.2)

103-103: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

go.mod (2)

20-20: Dependency pinned to v3.0.3.
Looks good. Confirm that it aligns with your tested version.


99-99: New indirect dependencies recognized.
These libraries are typical for EditorConfig checks. Please confirm their licenses are suitable for your project.

Also applies to: 127-127, 132-132

cmd/editor_config.go Outdated Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

📝 Walkthrough

Walkthrough

This pull request introduces a new CLI command editorconfig-checker in the cmd/editor_config.go file, leveraging the Cobra library to create a robust command-line interface for EditorConfig validation. The implementation provides comprehensive configuration loading, error handling, and flexible command-line flag options. The go.mod file was updated to include necessary dependencies for the EditorConfig checker functionality.

Changes

File Change Summary
cmd/editor_config.go Added new CLI command with configuration initialization, main logic for EditorConfig checking, flag handling, and error management
go.mod Added direct and indirect dependencies for EditorConfig checker, including github.com/editorconfig-checker/editorconfig-checker/v3

Assessment against linked issues

Objective Addressed Explanation
Implement atmos validate editorconfig [DEV-2836]

Possibly related PRs

Suggested Labels

minor

Suggested Reviewers

  • johncblandii
  • aknysh
  • gberenice

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
cmd/editor_config.go (1)

26-28: Offer usage examples for the new command.

Adding examples in the long description or using cmd.Example helps users understand usage quickly.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa75c6 and 342dae4.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • cmd/editor_config.go (1 hunks)
  • go.mod (3 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

46-46: printf: non-constant format string in call to github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Error

(govet)


62-62: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Debug

(govet)


77-77: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


83-83: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)


93-93: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


103-103: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (1)
go.mod (1)

20-20: Dependencies look good.

The newly added references appear consistent with the code. No issues detected.

Also applies to: 99-99, 127-127, 132-132

cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
cmd/editor_config.go (1)

39-60: ⚠️ Potential issue

Improve error handling and logger usage.

The function needs improvements in error handling and logger usage:

  1. Use proper format strings in logger calls
  2. Consider returning errors instead of calling os.Exit

Apply these changes to fix the logger format strings and improve error handling:

func initializeConfig() error {
    u.LogInfo(atmosConfig, fmt.Sprintf("EditorConfig Checker CLI Version: %s", editorConfigVersion))
    if configFilePath == "" {
        configFilePath = defaultConfigFilePath
    }

    var err error
    currentConfig, err = config.NewConfig(configFilePath)
    if err != nil {
-       logger.Error(err.Error())
-       os.Exit(1)
+       logger.Errorf("%v", err)
+       return fmt.Errorf("failed to create config: %w", err)
    }

    if err := currentConfig.Parse(); err != nil {
+       return fmt.Errorf("failed to parse config: %w", err)
    }

    if tmpExclude != "" {
        currentConfig.Exclude = append(currentConfig.Exclude, tmpExclude)
    }

    currentConfig.Merge(cliConfig)
+   return nil
}
🧰 Tools
🪛 golangci-lint (1.62.2)

49-49: printf: non-constant format string in call to github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Error

(govet)

🧹 Nitpick comments (1)
cmd/editor_config.go (1)

18-25: Consider encapsulating configuration variables.

The global variables could be encapsulated within a configuration struct to improve maintainability and testability.

+type editorConfigState struct {
+    version            string
+    defaultConfigPath  string
+    currentConfig      *config.Config
+    cliConfig          config.Config
+    configFilePath     string
+    tmpExclude         string
+}

+var state = &editorConfigState{
+    version:           "v3.0.3",  // Update to match dependency version
+    defaultConfigPath: ".ecrc",
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 342dae4 and 667e1e5.

📒 Files selected for processing (3)
  • cmd/editor_config.go (1 hunks)
  • examples/demo-stacks/.ecrc (1 hunks)
  • tests/test_cases.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • examples/demo-stacks/.ecrc
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

49-49: printf: non-constant format string in call to github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Error

(govet)


80-80: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


86-86: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)


96-96: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Error

(govet)


107-107: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (3)
tests/test_cases.yaml (1)

139-153: Ensure version string consistency across test and implementation.

The test expects EditorConfig Checker CLI Version "v3.0.0", but the dependency in go.mod uses v3.0.3. This mismatch could cause test failures.

cmd/editor_config.go (2)

27-37: LGTM! Well-structured command implementation.

The command follows Cobra best practices with clear separation between initialization and execution.


117-134: LGTM! Well-organized flag configuration.

The flags are comprehensive and well-documented, following Cobra best practices.

cmd/editor_config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/editor_config.go (1)

62-101: Consider refactoring for better testability

The function has multiple os.Exit calls which makes unit testing difficult. Consider:

  1. Returning errors instead of calling os.Exit
  2. Moving the version check to a separate function
  3. Centralizing error handling

Here's a suggested refactor pattern:

- func runMainLogic() {
+ func runMainLogic() error {
    config := *currentConfig
-   if utils.FileExists(config.Path) && config.Version != "" && config.Version != editorConfigVersion {
-     u.LogError(atmosConfig, fmt.Errorf("Version from config file is not the same as the version of the binary"))
-     u.LogError(atmosConfig, fmt.Errorf("Binary: %s, Config: %s", editorConfigVersion, config.Version))
-     os.Exit(1)
+   if err := checkVersion(config); err != nil {
+     return fmt.Errorf("version check failed: %w", err)
    }

    filePaths, err := files.GetFiles(config)
    if err != nil {
-     u.LogError(atmosConfig, err)
-     os.Exit(1)
+     return fmt.Errorf("failed to get files: %w", err)
    }

    // ... rest of the logic with similar error handling
+   return nil
}

+ func checkVersion(config config.Config) error {
+   if !utils.FileExists(config.Path) || config.Version == "" {
+     return nil
+   }
+   if config.Version != editorConfigVersion {
+     return fmt.Errorf("version mismatch: binary=%s, config=%s", 
+       editorConfigVersion, config.Version)
+   }
+   return nil
+ }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 667e1e5 and 167092e.

📒 Files selected for processing (1)
  • cmd/editor_config.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

106-106: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (3)
cmd/editor_config.go (3)

18-18: Align editorConfigVersion with library version

The hardcoded version v3.0.0 doesn't match the library version v3.0.3 from go.mod. This mismatch could cause confusion during version checks.

- editorConfigVersion   = "v3.0.0"
+ editorConfigVersion   = "v3.0.3"

26-36: Well-structured command implementation!

Clean separation of concerns between initialization and execution using Cobra's PreRun and Run hooks.


117-133: Excellent flag configuration!

The flags are well-documented, comprehensive, and follow a consistent pattern. The granular disable options provide good flexibility for users.

cmd/editor_config.go Outdated Show resolved Hide resolved
@samtholiya samtholiya force-pushed the feature/dev-2836-implement-atmos-validate-editorconfig branch from 879fb8b to 3db160d Compare December 27, 2024 13:43
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
examples/demo-stacks/.ecrc Outdated Show resolved Hide resolved
tests/test_cases.yaml Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
@osterman osterman changed the title Add editorconfig-checker to atmos cli Add editorconfig validation to atmos cli Dec 27, 2024
@osterman osterman changed the title Add editorconfig validation to atmos cli Add editorconfig validation Dec 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
cmd/editor_config.go (1)

120-120: Fix non-constant format string warning.

Address the govet warning about non-constant format string:

-		config.Logger.Output(editorConfigVersion)
+		config.Logger.Output("%s", editorConfigVersion)
🧰 Tools
🪛 golangci-lint (1.62.2)

120-120: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 167092e and d4a5ea2.

📒 Files selected for processing (2)
  • cmd/editor_config.go (1 hunks)
  • tests/test_cases.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_cases.yaml
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

120-120: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (3)
cmd/editor_config.go (3)

20-20: Use the conventional .editorconfig filename.

As suggested in previous feedback, let's use the standard .editorconfig filename instead of .ecrc.

-	defaultConfigFilePath = ".ecrc"
+	defaultConfigFilePath = ".editorconfig"

28-30: Update command name and descriptions for clarity.

As suggested in previous feedback:

-	Use:   "editorconfig-checker",
-	Short: "EditorConfig Checker CLI",
-	Long:  "A command-line tool to check your files against the EditorConfig rules",
+	Use:   "editorconfig",
+	Short: "Validate all files against the EditorConfig",
+	Long:  "Validate all files against the project's EditorConfig rules",

40-63: LGTM! Well-structured configuration initialization.

The configuration initialization is well-implemented with proper error handling and logging using Atmos utilities.

cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
cmd/editor_config.go (2)

17-25: Consider adding documentation for exported variables.

Adding documentation for these variables would improve code maintainability and help other developers understand their purpose.

 var (
+	// editorConfigVersion is the version of the editorconfig-checker being used
 	editorConfigVersion   = "v3.0.3"
+	// defaultConfigFilePath is the default path to look for the .editorconfig file
 	defaultConfigFilePath = ".editorconfig"
+	// initEditorConfig indicates whether to initialize a new .editorconfig file
 	initEditorConfig      bool
+	// currentConfig holds the current editorconfig configuration
 	currentConfig         *config.Config
+	// cliConfig holds the configuration from command line flags
 	cliConfig             config.Config
+	// configFilePath is the path to the .editorconfig file
 	configFilePath        string
+	// tmpExclude holds temporary exclude patterns from command line
 	tmpExclude            string
 )

69-105: Consider breaking down the main logic into smaller functions.

The runMainLogic function handles multiple responsibilities. Consider extracting the file processing and validation logic into separate functions for better maintainability.

+func processFiles(config config.Config) ([]string, error) {
+	filePaths, err := files.GetFiles(config)
+	if err != nil {
+		return nil, err
+	}
+	return filePaths, nil
+}
+
+func validateFiles(filePaths []string, config config.Config) error {
+	errors := validation.ProcessValidation(filePaths, config)
+	errorCount := er.GetErrorCount(errors)
+	if errorCount != 0 {
+		er.PrintErrors(errors, config)
+		return fmt.Errorf("%d errors found", errorCount)
+	}
+	return nil
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4a5ea2 and 80cf34b.

📒 Files selected for processing (3)
  • cmd/editor_config.go (1 hunks)
  • examples/quick-start-simple/.editorconfig (1 hunks)
  • tests/test_cases.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • examples/quick-start-simple/.editorconfig
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_cases.yaml
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

122-122: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (3)
cmd/editor_config.go (3)

60-60: Handle potential Parse() errors.

The error from currentConfig.Parse() is silently ignored. Consider handling potential parsing errors.


133-150: Support flag configuration in atmos.yaml.

These flags should be configurable via atmos.yaml for better consistency with other Atmos commands.


122-122: 🛠️ Refactor suggestion

Use constant format string in logger call.

The logger expects a format string. Use a format string to avoid the "non-constant format string" warning.

-		config.Logger.Output(editorConfigVersion)
+		config.Logger.Output("%s", editorConfigVersion)

Likely invalid or redundant comment.

🧰 Tools
🪛 golangci-lint (1.62.2)

122-122: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
cmd/editor_config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/editor_config.go (1)

37-37: Consider checking the error from cmd.Help()
While it’s common to ignore the return for cmd.Help(), static analysis tools flag this as an unhandled error.

🧰 Tools
🪛 golangci-lint (1.62.2)

37-37: Error return value of cmd.Help is not checked

(errcheck)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80cf34b and 97028ef.

📒 Files selected for processing (2)
  • cmd/editor_config.go (1 hunks)
  • pkg/schema/schema.go (2 hunks)
🧰 Additional context used
📓 Learnings (1)
cmd/editor_config.go (1)
Learnt from: osterman
PR: cloudposse/atmos#740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

37-37: Error return value of cmd.Help is not checked

(errcheck)


173-173: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

🔇 Additional comments (6)
cmd/editor_config.go (2)

66-66: Same existing concern about ignoring parsing errors


173-173: Switch to a constant format string
This logger invocation can raise “non-constant format string” warnings in some lint checks. Consider using a format method (e.g. config.Logger.Outputf("%s", editorConfigVersion)).

🧰 Tools
🪛 golangci-lint (1.62.2)

173-173: printf: non-constant format string in call to (github.com/editorconfig-checker/editorconfig-checker/v3/pkg/logger.Logger).Output

(govet)

pkg/schema/schema.go (4)

35-35: Good addition of the Validate field
The extension of the configuration schema is beneficial. Ensure you have corresponding documentation or comments explaining its usage.


42-44: Validate struct creation looks clean
No issues are spotted. This struct helps group editorconfig validation settings neatly.


46-56: New EditorConfig struct
Everything appears consistent with the rest of the configuration. If needed, add docstrings for clarity.


58-66: DisabledChecks struct is well-defined
This offers a flexible way to toggle checks. Looks good for maintainability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
cmd/editor_config.go (4)

19-26: Consider renaming tmpExclude for clarity.

The variable name tmpExclude doesn't clearly convey its purpose as a CLI-provided exclude pattern that gets merged into the configuration.

-	tmpExclude            string
+	cliExcludePattern     string

36-39: Handle potential Help() error.

The cmd.Help() function returns an error that should be handled.

 if cliConfig.Help {
-	cmd.Help()
-	os.Exit(0)
+	if err := cmd.Help(); err != nil {
+		u.LogErrorAndExit(atmosConfig, err)
+	}
+	os.Exit(0)
 }
🧰 Tools
🪛 golangci-lint (1.62.2)

37-37: Error return value of cmd.Help is not checked

(errcheck)


74-117: Consider simplifying config replacement logic.

The repetitive if-blocks for config replacement could be simplified using reflection or struct field mapping for similar fields, especially in the Disable section.

Consider extracting the Disable field handling into a separate function:

func replaceDisableConfig(cliConfig *config.Config, atmosConfig schema.AtmosConfiguration) {
    disableFields := map[string]struct{
        cli *bool
        atmos bool
    }{
        "TrimTrailingWhitespace": {&cliConfig.Disable.TrimTrailingWhitespace, atmosConfig.Validate.EditorConfig.Disable.TrimTrailingWhitespace},
        // ... other fields
    }
    
    for _, field := range disableFields {
        if field.atmos {
            *field.cli = field.atmos
        }
    }
}

146-146: Remove newline prefix from error message.

The error message starts with a newline character, which is unnecessary as the logging framework handles line formatting.

-		u.LogErrorAndExit(atmosConfig, fmt.Errorf("\n%d errors found", errorCount))
+		u.LogErrorAndExit(atmosConfig, fmt.Errorf("%d errors found", errorCount))
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97028ef and 6b86d1a.

📒 Files selected for processing (3)
  • cmd/editor_config.go (1 hunks)
  • examples/quick-start-simple/atmos.yaml (0 hunks)
  • tests/test_cases.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • examples/quick-start-simple/atmos.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_cases.yaml
🧰 Additional context used
📓 Learnings (1)
cmd/editor_config.go (1)
Learnt from: osterman
PR: cloudposse/atmos#740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.
🪛 golangci-lint (1.62.2)
cmd/editor_config.go

37-37: Error return value of cmd.Help is not checked

(errcheck)

🔇 Additional comments (4)
cmd/editor_config.go (4)

1-17: LGTM! Clean import organization.

The imports are well-organized and properly aliased to avoid naming conflicts.


44-72: LGTM! Solid configuration initialization.

The function follows established error handling patterns and correctly handles configuration initialization.


153-163: LGTM! Solid version check implementation.

The version check is well-implemented with clear error messages and proper handling of edge cases.


166-182: Consider previous feedback about flags.

The version flag and atmos.yaml configuration suggestions from previous reviews are still applicable.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
atmos.yaml (2)

97-111: Consider adding format validation.

The configuration is well-structured with clear documentation. However, the format option could benefit from validation to ensure only "default" or "json" are accepted.

Consider adding validation in the schema to restrict the format values:

format:
  type: string
  enum: ["default", "json"]
  default: "default"

113-131: Strong defaults that promote code quality!

The disable section is well-structured with all checks enabled by default (disable: false). This is a secure default that encourages consistent code formatting across the team. Each option is clearly documented and provides granular control when needed.

The default configuration (all checks enabled) will help maintain consistent code quality across teams. Consider documenting these defaults in your team's coding standards documentation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b86d1a and 97ce514.

📒 Files selected for processing (1)
  • atmos.yaml (1 hunks)
🔇 Additional comments (1)
atmos.yaml (1)

94-96: LGTM! Clean introduction of the validate section.

The section is well-structured and properly documented, following the established pattern in the configuration file.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 17, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 18, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 18, 2025
@samtholiya samtholiya force-pushed the feature/dev-2836-implement-atmos-validate-editorconfig branch from ee3a8e5 to 785394e Compare January 18, 2025 14:28
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please address a few comments

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
tests/snapshots/TestCLICommands_atmos_validate_editorconfig_error.stdout.golden (1)

1-3: Error messages look good, warrior! Consider enhancing clarity.

The error message format is clear and includes all necessary information. However, we could make it even more helpful for our fellow developers.

Consider this enhanced error format for better clarity:

-	267: Wrong amount of left-padding spaces(want multiple of 2)
+	267: Wrong amount of left-padding spaces (found: <actual>, expected: multiple of 2)

This would show the actual number of spaces found, making it easier to identify and fix the issue.

website/docs/cli/commands/validate/validate-editorconfig.mdx (3)

10-28: Consider adding workflow context.

The usage instructions are clear, but developers would benefit from knowing when in their workflow they should run this command (e.g., pre-commit, during CI/CD, etc.).

Consider adding a note like:

 This command validates files against the formatting rules defined in your .editorconfig file.
+
+It's recommended to run this command:
+- Before committing changes to ensure consistent formatting
+- As part of your CI/CD pipeline to enforce team-wide formatting standards

30-37: Enhance examples with explanatory comments.

The examples would be more helpful with brief explanations of when to use each variation.

Consider updating the examples like this:

 ```shell
 atmos validate editorconfig
-atmos validate editorconfig --logs-level trace
-atmos validate editorconfig --no-color
-atmos validate editorconfig --dry-run
+# For detailed debugging output
+atmos validate editorconfig --logs-level trace
+# For CI/CD environments or log parsing
+atmos validate editorconfig --no-color
+# To preview which files would be checked without making changes
+atmos validate editorconfig --dry-run

---

`41-57`: **Improve table formatting for better readability.**

The table content is comprehensive, but the formatting could be enhanced.

Consider these improvements:
1. Align the description column content consistently
2. Add spacing between cells for better readability
3. Group related flags together (e.g., all disable flags)

Example of aligned content:
```diff
-|`--disable-end-of-line`                 |Disable end-of-line check (default "false")                            |       |no        |
-|`--disable-indent-size`                 |Disable indent size check (default "false")                            |       |no        |
+|`--disable-end-of-line`                 |Disable end-of-line check (default "false")                           |       |no        |
+|`--disable-indent-size`                 |Disable indent size check (default "false")                           |       |no        |
🧰 Tools
🪛 LanguageTool

[typographical] ~44-~44: Consider using typographic quotation marks here.
Context: ... |Disable end-of-line check (default "false") | |no...

(EN_QUOTES)


[typographical] ~45-~45: Consider using typographic quotation marks here.
Context: ... |Disable indent size check (default "false") | |no...

(EN_QUOTES)


[typographical] ~46-~46: Consider using typographic quotation marks here.
Context: ... |Disable indentation check (default "false")||no| |--disable-insert-final-newline...

(EN_QUOTES)


[typographical] ~47-~47: Consider using typographic quotation marks here.
Context: ... |Disable final newline check (default "false")||no| |--disable-max-line-length ...

(EN_QUOTES)


[typographical] ~48-~48: Consider using typographic quotation marks here.
Context: ...|Disable max line length check (default "false")||no| |`--disable-trim-trailing-whitesp...

(EN_QUOTES)


[typographical] ~49-~49: Consider using typographic quotation marks here.
Context: ...able trailing whitespace check (default "false")||no| |--dry-run ...

(EN_QUOTES)


[typographical] ~50-~50: Consider using typographic quotation marks here.
Context: ...w which files would be checked (default "false")||no| |--exclude string ...

(EN_QUOTES)


[typographical] ~52-~52: Consider using typographic quotation marks here.
Context: ...he output format: default, gcc (default "default")||no| |--help ...

(EN_QUOTES)


[typographical] ~53-~53: Consider using typographic quotation marks here.
Context: ... |help for editorconfig (default "false")||no| |--ignore-defaults ...

(EN_QUOTES)


[typographical] ~54-~54: Consider using typographic quotation marks here.
Context: ... |Ignore default excludes (default "false")||no| |--init ...

(EN_QUOTES)


[typographical] ~55-~55: Consider using typographic quotation marks here.
Context: ...eates an initial configuration (default "false")||no| |--no-color ...

(EN_QUOTES)


[typographical] ~56-~56: Consider using typographic quotation marks here.
Context: ... |Don't print colors (default "false")||no| |--version ...

(EN_QUOTES)


[typographical] ~57-~57: Consider using typographic quotation marks here.
Context: ... |Print the version number (default "false")||no|

(EN_QUOTES)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e43d275 and bf67b39.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (8)
  • go.mod (3 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_config_-f_yaml.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig_error.stderr.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig_error.stdout.golden (1 hunks)
  • tests/test-cases/validate-editorconfig.yaml (1 hunks)
  • website/docs/cli/commands/validate/validate-editorconfig.mdx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig_error.stderr.golden
  • tests/snapshots/TestCLICommands_atmos_validate_editorconfig.stdout.golden
🚧 Files skipped from review as they are similar to previous changes (2)
  • go.mod
  • tests/test-cases/validate-editorconfig.yaml
🧰 Additional context used
🪛 LanguageTool
website/docs/cli/commands/validate/validate-editorconfig.mdx

[typographical] ~44-~44: Consider using typographic quotation marks here.
Context: ... |Disable end-of-line check (default "false") | |no...

(EN_QUOTES)


[typographical] ~45-~45: Consider using typographic quotation marks here.
Context: ... |Disable indent size check (default "false") | |no...

(EN_QUOTES)


[typographical] ~46-~46: Consider using typographic quotation marks here.
Context: ... |Disable indentation check (default "false")||no| |--disable-insert-final-newline...

(EN_QUOTES)


[typographical] ~47-~47: Consider using typographic quotation marks here.
Context: ... |Disable final newline check (default "false")||no| |--disable-max-line-length ...

(EN_QUOTES)


[typographical] ~48-~48: Consider using typographic quotation marks here.
Context: ...|Disable max line length check (default "false")||no| |`--disable-trim-trailing-whitesp...

(EN_QUOTES)


[typographical] ~49-~49: Consider using typographic quotation marks here.
Context: ...able trailing whitespace check (default "false")||no| |--dry-run ...

(EN_QUOTES)


[typographical] ~50-~50: Consider using typographic quotation marks here.
Context: ...w which files would be checked (default "false")||no| |--exclude string ...

(EN_QUOTES)


[typographical] ~52-~52: Consider using typographic quotation marks here.
Context: ...he output format: default, gcc (default "default")||no| |--help ...

(EN_QUOTES)


[typographical] ~53-~53: Consider using typographic quotation marks here.
Context: ... |help for editorconfig (default "false")||no| |--ignore-defaults ...

(EN_QUOTES)


[typographical] ~54-~54: Consider using typographic quotation marks here.
Context: ... |Ignore default excludes (default "false")||no| |--init ...

(EN_QUOTES)


[typographical] ~55-~55: Consider using typographic quotation marks here.
Context: ...eates an initial configuration (default "false")||no| |--no-color ...

(EN_QUOTES)


[typographical] ~56-~56: Consider using typographic quotation marks here.
Context: ... |Don't print colors (default "false")||no| |--version ...

(EN_QUOTES)


[typographical] ~57-~57: Consider using typographic quotation marks here.
Context: ... |Print the version number (default "false")||no|

(EN_QUOTES)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (4)
website/docs/cli/commands/validate/validate-editorconfig.mdx (1)

1-7: LGTM! Clear and accurate metadata.

The frontmatter metadata is well-structured and the description accurately reflects the command's purpose.

tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden (1)

139-142: LGTM! The new validate section is well-structured.

The addition of the validate.editorconfig configuration follows the established pattern and integrates cleanly with the existing configuration structure.

Let's verify that this matches the schema definition:

✅ Verification successful

Warrior's seal of approval! The validate.editorconfig configuration is battle-tested and ready.

The configuration structure perfectly matches the schema definition in pkg/schema/schema.go, where the Color field is properly defined as an optional boolean property. The YAML variant of this configuration exists in the test snapshots, showing consistent implementation across formats.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the validate.editorconfig structure matches the schema definition

# Search for the schema definition of the validate section
ast-grep --pattern 'type Validate struct {
  $$$
  EditorConfig $_ `$$$`
  $$$
}'

# Search for any other validate.editorconfig configuration examples
rg -l '"validate":\s*{.*"editorconfig":'

Length of output: 470


Script:

#!/bin/bash
# Search for EditorConfig struct definition
ast-grep --pattern 'type EditorConfig struct {
  $$$
}'

# Search for validate.editorconfig examples with fixed pattern
rg -l '"validate"\s*:\s*\{\s*"editorconfig"'

# Alternative search for yaml examples
rg -l 'validate:\s*\n\s*editorconfig:'

Length of output: 2444


Script:

#!/bin/bash
# Search for validate.editorconfig examples with multiline support
rg -U -l 'validate:(\s|\n)*editorconfig:'

# Also search for JSON examples with more flexible pattern
rg -l '"validate".*"editorconfig"' --type json

Length of output: 168

tests/snapshots/TestCLICommands_atmos_describe_config_-f_yaml.stdout.golden (2)

43-45: Consider expanding editorconfig validation settings.

The new validation section is well-placed at the root level, maintaining consistency with the existing configuration structure. However, based on the PR objectives, the editorconfig validation supports additional settings like exclude and ignore_defaults that aren't represented in this snapshot test.

Would you like me to propose a more comprehensive validation configuration that includes all supported options? This would help ensure the test covers the full range of configuration possibilities.


45-45: Verify color setting behavior.

The color: true setting suggests CLI output colorization. Let's verify this behavior is properly tested.

@aknysh aknysh merged commit 14bea36 into main Jan 18, 2025
45 checks passed
@aknysh aknysh deleted the feature/dev-2836-implement-atmos-validate-editorconfig branch January 18, 2025 17:06
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Jan 18, 2025
Copy link

These changes were released in v1.151.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants