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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

samtholiya
Copy link
Collaborator

@samtholiya samtholiya commented Dec 27, 2024

issue: https://linear.app/cloudposse/issue/DEV-2836/implement-atmos-validate-editorconfig

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

  • New Features

    • Added EditorConfig Checker CLI command for validating code style and formatting.
    • Introduced configuration file for consistent code formatting across Terraform, HCL, YAML, and TOML files.
    • Enhanced configuration capabilities in atmos.yaml for validation settings.
  • Bug Fixes

    • Improved validation settings in the configuration schema for better functionality.
  • Tests

    • Added test case for EditorConfig validation in atmos CLI.
  • Chores

    • Updated project dependencies to support EditorConfig Checker functionality.
    • Modified logging configuration in atmos YAML file.

@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

Warning

Rate limit exceeded

@samtholiya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 97ce514 and 2a322b3.

📒 Files selected for processing (1)
  • tests/test_cases.yaml (1 hunks)
📝 Walkthrough

Walkthrough

The pull request introduces a new command-line interface (CLI) for the EditorConfig Checker tool within the Atmos CLI. It includes a command for validating files against the .editorconfig specifications, with features such as configuration loading, version checking, and flexible validation options. The changes encompass updates to the command structure, new dependencies, and a test case to ensure the functionality works as intended.

Changes

File Change Summary
cmd/editor_config.go Added new CLI command for EditorConfig validation with configuration initialization, version checking, and validation logic.
go.mod Added direct and indirect dependencies for EditorConfig Checker and related libraries.
tests/test_cases.yaml Added new test case for atmos validate editorconfig command.
examples/quick-start-simple/.editorconfig Created new EditorConfig file with formatting rules for Terraform and related files.
pkg/schema/schema.go Enhanced AtmosConfiguration struct with new validation fields and types.
examples/quick-start-simple/atmos.yaml Updated logging configuration by removing the file entry under logs.
atmos.yaml Added new validate section with settings for the editorconfig-checker.

Assessment against linked issues

Objective Addressed Explanation
Implement atmos validate editorconfig (DEV-2836)
Use github.com/editorconfig-checker/editorconfig-checker (DEV-2836)

Possibly related PRs

Suggested labels

minor

Suggested reviewers

  • Gowiem
  • aknysh
  • RoseSecurity

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 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 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 Show resolved Hide resolved
cmd/editor_config.go 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.

@@ -17,5 +17,4 @@ stacks:
name_pattern: "{stage}"

logs:
file: "/dev/stderr"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suggest removing this from quick start simple

Especially because this config causes all the logs to direct towards error and a quick start guide should not do that.

Of course we can document and give a seperate example (which i found many already in the repo) for this behavior.

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.

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
@mergify mergify bot removed the triage Needs triage label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants