rubocop_config_updater 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b178acb0803883b9be0ce422a264f2af510eddfb1b10f74fefd0a85c5156733d
4
+ data.tar.gz: c675f075ecf27ec462260594106ccebf72a0f21ed2060edeadcb14aec06a8f0a
5
+ SHA512:
6
+ metadata.gz: 14aaeedcae5b0e935f5d957028958b27857769de16014765b3ffb264d7f22db5640db55402ed07e007df6dd4c66bc1364bf2f4ed1fa86764df59d5599926decd
7
+ data.tar.gz: b33e3e1ed180a70c7cfd86bae3ad4f61a93701daaa6174f77ce827c25d2c43a8ea64b85013895232c1f313a7a5ad1046b5501d2eafe0072f5fe126adf826de32
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
@@ -0,0 +1,40 @@
1
+ on:
2
+ pull_request:
3
+
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.4, 2.5, 2.6, 2.7]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+
19
+ - name: Setup ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+
24
+ - name: Install bundler
25
+ run: gem install bundler
26
+
27
+ - uses: actions/cache@v2
28
+ with:
29
+ path: vendor/bundle
30
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
31
+ restore-keys: |
32
+ ${{ runner.os }}-gems-
33
+
34
+ - name: Install dependencies
35
+ run: |
36
+ bundle config path vendor/bundle
37
+ bundle install --jobs 4 --retry 3
38
+
39
+ - name: Run rubocop
40
+ run: bundle exec rubocop
@@ -0,0 +1,40 @@
1
+ on:
2
+ pull_request:
3
+
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.4, 2.5, 2.6, 2.7]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+
19
+ - name: Setup ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+
24
+ - name: Install bundler
25
+ run: gem install bundler
26
+
27
+ - uses: actions/cache@v2
28
+ with:
29
+ path: vendor/bundle
30
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
31
+ restore-keys: |
32
+ ${{ runner.os }}-gems-
33
+
34
+ - name: Install dependencies
35
+ run: |
36
+ bundle config path vendor/bundle
37
+ bundle install --jobs 4 --retry 3
38
+
39
+ - name: Run tests
40
+ run: rake test
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,294 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+
13
+
14
+ AllCops:
15
+ TargetRubyVersion: 2.4
16
+
17
+ require:
18
+ - rubocop-performance
19
+ - rubocop-minitest
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ Metrics/MethodLength:
25
+ Enabled: false
26
+
27
+ Metrics/AbcSize:
28
+ Enabled: false
29
+
30
+ # https://docs.rubocop.org/rubocop/cops_layout.html#layoutemptylinesaroundattributeaccessor
31
+ Layout/EmptyLinesAroundAttributeAccessor:
32
+ Enabled: true
33
+
34
+ # https://docs.rubocop.org/rubocop/cops_layout.html#layoutspacearoundmethodcalloperator
35
+ Layout/SpaceAroundMethodCallOperator:
36
+ Enabled: true
37
+
38
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintdeprecatedopensslconstant
39
+ Lint/DeprecatedOpenSSLConstant:
40
+ Enabled: true
41
+
42
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintmixedregexpcapturetypes
43
+ Lint/MixedRegexpCaptureTypes:
44
+ Enabled: true
45
+
46
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintraiseexception
47
+ Lint/RaiseException:
48
+ Enabled: true
49
+
50
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintstructnewoverride
51
+ Lint/StructNewOverride:
52
+ Enabled: true
53
+
54
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleexponentialnotation
55
+ Style/ExponentialNotation:
56
+ Enabled: false
57
+
58
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylehasheachmethods
59
+ Style/HashEachMethods:
60
+ Enabled: true
61
+
62
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylehashtransformkeys
63
+ Style/HashTransformKeys:
64
+ Enabled: true
65
+
66
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylehashtransformvalues
67
+ Style/HashTransformValues:
68
+ Enabled: true
69
+
70
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantfetchblock
71
+ Style/RedundantFetchBlock:
72
+ Enabled: true
73
+
74
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantregexpcharacterclass
75
+ Style/RedundantRegexpCharacterClass:
76
+ Enabled: true
77
+
78
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantregexpescape
79
+ Style/RedundantRegexpEscape:
80
+ Enabled: true
81
+
82
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleslicingwithrange
83
+ Style/SlicingWithRange:
84
+ Enabled: true
85
+
86
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintbinaryoperatorwithidenticaloperands
87
+ Lint/BinaryOperatorWithIdenticalOperands:
88
+ Enabled: true
89
+
90
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintduplicateelsifcondition
91
+ Lint/DuplicateElsifCondition:
92
+ Enabled: true
93
+
94
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintduplicaterescueexception
95
+ Lint/DuplicateRescueException:
96
+ Enabled: true
97
+
98
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintemptyconditionalbody
99
+ Lint/EmptyConditionalBody:
100
+ Enabled: true
101
+
102
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintfloatcomparison
103
+ Lint/FloatComparison:
104
+ Enabled: false
105
+
106
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintmissingsuper
107
+ Lint/MissingSuper:
108
+ Enabled: false
109
+
110
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintoutofrangeregexpref
111
+ Lint/OutOfRangeRegexpRef:
112
+ Enabled: true
113
+
114
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintselfassignment
115
+ Lint/SelfAssignment:
116
+ Enabled: true
117
+
118
+ # https://docs.rubocop.org/rubocop/cops_lint.html#linttoplevelreturnwithargument
119
+ Lint/TopLevelReturnWithArgument:
120
+ Enabled: true
121
+
122
+ # https://docs.rubocop.org/rubocop/cops_lint.html#lintunreachableloop
123
+ Lint/UnreachableLoop:
124
+ Enabled: true
125
+
126
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleaccessorgrouping
127
+ Style/AccessorGrouping:
128
+ Enabled: true
129
+
130
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylearraycoercion
131
+ Style/ArrayCoercion:
132
+ Enabled: true
133
+
134
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylebisectedattraccessor
135
+ Style/BisectedAttrAccessor:
136
+ Enabled: true
137
+
138
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylecaselikeif
139
+ Style/CaseLikeIf:
140
+ Enabled: true
141
+
142
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleexplicitblockargument
143
+ Style/ExplicitBlockArgument:
144
+ Enabled: true
145
+
146
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleglobalstdstream
147
+ Style/GlobalStdStream:
148
+ Enabled: false
149
+
150
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylehashaslastarrayitem
151
+ Style/HashAsLastArrayItem:
152
+ Enabled: true
153
+
154
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylehashlikecase
155
+ Style/HashLikeCase:
156
+ Enabled: true
157
+
158
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleoptionalbooleanparameter
159
+ Style/OptionalBooleanParameter:
160
+ Enabled: true
161
+
162
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantassignment
163
+ Style/RedundantAssignment:
164
+ Enabled: true
165
+
166
+ # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantfileextensioninrequire
167
+ Style/RedundantFileExtensionInRequire:
168
+ Enabled: true
169
+
170
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylesingleargumentdig
171
+ Style/SingleArgumentDig:
172
+ Enabled: true
173
+
174
+ # https://docs.rubocop.org/rubocop/cops_style.html#stylestringconcatenation
175
+ Style/StringConcatenation:
176
+ Enabled: true
177
+
178
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performanceancestorsinclude
179
+ Performance/AncestorsInclude:
180
+ Enabled: true
181
+
182
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancebigdecimalwithnumericargument
183
+ Performance/BigDecimalWithNumericArgument:
184
+ Enabled: true
185
+
186
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performanceredundantsortblock
187
+ Performance/RedundantSortBlock:
188
+ Enabled: true
189
+
190
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performanceredundantstringchars
191
+ Performance/RedundantStringChars:
192
+ Enabled: true
193
+
194
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancereversefirst
195
+ Performance/ReverseFirst:
196
+ Enabled: true
197
+
198
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancesortreverse
199
+ Performance/SortReverse:
200
+ Enabled: true
201
+
202
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancesqueeze
203
+ Performance/Squeeze:
204
+ Enabled: true
205
+
206
+ # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancestringinclude
207
+ Performance/StringInclude:
208
+ Enabled: true
209
+
210
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestassertindelta
211
+ Minitest/AssertInDelta:
212
+ Enabled: true
213
+
214
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestassertioninlifecyclehook
215
+ Minitest/AssertionInLifecycleHook:
216
+ Enabled: true
217
+
218
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestassertkindof
219
+ Minitest/AssertKindOf:
220
+ Enabled: true
221
+
222
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestassertoutput
223
+ Minitest/AssertOutput:
224
+ Enabled: true
225
+
226
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestassertpathexists
227
+ Minitest/AssertPathExists:
228
+ Enabled: true
229
+
230
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestassertsilent
231
+ Minitest/AssertSilent:
232
+ Enabled: true
233
+
234
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestliteralasactualargument
235
+ Minitest/LiteralAsActualArgument:
236
+ Enabled: true
237
+
238
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestmultipleassertions
239
+ Minitest/MultipleAssertions:
240
+ Enabled: false
241
+
242
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestrefuteindelta
243
+ Minitest/RefuteInDelta:
244
+ Enabled: true
245
+
246
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestrefutekindof
247
+ Minitest/RefuteKindOf:
248
+ Enabled: true
249
+
250
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestrefutepathexists
251
+ Minitest/RefutePathExists:
252
+ Enabled: true
253
+
254
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitesttestmethodname
255
+ Minitest/TestMethodName:
256
+ Enabled: true
257
+
258
+ # https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestunspecifiedexception
259
+ Minitest/UnspecifiedException:
260
+ Enabled: true
261
+
262
+ Layout/BeginEndAlignment: # (new in 0.91)
263
+ Enabled: true
264
+ Lint/ConstantDefinitionInBlock: # (new in 0.91)
265
+ Enabled: true
266
+ Lint/DuplicateRequire: # (new in 0.90)
267
+ Enabled: true
268
+ Lint/EmptyFile: # (new in 0.90)
269
+ Enabled: true
270
+ Lint/IdentityComparison: # (new in 0.91)
271
+ Enabled: true
272
+ Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
273
+ Enabled: true
274
+ Lint/UselessMethodDefinition: # (new in 0.90)
275
+ Enabled: true
276
+ Lint/UselessTimes: # (new in 0.91)
277
+ Enabled: true
278
+ Style/CombinableLoops: # (new in 0.90)
279
+ Enabled: true
280
+ Style/KeywordParametersOrder: # (new in 0.90)
281
+ Enabled: true
282
+ Style/RedundantSelfAssignment: # (new in 0.90)
283
+ Enabled: true
284
+ Style/SoleNestedConditional: # (new in 0.89)
285
+ Enabled: true
286
+ Performance/Sum: # (new in 1.8)
287
+ Enabled: true
288
+ Lint/HashCompareByIdentity: # (new in 0.93)
289
+ Enabled: true
290
+ Lint/RedundantSafeNavigation: # (new in 0.93)
291
+ Enabled: true
292
+ Style/ClassEqualityComparison: # (new in 0.93)
293
+ Enabled: true
294
+
@@ -0,0 +1 @@
1
+ 2.7.1
@@ -0,0 +1,19 @@
1
+ {
2
+ "files.exclude": {
3
+ "**/.git": true,
4
+ "**/.svn": true,
5
+ "**/.hg": true,
6
+ "**/CVS": true,
7
+ "**/.DS_Store": true,
8
+ "Gemfile.lock": true,
9
+ "Gemfile": true,
10
+ ".vscode": true,
11
+ ".gitignore": true,
12
+ ".ruby-version": true,
13
+ ".editorconfig": true,
14
+ "bin": true,
15
+ "exe": true,
16
+ "LICENSE": true
17
+ },
18
+ "explorerExclude.backup": null
19
+ }
@@ -0,0 +1,3 @@
1
+ # Change log
2
+
3
+ ## v0.1.0: TODO DATE
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in dot_rubocop_updater.gemspec
6
+ gemspec
7
+
8
+ gem 'awesome_print'
9
+ gem 'minitest', '~> 5.14'
10
+ gem 'rake', '~> 13.0'
11
+ gem 'rubocop'
12
+ gem 'rubocop-minitest'
13
+ gem 'rubocop-performance'
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop_config_updater (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ awesome_print (1.8.0)
11
+ minitest (5.14.2)
12
+ parallel (1.19.2)
13
+ parser (2.7.2.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (13.0.1)
17
+ regexp_parser (1.8.2)
18
+ rexml (3.2.4)
19
+ rubocop (0.93.1)
20
+ parallel (~> 1.10)
21
+ parser (>= 2.7.1.5)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8)
24
+ rexml
25
+ rubocop-ast (>= 0.6.0)
26
+ ruby-progressbar (~> 1.7)
27
+ unicode-display_width (>= 1.4.0, < 2.0)
28
+ rubocop-ast (1.0.1)
29
+ parser (>= 2.7.1.5)
30
+ rubocop-minitest (0.10.1)
31
+ rubocop (>= 0.87)
32
+ rubocop-performance (1.8.1)
33
+ rubocop (>= 0.87.0)
34
+ rubocop-ast (>= 0.4.0)
35
+ ruby-progressbar (1.10.1)
36
+ unicode-display_width (1.7.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ awesome_print
43
+ minitest (~> 5.14)
44
+ rake (~> 13.0)
45
+ rubocop
46
+ rubocop-minitest
47
+ rubocop-performance
48
+ rubocop_config_updater!
49
+
50
+ BUNDLED WITH
51
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Adam Zapaśnik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # Rubocop Config Updater
2
+
3
+ Rubocop requires a lot of changes to its config if you didn't update it for a long time.
4
+ That's why I wrote this gem, because I was tired of manually changing the configuration file.
5
+ There is already [mry gem](https://github.com/pocke/mry) that solves the same problem, but it's a bit outdated.
6
+
7
+ This gem handles rubocop's stderr output, therefore it won't shouldn't get outdated. More info about how this gem works and what kind of errors it deals with, can be found in the section [#how-it-works](#how-it-works)
8
+
9
+ ## Installation
10
+
11
+ Install
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'rubocop_config_updater', require: false
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```sh
22
+ bundle install
23
+ ```
24
+
25
+ Or **preferred** install it yourself as:
26
+
27
+ ```sh
28
+ gem install rubocop_config_updater
29
+ ```
30
+
31
+ After usage you can uninstall with:
32
+
33
+ ```sh
34
+ gem cleanup rubocop_config_updater
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```sh
40
+ Usage: rubocop_config_updater [options]
41
+ -c, --config PATH Rubocop config path, i.e. .rubocop.yml
42
+ --rubocop COMMAND Rubocop command, i.e. bundle exec rubocop
43
+ -v, --version
44
+ ```
45
+
46
+ ## How it works
47
+
48
+ This gem runs a command against rubocop and collects errors from STDERR, which are used to update rubocop's configuration file.
49
+ If you are interested in Rubocop's code responsible for the above mentioned errors, here is a link to Rubocop's [config_obsoletion class](https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/config_obsoletion.rb)
50
+
51
+ ### Errors that are solved
52
+
53
+ - Renamed cops
54
+ `Naming/UncommunicativeMethodParamName` will be changed to `Naming/MethodParameterName`
55
+ - Moved cops
56
+ `Security/Eval` will be changed to `Lint/Eval`
57
+ - Renamed parameters
58
+ `SafeMode` will be changed to `SafeAutoCorrect`
59
+ - Missing department
60
+ `MethodLength` will be changed to `Metrics/MethodLength`
61
+
62
+ ### Errors that you have to manually solve
63
+
64
+ - Removed cops
65
+ - Splitted cops
66
+ - Obsolete parameters
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/adamzapasnik/rubocop_config_updater](https://github.com/adamzapasnik/rubocop_config_updater).
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
13
+
14
+ Rake::Task['release'].enhance do
15
+ puts "Don't forget to publish the release on GitHub!"
16
+ system 'open https://github.com/adamzapasnik/rubocop_config_updater/releases'
17
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rubocop_config_updater'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # require 'bundler/setup'
5
+
6
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
7
+
8
+ require 'rubocop_config_updater'
9
+
10
+ cli = RuboCopConfigUpdater::CLI.new
11
+ cli.run(ARGV)
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop_config_updater/version'
4
+
5
+ require_relative 'rubocop_config_updater/cli'
6
+
7
+ require_relative 'rubocop_config_updater/cli/command'
8
+ require_relative 'rubocop_config_updater/cli/command/base'
9
+ require_relative 'rubocop_config_updater/cli/command/fix_errors'
10
+ require_relative 'rubocop_config_updater/cli/command/no_errors'
11
+ require_relative 'rubocop_config_updater/cli/command/unknown_error'
12
+ require_relative 'rubocop_config_updater/cli/command/version'
13
+
14
+ module RuboCopConfigUpdater
15
+ end
16
+ # class Error < StandardError; end
17
+ # # Your code goes here...
18
+ # def new_cops(file)
19
+ # output = `bundle exec rubocop #{file}`
20
+
21
+ # end
22
+ # def clean_dot_rubocop
23
+ # output = `bundle exec rubocop 2>&1`
24
+ # correct_cops = `bundle exec rubocop --show-cops --force-default-config`.lines.select { |l| l.match(/^\w/) }
25
+ # printf output
26
+
27
+ # matchers = []
28
+ # removed = []
29
+ # ap correct_cops
30
+ # puts "OUTPUT"
31
+
32
+ # puts output.class
33
+ # output.each_line do |line|
34
+ # if /cop has been renamed to/.match?(line)
35
+ # matched = line.scan(/`(\w+\/+\w+)`/)
36
+ # elsif /has been renamed to/.match?(line)
37
+ # matched = line.scan(/`(\w+:\s[\w_]+)`/)
38
+ # elsif /has the wrong namespace -/.match?(line)
39
+ # first_match = line.scan(/\w+\/\w+/).first
40
+ # second_match = line.split.last + "/" + first_match.split("/").last
41
+ # matchers << [first_match, second_match]
42
+ # elsif /no department given for/.match?(line)
43
+ # first_match = line.split.last.chop
44
+ # # ap first_match
45
+ # second_match = correct_cops.grep(/#{first_match}/).first.trim.chop
46
+ # matchers << [first_match, second_match]
47
+ # elsif /cop has been removed/.match?(line)
48
+ # removed << line.scan(/`(\w+\/+\w+)`/).first
49
+ # end
50
+ # matchers << matched.flatten if matched
51
+ # end
52
+ # puts "WTF"
53
+
54
+ # # ap matchers
55
+
56
+ # # yml = YAML.load_file('.rubocop.yml')
57
+ # # puts yml
58
+
59
+ # rubocop_config = File.read('.rubocop.yml')
60
+ # matchers.each do |match|
61
+ # puts match
62
+ # rubocop_config.gsub!(match[0], match[1])
63
+ # end
64
+
65
+ # File.write('.rubocop.yml', rubocop_config)
66
+
67
+ # end
68
+ # end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module RuboCopConfigUpdater
6
+ class CLI
7
+ DEFAULT_OPTIONS = {
8
+ config_path: '.rubocop.yml',
9
+ cmd: 'bundle exec rubocop'
10
+ }.freeze
11
+
12
+ attr_accessor :options
13
+
14
+ def initialize
15
+ @options = DEFAULT_OPTIONS.dup
16
+ end
17
+
18
+ def run(args = ARGV)
19
+ parse_options(args)
20
+
21
+ command = RuboCopConfigUpdater::CLI::Command.new(@options)
22
+
23
+ return command.run(:version) if options[:version]
24
+
25
+ unless File.exist?(options[:config_path])
26
+ warn "File #{options[:config_path]} doesn't exist"
27
+ exit(1)
28
+ end
29
+
30
+ # a little hack to minimalize operation time and stdout length
31
+ stderr = `#{options[:cmd]} -L Gemfile 2>&1 >/dev/null`
32
+
33
+ command.fix_errors(stderr)
34
+ end
35
+
36
+ private
37
+
38
+ def parse_options(args)
39
+ OptionParser.new do |opts|
40
+ opts.banner = 'Usage: rubocop_config_updater [options]'
41
+
42
+ opts.on('-c', '--config PATH', 'Rubocop config path, i.e. .rubocop.yml') do |v|
43
+ options[:config_path] = v
44
+ end
45
+
46
+ opts.on('-r', '--rubocop COMMAND', 'Rubocop command, i.e. bundle exec rubocop') do |v|
47
+ options[:cmd] = v
48
+ end
49
+
50
+ opts.on('-v', '--version') do |v|
51
+ options[:version] = v
52
+ end
53
+ end.parse!(args)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ class CLI
5
+ class Command
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def run(name)
11
+ class_for(name).new(@options).run
12
+ end
13
+
14
+ def fix_errors(stderr)
15
+ class_for_errors(stderr).new(@options, stderr).run
16
+ end
17
+
18
+ private
19
+
20
+ def class_for(name)
21
+ Base.by_command_name(name)
22
+ end
23
+
24
+ def class_for_errors(stderr)
25
+ Base.by_errors(stderr) || UnknownError
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ class CLI
5
+ class Command
6
+ class Base
7
+ attr_reader :env
8
+
9
+ @subclasses = []
10
+
11
+ class << self
12
+ attr_accessor :command_name
13
+
14
+ def inherited(subclass)
15
+ @subclasses << subclass
16
+ end
17
+
18
+ def by_command_name(name)
19
+ @subclasses.detect { |s| s.command_name == name }
20
+ end
21
+
22
+ def by_errors(stderr)
23
+ @subclasses.detect { |s| s.fixes_error?(stderr) }
24
+ end
25
+
26
+ def fixes_error?(_stderr)
27
+ false
28
+ end
29
+ end
30
+
31
+ attr_accessor :options, :stderr
32
+
33
+ def initialize(options, stderr = '')
34
+ @options = options
35
+ @stderr = stderr
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ class CLI
5
+ class Command
6
+ class FixOutdatedCops < Base
7
+ # Error: The `Layout/AlignArray` cop has been renamed to `Layout/ArrayAlignment`.
8
+ COP_RENAMED_REGEXP = /cop has been renamed to/im.freeze
9
+
10
+ # `EnforcedStyle: rails` has been renamed to `EnforcedStyle: indented_internal_methods`
11
+ PROPERTY_RENAMED_REGEXP = /has been renamed to/im.freeze
12
+
13
+ # .rubocop.yml: Metrics/LineLength has the wrong namespace - should be Layout
14
+ WRONG_NAMESPACE_REGEXP = /has the wrong namespace/im.freeze
15
+
16
+ # .rubocop.yml: Warning: no department given for AccessModifierIndentation.
17
+ NO_DEPARTMENT_REGEXP = /no department given for/im.freeze
18
+
19
+ self.command_name = :fix_outdated_cops
20
+
21
+ def self.fixes_error?(stderr)
22
+ [
23
+ COP_RENAMED_REGEXP,
24
+ PROPERTY_RENAMED_REGEXP,
25
+ WRONG_NAMESPACE_REGEXP,
26
+ NO_DEPARTMENT_REGEXP
27
+ ].any? { |regexp| regexp.match(stderr) }
28
+ end
29
+
30
+ def run
31
+ @errors = []
32
+ @unknown_errors = []
33
+
34
+ collect_errors
35
+ fix_errors
36
+
37
+ log_changes
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :errors, :unknown_errors
43
+
44
+ def collect_errors
45
+ stderr.each_line do |line|
46
+ if COP_RENAMED_REGEXP.match?(line)
47
+ matched = line.scan(%r{`(\w+/\w+)`})
48
+
49
+ errors << [matched[0], matched[1]].flatten
50
+ elsif PROPERTY_RENAMED_REGEXP.match?(line)
51
+ matched = line.scan(/`(\w+:?\s?\w+)`/)
52
+
53
+ errors << [matched[0], matched[1]].flatten
54
+ elsif WRONG_NAMESPACE_REGEXP.match?(line)
55
+ to_replace = line.scan(%r{\w+/\w+}).first
56
+ replace_with = "#{line.split.last}/#{to_replace.split('/').last}"
57
+
58
+ errors << [to_replace, replace_with]
59
+ elsif NO_DEPARTMENT_REGEXP.match?(line)
60
+ to_replace = line.split.last.chop
61
+ replace_with = all_cops.grep(%r{/#{to_replace}:}).first.strip.chop
62
+
63
+ errors << [to_replace, replace_with]
64
+ else
65
+ unknown_errors << line
66
+ end
67
+ end
68
+ end
69
+
70
+ def fix_errors
71
+ rubocop_config = File.read(options[:config_path])
72
+
73
+ errors.each do |array|
74
+ rubocop_config.gsub!(array[0], array[1])
75
+ end
76
+
77
+ File.write(options[:config_path], rubocop_config)
78
+ end
79
+
80
+ # Style/ZeroLengthPredicate:
81
+ # Description: 'Use #empty? when testing for objects of length 0.'
82
+ # Enabled: true
83
+ # Safe: false
84
+ # VersionAdded: '0.37'
85
+ # VersionChanged: '0.39'
86
+ def all_cops
87
+ @all_cops ||= `#{options[:cmd]} --show-cops --force-default-config`.lines.select { |l| l.match(/^\w/) }
88
+ end
89
+
90
+ def log_changes
91
+ if errors.any?
92
+ puts 'Following changes were applied to configuration file:'
93
+
94
+ errors.each do |array|
95
+ puts " - #{array[0]} replaced with #{array[1]}"
96
+ end
97
+ end
98
+
99
+ return unless unknown_errors.any?
100
+
101
+ puts
102
+ puts "Following errors weren't fixed:"
103
+
104
+ unknown_errors.each do |e|
105
+ # doesn't print an insignificant line
106
+ next if /please update it/.match?(e)
107
+
108
+ puts " - #{e}"
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ class CLI
5
+ class Command
6
+ class NoErrors < Base
7
+ self.command_name = :no_errors
8
+
9
+ def self.fixes_error?(stderr)
10
+ # raise stderr.length.to_s
11
+ stderr.to_s.strip.length.zero?
12
+ end
13
+
14
+ def run
15
+ puts "Didn't detect any errors with the following configuration:"
16
+ puts "RuboCop command: #{options[:cmd]}"
17
+ puts "RuboCop config path: #{options[:config_path]}"
18
+ exit
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ class CLI
5
+ class Command
6
+ class UnknownError < Base
7
+ self.command_name = :unknown_error
8
+
9
+ def run
10
+ puts "Don't know how to fix received errors with the following configuration:"
11
+ puts "RuboCop command: #{options[:cmd]}"
12
+ puts "RuboCop config path: #{options[:config_path]}"
13
+ puts 'Errors:'
14
+ puts stderr
15
+ # raise "IMHRE"
16
+ exit
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ class CLI
5
+ class Command
6
+ class Version < Base
7
+ self.command_name = :version
8
+
9
+ def run
10
+ puts RuboCopConfigUpdater::VERSION
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCopConfigUpdater
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rubocop_config_updater/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop_config_updater'
7
+ spec.version = RuboCopConfigUpdater::VERSION
8
+ spec.authors = ['Adam Zapaśnik']
9
+ spec.email = ['contact@adamzapasnik.io']
10
+
11
+ spec.summary = 'Update obsolete rubocop configuration.'
12
+ spec.homepage = 'https://github.com/adamzapasnik/rubocop_config_updater'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/adamzapasnik/rubocop_config_updater'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/adamzapasnik/rubocop_config_updater/blob/master/CHANGELOG.md'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop_config_updater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Zapaśnik
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - contact@adamzapasnik.io
16
+ executables:
17
+ - rubocop_config_updater
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".editorconfig"
22
+ - ".github/workflows/lint.yml"
23
+ - ".github/workflows/test.yml"
24
+ - ".gitignore"
25
+ - ".rubocop.yml"
26
+ - ".ruby-version"
27
+ - ".vscode/settings.json"
28
+ - CHANGELOG.md
29
+ - Gemfile
30
+ - Gemfile.lock
31
+ - LICENSE
32
+ - README.md
33
+ - Rakefile
34
+ - bin/console
35
+ - bin/setup
36
+ - exe/rubocop_config_updater
37
+ - lib/rubocop_config_updater.rb
38
+ - lib/rubocop_config_updater/cli.rb
39
+ - lib/rubocop_config_updater/cli/command.rb
40
+ - lib/rubocop_config_updater/cli/command/base.rb
41
+ - lib/rubocop_config_updater/cli/command/fix_errors.rb
42
+ - lib/rubocop_config_updater/cli/command/no_errors.rb
43
+ - lib/rubocop_config_updater/cli/command/unknown_error.rb
44
+ - lib/rubocop_config_updater/cli/command/version.rb
45
+ - lib/rubocop_config_updater/version.rb
46
+ - rubocop_config_updater.gemspec
47
+ homepage: https://github.com/adamzapasnik/rubocop_config_updater
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/adamzapasnik/rubocop_config_updater
52
+ source_code_uri: https://github.com/adamzapasnik/rubocop_config_updater
53
+ changelog_uri: https://github.com/adamzapasnik/rubocop_config_updater/blob/master/CHANGELOG.md
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.4.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Update obsolete rubocop configuration.
73
+ test_files: []