rubocop-configuration_cleaner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 074f364173f5b4c3bc0c14bcdbd2a965d4aa6aa682b456080e85ea9010689592
4
+ data.tar.gz: e537c18a1e4ed735146d12b03f6fda1a863831500eb535293bd0b6a3a390420f
5
+ SHA512:
6
+ metadata.gz: 1974b1aedad47e0dfff95ab9ed6c37c43b37ab1ea9132ec73df0bcae37c09fff99457d76bd06b2175c0731b777538158c48db19c83a0933eaf706610f7e50812
7
+ data.tar.gz: 9ffdb6c7ad33714c925147c8f17b607b8c70ed2d5abcbb67b8d1c7040deebaa7cc5118f0ab9922bad33e7c838d37ef70ac2c074869404a18b782bbc01e5921a3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rubocop-configuration_cleaner.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # RuboCop::ConfigurationCleaner
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/configuration_cleaner`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rubocop-configuration_cleaner'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rubocop-configuration_cleaner
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/rubocop-configuration_cleaner.
36
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :smoke
3
+
4
+ task :smoke do
5
+ require 'pathname'
6
+ bad = Pathname('smoke/bad-rubocop.yml')
7
+ good = Pathname('smoke/good-rubocop.yml')
8
+
9
+ next if `rubocop-configuration_cleaner #{bad}` == good.read
10
+
11
+ system "git diff --no-index #{good} #{bad}"
12
+ fail
13
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubocop/configuration_cleaner"
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
@@ -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,5 @@
1
+ #!ruby
2
+
3
+ require 'rubocop/configuration_cleaner'
4
+
5
+ RuboCop::ConfigurationCleaner::CLI.new(ARGV).run
@@ -0,0 +1,83 @@
1
+ module RuboCop
2
+ module ConfigurationCleaner
3
+ class CLI
4
+ def initialize(argv)
5
+ @argv = argv
6
+ @params = {}
7
+ end
8
+
9
+ attr_reader :params
10
+ private :params
11
+
12
+ def run
13
+ parse_option!
14
+
15
+ target_configs.each do |path|
16
+ config = YAML.load(path.read)
17
+ default = default_configuration(requires(config))
18
+ needless_cops = config.map do |cop_name, values|
19
+ next unless values.is_a? Hash
20
+ next unless cop_name.include?('/')
21
+
22
+ cop_config = default[cop_name]
23
+ next unless values.all? { |key, config_val| cop_config[key] == config_val }
24
+
25
+ cop_name
26
+ end.compact
27
+
28
+ needless_re = Regexp.new("^(?:#{needless_cops.join('|')}):")
29
+ removing = false
30
+ content = path.read.lines.reject do |line|
31
+ if removing
32
+ if line.match?(/^\S/)
33
+ removing = false
34
+ else
35
+ true
36
+ end
37
+ else
38
+ if line.match?(needless_re)
39
+ removing = true
40
+ else
41
+ false
42
+ end
43
+ end
44
+ end.join
45
+
46
+ case
47
+ when params[:write]
48
+ path.write content
49
+ when params[:diff]
50
+ Tempfile.create do |f|
51
+ f.write content
52
+ f.flush
53
+ system("git", "diff", "--no-index", "--", path.to_s, f.path)
54
+ end
55
+ else
56
+ puts content
57
+ end
58
+ end
59
+ end
60
+
61
+ private def target_configs
62
+ paths = @argv.empty? ? ['.rubocop.yml'] : @argv
63
+ paths.map { |path| Pathname(path).expand_path }
64
+ end
65
+
66
+ private def default_configuration(requires)
67
+ config_str = `rubocop --force-default-config --show-cops #{requires.map { |r| "-r #{r}" }.join(' ')}`
68
+ YAML.load(config_str)
69
+ end
70
+
71
+ private def requires(config)
72
+ Array(config['require'])
73
+ end
74
+
75
+ private def parse_option!
76
+ opt = OptionParser.new
77
+ opt.on('--write')
78
+ opt.on('--diff')
79
+ opt.parse! into: @params
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module ConfigurationCleaner
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+ require 'optparse'
4
+ require 'tempfile'
5
+
6
+ require "rubocop/configuration_cleaner/version"
7
+ require "rubocop/configuration_cleaner/cli"
8
+
9
+ module RuboCop
10
+ module ConfigurationCleaner
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/rubocop/configuration_cleaner/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rubocop-configuration_cleaner"
5
+ spec.version = RuboCop::ConfigurationCleaner::VERSION
6
+ spec.authors = ["Masataka Pocke Kuwabara"]
7
+ spec.email = ["kuwabara@pocke.me"]
8
+
9
+ spec.summary = %q{.rubocop.yml cleaner}
10
+ spec.description = %q{.rubocop.yml cleaner}
11
+ spec.homepage = "https://github.com/pocke/rubocop-configuration_cleaner"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency 'rubocop'
28
+ end
@@ -0,0 +1,5 @@
1
+ Style/Strip: # Same as the default config, should be removed
2
+ Enabled: true
3
+
4
+ Lint/Void: # Not same, should be left
5
+ Enabled: false
@@ -0,0 +1,2 @@
1
+ Lint/Void: # Not same, should be left
2
+ Enabled: false
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-configuration_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-03 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: ".rubocop.yml cleaner"
28
+ email:
29
+ - kuwabara@pocke.me
30
+ executables:
31
+ - rubocop-configuration_cleaner
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - bin/console
40
+ - bin/setup
41
+ - exe/rubocop-configuration_cleaner
42
+ - lib/rubocop/configuration_cleaner.rb
43
+ - lib/rubocop/configuration_cleaner/cli.rb
44
+ - lib/rubocop/configuration_cleaner/version.rb
45
+ - rubocop-configuration_cleaner.gemspec
46
+ - smoke/bad-rubocop.yml
47
+ - smoke/good-rubocop.yml
48
+ homepage: https://github.com/pocke/rubocop-configuration_cleaner
49
+ licenses: []
50
+ metadata:
51
+ homepage_uri: https://github.com/pocke/rubocop-configuration_cleaner
52
+ source_code_uri: https://github.com/pocke/rubocop-configuration_cleaner
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.2.0.pre1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: ".rubocop.yml cleaner"
72
+ test_files: []