standard 0.1.0 → 1.51.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/test.yml +24 -0
- data/.github/workflows/update.yml +54 -0
- data/.gitignore +3 -0
- data/.standard.yml +1 -1
- data/CHANGELOG.md +703 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +71 -37
- data/LICENSE.txt +3 -4
- data/README.md +459 -264
- data/Rakefile +5 -4
- data/bin/console +0 -4
- data/bin/rake +27 -0
- data/bin/run +9 -0
- data/config/base.yml +1065 -193
- data/config/default.yml +8 -0
- data/config/ruby-1.8.yml +10 -2
- data/config/ruby-1.9.yml +11 -1
- data/config/ruby-2.0.yml +4 -0
- data/config/ruby-2.1.yml +4 -0
- data/config/ruby-2.2.yml +13 -5
- data/config/ruby-2.3.yml +10 -0
- data/config/ruby-2.4.yml +10 -0
- data/config/ruby-2.5.yml +10 -0
- data/config/ruby-2.6.yml +13 -0
- data/config/ruby-2.7.yml +10 -0
- data/config/ruby-3.0.yml +13 -0
- data/config/ruby-3.1.yml +11 -0
- data/config/ruby-3.2.yml +4 -0
- data/config/ruby-3.3.yml +7 -0
- data/docs/ARCHITECTURE.md +33 -0
- data/docs/RELEASE.md +41 -0
- data/docs/RUBY_VERSIONS.md +51 -0
- data/docs/UPGRADING.md +31 -0
- data/lib/ruby_lsp/standard/addon.rb +58 -0
- data/lib/ruby_lsp/standard/wraps_built_in_lsp_standardizer.rb +44 -0
- data/lib/standard/base/plugin.rb +69 -0
- data/lib/standard/base.rb +8 -0
- data/lib/standard/builds_config.rb +11 -1
- data/lib/standard/cli.rb +1 -7
- data/lib/standard/creates_config_store/assigns_rubocop_yaml.rb +2 -18
- data/lib/standard/creates_config_store/configures_ignored_paths.rb +2 -2
- data/lib/standard/creates_config_store/merges_user_config_extensions.rb +37 -0
- data/lib/standard/creates_config_store/sets_target_ruby_version.rb +21 -8
- data/lib/standard/creates_config_store.rb +5 -0
- data/lib/standard/formatter.rb +92 -37
- data/lib/standard/loads_runner.rb +17 -3
- data/lib/standard/loads_yaml_config.rb +18 -11
- data/lib/standard/lsp/diagnostic.rb +174 -0
- data/lib/standard/lsp/kills_server.rb +10 -0
- data/lib/standard/lsp/logger.rb +21 -0
- data/lib/standard/lsp/routes.rb +175 -0
- data/lib/standard/lsp/server.rb +37 -0
- data/lib/standard/lsp/standardizer.rb +34 -0
- data/lib/standard/lsp/stdin_rubocop_runner.rb +71 -0
- data/lib/standard/merges_settings.rb +22 -11
- data/lib/standard/plugin/combines_plugin_configs.rb +15 -0
- data/lib/standard/plugin/creates_runner_context.rb +15 -0
- data/lib/standard/plugin/determines_class_constant.rb +56 -0
- data/lib/standard/plugin/initializes_plugins.rb +23 -0
- data/lib/standard/plugin/merges_plugins_into_rubocop_config.rb +177 -0
- data/lib/standard/plugin/standardizes_configured_plugins.rb +37 -0
- data/lib/standard/plugin.rb +11 -0
- data/lib/standard/railtie.rb +1 -1
- data/lib/standard/rake.rb +8 -1
- data/lib/standard/{parses_cli_option.rb → resolves_yaml_option.rb} +9 -2
- data/lib/standard/rubocop/ext.rb +17 -0
- data/lib/standard/runners/genignore.rb +44 -0
- data/lib/standard/runners/help.rb +9 -5
- data/lib/standard/runners/lsp.rb +11 -0
- data/lib/standard/runners/rubocop.rb +14 -18
- data/lib/standard/runners/verbose_version.rb +14 -0
- data/lib/standard/version.rb +1 -1
- data/lib/standard.rb +6 -4
- data/standard.gemspec +22 -20
- metadata +72 -73
- data/.circleci/config.yml +0 -35
- data/lib/standard/cop/semantic_blocks.rb +0 -162
- data/lib/standard/detects_fixability.rb +0 -20
data/README.md
CHANGED
@@ -1,246 +1,266 @@
|
|
1
|
-
|
1
|
+
<img src="https://user-images.githubusercontent.com/79303/233717126-9fd13e6d-9a66-4f1c-b40c-fe875cb1d1b4.png" style="width: 100%"/>
|
2
2
|
|
3
|
-
[](https://github.com/
|
3
|
+
[](https://github.com/standardrb/standard/actions/workflows/test.yml)
|
4
|
+
[](https://github.com/standardrb/standard)
|
5
5
|
[](https://rubygems.org/gems/standard)
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
The `standard` gem brings the ethos of [StandardJS](https://standardjs.com) to
|
8
|
+
Ruby. It's a linter & formatter built on
|
9
|
+
[RuboCop](https://github.com/rubocop/rubocop) and provides an **unconfigurable
|
10
|
+
configuration** to all of RuboCop's built-in rules as well as those included in
|
11
|
+
[rubocop-performance](https://github.com/rubocop/rubocop-performance). It also
|
12
|
+
supports plugins built with
|
13
|
+
[lint_roller](https://github.com/standardrb/lint_roller), like
|
14
|
+
[standard-rails](https://github.com/standardrb/standard-rails) and
|
15
|
+
[standard-sorbet](https://github.com/standardrb/standard-sorbet).
|
16
|
+
|
17
|
+
Standard Ruby was created and is maintained by the team at [Test
|
18
|
+
Double](https://testdouble.com), because we appreciate the importance of
|
19
|
+
balancing predictable, consistent code with preserving developer autonomy. 💚
|
20
|
+
|
21
|
+
Topics covered in this README:
|
22
|
+
|
23
|
+
* [Wait, what?!](#wait-did-you-say-unconfigurable-configuration)
|
24
|
+
* [Basic usage](#usage)
|
25
|
+
* [Editor & CI integrations](#integrating-standard-into-your-workflow)
|
26
|
+
* [Ignoring errors](#ignoring-errors)
|
27
|
+
* [Configuration options](#configuring-standard)
|
28
|
+
* [Plugins and extensions](#extending-standard)
|
29
|
+
* [Community](#who-uses-standard-ruby)
|
30
|
+
|
31
|
+
## Wait, did you say unconfigurable configuration?
|
32
|
+
|
33
|
+
Yes, Standard is unconfigurable. See, pretty much every developer can agree that
|
34
|
+
automatically identifying and fixing slow, insecure, and error-prone code is a
|
35
|
+
good idea. People also agree it's easier to work in codebases that exhibit a
|
36
|
+
consistent style and format. So, what's the problem? **No two developers will
|
37
|
+
ever agree on what all the rules and format should be.**
|
38
|
+
|
39
|
+
This has resulted in innumerable teams arguing about how to configure their linters
|
40
|
+
and formatters over literal decades. Some teams routinely divert time and energy
|
41
|
+
from whatever they're building to reach consensus on where commas should go.
|
42
|
+
Other teams have an overzealous tech lead who sets up everything _his favorite
|
43
|
+
way_ and then imposes his will on others. It's not uncommon to witness
|
44
|
+
passive-aggressive programmers change a contentious rule back-and-forth,
|
45
|
+
resulting in both acrimony and git churn (and acrimony _about_ git churn).
|
46
|
+
Still, most developers give way to whoever cares more, often resulting in an
|
47
|
+
inconsistent configuration that nobody understands and isn't kept up-to-date
|
48
|
+
with changes to their linter and its target language. Whatever the approach,
|
49
|
+
time spent
|
50
|
+
[bikeshedding](https://blog.testdouble.com/posts/2019-09-17-bike-shed-history/)
|
51
|
+
is time wasted.
|
52
|
+
|
53
|
+
**But you can't configure Standard Ruby.** You can take it or leave it. If this
|
54
|
+
seems presumptive, constraining, and brusque: you're right, it usually does feel
|
55
|
+
that way at first. But [since
|
56
|
+
2018](https://www.youtube.com/watch?v=uLyV5hOqGQ8), the Ruby community has
|
57
|
+
debated Standard Ruby's ruleset, ultimately landing us on a
|
58
|
+
[sensible](/config/base.yml)
|
59
|
+
[set](https://github.com/standardrb/standard-performance/blob/main/config/base.yml)
|
60
|
+
of
|
61
|
+
[defaults](https://github.com/standardrb/standard-custom/blob/main/config/base.yml)
|
62
|
+
that—_while no one person's favorite way to format Ruby_—seems to be good enough
|
63
|
+
for most of the ways people use Ruby, most of the time.
|
64
|
+
|
65
|
+
If you adopt Standard Ruby, what's in it for you? Time saved that would've been
|
66
|
+
spent arguing over how to set things up. Also, seamless upgrades: we stay on top
|
67
|
+
of each new RuboCop rule and update our configuration on a monthly release
|
68
|
+
cadence. But the best part of adopting Standard as your linter and formatter?
|
69
|
+
**You'll spend a whole lot less time thinking about linters and formatters.**
|
70
|
+
|
71
|
+
So please, give Standard Ruby a try. If you're like [these
|
72
|
+
folks](#who-uses-standard-ruby), you'll soon realize that the value of a linter
|
73
|
+
is in using one at all and not in the particulars of how it's configured.
|
9
74
|
|
10
|
-
|
11
|
-
project. Just drop it in.
|
12
|
-
* **Automatically format code.** Just run `standardrb --fix` and say goodbye to
|
13
|
-
messy or inconsistent code.
|
14
|
-
* **Catch style issues & programmer errors early.** Save precious code review
|
15
|
-
time by eliminating back-and-forth between reviewer & contributor.
|
75
|
+
## Usage
|
16
76
|
|
17
|
-
|
77
|
+
### Install
|
18
78
|
|
19
|
-
|
79
|
+
Getting started is as easy as `gem install standard` or throwing it in your
|
80
|
+
project's Gemfile and running `bundle install`:
|
20
81
|
|
21
82
|
```ruby
|
22
|
-
gem "standard"
|
83
|
+
gem "standard"
|
23
84
|
```
|
24
85
|
|
25
|
-
|
26
|
-
|
27
|
-
Run Standard from the command line with:
|
86
|
+
### Running Standard Ruby
|
28
87
|
|
29
|
-
|
30
|
-
|
31
|
-
```
|
32
|
-
|
33
|
-
And if you'd like, Standard can autocorrect your code by tacking on a `--fix`
|
34
|
-
flag.
|
35
|
-
|
36
|
-
## StandardRB — The Rules
|
37
|
-
|
38
|
-
- **2 spaces** – for indentation
|
39
|
-
- **Double quotes for string literals** - because pre-committing to whether
|
40
|
-
you'll need interpolation in a string slows people down
|
41
|
-
- **1.9 hash syntax** - When all the keys in a hash literal are symbols,
|
42
|
-
Standard enforces Ruby 1.9's `{hash: syntax}`
|
43
|
-
- **Semantic blocks** - `{`/`}` for functional blocks that return a value, and
|
44
|
-
`do`/`end` for procedural blocks that have side effects. More
|
45
|
-
[here](http://www.virtuouscode.com/2011/07/26/the-procedurefunction-block-convention-in-ruby/)
|
46
|
-
and [here](https://github.com/rubocop-hq/ruby-style-guide/issues/162)
|
47
|
-
- **Leading dots on multi-line method chains** - chosen for
|
48
|
-
[these](https://github.com/testdouble/standard/issues/75) reasons.
|
49
|
-
- **Spaces inside blocks, but not hash literals** - In Ruby, the `{` and `}`
|
50
|
-
characters do a lot of heavy lifting. To visually distinguish array literals
|
51
|
-
from blocks, Standard enforces that (like arrays), no leading or trailing
|
52
|
-
spaces be added to pad hashes
|
53
|
-
- **And a good deal more**
|
54
|
-
|
55
|
-
If you're familiar with [RuboCop](https://github.com/rubocop-hq/rubocop), you
|
56
|
-
can look at Standard's current base configuration in
|
57
|
-
[config/base.yml](/config/base.yml).
|
58
|
-
|
59
|
-
**[NOTE: until StandardRB hits 1.0.0, we consider this configuration to be a
|
60
|
-
non-final work in progress and we encourage you to submit your opinions (and
|
61
|
-
reasoned arguments) for the addition, removal, or change to a rule by [opening
|
62
|
-
an issue](https://github.com/testdouble/standard/issues/new). If you start using
|
63
|
-
Standard, don't be shocked if things change a bit!]**
|
88
|
+
Once installed, you can run Standard from the command line via its built-in
|
89
|
+
executable or as a Rake task.
|
64
90
|
|
65
|
-
|
91
|
+
Standard Ruby's binary is named `standardrb` to distinguish it from
|
92
|
+
[StandardJS](https://github.com/standard/standard):
|
66
93
|
|
67
|
-
|
68
|
-
|
69
|
-
files in the current working directory:
|
70
|
-
|
71
|
-
```bash
|
72
|
-
$ bundle exec standardrb
|
73
|
-
standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
|
74
|
-
standard: Run `standardrb --fix` to automatically fix some problems.
|
75
|
-
/Users/code/cli.rb:31:23: Style/Semicolon: Do not use semicolons to terminate expressions.
|
94
|
+
```
|
95
|
+
$ standardrb
|
76
96
|
```
|
77
97
|
|
78
|
-
|
79
|
-
|
80
|
-
`standardrb` instead of your shell:
|
98
|
+
And the Rake task can be run if your Rakefile includes `require
|
99
|
+
"standard/rake"`. This will load the `standard` task, allowing you to run:
|
81
100
|
|
82
|
-
```
|
83
|
-
$
|
101
|
+
```
|
102
|
+
$ rake standard
|
84
103
|
```
|
85
104
|
|
86
|
-
|
87
|
-
|
105
|
+
Either way, Standard will inspect any Ruby files found in the current directory
|
106
|
+
tree. If any errors are found, it'll report them. If your code is
|
107
|
+
standard-compliant, it will get out of your way by quietly exiting code 0.
|
88
108
|
|
89
|
-
###
|
109
|
+
### Fixing errors
|
90
110
|
|
91
|
-
|
92
|
-
autoload and be available after installing Standard. Otherwise, just require the
|
93
|
-
tasks in your `Rakefile`:
|
111
|
+
A majority of Standard's rules can be safely fixed automatically.
|
94
112
|
|
95
|
-
```ruby
|
96
|
-
require "standard/rake"
|
97
113
|
```
|
114
|
+
# CLI
|
115
|
+
$ standardrb --fix
|
98
116
|
|
99
|
-
|
100
|
-
|
101
|
-
```
|
102
|
-
$ rake standard # equivalent to running `standardrb`
|
103
|
-
$ rake standard:fix # equivalent to running `standardrb --fix`
|
117
|
+
# Rake
|
118
|
+
$ rake standard:fix
|
104
119
|
```
|
105
120
|
|
106
|
-
|
107
|
-
|
108
|
-
|
121
|
+
Because we're confident Standard's fixes won't change the behavior of our code,
|
122
|
+
we typically run with fix enabled _all the time_ because it saves us from having
|
123
|
+
to look at and think about problems the computer can solve for us.
|
124
|
+
|
125
|
+
### Applying unsafe fixes
|
126
|
+
|
127
|
+
There are a number of other rules that can be automatically remedied, but not
|
128
|
+
without the risk of changing your code's behavior. While we wouldn't recommend
|
129
|
+
running it all the time, if the CLI suggests that additional errors can be fixed
|
130
|
+
_unsafely_, here's how to do that:
|
109
131
|
|
110
132
|
```
|
111
|
-
#
|
112
|
-
$
|
133
|
+
# CLI
|
134
|
+
$ standardrb --fix-unsafely
|
113
135
|
|
114
|
-
#
|
115
|
-
$ rake standard
|
136
|
+
# Rake
|
137
|
+
$ rake standard:fix_unsafely
|
116
138
|
```
|
117
139
|
|
118
|
-
|
140
|
+
So long as your code is checked into source control, there's no mortal harm in
|
141
|
+
running with unsafe fixes enabled. If the changes look good to you and your
|
142
|
+
tests pass, then it's probably no more error prone than manually editing
|
143
|
+
every change by hand.
|
119
144
|
|
120
|
-
|
121
|
-
are available creating a `.standard.yml` file in the root of your project.
|
145
|
+
## Integrating Standard into your workflow
|
122
146
|
|
123
|
-
|
147
|
+
Because code formatting is so integral to programming productivity and linter
|
148
|
+
violations risk becoming bugs if released into production, tools like
|
149
|
+
Standard Ruby are only as useful as their integration into code editors and
|
150
|
+
continuous integration systems.
|
124
151
|
|
125
|
-
|
126
|
-
fix: true # default: false
|
127
|
-
parallel: true # default: false
|
128
|
-
format: progress # default: Standard::Formatter
|
129
|
-
ruby_version: 2.3.3 # default: RUBY_VERSION
|
130
|
-
default_ignores: false # default: true
|
152
|
+
### Editor support
|
131
153
|
|
132
|
-
|
133
|
-
- 'db/schema.rb'
|
134
|
-
- 'vendor/**/*'
|
135
|
-
- 'test/**/*':
|
136
|
-
- Layout/AlignHash
|
137
|
-
```
|
154
|
+
We've added a number of editing guides for getting started:
|
138
155
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
156
|
+
- [Atom](https://github.com/standardrb/standard/wiki/IDE:-Atom)
|
157
|
+
- [emacs](https://www.flycheck.org/en/latest/languages.html#syntax-checker-ruby-standard)
|
158
|
+
- [Helix](https://github.com/helix-editor/helix/wiki/Formatter-configurations#standardrb)
|
159
|
+
- [neovim](https://github.com/standardrb/standard/wiki/IDE:-neovim)
|
160
|
+
- [Nova](https://codeberg.org/edwardloveall/nova-standard)
|
161
|
+
- [RubyMine](https://www.jetbrains.com/help/ruby/rubocop.html#disable_rubocop)
|
162
|
+
- [vim](https://github.com/standardrb/standard/wiki/IDE:-vim)
|
163
|
+
- [VS Code](https://github.com/standardrb/standard/wiki/IDE:-vscode)
|
164
|
+
- [Zed](https://zed.dev/docs/languages/ruby#setting-up-ruby-lsp)
|
165
|
+
- [Sublime Text](https://github.com/standardrb/standard/wiki/IDE:-Sublime-Text)
|
143
166
|
|
144
|
-
|
167
|
+
If you'd like to help by creating a guide, please draft one [in an
|
168
|
+
issue](https://github.com/standardrb/standard/issues/new) and we'll get it
|
169
|
+
added!
|
145
170
|
|
146
|
-
|
147
|
-
[RuboCop](https://github.com/rubocop-hq/rubocop), it will actually forward the
|
148
|
-
vast majority of CLI and ENV arguments forward to RuboCop.
|
171
|
+
#### Language Server Protocol support
|
149
172
|
|
150
|
-
|
151
|
-
[
|
152
|
-
|
173
|
+
If you don't see your preferred editor above, Standard Ruby also offers robust
|
174
|
+
[language server](https://microsoft.github.io/language-server-protocol/) support,
|
175
|
+
in two ways, both included with the `standard` gem:
|
153
176
|
|
154
|
-
|
177
|
+
1. A [Ruby LSP](https://github.com/Shopify/ruby-lsp) add-on, which (if
|
178
|
+
the `standard` gem is in your `Gemfile`) will be loaded automatically
|
179
|
+
2. A language server executable, which can be run from the command line
|
180
|
+
with `standardrb --lsp`
|
155
181
|
|
156
|
-
|
157
|
-
|
158
|
-
|
182
|
+
| Capability | Ruby LSP Add-on | Internal Server |
|
183
|
+
| ------------- | ------------- | ------------- |
|
184
|
+
| Diagnostics (Linting) | ✅ ([Pull](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics)) | ✅ ([Push](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics)) |
|
185
|
+
| [Formatting](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting) | ✅ | ✅ |
|
186
|
+
| [Code Actions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction) | ✅ | ❌ |
|
187
|
+
| Everything else | ❌ | ❌ |
|
159
188
|
|
160
|
-
|
161
|
-
|
162
|
-
|
189
|
+
Due to the advantages of Pull diagnostics and its inclusion of Code Actions
|
190
|
+
("Quick Fixes" in VS Code parlance), we recommend using Standard's [Ruby LSP
|
191
|
+
add-on](https://github.com/standardrb/standard/wiki/IDE:-vscode#using-ruby-lsp)
|
192
|
+
where possible.
|
163
193
|
|
164
|
-
|
194
|
+
Regardless of which language server you use, many editors have added LSP
|
195
|
+
support, with each bringing their own approach to configuration. Many LSP
|
196
|
+
features should "just work", but when in doubt, please consult our [editor
|
197
|
+
guides above](#editor-support) as well as your editor's own documentation on how
|
198
|
+
to configure LSP formatters and linters.
|
165
199
|
|
166
|
-
|
167
|
-
project. Just drop it in.
|
168
|
-
- **Automatically format code.** Just run `standardrb --fix` and say goodbye to
|
169
|
-
messy or inconsistent code.
|
170
|
-
- **Catch style issues & programmer errors early.** Save precious code review
|
171
|
-
time by eliminating back-and-forth between reviewer & contributor.
|
200
|
+
### CI support
|
172
201
|
|
173
|
-
|
174
|
-
|
175
|
-
100% of projects and development cultures, however open source can be a hostile
|
176
|
-
place for newbies. Setting up clear, automated contributor expectations makes a
|
177
|
-
project healthier.
|
202
|
+
Various continuous integration and quality-checking tools have been made to
|
203
|
+
support Standard Ruby, as well.
|
178
204
|
|
179
|
-
|
205
|
+
* [GitHub Actions](https://github.com/standardrb/standard-ruby-action)
|
206
|
+
* [Code Climate](https://github.com/standardrb/standard/wiki/CI:-Code-Climate)
|
207
|
+
* [Pronto](https://github.com/julianrubisch/pronto-standardrb)
|
208
|
+
* [Danger](https://github.com/ashfurrow/danger-rubocop/)
|
180
209
|
|
181
|
-
|
182
|
-
|
183
|
-
if you've used StandardJS.)
|
210
|
+
Of course, no special plugin is necessary to run Standard Ruby in a CI
|
211
|
+
environment, as `standardrb` and `rake standard` work just fine on their own!
|
184
212
|
|
185
|
-
|
186
|
-
* [Collective Idea](https://collectiveidea.com/)
|
187
|
-
* [Culture Foundry](https://www.culturefoundry.com/)
|
188
|
-
* [Evil Martians](https://evilmartians.com)
|
189
|
-
* [Rebase Interactive](https://www.rebaseinteractive.com/)
|
190
|
-
* [Hashrocket](https://hashrocket.com)
|
191
|
-
* And that's about it so far!
|
213
|
+
### Other tools
|
192
214
|
|
193
|
-
|
194
|
-
request](https://github.com/testdouble/standard/edit/master/README.md) to let us
|
195
|
-
know!
|
215
|
+
These tool integrations are also available:
|
196
216
|
|
197
|
-
|
217
|
+
* [Guard](https://github.com/JodyVanden/guard-standardrb)
|
218
|
+
* [Spring](https://github.com/lakim/spring-commands-standard)
|
198
219
|
|
199
|
-
|
200
|
-
badges in your readme to let people know that your code is using the StandardRB
|
201
|
-
style.
|
220
|
+
## Ignoring errors
|
202
221
|
|
203
|
-
|
222
|
+
While Standard is very strict in how each formatting and linting rule is configured,
|
223
|
+
it's mercifully flexible when you need to ignore a violation to focus on a higher
|
224
|
+
priority (like, say, keeping the build running). There are a number of ways to
|
225
|
+
ignore any errors, with the right answer depending on the situation.
|
204
226
|
|
205
|
-
|
206
|
-
[](https://github.com/testdouble/standard)
|
207
|
-
```
|
227
|
+
### Ignoring a line with a comment
|
208
228
|
|
209
|
-
|
229
|
+
Individual lines can be ignored with a comment directive at the end of the line.
|
230
|
+
As an example, the line `text = 'hi'` violates two rules,
|
231
|
+
[Lint/UselessAssignment](https://docs.rubocop.org/rubocop/cops_lint.html#lintuselessassignment)
|
232
|
+
and
|
233
|
+
[Style/StringLiterals](https://docs.rubocop.org/rubocop/cops_style.html#stylestringliterals).
|
210
234
|
|
211
|
-
|
212
|
-
[opening an issue](https://github.com/testdouble/standard/issues/new) and
|
213
|
-
convincing [@searls](https://twitter.com/searls) (the BDFNow) to make the
|
214
|
-
change.]**
|
235
|
+
You could ignore one, both, or all errors with the following comments:
|
215
236
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
that will never be resolved. These debates just distract from getting stuff
|
220
|
-
done. At the end of the day you have to 'just pick something', and that's the
|
221
|
-
whole philosophy of Standard -- its a bunch of sensible 'just pick something'
|
222
|
-
opinions. Hopefully, users see the value in that over defending their own
|
223
|
-
opinions.
|
224
|
-
|
225
|
-
Pro tip: Just use Standard and move on. There are actual real problems that
|
226
|
-
you could spend your time solving! :P
|
237
|
+
```ruby
|
238
|
+
# Disable one error but keep Lint/UselessAssignment
|
239
|
+
text = 'hi' # standard:disable Style/StringLiterals
|
227
240
|
|
228
|
-
|
241
|
+
# Disable both errors explicitly
|
242
|
+
text = 'hi' # standard:disable Style/StringLiterals, Lint/UselessAssignment
|
229
243
|
|
230
|
-
|
244
|
+
# Disable all errors on the line with "all"
|
245
|
+
text = "hi" # standard:disable all
|
246
|
+
```
|
231
247
|
|
232
|
-
|
233
|
-
problems are fixable, but some errors must be fixed manually.
|
248
|
+
### Ignoring multiple lines with comments
|
234
249
|
|
235
|
-
|
250
|
+
Similarly to individual lines, you can also disable multiple lines by wrapping
|
251
|
+
them in comments that disable and re-enable them:
|
236
252
|
|
237
|
-
|
253
|
+
```ruby
|
254
|
+
# standard:disable Style/StringLiterals, Lint/UselessAssignment
|
255
|
+
text = "hi"
|
256
|
+
puts 'bye'
|
257
|
+
# standard:enable Style/StringLiterals, Lint/UselessAssignment
|
258
|
+
```
|
238
259
|
|
239
|
-
|
260
|
+
### Ignoring entire files and globs
|
240
261
|
|
241
|
-
|
242
|
-
|
243
|
-
list of files and globs that should be excluded:
|
262
|
+
You can ignore entire files and file patterns by adding them to `ignore:` in
|
263
|
+
your project's `.standard.yml` file:
|
244
264
|
|
245
265
|
```yaml
|
246
266
|
ignore:
|
@@ -248,135 +268,310 @@ ignore:
|
|
248
268
|
- 'a/whole/directory/**/*'
|
249
269
|
```
|
250
270
|
|
251
|
-
|
252
|
-
|
271
|
+
### Ignoring specific rules in files and globs
|
272
|
+
|
273
|
+
For a given file or glob, you can even ignore only specific rules by nesting an
|
274
|
+
array of the rules you'd like to ignore:
|
275
|
+
|
276
|
+
```yaml
|
277
|
+
ignore:
|
278
|
+
- 'test/**/*':
|
279
|
+
- Layout/AlignHash
|
280
|
+
```
|
281
|
+
|
282
|
+
### Ignoring every violation and converting them into a todo list
|
253
283
|
|
254
|
-
|
284
|
+
If you're adopting Standard in a large codebase and you don't want to convert
|
285
|
+
everything all at once, you can work incrementally by generating a "todo" file
|
286
|
+
which will cause Standard to ignore every violation present in each file of the
|
287
|
+
codebase.
|
255
288
|
|
256
|
-
|
257
|
-
|
289
|
+
This way, you can gradually work through the todo list, removing ignore
|
290
|
+
directives and fixing any associated errors, while also being alerted to any
|
291
|
+
regressions if they're introduced into the project.
|
258
292
|
|
259
|
-
|
260
|
-
under-the-hood and you can hide warnings as you normally would if you used
|
261
|
-
RuboCop directly.
|
293
|
+
Here are the commands you might run to get started:
|
262
294
|
|
263
|
-
|
264
|
-
|
265
|
-
|
295
|
+
```
|
296
|
+
# Start by clearing any auto-fixable errors:
|
297
|
+
$ standardrb --fix
|
298
|
+
|
299
|
+
# Generate a `.standard_todo.yml' to work from
|
300
|
+
$ standardrb --generate-todo
|
301
|
+
```
|
302
|
+
|
303
|
+
## Configuring Standard
|
304
|
+
|
305
|
+
While the rules aren't configurable, Standard offers a number of options that
|
306
|
+
can be configured as CLI flags and YAML properties.
|
307
|
+
|
308
|
+
### CLI flags
|
309
|
+
|
310
|
+
The easiest way to summarize the available CLI flags is to invoke `standardrb -h`:
|
311
|
+
|
312
|
+
```
|
313
|
+
Usage: standardrb [--fix] [--lsp] [-vh] [--format <name>] [--] [FILE]...
|
314
|
+
|
315
|
+
Options:
|
316
|
+
|
317
|
+
--fix Apply automatic fixes that we're confident won't break your code
|
318
|
+
--fix-unsafely Apply even more fixes, including some that may change code behavior
|
319
|
+
--no-fix Do not automatically fix failures
|
320
|
+
--format <name> Format output with any RuboCop formatter (e.g. "json")
|
321
|
+
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
|
322
|
+
--lsp Start a LSP server listening on STDIN
|
323
|
+
-v, --version Print the version of Standard
|
324
|
+
-V, --verbose-version Print the version of Standard and its dependencies.
|
325
|
+
-h, --help Print this message
|
326
|
+
FILE Files to lint [default: ./]
|
327
|
+
|
328
|
+
Standard also forwards most CLI arguments to RuboCop. To see them, run:
|
329
|
+
|
330
|
+
$ rubocop --help
|
331
|
+
```
|
332
|
+
|
333
|
+
If you run Standard via Rake, you can specify your CLI flags in an environment
|
334
|
+
variable named `STANDARDOPTS` like so:
|
335
|
+
|
336
|
+
```
|
337
|
+
$ rake standard STANDARDOPTS="--format progress"
|
338
|
+
```
|
339
|
+
|
340
|
+
### YAML options
|
341
|
+
|
342
|
+
In addition to CLI flags, Standard will search for a `.standard.yml` file
|
343
|
+
(ascending to parent directories if the current working directory doesn't
|
344
|
+
contain one). If you find yourself repeatedly running Standard with the same
|
345
|
+
CLI options, it probably makes more sense to set it once in a YAML file:
|
266
346
|
|
267
347
|
```yaml
|
268
|
-
|
269
|
-
|
270
|
-
|
348
|
+
fix: true # default: false
|
349
|
+
parallel: true # default: false
|
350
|
+
format: progress # default: Standard::Formatter
|
351
|
+
ruby_version: 3.0 # default: RUBY_VERSION
|
352
|
+
default_ignores: false # default: true
|
353
|
+
|
354
|
+
ignore: # default: []
|
355
|
+
- 'vendor/**/*'
|
356
|
+
|
357
|
+
plugins: # default: []
|
358
|
+
- standard-rails
|
359
|
+
|
360
|
+
extend_config: # default: []
|
361
|
+
- .standard_ext.yml
|
362
|
+
```
|
363
|
+
|
364
|
+
#### Configuring ruby_version
|
365
|
+
|
366
|
+
One notable YAML setting is `ruby_version`, which allows you to set the **oldest
|
367
|
+
version of Ruby the project needs to support** [RuboCop's `TargetRubyVersion`
|
368
|
+
setting](https://docs.rubocop.org/rubocop/configuration.html#setting-the-target-ruby-version)
|
369
|
+
explicitly. Because this value is inferred from any `.ruby-version`,
|
370
|
+
`.tool-versions`, `Gemfile.lock`, and `*.gemspec` files that might be present,
|
371
|
+
most applications won't need to set this.
|
372
|
+
|
373
|
+
However, gems and libraries that support older versions of Ruby will want
|
374
|
+
to lock the `ruby-version:` explicitly in their `.standard.yml` file to ensure
|
375
|
+
new rules don't break old rubies:
|
376
|
+
|
377
|
+
```yaml
|
378
|
+
ruby_version: 2.7
|
271
379
|
```
|
272
380
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
381
|
+
## Extending Standard
|
382
|
+
|
383
|
+
Standard includes two extension mechanisms: plugins and configuration
|
384
|
+
extensions. While neither can _change_ the rules configured out-of-the-box by
|
385
|
+
Standard, they can define, require, and configure _additional_ RuboCop rules.
|
277
386
|
|
278
|
-
|
387
|
+
Both are "first-in-wins", meaning once a rule is configured by a plugin or
|
388
|
+
extension, it can't be changed or reconfigured by a later plugin or extension.
|
389
|
+
This way, each Standard plugin you add becomes a de facto "standard" of its
|
390
|
+
own. Plugins have precedence over extensions as they are loaded first.
|
279
391
|
|
280
|
-
|
281
|
-
requirements](https://github.com/rubocop-hq/rubocop#compatibility)—currently,
|
282
|
-
that's MRI 2.3 and newer. While Standard can't avoid this runtime requirement,
|
283
|
-
it does allow you to lint codebases that target Ruby versions older than 2.3 by
|
284
|
-
narrowing the ruleset somewhat.
|
392
|
+
### Plugins
|
285
393
|
|
286
|
-
|
287
|
-
|
288
|
-
|
394
|
+
Adding a plugin to your project is as easy as adding it to your Gemfile and
|
395
|
+
specifying it in `.standard.yml` in the root of your project. For example, after
|
396
|
+
installing [standard-rails](https://github.com/standardrb/standard-rails), you
|
397
|
+
can configure it by adding it to `plugins`:
|
289
398
|
|
399
|
+
```yaml
|
400
|
+
plugins:
|
401
|
+
- standard-rails
|
290
402
|
```
|
291
|
-
|
403
|
+
|
404
|
+
Each plugin can be passed configuration options by specifying them in a nested
|
405
|
+
hash. For example, `standard-rails` allows you to configure its rules for
|
406
|
+
a particular version of Rails (though this will usually be detected for you
|
407
|
+
automatically):
|
408
|
+
|
409
|
+
```yaml
|
410
|
+
plugins:
|
411
|
+
- standard-rails:
|
412
|
+
target_rails_version: 7.0
|
292
413
|
```
|
293
414
|
|
294
|
-
|
295
|
-
[
|
296
|
-
|
415
|
+
You can develop your own plugins, too! Check out the
|
416
|
+
[lint_roller](https://github.com/standardrb/lint_roller) gem to learn how. For a
|
417
|
+
simple example, you can look at
|
418
|
+
[standard-custom](https://github.com/standardrb/standard-custom), which is one
|
419
|
+
of the default plugins included by Standard.
|
297
420
|
|
298
|
-
|
299
|
-
may or may not match the version of the runtime (suppose you're on Ruby 2.5.1,
|
300
|
-
but your library supports Ruby 2.3.0). In this case, specify `ruby_version` and
|
301
|
-
you should be okay. However, note that if you target a _newer_ Ruby version than
|
302
|
-
the runtime, RuboCop may behave in surprising or inconsistent ways.
|
421
|
+
### Extended config files
|
303
422
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
423
|
+
Of course, you may want to add more rules without going to the trouble
|
424
|
+
of packaging them in a plugin gem. For cases like this, you can define one or
|
425
|
+
more [RuboCop configuration
|
426
|
+
files](https://docs.rubocop.org/rubocop/configuration.html) and then list them
|
427
|
+
in your `.standard.yml` file under `extend_config`.
|
309
428
|
|
310
|
-
|
429
|
+
For example, after installing the
|
430
|
+
[betterlint](https://github.com/Betterment/betterlint) gem from our friends at
|
431
|
+
[Betterment](https://www.betterment.com), we could create a RuboCop config
|
432
|
+
file named `.betterlint.yml`:
|
311
433
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
write your own.
|
434
|
+
```yaml
|
435
|
+
require:
|
436
|
+
- rubocop/cop/betterment.rb
|
316
437
|
|
317
|
-
|
318
|
-
|
438
|
+
Betterment/UnscopedFind:
|
439
|
+
Enabled: true
|
319
440
|
|
441
|
+
unauthenticated_models:
|
442
|
+
- SystemConfiguration
|
320
443
|
```
|
321
|
-
$ bundle exec standardrb --format progress
|
322
|
-
Inspecting 15 files
|
323
|
-
...............
|
324
444
|
|
325
|
-
|
445
|
+
And then reference it in our `.standard.yml`:
|
446
|
+
|
447
|
+
```yml
|
448
|
+
extend_config:
|
449
|
+
- .betterlint.yml
|
326
450
|
```
|
327
451
|
|
328
|
-
|
452
|
+
### Running Standard's rules via RuboCop
|
453
|
+
|
454
|
+
**Please note that the following usage is not supported and may break at any
|
455
|
+
time. Use at your own risk and please refrain from opening GitHub issues with
|
456
|
+
respect to loading Standard or its plugins' YAML configurations for use by
|
457
|
+
the `rubocop` CLI.**
|
458
|
+
|
459
|
+
If you find that neither plugins or configuration extensions meet your needs or
|
460
|
+
if you have some other reason to run Standard's rules with RuboCop's CLI (e.g.,
|
461
|
+
to continue using your favorite IDE/tooling/workflow with RuboCop support) Evil
|
462
|
+
Martians also maintains [a regularly updated
|
463
|
+
guide](https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard)
|
464
|
+
on how to configure RuboCop to load and execute Standard's ruleset.
|
465
|
+
|
466
|
+
In short, you can configure this in your `.rubocop.yml` to load Standard's three
|
467
|
+
default rulesets, just as you would any other gem:
|
329
468
|
|
330
469
|
```yaml
|
331
|
-
|
470
|
+
require:
|
471
|
+
- standard
|
472
|
+
- standard-custom
|
473
|
+
- standard-performance
|
474
|
+
- rubocop-performance
|
475
|
+
|
476
|
+
inherit_gem:
|
477
|
+
standard: config/base.yml
|
478
|
+
standard-custom: config/base.yml
|
479
|
+
standard-performance: config/base.yml
|
332
480
|
```
|
333
481
|
|
334
|
-
|
335
|
-
formatters](https://rubocop.readthedocs.io/en/latest/formatters/) for more
|
336
|
-
information.
|
482
|
+
## Who uses Standard Ruby?
|
337
483
|
|
338
|
-
|
484
|
+
Here are a few examples of Ruby Standard-compliant teams & projects:
|
339
485
|
|
340
|
-
|
341
|
-
|
486
|
+
* [Test Double](https://testdouble.com/agency)
|
487
|
+
* [AdBarker](https://adbarker.com)
|
488
|
+
* [AlchemyCMS](https://alchemy-cms.com)
|
489
|
+
* [Amazon Web Services](https://aws.amazon.com/)
|
490
|
+
* [Arrows](https://arrows.to/)
|
491
|
+
* [Avo Admin](https://avohq.io/)
|
492
|
+
* [Babylist](https://www.babylist.com/)
|
493
|
+
* [BLISH](https://blish.cloud)
|
494
|
+
* [Brand New Box](https://brandnewbox.com)
|
495
|
+
* [Brave Software](https://github.com/brave-intl/publishers)
|
496
|
+
* [Collective Idea](https://collectiveidea.com/)
|
497
|
+
* [Culture Foundry](https://www.culturefoundry.com/)
|
498
|
+
* [Datadog](https://www.datadoghq.com/)
|
499
|
+
* [Donut](https://www.donut.com/)
|
500
|
+
* [Elevate Labs](https://elevatelabs.com)
|
501
|
+
* [Envoy](https://www.envoy.com)
|
502
|
+
* [Evil Martians](https://evilmartians.com)
|
503
|
+
* [Firstline](https://firstline.org/)
|
504
|
+
* [Hashrocket](https://hashrocket.com)
|
505
|
+
* [Honeybadger](https://www.honeybadger.io)
|
506
|
+
* [JetThoughts](https://www.jetthoughts.com/)
|
507
|
+
* [Level UP Solutions](https://levups.com)
|
508
|
+
* [Lobsters](https://github.com/lobsters/lobsters)
|
509
|
+
* [Monterail](https://www.monterail.com)
|
510
|
+
* [myRent](https://www.myrent.co.nz)
|
511
|
+
* [OBLSK](https://oblsk.com/)
|
512
|
+
* [Oyster](https://www.oysterhr.com/)
|
513
|
+
* [Planet Argon](https://www.planetargon.com/)
|
514
|
+
* [PLT4M](https://plt4m.com/)
|
515
|
+
* [Podia](https://www.podia.com/)
|
516
|
+
* [Privy](https://www.privy.com/)
|
517
|
+
* [Rebase Interactive](https://www.rebaseinteractive.com/)
|
518
|
+
* [Renuo](https://www.renuo.ch/)
|
519
|
+
* [RubyCI](https://ruby.ci)
|
520
|
+
* [SearchApi](https://www.searchapi.io/)
|
521
|
+
* [Spinal](https://spinalcms.com/)
|
522
|
+
* [Teamtailor](https://www.teamtailor.com/)
|
523
|
+
* [thoughtbot](https://thoughtbot.com/)
|
524
|
+
* [Topkey](https://topkey.io)
|
525
|
+
* [University of Wisconsin-Eau Claire](https://www.uwec.edu/)
|
526
|
+
* [Cartwheel](https://www.cartwheel.org)
|
342
527
|
|
343
|
-
|
528
|
+
Does your team use Standard? [Add your name to the list](https://github.com/standardrb/standard/edit/main/README.md)!
|
344
529
|
|
345
|
-
|
530
|
+
If you really want to show off, you can also add a badge to your project's README, like this one:
|
346
531
|
|
347
|
-
|
532
|
+
[](https://github.com/standardrb/standard)
|
348
533
|
|
349
|
-
|
534
|
+
```md
|
535
|
+
[](https://github.com/standardrb/standard)
|
536
|
+
```
|
350
537
|
|
351
|
-
|
538
|
+
## Help, I'm seeing an install error!
|
352
539
|
|
353
|
-
|
354
|
-
|
540
|
+
This section is really only here to feed Google, but if you see an error like
|
541
|
+
any of the following:
|
355
542
|
|
356
|
-
```
|
357
|
-
|
358
|
-
let g:ale_fixers = {'ruby': ['standardrb']}
|
543
|
+
```
|
544
|
+
ERROR: Could not find a valid gem 'standard' (= 0.0.36) in any repository
|
359
545
|
```
|
360
546
|
|
361
|
-
|
362
|
-
|
363
|
-
|
547
|
+
```
|
548
|
+
Could not find gem 'standard (= 0.0.36)' in rubygems repository https://rubygems.org/ or installed locally.
|
549
|
+
```
|
364
550
|
|
365
551
|
```
|
366
|
-
|
552
|
+
Your bundle is locked to standard (0.0.36) from rubygems repository https://rubygems.org/ or installed locally, but that version can no longer be found in that source. That means the author of standard (0.0.36) has removed it. You'll need to update your bundle to a version other than standard (0.0.36) that hasn't been removed in order to install.
|
367
553
|
```
|
368
554
|
|
369
|
-
|
555
|
+
This is because on August 18th, 2023, we yanked versions 0.0.1~0.0.36.1 from
|
556
|
+
[RubyGems.org](https://rubygems.org) for the reasons discussed in [this
|
557
|
+
issue](https://github.com/standardrb/standard/issues/340). Because these
|
558
|
+
versions are now over four years old and no longer track supported versions of
|
559
|
+
Ruby or RuboCop, the correct fix for any of the above errors is probably to
|
560
|
+
**upgrade to the latest version of Standard Ruby**.
|
370
561
|
|
371
|
-
|
562
|
+
If for whatever reason you need to install one of these versions, you can
|
563
|
+
change your Gemfile to point to the corresponding git tag from the source
|
564
|
+
repository:
|
372
565
|
|
373
|
-
```
|
374
|
-
|
375
|
-
$ cd standard
|
376
|
-
$ gem install bundler # if working with ruby version below 2.6.0
|
377
|
-
$ bundle install
|
378
|
-
$ bundle exec rake # to run test suite
|
566
|
+
```ruby
|
567
|
+
gem "standard", git: "https://github.com/testdouble/standard.git", tag: "v0.0.36"
|
379
568
|
```
|
380
569
|
|
381
570
|
## Code of Conduct
|
382
|
-
|
571
|
+
|
572
|
+
This project follows Test Double's [code of
|
573
|
+
conduct](https://testdouble.com/code-of-conduct) for all community interactions,
|
574
|
+
including (but not limited to) one-on-one communications, public posts/comments,
|
575
|
+
code reviews, pull requests, and GitHub issues. If violations occur, Test Double
|
576
|
+
will take any action they deem appropriate for the infraction, up to and
|
577
|
+
including blocking a user from the organization's repositories.
|