rubocop-rake 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '08c0328080d816a5440b34c59982e558d8816b5c7c6b02b0a047631fe53b056f'
4
+ data.tar.gz: 354fb71bfa405da3dcc0818e3e7de4e8cafb4ba1bc1d484cf578ac80403eac1a
5
+ SHA512:
6
+ metadata.gz: 98e781c7ee3a6861f4c8b7236e0afa989158b6259ec1e490109140aaeafeb0a9e0b8f6506e525d5b4e8c2cd4b92ff66563d1825763c4a5d688b77c6c1774c07b
7
+ data.tar.gz: b2b54fcd86a9e40bb34cd04998e577ae802c340041715e6b2eb79d10e7911bd2c95ae9ddb6d863a9669bd28a385eba2f608baa1ef1c49848795e9a2231c9d27a
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/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rubocop-rake.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem 'rspec'
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # RuboCop Rake
2
+
3
+ A [RuboCop](https://github.com/rubocop-hq/rubocop) plugin for Rake.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubocop-rake'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rubocop-rake
20
+
21
+ ## Usage
22
+
23
+ Put this into your `.rubocop.yml`.
24
+
25
+ ```yaml
26
+ require: rubocop-rake
27
+ ```
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/rubocop-rake.
38
+
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ desc 'Generate a new cop with a template'
11
+ task :new_cop, [:cop] do |_task, args|
12
+ require 'rubocop'
13
+
14
+ cop_name = args.fetch(:cop) do
15
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
16
+ exit!
17
+ end
18
+
19
+ github_user = `git config github.user`.chop
20
+ github_user = 'your_id' if github_user.empty?
21
+
22
+ generator = RuboCop::Cop::Generator.new(cop_name, github_user)
23
+
24
+ generator.write_source
25
+ generator.write_spec
26
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/rake_cops.rb')
27
+ generator.inject_config(config_file_path: 'config/default.yml')
28
+
29
+ puts generator.todo
30
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubocop/rake"
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,7 @@
1
+ Rake/Desc:
2
+ Description: 'Describe the task with `desc` method.'
3
+ Enabled: true
4
+ VersionAdded: '0.1.0'
5
+ Include:
6
+ - 'Rakefile'
7
+ - '**/*.rake'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/rake'
6
+ require_relative 'rubocop/rake/version'
7
+ require_relative 'rubocop/rake/inject'
8
+
9
+ RuboCop::Rake::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/rake_cops'
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rake
6
+ # Rake task definition should have a description with `desc` method.
7
+ # It is useful as a documentation of task. And Rake does not display
8
+ # task that does not have `desc` by `rake -T`.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # task :do_something
13
+ #
14
+ # # bad
15
+ # task :do_something do
16
+ # end
17
+ #
18
+ # # good
19
+ # desc 'Do something'
20
+ # task :do_something
21
+ #
22
+ # # good
23
+ # desc 'Do something'
24
+ # task :do_something do
25
+ # end
26
+ #
27
+ class Desc < Cop
28
+ MSG = 'Describe the task with `desc` method.'.freeze
29
+
30
+ def_node_matcher :task?, <<~PATTERN
31
+ (send nil? :task ...)
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ return unless task?(node)
36
+ return if task_with_desc?(node)
37
+
38
+ add_offense(node)
39
+ end
40
+
41
+ private def task_with_desc?(node)
42
+ parent, task = parent_and_task(node)
43
+ return false unless parent
44
+
45
+ idx = parent.children.find_index(task) - 1
46
+ desc_candidate = parent.children[idx]
47
+ return false unless desc_candidate
48
+
49
+ desc_candidate.send_type? && desc_candidate.method_name == :desc
50
+ end
51
+
52
+ private def parent_and_task(task_node)
53
+ parent = task_node.parent
54
+ return nil, task_node unless parent
55
+ return parent, task_node unless parent.block_type?
56
+
57
+ if parent.children.find_index(task_node) == 0
58
+ # when task {}
59
+ return parent.parent, parent
60
+ else
61
+ # when something { task }
62
+ return parent, task_node
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './rake/desc'
@@ -0,0 +1,13 @@
1
+ require "rubocop/rake/version"
2
+
3
+ module RuboCop
4
+ module Rake
5
+ class Error < StandardError; end
6
+
7
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
8
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
9
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
10
+
11
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Rake
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)
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,5 @@
1
+ module RuboCop
2
+ module Rake
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'lib/rubocop/rake/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rubocop-rake"
5
+ spec.version = RuboCop::Rake::VERSION
6
+ spec.authors = ["Masataka Pocke Kuwabara"]
7
+ spec.email = ["kuwabara@pocke.me"]
8
+
9
+ spec.summary = %q{A RuboCop plugin for Rake}
10
+ spec.description = %q{A RuboCop plugin for Rake}
11
+ spec.homepage = "https://github.com/pocke/rubocop-rake"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.licenses = ['MIT']
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
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('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency 'rubocop'
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-rake
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: 2019-09-04 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: A RuboCop plugin for Rake
28
+ email:
29
+ - kuwabara@pocke.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - bin/console
40
+ - bin/setup
41
+ - config/default.yml
42
+ - lib/rubocop-rake.rb
43
+ - lib/rubocop/cop/rake/desc.rb
44
+ - lib/rubocop/cop/rake_cops.rb
45
+ - lib/rubocop/rake.rb
46
+ - lib/rubocop/rake/inject.rb
47
+ - lib/rubocop/rake/version.rb
48
+ - rubocop-rake.gemspec
49
+ homepage: https://github.com/pocke/rubocop-rake
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://github.com/pocke/rubocop-rake
55
+ source_code_uri: https://github.com/pocke/rubocop-rake
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.3.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A RuboCop plugin for Rake
75
+ test_files: []