Lintf

Linter and formatter runner for Ruby, including configuration for RuboCop (Performance, Rails, RSpec, RSpecRails) and ERB Lint.

Installation

  1. Add gem 'lintf', require: false to the development group in your Gemfile.
  2. Run bundle.

Configuration

RuboCop

Edit .rubocop.yml and select the cops you want to use:

inherit_gem:
  lintf:
    - config/rubocop.yml
    - config/rubocop-performance.yml
    - config/rubocop-rails.yml
    - config/rubocop-rspec.yml
    - config/rubocop-rspec_rails.yml

Don't forget to add the cop's gem to your Gemfile as well, since Lintf only includes the rubocop gem.

ERB Lint

Edit .erb_lint.yml and add erb_lint to your Gemfile:

inherit_gem:
  lintf: config/erb_lint.yml

Usage

Config File

You can create your own tool definitions in a .lintf.yml file and add them to the run key, or override the default. Your config will be deep merged with the default configuration.

CLI

By default, Lintf checks all touched files in the current branch using git diff origin/main. You can change this behavior by passing the following options to the CLI:

  • -a: All files tracked by Git (uses git ls-files)
  • -f: Fix problems automatically (i.e. autocorrect)

Other flags are passed to the tools (e.g. lintf rubocop --help).

Examples

Here are some examples of how to use the CLI:

  • bundle exec lintf: Run all tools, but only on touched files
  • bundle exec lintf -f: Fix/format touched files with all tools
  • bundle exec lintf er r: Run ERB Lint, then RuboCop
  • bundle exec lintf -a rubocop: Check all files with RuboCop
  • bundle exec lintf -fa r: Format all files with RuboCop

Here are some examples of how to override the default config with .lintf.yml:

run: [rubocop, my_custom_linter]

rubocop:
  fix: -a

my_custom_linter:
  alias: mcl
  run: bundle exec my_custom_linter --fail-fast
  files: [md, yml]

This changes the RuboCop autocorrection from the default -A to the safe -a and defines a new tool that will be run by default (after RuboCop), or via bundle exec lintf my_custom_linter or bundle exec lintf mcl.

License

Lintf is released under the terms of the MIT License.