rubocop
rubocop documentation
- Version in MegaLinter: 1.69.1
- Visit Official Web Site
- See How to configure rubocop rules
- If custom
.ruby-lint.yml
config file isn't found, .ruby-lint.yml will be used
- If custom
- See How to disable rubocop rules in files
- See Index of problems detected by rubocop
Configuration in MegaLinter
- Enable rubocop by adding
RUBY_RUBOCOP
in ENABLE_LINTERS variable - Disable rubocop by adding
RUBY_RUBOCOP
in DISABLE_LINTERS variable
- Enable autofixes by adding
RUBY_RUBOCOP
in APPLY_FIXES variable
Variable | Description | Default value |
---|---|---|
RUBY_RUBOCOP_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
RUBY_RUBOCOP_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
RUBY_RUBOCOP_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
RUBY_RUBOCOP_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
RUBY_RUBOCOP_CLI_LINT_MODE | Override default CLI lint mode - file : Calls the linter for each file- project : Call the linter from the root of the project |
file |
RUBY_RUBOCOP_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".rb"] |
RUBY_RUBOCOP_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
RUBY_RUBOCOP_PRE_COMMANDS | List of bash commands to run before the linter | None |
RUBY_RUBOCOP_POST_COMMANDS | List of bash commands to run after the linter | None |
RUBY_RUBOCOP_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling RUBY_RUBOCOP and its pre/post commands | None |
RUBY_RUBOCOP_CONFIG_FILE | rubocop configuration file nameUse LINTER_DEFAULT to let the linter find it |
.ruby-lint.yml |
RUBY_RUBOCOP_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
RUBY_RUBOCOP_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
RUBY_RUBOCOP_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
RUBY_RUBOCOP_CLI_EXECUTABLE | Override CLI executable | ['rubocop'] |
IDE Integration
Use rubocop in your favorite IDE to catch errors before MegaLinter !
MegaLinter Flavors
This linter is available in the following flavors
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
all | Default MegaLinter Flavor | 124 | ||
cupcake | MegaLinter for the most commonly used languages | 83 | ||
ruby | Optimized for RUBY based projects | 50 |
Behind the scenes
How are identified applicable files
- File extensions:
.rb
How the linting is performed
- rubocop is called one time by identified file (
file
CLI lint mode)
Example calls
rubocop --force-exclusion myfile.rb
rubocop --force-exclusion -c .ruby-lint.yml myfile.rb
rubocop --force-exclusion --safe-auto-correct -c .ruby-lint.yml myfile.rb
Help content
Usage: rubocop [options] [file1, file2, ...]
Basic Options:
-l, --lint Run only lint cops.
-x, --fix-layout Run only layout cops, with autocorrect on.
--safe Run only safe cops.
--except [COP1,COP2,...] Exclude 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.
-F, --fail-fast Inspect files in order of modification
time and stop after the first file
containing offenses.
--disable-pending-cops Run without pending cops.
--enable-pending-cops Run with pending cops.
--ignore-disable-comments Run cops even when they are disabled locally
by a `rubocop:disable` directive.
--force-exclusion Any files excluded by `Exclude` in configuration
files will be excluded, even if given explicitly
as arguments.
--only-recognized-file-types Inspect files given on the command line only if
they are listed in `AllCops/Include` parameters
of user configuration or default configuration.
--ignore-parent-exclusion Prevent from inheriting `AllCops/Exclude` from
parent folders.
--ignore-unrecognized-cops Ignore unrecognized cops or departments in the config.
--force-default-config Use default configuration even if configuration
files are present in the directory tree.
-s, --stdin FILE Pipe source from STDIN, using FILE in offense
reports. This is useful for editor integration.
--editor-mode Optimize real-time feedback in editors,
adjusting behaviors for editing experience.
-P, --[no-]parallel Use available CPUs to execute inspection in
parallel. Default is true.
You can specify the number of parallel processes using
the $PARALLEL_PROCESSOR_COUNT environment variable.
--raise-cop-error Raise cop-related errors with cause and location.
This is used to prevent cops from failing silently.
Default is false.
--fail-level SEVERITY Minimum severity for exit with error code.
[A] autocorrect
[I] info
[R] refactor
[C] convention
[W] warning
[E] error
[F] fatal
Caching:
-C, --cache FLAG Use result caching (FLAG=true) or don't
(FLAG=false), default determined by
configuration parameter AllCops: UseCache.
--cache-root DIR Set the cache root directory.
Takes precedence over the configuration
parameter AllCops: CacheRootDirectory and
the $RUBOCOP_CACHE_ROOT environment variable.
LSP Option:
--lsp Start a language server listening on STDIN.
Server Options:
--[no-]server If a server process has not been started yet, start
the server process and execute inspection with server.
Default is false.
You can specify the server host and port with the
$RUBOCOP_SERVER_HOST and the $RUBOCOP_SERVER_PORT
environment variables.
--restart-server Restart server process.
--start-server Start server process.
--stop-server Stop server process.
--server-status Show server status.
--no-detach Run the server process in the foreground.
Output Options:
-f, --format FORMATTER Choose an output formatter. This option
can be specified multiple times to enable
multiple formatters at the same time.
[a]utogenconf
[c]lang
[e]macs
[fi]les
[fu]ubar
[g]ithub
[h]tml
[j]son
[ju]nit
[m]arkdown
[o]ffenses
[pa]cman
[p]rogress (default)
[q]uiet
[s]imple
[t]ap
[w]orst
custom formatter class name
-D, --[no-]display-cop-names Display cop names in offense messages.
Default is true.
-E, --extra-details Display extra details in offense messages.
-S, --display-style-guide Display style guide URLs in offense messages.
-o, --out FILE Write output to a file instead of STDOUT.
This option applies to the previously
specified --format, or the default format
if no format is specified.
--stderr Write all output to stderr except for the
autocorrected source. This is especially useful
when combined with --autocorrect and --stdin.
--display-time Display elapsed time in seconds.
--display-only-failed Only output offense messages. Omit passing
cops. Only valid for --format junit.
--display-only-fail-level-offenses
Only output offense messages at
the specified --fail-level or above.
--display-only-correctable Only output correctable offense messages.
--display-only-safe-correctable
Only output safe-correctable offense messages
when combined with --display-only-correctable.
Autocorrection:
-a, --autocorrect Autocorrect offenses (only when it's safe).
--auto-correct (same, deprecated)
--safe-auto-correct (same, deprecated)
-A, --autocorrect-all Autocorrect offenses (safe and unsafe).
--auto-correct-all (same, deprecated)
--disable-uncorrectable Used with --autocorrect to annotate any
offenses that do not support autocorrect
with `rubocop:todo` comments.
Config Generation:
--auto-gen-config Generate a configuration file acting as a
TODO list.
--regenerate-todo Regenerate the TODO configuration file using
the last configuration. If there is no existing
TODO file, acts like --auto-gen-config.
--exclude-limit COUNT Set the limit for how many files to explicitly exclude.
If there are more files than the limit, the cop will
be disabled instead. Default is 15.
--no-exclude-limit Do not set the limit for how many files to exclude.
--[no-]offense-counts Include offense counts in configuration
file generated by --auto-gen-config.
Default is true.
--[no-]auto-gen-only-exclude Generate only Exclude parameters and not Max
when running --auto-gen-config, except if the
number of files with offenses is bigger than
exclude-limit. Default is false.
--[no-]auto-gen-timestamp Include the date and time when the --auto-gen-config
was run in the file it generates. Default is true.
--[no-]auto-gen-enforced-style
Add a setting to the TODO configuration file to enforce
the style used, rather than a per-file exclusion
if one style is used in all files for cop with
EnforcedStyle as a configurable option
when the --auto-gen-config was run
in the file it generates. Default is true.
Additional Modes:
-L, --list-target-files List all files RuboCop will inspect.
--show-cops [COP1,COP2,...] Shows the given cops, or all cops by
default, and their configurations for the
current directory.
--show-docs-url [COP1,COP2,...]
Display url to documentation for the given
cops, or base url by default.
General Options:
--init Generate a .rubocop.yml file in the current directory.
-c, --config FILE Specify configuration file.
-d, --debug Display debug info.
-r, --require FILE Require Ruby file.
--[no-]color Force color output on or off.
-v, --version Display version.
-V, --verbose-version Display verbose version.
Profiling Options:
--profile Profile rubocop.
--memory Profile rubocop memory usage.
Installation on mega-linter Docker image
- GEM packages (Ruby) :