rubocop-sensei 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: 3d5985f2ba4b1583ff53baadfc49b88342901c7b17aa0e353da4d8bca55ae8d1
4
+ data.tar.gz: 785df89fde862a0fab0f4756307876f54c133896c2ff9360a4b28f3ffdf88aa5
5
+ SHA512:
6
+ metadata.gz: c95241d23a5acb41f201da2310f41d28cceda048721e730d3250fc5921e69c4736c49f39d3e4597c0c7e8ccb51e2c46ab408e219cb86048f08b67479c27680ac
7
+ data.tar.gz: dff62e0eb119d25d819616b25994ff482860a7ba61a1f1a35c8ae96651176c035c71dc73702cfedf77a571bad966e43d837862b1ac56cd8d45d8462c7eb0acb8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+
5
+ Naming/FileName:
6
+ Exclude:
7
+ - lib/rubocop-sensei.rb
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rubocop-sensei.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+ gem "rspec"
12
+ gem "debug"
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-sensei (0.1.0)
5
+ rubocop
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ debug (1.7.0)
12
+ irb (>= 1.5.0)
13
+ reline (>= 0.3.1)
14
+ diff-lcs (1.5.0)
15
+ io-console (0.5.11)
16
+ irb (1.6.0)
17
+ reline (>= 0.3.0)
18
+ json (2.6.1)
19
+ minitest (5.15.0)
20
+ parallel (1.22.1)
21
+ parser (3.1.3.0)
22
+ ast (~> 2.4.1)
23
+ rainbow (3.1.1)
24
+ rake (13.0.6)
25
+ regexp_parser (2.6.1)
26
+ reline (0.3.1)
27
+ io-console (~> 0.5)
28
+ rexml (3.2.5)
29
+ rspec (3.12.0)
30
+ rspec-core (~> 3.12.0)
31
+ rspec-expectations (~> 3.12.0)
32
+ rspec-mocks (~> 3.12.0)
33
+ rspec-core (3.12.0)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-expectations (3.12.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-mocks (3.12.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-support (3.12.0)
42
+ rubocop (1.40.0)
43
+ json (~> 2.3)
44
+ parallel (~> 1.10)
45
+ parser (>= 3.1.2.1)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 1.8, < 3.0)
48
+ rexml (>= 3.2.5, < 4.0)
49
+ rubocop-ast (>= 1.23.0, < 2.0)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 1.4.0, < 3.0)
52
+ rubocop-ast (1.24.0)
53
+ parser (>= 3.1.1.0)
54
+ ruby-progressbar (1.11.0)
55
+ unicode-display_width (2.3.0)
56
+
57
+ PLATFORMS
58
+ arm64-darwin-21
59
+
60
+ DEPENDENCIES
61
+ debug
62
+ minitest (~> 5.0)
63
+ rake (~> 13.0)
64
+ rspec
65
+ rubocop-sensei!
66
+
67
+ BUNDLED WITH
68
+ 2.3.26
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright 2022 Kuniaki Igarashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Rubocop::Sensei
2
+
3
+ # License
4
+
5
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,36 @@
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
+ # task default: :test
12
+
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec) do |spec|
16
+ spec.pattern = FileList['spec/**/*_spec.rb']
17
+ end
18
+
19
+ desc 'Generate a new cop with a template'
20
+ task :new_cop, [:cop] do |_task, args|
21
+ require 'rubocop'
22
+
23
+ cop_name = args.fetch(:cop) do
24
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
25
+ exit!
26
+ end
27
+
28
+ generator = RuboCop::Cop::Generator.new(cop_name)
29
+
30
+ generator.write_source
31
+ generator.write_spec
32
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/sensei_cops.rb')
33
+ generator.inject_config(config_file_path: 'config/default.yml')
34
+
35
+ puts generator.todo
36
+ end
@@ -0,0 +1,6 @@
1
+ # Write it!
2
+
3
+ Lint/ReplaceElsif:
4
+ Description: 'elsifはCaseで置換できる'
5
+ Enabled: pending
6
+ VersionAdded: '<<next>>'
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'style/replace_elsif'
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # `elsif`は`case`で書き換え可能です。
7
+ # N個の分岐から1つ選ぶ「N者択一」のときはcaseをつかうと読みやすくなります。
8
+ #
9
+ # @example
10
+ # # bad
11
+ # if x == 1
12
+ # do_something1
13
+ # elsif y == 2
14
+ # do_something2
15
+ # end
16
+ #
17
+ # # good
18
+ # case
19
+ # when x == 1
20
+ # do_something1
21
+ # when y == 2
22
+ # do_something2
23
+ # end
24
+ #
25
+ # # good
26
+ # case x
27
+ # when (1..20)
28
+ # do_something1
29
+ # when (21..)
30
+ # do_something2
31
+ # end
32
+ #
33
+ class ReplaceElsif < Base
34
+ extend RuboCop::Cop::AutoCorrector
35
+
36
+ MSG = <<~STRING
37
+ `elsif`は`case`で書き換え可能です。
38
+ N個の分岐から1つ選ぶ「N者択一」のときはcaseをつかうと読みやすくなります。
39
+
40
+ たとえば、elsifをつかった次のようなコードがあるとき、
41
+
42
+ if x == 1
43
+ elsif y == 2
44
+ else
45
+ end
46
+
47
+ caseをつかうと次のように書き換えられます。
48
+
49
+ case
50
+ when x == 1
51
+ when y == 2
52
+ else
53
+ end
54
+
55
+ 同じ変数の値で分岐するときは次のようにも書けます。
56
+
57
+ case x
58
+ when 1
59
+ when 2
60
+ else
61
+ end
62
+ STRING
63
+
64
+ def on_if(node)
65
+ return unless node.elsif?
66
+
67
+ add_offense(node) do |corrector|
68
+ corrector.replace(node.parent.loc.keyword, "case\nwhen") # if => case when
69
+ corrector.replace(node.loc.keyword, "when") # elsif => when
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Sensei
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Sensei
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "yaml"
5
+ require_relative "sensei/version"
6
+
7
+ module RuboCop
8
+ module Sensei
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
12
+ CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
13
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
14
+
15
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
16
+ end
17
+ end
18
+
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/sensei'
6
+ require_relative 'rubocop/sensei/version'
7
+ require_relative 'rubocop/sensei/inject'
8
+
9
+ RuboCop::Sensei::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/sensei_cops'
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rubocop/sensei/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rubocop-sensei"
7
+ spec.version = RuboCop::Sensei::VERSION
8
+ spec.authors = ["Kuniaki Igarashi"]
9
+ spec.email = ["kuniaki.igarashi@garnettech373.com"]
10
+
11
+ spec.summary = "Rubocop Sensei"
12
+ spec.description = "."
13
+ spec.homepage = "https://github.com/igaiga/rubocop-sensei"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/igaiga/rubocop-sensei"
20
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+
39
+ spec.add_runtime_dependency 'rubocop'
40
+ end
41
+
@@ -0,0 +1,6 @@
1
+ module Rubocop
2
+ module Sensei
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-sensei
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kuniaki Igarashi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-30 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: "."
28
+ email:
29
+ - kuniaki.igarashi@garnettech373.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - 'LICENSE '
39
+ - README.md
40
+ - Rakefile
41
+ - config/default.yml
42
+ - lib/rubocop-sensei.rb
43
+ - lib/rubocop/cop/sensei_cops.rb
44
+ - lib/rubocop/cop/style/replace_elsif.rb
45
+ - lib/rubocop/sensei.rb
46
+ - lib/rubocop/sensei/inject.rb
47
+ - lib/rubocop/sensei/version.rb
48
+ - rubocop-sensei.gemspec
49
+ - sig/rubocop/sensei.rbs
50
+ homepage: https://github.com/igaiga/rubocop-sensei
51
+ licenses: []
52
+ metadata:
53
+ homepage_uri: https://github.com/igaiga/rubocop-sensei
54
+ source_code_uri: https://github.com/igaiga/rubocop-sensei
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.7.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.4.1
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Rubocop Sensei
74
+ test_files: []