rubocop-rake 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.rubocop_todo.yml +7 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile +3 -0
- data/README.md +1 -1
- data/Rakefile +8 -1
- data/bin/console +1 -0
- data/config/default.yml +5 -0
- data/lib/rubocop-rake.rb +2 -0
- data/lib/rubocop/cop/rake/class_definition_in_task.rb +49 -0
- data/lib/rubocop/cop/rake/desc.rb +24 -1
- data/lib/rubocop/cop/rake/helper/class_definition.rb +31 -0
- data/lib/rubocop/cop/rake/helper/task_definition.rb +28 -0
- data/lib/rubocop/cop/rake/method_definition_in_task.rb +3 -38
- data/lib/rubocop/cop/rake_cops.rb +1 -0
- data/lib/rubocop/rake.rb +3 -0
- data/lib/rubocop/rake/version.rb +3 -1
- data/rubocop-rake.gemspec +5 -4
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43a2bfee062536e5b93f61f3e3be4a2189ab8b694b4511c5b5be945229940607
|
4
|
+
data.tar.gz: 041a6a8562c844204db1757bf2503e33b641fa53eda3555cb7befe384dfe7845
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4f7183c42528b767447731b7de87b025ba1f7f15f225658b162e00d204c3d5499c612a01d32ad06e41574daf0e6a8412da92f784de032635a412e171fdb3337
|
7
|
+
data.tar.gz: 8499dcd7ab87b21c251af73afde006f61832402277fb842eb05f55a5d5bff8a055f0c81c7963b63628ad60a53df442cd03fdf532c0b3707c1fd1bc03433d2ce7
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rake
|
5
|
+
- rubocop-rspec
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 2.4
|
9
|
+
|
10
|
+
Metrics:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/StringLiterals:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/AccessModifierDeclarations:
|
17
|
+
EnforcedStyle: inline
|
18
|
+
|
19
|
+
Style/NumericPredicate:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/UnneededPercentQ:
|
23
|
+
Exclude:
|
24
|
+
- '*.gemspec'
|
25
|
+
|
26
|
+
Style/ModuleFunction:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/PercentLiteralDelimiters:
|
33
|
+
Exclude:
|
34
|
+
- '*.gemspec'
|
35
|
+
|
36
|
+
RSpec/ExampleLength:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Naming/FileName:
|
40
|
+
Exclude:
|
41
|
+
- 'lib/rubocop-rake.rb'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-09-18 21:43:54 +0900 using RuboCop version 0.74.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
data/CHANGELOG.md
CHANGED
@@ -12,11 +12,21 @@
|
|
12
12
|
|
13
13
|
-->
|
14
14
|
|
15
|
+
## 0.3.0 (2019-09-25)
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
* [#6](https://github.com/rubocop-hq/rubocop-rake/issues/6): Add `Rake/ClassDefinitionInTask` cop. ([@pocke][])
|
20
|
+
|
21
|
+
### Bug fixes
|
22
|
+
|
23
|
+
* [#8](https://github.com/rubocop-hq/rubocop-rake/issues/8): Make Rake/Desc to not require description for the default task. ([@pocke][])
|
24
|
+
|
15
25
|
## 0.2.0 (2019-09-17)
|
16
26
|
|
17
27
|
### New features
|
18
28
|
|
19
|
-
* [#5](https://github.com/
|
29
|
+
* [#5](https://github.com/rubocop-hq/rubocop-rake/pull/5): Add `Rake/MethodDefinitionInTask`. ([@pocke][])
|
20
30
|
|
21
31
|
## 0.1.0 (2019-09-04)
|
22
32
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -34,5 +34,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
34
|
|
35
35
|
## Contributing
|
36
36
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop-hq/rubocop-rake.
|
38
38
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
|
-
task :
|
4
|
+
task default: %i[rubocop spec]
|
3
5
|
|
4
6
|
require 'rspec/core/rake_task'
|
5
7
|
|
@@ -28,3 +30,8 @@ task :new_cop, [:cop] do |_task, args|
|
|
28
30
|
|
29
31
|
puts generator.todo
|
30
32
|
end
|
33
|
+
|
34
|
+
desc 'Run rubocop'
|
35
|
+
task :rubocop do
|
36
|
+
sh 'rubocop'
|
37
|
+
end
|
data/bin/console
CHANGED
data/config/default.yml
CHANGED
data/lib/rubocop-rake.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
# This cop detects class or module definition in a task or namespace,
|
7
|
+
# because it is defined to the top level.
|
8
|
+
# It is confusing because the scope looks in the task or namespace,
|
9
|
+
# but actually it is defined to the top level.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# task :foo do
|
14
|
+
# class C
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# # bad
|
19
|
+
# namespace :foo do
|
20
|
+
# module M
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # good - It is also defined to the top level,
|
25
|
+
# # but it looks expected behavior.
|
26
|
+
# class C
|
27
|
+
# end
|
28
|
+
# task :foo do
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
class ClassDefinitionInTask < Cop
|
32
|
+
MSG = 'Do not define a %<type>s in rake task, because it will be defined to the top level.'
|
33
|
+
|
34
|
+
def on_class(node)
|
35
|
+
return if Helper::ClassDefinition.in_class_definition?(node)
|
36
|
+
return unless Helper::TaskDefinition.in_task_or_namespace?(node)
|
37
|
+
|
38
|
+
add_offense(node)
|
39
|
+
end
|
40
|
+
|
41
|
+
def message(node)
|
42
|
+
format(MSG, type: node.type)
|
43
|
+
end
|
44
|
+
|
45
|
+
alias on_module on_class
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -7,6 +7,9 @@ module RuboCop
|
|
7
7
|
# It is useful as a documentation of task. And Rake does not display
|
8
8
|
# task that does not have `desc` by `rake -T`.
|
9
9
|
#
|
10
|
+
# Note: This cop does not require description for the default task,
|
11
|
+
# because the default task is executed with `rake` without command.
|
12
|
+
#
|
10
13
|
# @example
|
11
14
|
# # bad
|
12
15
|
# task :do_something
|
@@ -25,7 +28,7 @@ module RuboCop
|
|
25
28
|
# end
|
26
29
|
#
|
27
30
|
class Desc < Cop
|
28
|
-
MSG = 'Describe the task with `desc` method.'
|
31
|
+
MSG = 'Describe the task with `desc` method.'
|
29
32
|
|
30
33
|
def_node_matcher :task?, <<~PATTERN
|
31
34
|
(send nil? :task ...)
|
@@ -34,6 +37,7 @@ module RuboCop
|
|
34
37
|
def on_send(node)
|
35
38
|
return unless task?(node)
|
36
39
|
return if task_with_desc?(node)
|
40
|
+
return if task_name(node) == :default
|
37
41
|
|
38
42
|
add_offense(node)
|
39
43
|
end
|
@@ -49,11 +53,29 @@ module RuboCop
|
|
49
53
|
desc_candidate.send_type? && desc_candidate.method_name == :desc
|
50
54
|
end
|
51
55
|
|
56
|
+
private def task_name(node)
|
57
|
+
first_arg = node.arguments[0]
|
58
|
+
case first_arg&.type
|
59
|
+
when :sym, :str
|
60
|
+
return first_arg.value.to_sym
|
61
|
+
when :hash
|
62
|
+
return nil if first_arg.children.size != 1
|
63
|
+
|
64
|
+
pair = first_arg.children.first
|
65
|
+
key = pair.children.first
|
66
|
+
case key.type
|
67
|
+
when :sym, :str
|
68
|
+
key.value.to_sym
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
52
73
|
private def parent_and_task(task_node)
|
53
74
|
parent = task_node.parent
|
54
75
|
return nil, task_node unless parent
|
55
76
|
return parent, task_node unless parent.block_type?
|
56
77
|
|
78
|
+
# rubocop:disable Style/GuardClause
|
57
79
|
if parent.children.find_index(task_node) == 0
|
58
80
|
# when task {}
|
59
81
|
return parent.parent, parent
|
@@ -61,6 +83,7 @@ module RuboCop
|
|
61
83
|
# when something { task }
|
62
84
|
return parent, task_node
|
63
85
|
end
|
86
|
+
# rubocop:enable Style/GuardClause
|
64
87
|
end
|
65
88
|
end
|
66
89
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
module Helper
|
7
|
+
module ClassDefinition
|
8
|
+
extend NodePattern::Macros
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def_node_matcher :class_definition?, <<~PATTERN
|
12
|
+
{
|
13
|
+
class module sclass
|
14
|
+
(block
|
15
|
+
(send (const {nil? cbase} {:Class :Module}) :new)
|
16
|
+
args
|
17
|
+
_
|
18
|
+
)
|
19
|
+
}
|
20
|
+
PATTERN
|
21
|
+
|
22
|
+
def in_class_definition?(node)
|
23
|
+
node.each_ancestor(:class, :module, :sclass, :block).any? do |a|
|
24
|
+
class_definition?(a)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
module Helper
|
7
|
+
module TaskDefinition
|
8
|
+
extend NodePattern::Macros
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def_node_matcher :task_or_namespace?, <<-PATTERN
|
12
|
+
(block
|
13
|
+
(send _ {:task :namespace} ...)
|
14
|
+
args
|
15
|
+
_
|
16
|
+
)
|
17
|
+
PATTERN
|
18
|
+
|
19
|
+
def in_task_or_namespace?(node)
|
20
|
+
node.each_ancestor(:block).any? do |a|
|
21
|
+
task_or_namespace?(a)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -31,51 +31,16 @@ module RuboCop
|
|
31
31
|
# end
|
32
32
|
#
|
33
33
|
class MethodDefinitionInTask < Cop
|
34
|
-
MSG = 'Do not define a method in rake task, because it will be defined to the top level.'
|
35
|
-
|
36
|
-
def_node_matcher :bad_method?, <<~PATTERN
|
37
|
-
(send nil? :bad_method ...)
|
38
|
-
PATTERN
|
39
|
-
|
40
|
-
def_node_matcher :class_definition?, <<~PATTERN
|
41
|
-
{
|
42
|
-
class module sclass
|
43
|
-
(block
|
44
|
-
(send (const {nil? cbase} {:Class :Module}) :new)
|
45
|
-
args
|
46
|
-
_
|
47
|
-
)
|
48
|
-
}
|
49
|
-
PATTERN
|
50
|
-
|
51
|
-
def_node_matcher :task_or_namespace?, <<-PATTERN
|
52
|
-
(block
|
53
|
-
(send _ {:task :namespace} ...)
|
54
|
-
args
|
55
|
-
_
|
56
|
-
)
|
57
|
-
PATTERN
|
34
|
+
MSG = 'Do not define a method in rake task, because it will be defined to the top level.'
|
58
35
|
|
59
36
|
def on_def(node)
|
60
|
-
return if in_class_definition?(node)
|
61
|
-
return unless in_task_or_namespace?(node)
|
37
|
+
return if Helper::ClassDefinition.in_class_definition?(node)
|
38
|
+
return unless Helper::TaskDefinition.in_task_or_namespace?(node)
|
62
39
|
|
63
40
|
add_offense(node)
|
64
41
|
end
|
65
42
|
|
66
43
|
alias on_defs on_def
|
67
|
-
|
68
|
-
private def in_class_definition?(node)
|
69
|
-
node.each_ancestor(:class, :module, :sclass, :block).any? do |a|
|
70
|
-
class_definition?(a)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private def in_task_or_namespace?(node)
|
75
|
-
node.each_ancestor(:block).any? do |a|
|
76
|
-
task_or_namespace?(a)
|
77
|
-
end
|
78
|
-
end
|
79
44
|
end
|
80
45
|
end
|
81
46
|
end
|
data/lib/rubocop/rake.rb
CHANGED
data/lib/rubocop/rake/version.rb
CHANGED
data/rubocop-rake.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/rubocop/rake/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
@@ -8,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
8
10
|
|
9
11
|
spec.summary = %q{A RuboCop plugin for Rake}
|
10
12
|
spec.description = %q{A RuboCop plugin for Rake}
|
11
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/rubocop-hq/rubocop-rake"
|
12
14
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
13
15
|
spec.licenses = ['MIT']
|
14
16
|
|
@@ -16,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
16
18
|
|
17
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
20
|
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
-
spec.metadata["changelog_uri"] = "https://github.com/
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/rubocop-hq/rubocop-rake/blob/master/CHANGELOG.md"
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
27
|
end
|
26
28
|
spec.bindir = "exe"
|
@@ -29,4 +31,3 @@ Gem::Specification.new do |spec|
|
|
29
31
|
|
30
32
|
spec.add_runtime_dependency 'rubocop'
|
31
33
|
end
|
32
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -33,6 +33,8 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
35
|
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".rubocop_todo.yml"
|
36
38
|
- ".travis.yml"
|
37
39
|
- CHANGELOG.md
|
38
40
|
- Gemfile
|
@@ -43,21 +45,24 @@ files:
|
|
43
45
|
- bin/setup
|
44
46
|
- config/default.yml
|
45
47
|
- lib/rubocop-rake.rb
|
48
|
+
- lib/rubocop/cop/rake/class_definition_in_task.rb
|
46
49
|
- lib/rubocop/cop/rake/desc.rb
|
50
|
+
- lib/rubocop/cop/rake/helper/class_definition.rb
|
51
|
+
- lib/rubocop/cop/rake/helper/task_definition.rb
|
47
52
|
- lib/rubocop/cop/rake/method_definition_in_task.rb
|
48
53
|
- lib/rubocop/cop/rake_cops.rb
|
49
54
|
- lib/rubocop/rake.rb
|
50
55
|
- lib/rubocop/rake/inject.rb
|
51
56
|
- lib/rubocop/rake/version.rb
|
52
57
|
- rubocop-rake.gemspec
|
53
|
-
homepage: https://github.com/
|
58
|
+
homepage: https://github.com/rubocop-hq/rubocop-rake
|
54
59
|
licenses:
|
55
60
|
- MIT
|
56
61
|
metadata:
|
57
62
|
allowed_push_host: https://rubygems.org
|
58
|
-
homepage_uri: https://github.com/
|
59
|
-
source_code_uri: https://github.com/
|
60
|
-
changelog_uri: https://github.com/
|
63
|
+
homepage_uri: https://github.com/rubocop-hq/rubocop-rake
|
64
|
+
source_code_uri: https://github.com/rubocop-hq/rubocop-rake
|
65
|
+
changelog_uri: https://github.com/rubocop-hq/rubocop-rake/blob/master/CHANGELOG.md
|
61
66
|
post_install_message:
|
62
67
|
rdoc_options: []
|
63
68
|
require_paths:
|