standard 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of standard might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +40 -0
- data/README.md +252 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/base.yml +142 -0
- data/exe/standard +7 -0
- data/exe/standardrb +1 -0
- data/lib/standard/cli.rb +42 -0
- data/lib/standard/config.rb +100 -0
- data/lib/standard/file_finder.rb +13 -0
- data/lib/standard/formatter.rb +25 -0
- data/lib/standard/timer.rb +13 -0
- data/lib/standard/version.rb +3 -0
- data/lib/standard.rb +5 -0
- data/standard.gemspec +26 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 040b9b258bb3af7fe3518de76a33003f6e576d7a7ba3f80930dfb6f932c82b61
|
4
|
+
data.tar.gz: abfb172a46b7ee0ad7a7ba70d454d5160889149ea6c62e220c65ebb1628c0e7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2eed490d1bf9e46623019252225cbf738ab3f7ee92d999085557ae51a15d8a1997b9991b4f788fb0f87722482b35e69d95354768c9be7ac04c8f533761613091
|
7
|
+
data.tar.gz: d412b22bb421cc2833a0e9a2bbb78b6664fbcfa627eebb876d200080eae43a1bbb8e81f51e097c4a5772fc3643eb861a2a84ee1142a1b7788eb86cc5cf118be2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
standard (0.0.1)
|
5
|
+
rubocop (>= 0.60)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
jaro_winkler (1.5.1)
|
12
|
+
minitest (5.11.3)
|
13
|
+
parallel (1.12.1)
|
14
|
+
parser (2.5.3.0)
|
15
|
+
ast (~> 2.4.0)
|
16
|
+
powerpack (0.1.2)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (10.5.0)
|
19
|
+
rubocop (0.60.0)
|
20
|
+
jaro_winkler (~> 1.5.1)
|
21
|
+
parallel (~> 1.10)
|
22
|
+
parser (>= 2.5, != 2.5.1.1)
|
23
|
+
powerpack (~> 0.1)
|
24
|
+
rainbow (>= 2.2.2, < 4.0)
|
25
|
+
ruby-progressbar (~> 1.7)
|
26
|
+
unicode-display_width (~> 1.4.0)
|
27
|
+
ruby-progressbar (1.10.0)
|
28
|
+
unicode-display_width (1.4.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.17)
|
35
|
+
minitest (~> 5.0)
|
36
|
+
rake (~> 10.0)
|
37
|
+
standard!
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
1.17.1
|
data/README.md
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
## Standard - Ruby style guide, linter, and formatter
|
2
|
+
|
3
|
+
This gem is a spiritual port of [StandardJS](https://standardjs.com) and aims
|
4
|
+
to save you (and others!) time in the same three ways:
|
5
|
+
|
6
|
+
* **No configuration.** The easiest way to enforce consistent style in your
|
7
|
+
project. Just drop it in.
|
8
|
+
* **Automatically format code.** Just run `standard --fix` and say goodbye to
|
9
|
+
messy or inconsistent code.
|
10
|
+
* **Catch style issues & programmer errors early.** Save precious code review
|
11
|
+
time by eliminating back-and-forth between reviewer & contributor.
|
12
|
+
|
13
|
+
No decisions to make. It just works.
|
14
|
+
|
15
|
+
Install by adding it to your Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem "standard", :require => false
|
19
|
+
```
|
20
|
+
|
21
|
+
And running `bundle install`.
|
22
|
+
|
23
|
+
Run StandardRB from the command line with:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
$ bundle exec standard
|
27
|
+
```
|
28
|
+
|
29
|
+
And if you'd like, StandardRB can autocorrect your code by tacking on a `--fix`
|
30
|
+
flag.
|
31
|
+
|
32
|
+
## StandardRB — The Rules
|
33
|
+
|
34
|
+
- **2 spaces** – for indentation
|
35
|
+
- **Double quotes for string literals ** - because pre-committing to whether
|
36
|
+
you'll need interpolation in a string slows people down
|
37
|
+
- **Hashrockets** - Hashrockets.
|
38
|
+
- **Semantic blocks** - `{`/`}` for functional blocks that return a value, and
|
39
|
+
`do`/`end` for procedural blocks that have side effects. More
|
40
|
+
[here](http://www.virtuouscode.com/2011/07/26/the-procedurefunction-block-convention-in-ruby/)
|
41
|
+
and [here](https://github.com/rubocop-hq/ruby-style-guide/issues/162)
|
42
|
+
- **Trailing dots on multi-line method chains** - chosen because it makes
|
43
|
+
copying lines into a REPL easier
|
44
|
+
- **And a good deal more**
|
45
|
+
|
46
|
+
If you're familiar with [RuboCop](https://github.com/rubocop-hq/rubocop), you
|
47
|
+
can look at StandardRB's current base configuration in
|
48
|
+
[config/base.yml](/config/base.yml).
|
49
|
+
|
50
|
+
**[NOTE: until StandardRB hits 1.0.0, we consider this configuration to be a
|
51
|
+
non-final work in progress and we encourage you to submit your opinions (and
|
52
|
+
reasoned arguments) for the addition, removal, or change to a rule by [opening
|
53
|
+
an issue](/issues/new). If you start using StandardRB, don't be shocked if
|
54
|
+
things change a bit!]**
|
55
|
+
|
56
|
+
## Usage
|
57
|
+
|
58
|
+
ONce you've installed `standard`, you should be able to use the `standard`
|
59
|
+
program. The simplest use case would be checking the style of all JavaScript
|
60
|
+
files in the current working directory:
|
61
|
+
|
62
|
+
```bash
|
63
|
+
$ bundle exec standard
|
64
|
+
standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
|
65
|
+
standard: Run `standard --fix` to automatically fix some problems.
|
66
|
+
/Users/code/cli.rb:31:23: Style/Semicolon: Do not use semicolons to terminate expressions.
|
67
|
+
```
|
68
|
+
|
69
|
+
You can optionally pass in a directory (or directories) using the glob pattern. Be
|
70
|
+
sure to quote paths containing glob patterns so that they are expanded by
|
71
|
+
`standard` instead of your shell:
|
72
|
+
|
73
|
+
```bash
|
74
|
+
$ bundle exec standard "lib/**/*.rb" test
|
75
|
+
```
|
76
|
+
|
77
|
+
**Note:** by default `standard` will look for all `*.rb` files (and some other
|
78
|
+
files typically associated with Ruby like `*.gemspec` and `Gemfile)
|
79
|
+
|
80
|
+
## What you might do if you're clever
|
81
|
+
|
82
|
+
If you want or need to configure StandardRB, there are a _handful_ of options
|
83
|
+
are available creating a `.standard.yml` file in the root of your project.
|
84
|
+
|
85
|
+
Here's an example yaml file with every option set:
|
86
|
+
|
87
|
+
```yaml
|
88
|
+
fix: true
|
89
|
+
parallel: true
|
90
|
+
format: progress
|
91
|
+
|
92
|
+
ignore:
|
93
|
+
- 'db/schema.rb'
|
94
|
+
- 'vendor/bundle/**/*'
|
95
|
+
- 'test/**/*':
|
96
|
+
- Style/BlockDelimiters
|
97
|
+
```
|
98
|
+
|
99
|
+
## What you might do if you're REALLY clever
|
100
|
+
|
101
|
+
Because StandardRB is essentially a wrapper on top of
|
102
|
+
[RuboCop](https://github.com/rubocop-hq/rubocop), it will actually forward the
|
103
|
+
vast majority of CLI and ENV arguments forward to RuboCop.
|
104
|
+
|
105
|
+
You can see a list of
|
106
|
+
[RuboCop](https://docs.rubocop.org/en/latest/basic_usage/#other-useful-command-line-flags)'s
|
107
|
+
CLI flags here.
|
108
|
+
|
109
|
+
## Why should I use Ruby Standard Style?
|
110
|
+
|
111
|
+
(This section will [look
|
112
|
+
familiar](https://github.com/standard/standard#why-should-i-use-javascript-standard-style)
|
113
|
+
if you've used StandardJS.)
|
114
|
+
|
115
|
+
The beauty of Ruby Standard Style is that it's simple. No one wants to
|
116
|
+
maintain multiple hundred-line style configuration files for every module/project
|
117
|
+
they work on. Enough of this madness!
|
118
|
+
|
119
|
+
This module saves you (and others!) time in three ways:
|
120
|
+
|
121
|
+
- **No configuration.** The easiest way to enforce consistent style in your
|
122
|
+
project. Just drop it in.
|
123
|
+
- **Automatically format code.** Just run `standard --fix` and say goodbye to
|
124
|
+
messy or inconsistent code.
|
125
|
+
- **Catch style issues & programmer errors early.** Save precious code review
|
126
|
+
time by eliminating back-and-forth between reviewer & contributor.
|
127
|
+
|
128
|
+
Adopting `standard` style means ranking the importance of code clarity and
|
129
|
+
community conventions higher than personal style. This might not make sense for
|
130
|
+
100% of projects and development cultures, however open source can be a hostile
|
131
|
+
place for newbies. Setting up clear, automated contributor expectations makes a
|
132
|
+
project healthier.
|
133
|
+
|
134
|
+
## Who uses Ruby Standard Style?
|
135
|
+
|
136
|
+
(This section will not [look very familiar
|
137
|
+
familiar](https://github.com/standard/standard#who-uses-javascript-standard-style)
|
138
|
+
if you've used StandardJS.)
|
139
|
+
|
140
|
+
Almost nobody! (Yet!)
|
141
|
+
|
142
|
+
## Is there a readme badge?
|
143
|
+
|
144
|
+
Yes! If you use `standard` in your project, you can include one of these badges
|
145
|
+
in your readme to let people know that your code is using the standard style.
|
146
|
+
|
147
|
+
|
148
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
149
|
+
|
150
|
+
```md
|
151
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
152
|
+
```
|
153
|
+
|
154
|
+
## I disagree with rule X, can you change it?
|
155
|
+
|
156
|
+
**[NOTE: until StandardRB hits 1.0.0, the answer is yes! It just requires
|
157
|
+
[opening an issue](/issues/new) and convincing
|
158
|
+
[@searls](https://twitter.com/searls) (the BDFNow) to make the change.]**
|
159
|
+
|
160
|
+
No. The whole point of `standard` is to save you time by avoiding
|
161
|
+
[bikeshedding](https://www.freebsd.org/doc/en/books/faq/misc.html#bikeshed-painting)
|
162
|
+
about code style. There are lots of debates online about tabs vs. spaces, etc.
|
163
|
+
that will never be resolved. These debates just distract from getting stuff
|
164
|
+
done. At the end of the day you have to 'just pick something', and that's the
|
165
|
+
whole philosophy of `standard` -- its a bunch of sensible 'just pick something'
|
166
|
+
opinions. Hopefully, users see the value in that over defending their own
|
167
|
+
opinions.
|
168
|
+
|
169
|
+
Pro tip: Just use `standard` and move on. There are actual real problems that
|
170
|
+
you could spend your time solving! :P
|
171
|
+
|
172
|
+
## Is there an automatic formatter?
|
173
|
+
|
174
|
+
Yes! You can use `standard --fix` to fix most issues automatically.
|
175
|
+
|
176
|
+
`standard --fix` is built into `standard` for maximum convenience. Most problems
|
177
|
+
are fixable, but some errors (like forgetting to handle errors) must be fixed
|
178
|
+
manually.
|
179
|
+
|
180
|
+
To save you time, `standard` outputs the message "`Run standard --fix to
|
181
|
+
automatically fix some problems`" when it detects problems that can be fixed
|
182
|
+
automatically.
|
183
|
+
|
184
|
+
## How do I ignore files?
|
185
|
+
|
186
|
+
Sometimes you need to ignore additional folders or specific minified files. To
|
187
|
+
do that, add a `.standard.yml` file to the root of your project and specify a
|
188
|
+
list of files and globs that should be excluded:
|
189
|
+
|
190
|
+
```yaml
|
191
|
+
ignore:
|
192
|
+
- 'db/schema.rb'
|
193
|
+
- 'vendor/bundle/**/*'
|
194
|
+
```
|
195
|
+
|
196
|
+
## How do I hide a certain warning?
|
197
|
+
|
198
|
+
In rare cases, you'll need to break a rule and hide the warning generated by
|
199
|
+
`standard`.
|
200
|
+
|
201
|
+
Ruby Standard Style uses [RuboCop](https://github.com/rubocop-hq/rubocop)
|
202
|
+
under-the-hood and you can hide warnings as you normally would if you used
|
203
|
+
RuboCop directly.
|
204
|
+
|
205
|
+
To ignore only certain rules from certain globs (not recommended, but maybe your
|
206
|
+
test suite uses a non-standardable DSL, you can specify an array of RuboCop
|
207
|
+
rules to ignore for a particular glob:
|
208
|
+
|
209
|
+
```yaml
|
210
|
+
ignore:
|
211
|
+
- 'test/**/*':
|
212
|
+
- Style/BlockDelimiters
|
213
|
+
```
|
214
|
+
|
215
|
+
You can also use special comments to disable all or certain rules within your
|
216
|
+
source code. See [RuboCop's
|
217
|
+
docs](https://docs.rubocop.org/en/latest/configuration/#disabling-cops-within-source-code)
|
218
|
+
for details.
|
219
|
+
|
220
|
+
## How do I change the output?
|
221
|
+
|
222
|
+
StandardRB's built-in formatter is intentionally minimal, printing only unfixed
|
223
|
+
failures or (if successful) a "Done" message. If you'd like to use a different
|
224
|
+
formatter, you can specify any of RuboCopy's built-in formatters or write your
|
225
|
+
own.
|
226
|
+
|
227
|
+
For example, if you'd like to see colorful progress dots, you can either run
|
228
|
+
standard with:
|
229
|
+
|
230
|
+
```
|
231
|
+
$ bundle exec standard --format progress
|
232
|
+
Inspecting 15 files
|
233
|
+
...............
|
234
|
+
|
235
|
+
15 files inspected, no offenses detected
|
236
|
+
✨ Done in 0.42s.
|
237
|
+
```
|
238
|
+
|
239
|
+
Or, in your project's `.standard.yml` file, specify:
|
240
|
+
|
241
|
+
```yaml
|
242
|
+
format: progress
|
243
|
+
```
|
244
|
+
|
245
|
+
Refer to RuboCop's [documentation on
|
246
|
+
formatters](https://rubocop.readthedocs.io/en/latest/formatters/) for more
|
247
|
+
information.
|
248
|
+
|
249
|
+
## License
|
250
|
+
|
251
|
+
[MIT](LICENSE). Copyright (c) [Test Double, LLC](https://testdouble.com).
|
252
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "standard"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config/base.yml
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
Bundler/OrderedGems:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Layout/AlignParameters:
|
5
|
+
EnforcedStyle: with_fixed_indentation
|
6
|
+
|
7
|
+
Layout/AlignHash:
|
8
|
+
EnforcedLastArgumentHashStyle: always_ignore
|
9
|
+
|
10
|
+
# Disabled because IndentOneStep can't be configured for one-liner cases. See:
|
11
|
+
# https://github.com/rubocop-hq/rubocop/issues/6447
|
12
|
+
Layout/CaseIndentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Layout/DotPosition:
|
16
|
+
EnforcedStyle: trailing
|
17
|
+
|
18
|
+
Layout/EmptyLineAfterGuardClause:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/EndAlignment:
|
22
|
+
EnforcedStyleAlignWith: variable
|
23
|
+
|
24
|
+
Layout/FirstParameterIndentation:
|
25
|
+
EnforcedStyle: consistent
|
26
|
+
|
27
|
+
Layout/IndentHash:
|
28
|
+
EnforcedStyle: consistent
|
29
|
+
|
30
|
+
Layout/IndentArray:
|
31
|
+
EnforcedStyle: consistent
|
32
|
+
|
33
|
+
Layout/MultilineMethodCallIndentation:
|
34
|
+
EnforcedStyle: indented
|
35
|
+
|
36
|
+
# Disabled without this:
|
37
|
+
# http://github.com/rubocop-hq/rubocop/issues/6446
|
38
|
+
Layout/SpaceInsideBlockBraces:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Layout/SpaceInsideHashLiteralBraces:
|
42
|
+
EnforcedStyle: no_space
|
43
|
+
|
44
|
+
Lint/AssignmentInCondition:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Metrics/AbcSize:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/BlockLength:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Metrics/ClassLength:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Metrics/LineLength:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Metrics/MethodLength:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Metrics/ModuleLength:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Metrics/ParameterLists:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Naming/UncommunicativeMethodParamName:
|
69
|
+
AllowedNames: ['io', 'id', 'to', 'by', 'on', 'in', 'at', 'ip', 'db', 'po', 'me', 'pt']
|
70
|
+
|
71
|
+
Naming/VariableNumber:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
Style/BlockDelimiters:
|
75
|
+
EnforcedStyle: semantic
|
76
|
+
|
77
|
+
Style/ClassAndModuleChildren:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Style/Documentation:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Style/DoubleNegation:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Style/EmptyMethod:
|
87
|
+
EnforcedStyle: expanded
|
88
|
+
|
89
|
+
Style/ExpandPathArguments:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/FormatStringToken:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/FrozenStringLiteralComment:
|
96
|
+
EnforcedStyle: never
|
97
|
+
|
98
|
+
Style/GuardClause:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
Style/HashSyntax:
|
102
|
+
EnforcedStyle: hash_rockets
|
103
|
+
|
104
|
+
Style/IfUnlessModifier:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
Style/MultilineBlockChain:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
Style/MutableConstant:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
Style/NumericPredicate:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
Style/RescueStandardError:
|
117
|
+
EnforcedStyle: implicit
|
118
|
+
|
119
|
+
Style/StringLiterals:
|
120
|
+
EnforcedStyle: double_quotes
|
121
|
+
|
122
|
+
Style/StringLiteralsInInterpolation:
|
123
|
+
EnforcedStyle: double_quotes
|
124
|
+
|
125
|
+
Style/StructInheritance:
|
126
|
+
Enabled: false
|
127
|
+
|
128
|
+
Style/SymbolArray:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
Style/TrailingCommaInArguments:
|
132
|
+
Enabled: false
|
133
|
+
|
134
|
+
Style/TrailingCommaInArrayLiteral:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
Style/TrailingCommaInHashLiteral:
|
138
|
+
Enabled: false
|
139
|
+
|
140
|
+
Style/WordArray:
|
141
|
+
Enabled: false
|
142
|
+
|
data/exe/standard
ADDED
data/exe/standardrb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
exe/standard
|
data/lib/standard/cli.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "rubocop"
|
2
|
+
require_relative "config"
|
3
|
+
require_relative "timer"
|
4
|
+
|
5
|
+
module Standard
|
6
|
+
class Cli
|
7
|
+
SUCCESS_STATUS_CODE = 0
|
8
|
+
FAILURE_STATUS_CODE = 1
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@config = Config.new(ARGV)
|
12
|
+
@timer = Timer.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
rubocop_config = @config.to_rubocop
|
17
|
+
runner = RuboCop::Runner.new(
|
18
|
+
rubocop_config.options,
|
19
|
+
rubocop_config.config_store
|
20
|
+
)
|
21
|
+
|
22
|
+
time, run_succeeded = @timer.time {
|
23
|
+
runner.run(rubocop_config.paths)
|
24
|
+
}
|
25
|
+
|
26
|
+
if run_succeeded
|
27
|
+
puts "✨ Done in #{time.round(2)}s."
|
28
|
+
SUCCESS_STATUS_CODE
|
29
|
+
else
|
30
|
+
(runner.warnings + runner.errors).each do |message|
|
31
|
+
warn message
|
32
|
+
end
|
33
|
+
puts <<~CALL_TO_ACTION
|
34
|
+
|
35
|
+
Notice: Disagree with these rules? While StandardRB is pre-1.0.0, feel free to submit suggestions to:
|
36
|
+
https://github.com/testdouble/standard/issues/new
|
37
|
+
CALL_TO_ACTION
|
38
|
+
FAILURE_STATUS_CODE
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "rubocop"
|
2
|
+
require "pathname"
|
3
|
+
require "yaml"
|
4
|
+
require_relative "file_finder"
|
5
|
+
require_relative "formatter"
|
6
|
+
|
7
|
+
module Standard
|
8
|
+
class Config
|
9
|
+
RuboCopConfig = Struct.new(:paths, :options, :config_store)
|
10
|
+
|
11
|
+
def initialize(argv)
|
12
|
+
filtered_argv, fix_flag = parse_argv(argv)
|
13
|
+
@rubocop_options, @paths = RuboCop::Options.new.parse(filtered_argv)
|
14
|
+
@standard_yml_path = FileFinder.new.call(".standard.yml", Dir.pwd)
|
15
|
+
@standard_config = init_standard_config(@standard_yml_path, fix_flag)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_rubocop
|
19
|
+
RuboCopConfig.new(
|
20
|
+
@paths,
|
21
|
+
wrap_rubocop_options(@rubocop_options),
|
22
|
+
RuboCop::ConfigStore.new.tap(&method(:mutate_config_store!))
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Filtered b/c RuboCop will switch to --only Layout when --fix is set (undocumented behavior)
|
29
|
+
def parse_argv(argv)
|
30
|
+
filtered_argv = argv.dup
|
31
|
+
fix_flag = !!filtered_argv.delete("--fix")
|
32
|
+
[filtered_argv, fix_flag]
|
33
|
+
end
|
34
|
+
|
35
|
+
def init_standard_config(yml_path, fix_flag)
|
36
|
+
user_config = if yml_path
|
37
|
+
YAML.load_file(Pathname.new(Dir.pwd).join(yml_path))
|
38
|
+
else
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
42
|
+
{
|
43
|
+
:fix => fix_flag || !!user_config["fix"],
|
44
|
+
:format => user_config["format"],
|
45
|
+
:ignore => expand_ignore_config(user_config["ignore"]),
|
46
|
+
:parallel => !!user_config["parallel"],
|
47
|
+
:ruby_version => ruby_version(user_config["ruby_version"] || RUBY_VERSION)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def wrap_rubocop_options(rubocop_options)
|
52
|
+
{
|
53
|
+
:auto_correct => @standard_config[:fix],
|
54
|
+
:safe_auto_correct => @standard_config[:fix],
|
55
|
+
:formatters => [[@standard_config[:format] || "Standard::Formatter", nil]],
|
56
|
+
:parallel => @standard_config[:parallel]
|
57
|
+
}.merge(rubocop_options)
|
58
|
+
end
|
59
|
+
|
60
|
+
def mutate_config_store!(config_store)
|
61
|
+
config_store.options_config = Pathname.new(__dir__).join("../../config/base.yml")
|
62
|
+
options_config = config_store.instance_variable_get("@options_config")
|
63
|
+
|
64
|
+
options_config["AllCops"]["TargetRubyVersion"] = @standard_config[:ruby_version]
|
65
|
+
|
66
|
+
@standard_config[:ignore].each do |(path, cops)|
|
67
|
+
cops.each do |cop|
|
68
|
+
options_config[cop] ||= {}
|
69
|
+
options_config[cop]["Exclude"] ||= []
|
70
|
+
options_config[cop]["Exclude"] |= [Pathname.new(@standard_yml_path).dirname.join(path).to_s]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def expand_ignore_config(ignore_config)
|
76
|
+
arrayify(ignore_config).map { |rule|
|
77
|
+
if rule.is_a?(String)
|
78
|
+
[rule, ["AllCops"]]
|
79
|
+
elsif rule.is_a?(Hash)
|
80
|
+
rule.entries.first
|
81
|
+
end
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def ruby_version(version)
|
86
|
+
major, minor = Gem::Version.new(version).segments
|
87
|
+
"#{major}.#{minor}".to_f # lol
|
88
|
+
end
|
89
|
+
|
90
|
+
def arrayify(object)
|
91
|
+
if object.nil?
|
92
|
+
[]
|
93
|
+
elsif object.respond_to?(:to_ary)
|
94
|
+
object.to_ary || [object]
|
95
|
+
else
|
96
|
+
[object]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "rubocop"
|
2
|
+
|
3
|
+
module Standard
|
4
|
+
class Formatter < RuboCop::Formatter::BaseFormatter
|
5
|
+
def file_finished(file, offenses)
|
6
|
+
uncorrected_offenses = offenses.reject(&:corrected?)
|
7
|
+
print_header_once unless uncorrected_offenses.empty?
|
8
|
+
|
9
|
+
uncorrected_offenses.each do |o|
|
10
|
+
output.printf(" %s:%d:%d: %s\n", file, o.line, o.real_column, o.message.tr("\n", " "))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def print_header_once
|
17
|
+
return if @header_printed_already
|
18
|
+
output.print <<~HEADER
|
19
|
+
standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
|
20
|
+
standard: Run `standard --fix` to automatically fix some problems.
|
21
|
+
HEADER
|
22
|
+
@header_printed_already = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/standard.rb
ADDED
data/standard.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "standard/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "standard"
|
7
|
+
spec.version = Standard::VERSION
|
8
|
+
spec.authors = ["Justin Searls"]
|
9
|
+
spec.email = ["searls@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby Style Guide, with linter & automatic code fixer"
|
12
|
+
spec.homepage = "https://github.com/testdouble/standard"
|
13
|
+
|
14
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
15
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
end
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rubocop", ">= 0.60"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: standard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Searls
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.60'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.60'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- searls@gmail.com
|
72
|
+
executables:
|
73
|
+
- standard
|
74
|
+
- standardrb
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- config/base.yml
|
86
|
+
- exe/standard
|
87
|
+
- exe/standardrb
|
88
|
+
- lib/standard.rb
|
89
|
+
- lib/standard/cli.rb
|
90
|
+
- lib/standard/config.rb
|
91
|
+
- lib/standard/file_finder.rb
|
92
|
+
- lib/standard/formatter.rb
|
93
|
+
- lib/standard/timer.rb
|
94
|
+
- lib/standard/version.rb
|
95
|
+
- standard.gemspec
|
96
|
+
homepage: https://github.com/testdouble/standard
|
97
|
+
licenses: []
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.7.6
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Ruby Style Guide, with linter & automatic code fixer
|
119
|
+
test_files: []
|