RuboCop

RuboCop is a Ruby static code analyzer.

Version

0.50.0

Runtime

Ruby Versions

Supported Languages

Ruby

Official Documentation

https://github.com/bbatsov/rubocop

YAML Configuration

rubocop:

  • input:

    Patterns to include in execution and reports.

  • ignore:

    Patterns to exclude from execution and reports.

  • auto-fix:

    true/false

    Specifying true implies --auto-correct option.

    Note: As of now, rubocop does not keep CRLF line endings and all EOL characters are converted to LF in files where the auto-fix is applied. We will solve this problem, but for the time being, please don't enable the auto-fix feature if you need to keep CRLF line endings.

  • config-file:

    Alias of --config option.

  • machine:

    • cpu:

      Amount of CPU. The default machine has 0.5 CPU with 1920 MiB RAM.

  • options:

    Below is the list of options that are supported:

        --except [COP1,COP2,...]     Disable the given cop(s).
        --only [COP1,COP2,...]       Run only the given cop(s).
        --only-guide-cops            Run only cops for rules that link to a
                                     style guide.
    -c, --config FILE                Specify configuration file.
        --force-exclusion            Force excluding files specified in the
                                     configuration `Exclude` even if they are
                                     explicitly passed as arguments.
        --force-default-config       Use default configuration even if configuration
                                     files are present in the directory tree.
    -D, --display-cop-names          Display cop names in offense messages.
    -E, --extra-details              Display extra details in offense messages.
    -S, --display-style-guide        Display style guide URLs in offense messages.
    -R, --rails                      Run extra Rails cops.
  • thresholds:

    • num-issues:

      In addition to general severity levels, the following tool specific severity levels can be specified:

      • fatal (equivalent to general severity level critical)
      • refactor (equivalent to general severity level info)
      • convention (equivalent to general severity level info)
  • experimental:

    • incremental:

      true/false

      Note: The incremental analysis is disabled if any kinds of configuration files are changed. The files recognized as configuration files are as follows:

      • Configuration files:
        • Files specified in config-file field
        • Files specified to -c, --config options
        • If none of the above configuration files are found and --force-default-config option is not specified:
          • **/.rubocop.yml, **/rubocop.yml

      Note: The incremental analysis is disabled if external dependencies are required. See Resolving Dependencies about how the dependencies are resolved.

YAML Examples

  • With default options:

    inspecode:
      rubocop: default
  • With enabling auto-fixing and default options:

    inspecode:
      rubocop: auto-fix
  • With custom machine:

    inspecode:
      rubocop:
        machine:
          cpu: 1.5 # 1.5 CPU, 5760 MiB RAM
  • With custom options:

    inspecode:
      rubocop:
        options: [--rails, --only-guide-cops, --display-cop-names, --extra-details]
  • With a configuration file:

    inspecode:
      rubocop:
        config-file: rails/.rubocop.yaml

    The above configuration is equivalent to:

    inspecode:
      rubocop:
        options:
          --config: rails/.rubocop.yaml

Configuration File Detection

If no configuration files are specified via config-file or options field, Inspecode first lets RuboCop to find configuration files in your repository. See http://rubocop.readthedocs.io/en/latest/configuration/ about how RuboCop looks for configuration files.

In addition, if RuboCop cannot find any configuration files, Inspecode also walks the file tree in lexical order in your repository to find a configuration file, named .rubocop.yml or rubocop.yml, and specifies the file first found to RuboCop automatically via --config option.

Note: Inspecode ignores specific configuration files while searching. See Configuration > Tool Configuration > Field: config-file for detail.

If the configuration file detected by Inspecode is not the one you want to use or you do not want to use any configuration files, you can disable Inspecode from detecting configuration files by explicitly setting an empty string to config-file field like below:

inspecode:
  rubocop:
    config-file: ""

Resolving Dependencies

By default, no RuboCop extensions are installed. But Inspecode searches your repository for Gemfile files and runs bundle install at each directory where Gemfile exists so that you can use any RuboCop extensions.

results matching ""

    No results matching ""