rubocop-rake 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +22 -0
- data/CHANGELOG.md +28 -0
- data/LICENSE +21 -0
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/rake/method_definition_in_task.rb +82 -0
- data/lib/rubocop/cop/rake_cops.rb +2 -1
- data/lib/rubocop/rake/version.rb +1 -1
- data/rubocop-rake.gemspec +2 -2
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8abee9ef7094059a116c1dcb7ef0c36c9494351fd14f5ee57d064b5736318fa4
|
4
|
+
data.tar.gz: 24e4b728616fb46f871d917712504961b36ee4aed7f993689af1d20812f54e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a47d61558777d3a42b5fc9e1dcc0ed5e12565cbf99fbadeef9a67eb9a9c604797986f52a1897c16c5eed1f7874590e56f916ebc8a0d44831d9c11d53bb1a310
|
7
|
+
data.tar.gz: eb65d73cbb79e4f1ab59bad336b7e23f236c221ff03cb46dd4418062f91c44fe0341a052334766dc382c195bfc678c6efdaa9a402175018160eb654020d0bba1
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.4.7
|
5
|
+
- 2.5.6
|
6
|
+
- 2.6.4
|
7
|
+
- ruby-head
|
8
|
+
|
9
|
+
cache: bundler
|
10
|
+
bundler_args: --jobs=4 --retry=3
|
11
|
+
sudo: false
|
12
|
+
|
13
|
+
|
14
|
+
before_install: 'gem update --system'
|
15
|
+
|
16
|
+
script:
|
17
|
+
- bundle exec rake
|
18
|
+
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
22
|
+
fast_finish: true
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
<!--
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
### Bug fixes
|
10
|
+
|
11
|
+
### Changes
|
12
|
+
|
13
|
+
-->
|
14
|
+
|
15
|
+
## 0.2.0 (2019-09-17)
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
* [#5](https://github.com/pocke/rubocop-rake): Add `Rake/MethodDefinitionInTask`. ([@pocke][])
|
20
|
+
|
21
|
+
## 0.1.0 (2019-09-04)
|
22
|
+
|
23
|
+
### New features
|
24
|
+
|
25
|
+
* The first release!
|
26
|
+
* Add `Rake/Desc`. ([@pocke][])
|
27
|
+
|
28
|
+
[@pocke]: https://github.com/pocke
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Masataka Pocke Kuwabara
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/config/default.yml
CHANGED
@@ -5,3 +5,11 @@ Rake/Desc:
|
|
5
5
|
Include:
|
6
6
|
- 'Rakefile'
|
7
7
|
- '**/*.rake'
|
8
|
+
|
9
|
+
Rake/MethodDefinitionInTask:
|
10
|
+
Description: 'Do not define a method in rake task, because it will be defined to the top level.'
|
11
|
+
Enabled: true
|
12
|
+
VersionAdded: '0.2.0'
|
13
|
+
Include:
|
14
|
+
- 'Rakefile'
|
15
|
+
- '**/*.rake'
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
# This cop detects method 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
|
+
# def helper_method
|
15
|
+
# do_something
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
# namespace :foo do
|
21
|
+
# def helper_method
|
22
|
+
# do_something
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # good - It is also defined to the top level,
|
27
|
+
# # but it looks expected behavior.
|
28
|
+
# def helper_method
|
29
|
+
# end
|
30
|
+
# task :foo do
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
class MethodDefinitionInTask < Cop
|
34
|
+
MSG = 'Do not define a method in rake task, because it will be defined to the top level.'.freeze
|
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
|
58
|
+
|
59
|
+
def on_def(node)
|
60
|
+
return if in_class_definition?(node)
|
61
|
+
return unless in_task_or_namespace?(node)
|
62
|
+
|
63
|
+
add_offense(node)
|
64
|
+
end
|
65
|
+
|
66
|
+
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
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/rubocop/rake/version.rb
CHANGED
data/rubocop-rake.gemspec
CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.summary = %q{A RuboCop plugin for Rake}
|
10
10
|
spec.description = %q{A RuboCop plugin for Rake}
|
11
11
|
spec.homepage = "https://github.com/pocke/rubocop-rake"
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
13
13
|
spec.licenses = ['MIT']
|
14
14
|
|
15
15
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
-
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/pocke/rubocop-rake/blob/master/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
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.2.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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -33,7 +33,10 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
35
|
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CHANGELOG.md
|
36
38
|
- Gemfile
|
39
|
+
- LICENSE
|
37
40
|
- README.md
|
38
41
|
- Rakefile
|
39
42
|
- bin/console
|
@@ -41,6 +44,7 @@ files:
|
|
41
44
|
- config/default.yml
|
42
45
|
- lib/rubocop-rake.rb
|
43
46
|
- lib/rubocop/cop/rake/desc.rb
|
47
|
+
- lib/rubocop/cop/rake/method_definition_in_task.rb
|
44
48
|
- lib/rubocop/cop/rake_cops.rb
|
45
49
|
- lib/rubocop/rake.rb
|
46
50
|
- lib/rubocop/rake/inject.rb
|
@@ -53,6 +57,7 @@ metadata:
|
|
53
57
|
allowed_push_host: https://rubygems.org
|
54
58
|
homepage_uri: https://github.com/pocke/rubocop-rake
|
55
59
|
source_code_uri: https://github.com/pocke/rubocop-rake
|
60
|
+
changelog_uri: https://github.com/pocke/rubocop-rake/blob/master/CHANGELOG.md
|
56
61
|
post_install_message:
|
57
62
|
rdoc_options: []
|
58
63
|
require_paths:
|
@@ -61,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
66
|
requirements:
|
62
67
|
- - ">="
|
63
68
|
- !ruby/object:Gem::Version
|
64
|
-
version: 2.
|
69
|
+
version: 2.4.0
|
65
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
71
|
requirements:
|
67
72
|
- - ">="
|