ruboclean 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +48 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +70 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +122 -0
- data/Rakefile +12 -0
- data/bin/console +16 -0
- data/bin/ruboclean +11 -0
- data/bin/setup +11 -0
- data/bin/test +28 -0
- data/lib/ruboclean.rb +17 -0
- data/lib/ruboclean/grouper.rb +34 -0
- data/lib/ruboclean/orderer.rb +29 -0
- data/lib/ruboclean/rubocop_configuration.rb +14 -0
- data/lib/ruboclean/rubocop_configuration_path.rb +47 -0
- data/lib/ruboclean/version.rb +5 -0
- data/ruboclean.gemspec +29 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fd9b5156a1868e0cac70e314d59f7d17a878a564b597ccc19e4fdbc40d56ce5
|
4
|
+
data.tar.gz: 96da31ede8824d61f59376df26f19a6184eb018f5d5dae214a296c9a750117b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7681c72564a7e23c72a7b753b1a6326fef3d67485b09b2cbbc9b321ba7344eaa4f56abaf88a2f950ee01505456e3a4f3d7a928c15473e6a77103a7a2b830477
|
7
|
+
data.tar.gz: 4b8acb5a91d422876058adca6efcfb422ba698c1d08b6c3dcec79a92e34fa75f82bd9f0458bff251ff76681b7491872d8a578eb33e025b2bd2959634647eec58
|
@@ -0,0 +1,48 @@
|
|
1
|
+
env:
|
2
|
+
RUBY_VERSION: 2.7
|
3
|
+
CC_TEST_REPORTER_BINARY_URL: https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
4
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
5
|
+
|
6
|
+
name: Continuous Integration
|
7
|
+
on: [pull_request]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
name: Run bin/test
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v1
|
15
|
+
|
16
|
+
- uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ env.RUBY_VERSION }}
|
19
|
+
|
20
|
+
# install gems
|
21
|
+
- name: Cache Ruby gems
|
22
|
+
uses: actions/cache@v2
|
23
|
+
with:
|
24
|
+
path: vendor/bundle
|
25
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
26
|
+
|
27
|
+
- name: Bundle install
|
28
|
+
run: |
|
29
|
+
bundle config path vendor/bundle
|
30
|
+
bundle install --jobs 4 --retry 3
|
31
|
+
|
32
|
+
# prepare CC test reporter
|
33
|
+
- name: Download CC test reporter binary
|
34
|
+
run: |
|
35
|
+
curl -L ${CC_TEST_REPORTER_BINARY_URL} > ./cc-test-reporter
|
36
|
+
chmod +x ./cc-test-reporter
|
37
|
+
./cc-test-reporter before-build
|
38
|
+
|
39
|
+
# run tests
|
40
|
+
- name: Run tests
|
41
|
+
run: bin/test
|
42
|
+
|
43
|
+
# report to CC
|
44
|
+
- run: ./cc-test-reporter after-build --exit-code 1
|
45
|
+
if: ${{ failure() }}
|
46
|
+
|
47
|
+
- run: ./cc-test-reporter after-build --exit-code 0
|
48
|
+
if: ${{ success() }}
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
|
3
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
4
|
+
Enabled: true
|
5
|
+
|
6
|
+
Layout/SpaceAroundMethodCallOperator:
|
7
|
+
Enabled: true
|
8
|
+
|
9
|
+
Lint/DeprecatedOpenSSLConstant:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Lint/DuplicateElsifCondition:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
Lint/MixedRegexpCaptureTypes:
|
16
|
+
Enabled: true
|
17
|
+
|
18
|
+
Lint/RaiseException:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Lint/StructNewOverride:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Style/AccessorGrouping:
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
Style/ArrayCoercion:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Style/BisectedAttrAccessor:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Style/CaseLikeIf:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Style/ExponentialNotation:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Style/HashAsLastArrayItem:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Style/HashEachMethods:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Style/HashLikeCase:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Style/HashTransformKeys:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Style/HashTransformValues:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Style/RedundantAssignment:
|
55
|
+
Enabled: true
|
56
|
+
|
57
|
+
Style/RedundantFetchBlock:
|
58
|
+
Enabled: true
|
59
|
+
|
60
|
+
Style/RedundantFileExtensionInRequire:
|
61
|
+
Enabled: true
|
62
|
+
|
63
|
+
Style/RedundantRegexpCharacterClass:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
Style/RedundantRegexpEscape:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
Style/SlicingWithRange:
|
70
|
+
Enabled: true
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at lxxxvi@users.noreply.github.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruboclean (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
docile (1.3.2)
|
11
|
+
json (2.3.1)
|
12
|
+
minitest (5.14.1)
|
13
|
+
parallel (1.19.2)
|
14
|
+
parser (2.7.1.4)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rake (12.3.3)
|
18
|
+
regexp_parser (1.7.1)
|
19
|
+
rexml (3.2.4)
|
20
|
+
rubocop (0.88.0)
|
21
|
+
parallel (~> 1.10)
|
22
|
+
parser (>= 2.7.1.1)
|
23
|
+
rainbow (>= 2.2.2, < 4.0)
|
24
|
+
regexp_parser (>= 1.7)
|
25
|
+
rexml
|
26
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
27
|
+
ruby-progressbar (~> 1.7)
|
28
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
29
|
+
rubocop-ast (0.3.0)
|
30
|
+
parser (>= 2.7.1.4)
|
31
|
+
ruby-progressbar (1.10.1)
|
32
|
+
simplecov (0.17.1)
|
33
|
+
docile (~> 1.1)
|
34
|
+
json (>= 1.8, < 3)
|
35
|
+
simplecov-html (~> 0.10.0)
|
36
|
+
simplecov-html (0.10.2)
|
37
|
+
unicode-display_width (1.7.0)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
minitest
|
44
|
+
rake
|
45
|
+
ruboclean!
|
46
|
+
rubocop
|
47
|
+
simplecov (< 0.18)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 lxxxvi
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
![Continuous Integration](https://github.com/lxxxvi/ruboclean/workflows/Continuous%20Integration/badge.svg)
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/a940762e1c0b27caa905/maintainability)](https://codeclimate.com/github/lxxxvi/ruboclean/maintainability)
|
3
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/a940762e1c0b27caa905/test_coverage)](https://codeclimate.com/github/lxxxvi/ruboclean/test_coverage)
|
4
|
+
|
5
|
+
# ruboclean
|
6
|
+
|
7
|
+
**ruboclean** puts `.rubocop.yml` into order. It groups the configuration into three groups:
|
8
|
+
|
9
|
+
1. `require`
|
10
|
+
2. `Namespaces`
|
11
|
+
3. `Namespace/Cops`
|
12
|
+
|
13
|
+
Finally it orders the configurations **alphabetically** within these groups.
|
14
|
+
|
15
|
+
## Example
|
16
|
+
|
17
|
+
### Input `.rubocop.yml`:
|
18
|
+
|
19
|
+
```yml
|
20
|
+
Rails/ShortI18n:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
Layout/LineLength:
|
24
|
+
Max: 120
|
25
|
+
|
26
|
+
Rails:
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
AllCops:
|
30
|
+
Exclude:
|
31
|
+
- bin/**/*
|
32
|
+
|
33
|
+
require:
|
34
|
+
- rubocop-rails
|
35
|
+
```
|
36
|
+
|
37
|
+
### Output `.rubocop.yml`:
|
38
|
+
|
39
|
+
```yml
|
40
|
+
---
|
41
|
+
|
42
|
+
require:
|
43
|
+
- rubocop-rails
|
44
|
+
|
45
|
+
AllCops:
|
46
|
+
Exclude:
|
47
|
+
- bin/**/*
|
48
|
+
|
49
|
+
Rails:
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
Layout/LineLength:
|
53
|
+
Max: 120
|
54
|
+
|
55
|
+
Rails/ShortI18n:
|
56
|
+
Enabled: true
|
57
|
+
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
## Installation
|
62
|
+
|
63
|
+
Add this line to your application's Gemfile:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
gem 'ruboclean', require: false
|
67
|
+
```
|
68
|
+
|
69
|
+
And then execute:
|
70
|
+
|
71
|
+
```shell
|
72
|
+
bundle install
|
73
|
+
```
|
74
|
+
|
75
|
+
Or install it yourself as:
|
76
|
+
|
77
|
+
```shell
|
78
|
+
gem install ruboclean
|
79
|
+
```
|
80
|
+
|
81
|
+
## Usage
|
82
|
+
|
83
|
+
```shell
|
84
|
+
ruboclean [path]
|
85
|
+
```
|
86
|
+
|
87
|
+
* `path` is optional, it defaults to the current working directory
|
88
|
+
* `path` can be a directory that contains a `.rubocop.yml`
|
89
|
+
* `path` can be a path to a `.rubocop.yml` directly
|
90
|
+
|
91
|
+
### Examples
|
92
|
+
|
93
|
+
```shell
|
94
|
+
ruboclean # uses `.rubocop.yml` of current working directory
|
95
|
+
```
|
96
|
+
|
97
|
+
```shell
|
98
|
+
ruboclean /path/to/dir # uses `.rubocop.yml` of /path/to/dir
|
99
|
+
```
|
100
|
+
|
101
|
+
```shell
|
102
|
+
ruboclean /path/to/dir/.rubocop.yml
|
103
|
+
```
|
104
|
+
|
105
|
+
## Development
|
106
|
+
|
107
|
+
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.
|
108
|
+
|
109
|
+
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).
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lxxxvi/ruboclean. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lxxxvi/ruboclean/blob/master/CODE_OF_CONDUCT.md).
|
114
|
+
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
119
|
+
|
120
|
+
## Code of Conduct
|
121
|
+
|
122
|
+
Everyone interacting in the Ruboclean project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lxxxvi/ruboclean/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'ruboclean'
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require 'pry'
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
require 'irb'
|
16
|
+
IRB.start(__FILE__)
|
data/bin/ruboclean
ADDED
data/bin/setup
ADDED
data/bin/test
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
# Runs all tests and linters
|
8
|
+
class BinTest
|
9
|
+
include FileUtils
|
10
|
+
|
11
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
12
|
+
|
13
|
+
def system!(*args)
|
14
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
chdir APP_ROOT do
|
19
|
+
puts "\n== Run tests =="
|
20
|
+
system! 'bundle exec rake test'
|
21
|
+
|
22
|
+
puts "\n== Run rubocop =="
|
23
|
+
system! 'bundle exec rubocop -p'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
BinTest.new.run
|
data/lib/ruboclean.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruboclean/version'
|
4
|
+
require 'ruboclean/rubocop_configuration'
|
5
|
+
require 'ruboclean/rubocop_configuration_path'
|
6
|
+
require 'ruboclean/orderer'
|
7
|
+
|
8
|
+
# Ruboclean entry point
|
9
|
+
module Ruboclean
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
def self.run(path)
|
13
|
+
rubocop_configuration_path = RubocopConfigurationPath.new(path)
|
14
|
+
rubocop_configuration = rubocop_configuration_path.load
|
15
|
+
rubocop_configuration_path.write(rubocop_configuration.order)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruboclean
|
4
|
+
# Groups the rubocop configuration items into three categories:
|
5
|
+
# - require: the require block
|
6
|
+
# - namespaces: every item which does **not** include an "/"
|
7
|
+
# - cops: every item which **includes** an "/"
|
8
|
+
class Grouper
|
9
|
+
def initialize(config_hash)
|
10
|
+
@config_hash = config_hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def group_config
|
14
|
+
@config_hash.each_with_object(empty_groups) do |item, result|
|
15
|
+
key, value = item
|
16
|
+
target_group = find_target_group(key)
|
17
|
+
result[target_group].merge! Hash[key, value]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def empty_groups
|
24
|
+
{ require: {}, namespaces: {}, cops: {} }
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_target_group(key)
|
28
|
+
return :require if key == 'require'
|
29
|
+
return :cops if key.include?('/')
|
30
|
+
|
31
|
+
:namespaces
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruboclean/grouper'
|
4
|
+
|
5
|
+
module Ruboclean
|
6
|
+
# Orders the items within the groups alphabetically
|
7
|
+
class Orderer
|
8
|
+
def initialize(config_hash)
|
9
|
+
@config_hash = config_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def order
|
13
|
+
grouped_config.reduce({}) do |result, group|
|
14
|
+
_group_name, group_items = group
|
15
|
+
result.merge!(order_by_key(group_items))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def order_by_key(config_hash)
|
22
|
+
config_hash.sort_by(&:first).to_h
|
23
|
+
end
|
24
|
+
|
25
|
+
def grouped_config
|
26
|
+
Ruboclean::Grouper.new(@config_hash).group_config
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruboclean
|
4
|
+
# Contains the config_hash representation of the `.rubocop.yml` file
|
5
|
+
class RubocopConfiguration
|
6
|
+
def initialize(config_hash)
|
7
|
+
@config_hash = config_hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def order
|
11
|
+
Ruboclean::Orderer.new(@config_hash).order
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Ruboclean
|
7
|
+
# Interface for reading and writing the `.rubocop.yml` file
|
8
|
+
class RubocopConfigurationPath
|
9
|
+
# Thrown if given path is invalid
|
10
|
+
class InvalidPathError < StandardError
|
11
|
+
def initialize(path)
|
12
|
+
super "path does not exist: '#{path}'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(path)
|
17
|
+
input_path = Pathname.new(path)
|
18
|
+
|
19
|
+
@rubocop_configuration_path = if input_path.directory?
|
20
|
+
input_path.join('.rubocop.yml')
|
21
|
+
else
|
22
|
+
input_path
|
23
|
+
end
|
24
|
+
|
25
|
+
raise InvalidPathError, @rubocop_configuration_path unless @rubocop_configuration_path.exist?
|
26
|
+
end
|
27
|
+
|
28
|
+
def load
|
29
|
+
Ruboclean::RubocopConfiguration.new(load_yaml)
|
30
|
+
end
|
31
|
+
|
32
|
+
def write(rubocop_configuration)
|
33
|
+
output = sanitize_yaml(rubocop_configuration.to_yaml)
|
34
|
+
@rubocop_configuration_path.write(output)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def sanitize_yaml(data)
|
40
|
+
data.gsub(/^([a-zA-Z]+)/, "\n\\1")
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_yaml
|
44
|
+
YAML.safe_load(@rubocop_configuration_path.read)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/ruboclean.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/ruboclean/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ruboclean'
|
7
|
+
spec.version = Ruboclean::VERSION
|
8
|
+
spec.authors = ['lxxxvi']
|
9
|
+
spec.email = ['lxxxvi@users.noreply.github.com']
|
10
|
+
|
11
|
+
spec.summary = 'Cleans and orders settings in .rubocop.yml'
|
12
|
+
spec.description = 'Cleans and orders settings in .rubocop.yml'
|
13
|
+
spec.homepage = 'https://github.com/lxxxvi/ruboclean'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/lxxxvi/ruboclean'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/lxxxvi/ruboclean/blob/master/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.executables << 'ruboclean'
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboclean
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lxxxvi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Cleans and orders settings in .rubocop.yml
|
14
|
+
email:
|
15
|
+
- lxxxvi@users.noreply.github.com
|
16
|
+
executables:
|
17
|
+
- ruboclean
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".github/workflows/ci.yml"
|
22
|
+
- ".gitignore"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- bin/console
|
31
|
+
- bin/ruboclean
|
32
|
+
- bin/setup
|
33
|
+
- bin/test
|
34
|
+
- lib/ruboclean.rb
|
35
|
+
- lib/ruboclean/grouper.rb
|
36
|
+
- lib/ruboclean/orderer.rb
|
37
|
+
- lib/ruboclean/rubocop_configuration.rb
|
38
|
+
- lib/ruboclean/rubocop_configuration_path.rb
|
39
|
+
- lib/ruboclean/version.rb
|
40
|
+
- ruboclean.gemspec
|
41
|
+
homepage: https://github.com/lxxxvi/ruboclean
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
homepage_uri: https://github.com/lxxxvi/ruboclean
|
46
|
+
source_code_uri: https://github.com/lxxxvi/ruboclean
|
47
|
+
changelog_uri: https://github.com/lxxxvi/ruboclean/blob/master/CHANGELOG.md
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.7.0
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.1.2
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Cleans and orders settings in .rubocop.yml
|
67
|
+
test_files: []
|