In a .standard.yml file, what do ignore, default_ignores and ruby_version control, and what does Standard assume when ruby_version is missing?
answer
- ignore: paths, or paths with cop lists
- default ignores include db/schema.rb and bin/*
- default_ignores: false drops them
- ruby_version sets TargetRubyVersion
- missing: the running Ruby's version
basics
~20 signore skips paths, or only named cops for a path; default_ignores (true by default) adds Standard's own skips such as vendor/**/, bin/ and db/schema.rb. ruby_version sets RuboCop's target; without it Standard uses the Ruby running standardrb.
solid answer
~40 s`.standard.yml` is Standard's options file, found by searching upward from the working directory. `ignore:` takes a list: a plain glob excludes that path from every cop, and a glob mapped to a list of cop names excludes it from only those cops. `default_ignores:` (default `true`) keeps Standard's built-in exclusions: `.git/**/*`, `node_modules/**/*`, `vendor/**/*`, `tmp/**/*`, `bin/*` and `db/schema.rb`; setting it to `false` inspects those too. `ruby_version:` sets RuboCop's `TargetRubyVersion` and selects a version-specific ruleset that turns off cops whose suggestions need a newer Ruby. When it is missing, Standard uses `RUBY_VERSION`, the version of the Ruby running `standardrb`, not `.ruby-version` or the gemspec. A gem developed on Ruby 4.0 but supporting 3.2 must set `ruby_version: 3.2`, or Standard will suggest code that Ruby 3.2 cannot run.
code
yaml · 8 lines# .standard.yml for a gem that supports Ruby 3.2 and later
ruby_version: 3.2
parallel: true
ignore:
- "lib/my_gem/generated/**/*"
- "test/**/*":
- Style/GlobalVarsgo deeper
Recall that .standard.yml holds options like ignore and ruby_version, and that Standard skips vendor/ and db/schema.rb by default.
Explain ignore with and without cop lists, what default_ignores: false removes, and that ruby_version defaults to the running Ruby.
Pin ruby_version to the oldest supported Ruby so results match across machines and --fix never introduces code older Rubies cannot run.
Make the Standard options part of the project's support policy, so the declared Ruby range, the gemspec and the lint target never drift apart.
## Where the file lives Standard looks for **`.standard.yml`** in the working directory and then in each parent directory, and uses the first one it finds; `standardrb --config path/to/file.yml` names another file in the same format. It holds **options**, not cop settings: Standard's rules cannot be changed there. The keys and their defaults: | Key | Default | Meaning | |---|---|---| | `fix` | `false` | apply safe fixes on every run | | `parallel` | `false` | inspect files in parallel | | `format` | Standard's formatter | any RuboCop formatter name | | `ruby_version` | the running Ruby | the oldest Ruby the code must support | | `default_ignores` | `true` | keep Standard's built-in ignores | | `ignore` | `[]` | extra paths, or paths per cop, to skip | | `plugins` | `[]` | extra lint_roller plugins | | `extend_config` | `[]` | extra RuboCop YAML files | ## `ignore` Each entry is either a glob or a glob with a list of cops: - `- 'lib/generated/**/*'` excludes the files from **every** cop; - `- 'test/**/*': [Style/GlobalVars]` excludes them from **only** those cops. Relative globs are resolved from the directory holding `.standard.yml`. Entries are added to the matching `Exclude` lists in the configuration Standard hands to RuboCop, so the effect is the same as a RuboCop `Exclude`. ## `default_ignores` With the default `true`, Standard always excludes: 1. `.git/**/*`, `node_modules/**/*`, `vendor/**/*` and `tmp/**/*` (matching RuboCop's own defaults); 2. `bin/*` (generated binstubs); 3. `db/schema.rb` (a generated file in many applications). Setting `default_ignores: false` removes all six, so a project that wants to lint its hand-written `bin/` scripts must then re-add the other patterns under `ignore` itself. ## `ruby_version` This is the setting that most often matters. Standard **always** writes RuboCop's `AllCops: TargetRubyVersion` from it, and also picks one of its per-Ruby rule files (`ruby-3.3.yml`, `ruby-3.2.yml` and so on) that switch off cops whose corrections need newer Ruby. For example, the 3.3 file disables `Style/ItBlockParameter`, which suggests the `it` parameter from Ruby 3.4. When `ruby_version` is absent, Standard uses **`RUBY_VERSION`**: the version of the interpreter running `standardrb`. It does not consult `.ruby-version`, `.tool-versions`, `Gemfile.lock` or the gemspec, because it overwrites RuboCop's own target detection. The README's configuration section says the value is inferred from those files; the source sets it from `RUBY_VERSION` instead. Consequences: - an **application** whose developers and CI all run the deployed Ruby rarely needs the key; - a **gem** that supports older Rubies must set it to the oldest supported version, or `standardrb --fix` run on a newer Ruby may rewrite code into forms the older ones cannot run, such as `_1` into `it`; - two developers on different Ruby versions can get **different results** from the same commit until the key is set. ## The other keys - **`fix: true`** makes a plain `standardrb` apply safe fixes; `--no-fix` overrides it for a single run. - **`parallel: true`** inspects files in parallel processes, which speeds up large projects. - **`format:`** chooses any RuboCop formatter by name, such as `progress` or `json`, instead of Standard's own compact output. - **`plugins:`** and **`extend_config:`** add rules from lint_roller plugin gems and from RuboCop YAML files; neither can change Standard's built-in rules. Command-line flags are merged over these values, so `standardrb --format json` wins over `format:` in the file. ## Putting it together - Set `ruby_version` explicitly in every project, to the lowest Ruby the code supports. - Keep `default_ignores` on, and list further generated code under `ignore`. - Prefer per-cop `ignore` entries to whole-file ones, so the rest of Standard's rules still apply. - Keep `.standard.yml` in version control, so every run - local, editor and CI - uses the same options.
- Two developers run standardrb on the same commit, one on Ruby 3.3 and one on Ruby 4.0, and get different offenses. Why?Without `ruby_version` in `.standard.yml`, Standard uses the running interpreter's `RUBY_VERSION` as RuboCop's target and picks its per-version rule file from it. On 3.3 a cop such as `Style/ItBlockParameter` is switched off; on 4.0 it is on. Setting `ruby_version` makes every run use the same target.
- How do you make Standard lint the scripts in bin/ that it normally skips?Set `default_ignores: false`, which removes all of Standard's built-in ignores, then add back the ones you still want under `ignore`, such as `vendor/**/*`, `tmp/**/*`, `node_modules/**/*` and `db/schema.rb`. There is no key that removes just one default.
saying these in an interview costs you the question
- Standard reads .ruby-version to choose the target Ruby when ruby_version is missing.
- An ignore entry always excludes a file from every cop.
- default_ignores: false removes only the bin/* entry.
- ruby_version in .standard.yml should be the newest Ruby the gem supports.
- You can set Style/StringLiterals EnforcedStyle in .standard.yml.