LinterChanges is a Ruby gem that runs linters on files changed between your current branch and a target branch (e.g., master
). It helps maintain code quality by ensuring that only the changed files are linted, saving time and resources.
What sets LinterChanges apart from other tools like Pronto is that it checks entire files rather than just the changed lines when raising errors. Additionally, if configuration changes for the linter occur, LinterChanges will run the linter on the entire repository, not just on the current changes.
Currently, LinterChanges supports RuboCop for Ruby code. Support for additional linters can be added in the future.
Add this line to your application's Gemfile
:
gem 'linter_changes', git: 'https://github.com/bukhr/linter_changes.git'
bundle install
LinterChanges provides a command-line interface (CLI) to run RuboCop on the files changed between your current branch and the target branch.
By default, LinterChanges will:
- Compare your current branch with the
main
branch. - Run the linters on the changed files that linter listen to.
Command:
bin/linter_changes lint
Example Output:
Running RuboCop linter
Linting files with RuboCop: app/models/user.rb, app/controllers/users_controller.rb
Inspecting 2 files
..
2 files inspected, no offenses detected
If you want to compare against a different branch, you can specify it using the --target-branch
option.
Command:
bin/linter_changes lint --target-branch origin/master
This will compare your current branch with the origin/master
branch.
You can customize the RuboCop configuration files and command options.
Specify Custom Config Files:
Note: each config file passed is interpreted as regex on the full file path
bin/linter_changes lint --config-files rubocop:rubocop,custom_rubocop.yml
Specify Custom RuboCop Command:
bin/linter_changes lint --linter-command rubocop:"rubocop --parallel"
Combining Both:
bin/linter_changes lint \
--config-files rubocop:.rubocop.yml,custom_rubocop.yml \
--linter-command rubocop:"rubocop --parallel"
Contributions are welcome! If you'd like to contribute, please follow these steps:
-
Fork the repository.
-
Create a new branch:
git checkout -b feature/your_feature_name
-
Make your changes.
-
Commit your changes:
git commit -m "Add your commit message"
-
Push to your branch:
git push origin feature/your_feature_name
-
Open a pull request on GitHub.
bundle exec rake test
- RuboCop - The Ruby static code analyzer and formatter.
- Thor - A toolkit for building powerful command-line interfaces.
Note: Currently, LinterChanges supports only RuboCop for linting Ruby files. Support for additional linters may be added in the future.
Key Features:
- Full File Linting: Unlike tools like Pronto that only check the changed lines, LinterChanges lints the entire files that have been modified. This ensures that any issues in the modified files are caught, not just those in the changed lines.
- Configuration Change Detection: If a configuration file for the linter (e.g.,
.rubocop.yml
) has changed, LinterChanges will run the linter on the entire repository. This ensures that any new or altered linting rules are applied across all files.