rubocop-gemfile 0.1.0.beta1 → 0.1.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/config/default.yml +5 -0
- data/lib/rubocop/cop/gemfile/group_type.rb +13 -10
- data/lib/rubocop/cop/gemfile/single_group.rb +2 -2
- data/lib/rubocop/cop/gemfile/sort_gem_ascending.rb +114 -0
- data/lib/rubocop/gemfile.rb +1 -0
- data/lib/rubocop/gemfile/version.rb +1 -1
- data/lib/tasks/yard.rake +7 -0
- data/rubocop-gemfile.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a0697ca088fd3ff185890ccfb0d280f8fa2d3b4
|
4
|
+
data.tar.gz: 25fe1ed50f3818b478ecb14d87f7d4cecd3ed46b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a2f20800fa4c82582b5d3d6296836066c8cf753f45bd1ebccb05a7662a695297e184c805502fd49db833eb8cb18b9e14dc648642ce6edb329136c371a85815
|
7
|
+
data.tar.gz: 319858fc8bded038f97547e81a5ba89b33cfb17971d34b1979f2023e11a8e6ac145675d7b8b96c3f47086c532b9a1e80da86136b71def7725a4fc03573354912
|
data/Rakefile
CHANGED
data/config/default.yml
CHANGED
@@ -6,8 +6,7 @@ module RuboCop
|
|
6
6
|
# This cop makes sure that `group` has symbol group name
|
7
7
|
#
|
8
8
|
# @example
|
9
|
-
#
|
10
|
-
# EnforcedStyle: symbol
|
9
|
+
# # EnforcedStyle: symbol
|
11
10
|
#
|
12
11
|
# # bad
|
13
12
|
# group "test" do
|
@@ -23,7 +22,7 @@ module RuboCop
|
|
23
22
|
# gem "rspec-rails"
|
24
23
|
# end
|
25
24
|
#
|
26
|
-
# EnforcedStyle: single_quotes
|
25
|
+
# # EnforcedStyle: single_quotes
|
27
26
|
#
|
28
27
|
# # bad
|
29
28
|
# group :test do
|
@@ -39,7 +38,7 @@ module RuboCop
|
|
39
38
|
# gem "rspec-rails"
|
40
39
|
# end
|
41
40
|
#
|
42
|
-
# EnforcedStyle: double_quotes
|
41
|
+
# # EnforcedStyle: double_quotes
|
43
42
|
#
|
44
43
|
# # bad
|
45
44
|
# group :test do
|
@@ -57,6 +56,10 @@ module RuboCop
|
|
57
56
|
class GroupType < Cop
|
58
57
|
MSG = 'Use %s group'.freeze
|
59
58
|
|
59
|
+
ENFORCED_STYLE_SYMBOL = "symbol".freeze
|
60
|
+
ENFORCED_STYLE_DOUBLE_QUOTES = "double_quotes".freeze
|
61
|
+
ENFORCED_STYLE_SINGLE_QUOTES = "single_quotes".freeze
|
62
|
+
|
60
63
|
def on_send(node)
|
61
64
|
_, method_name, *args = *node
|
62
65
|
|
@@ -71,11 +74,11 @@ module RuboCop
|
|
71
74
|
|
72
75
|
args.each do |arg|
|
73
76
|
case enforced_style
|
74
|
-
when
|
77
|
+
when ENFORCED_STYLE_SYMBOL
|
75
78
|
add_offense(node, arg.loc.expression, message) if arg.str_type?
|
76
|
-
when
|
79
|
+
when ENFORCED_STYLE_DOUBLE_QUOTES
|
77
80
|
add_offense(node, arg.loc.expression, message) if arg.sym_type? || single_quotes?(arg)
|
78
|
-
when
|
81
|
+
when ENFORCED_STYLE_SINGLE_QUOTES
|
79
82
|
add_offense(node, arg.loc.expression, message) if arg.sym_type? || double_quotes?(arg)
|
80
83
|
end
|
81
84
|
end
|
@@ -85,21 +88,21 @@ module RuboCop
|
|
85
88
|
_receiver, _method_name, *args = *node
|
86
89
|
|
87
90
|
case cop_config["EnforcedStyle"]
|
88
|
-
when
|
91
|
+
when ENFORCED_STYLE_SYMBOL
|
89
92
|
lambda do |corrector|
|
90
93
|
args.each do |arg|
|
91
94
|
content = arg_content(arg)
|
92
95
|
corrector.replace(arg_location(arg), to_symbol_literal(content)) if content
|
93
96
|
end
|
94
97
|
end
|
95
|
-
when
|
98
|
+
when ENFORCED_STYLE_DOUBLE_QUOTES
|
96
99
|
lambda do |corrector|
|
97
100
|
args.each do |arg|
|
98
101
|
content = arg_content(arg)
|
99
102
|
corrector.replace(arg_location(arg), content.inspect) if content
|
100
103
|
end
|
101
104
|
end
|
102
|
-
when
|
105
|
+
when ENFORCED_STYLE_SINGLE_QUOTES
|
103
106
|
lambda do |corrector|
|
104
107
|
args.each do |arg|
|
105
108
|
content = arg_content(arg)
|
@@ -23,12 +23,12 @@ module RuboCop
|
|
23
23
|
|
24
24
|
return unless method_name == :group
|
25
25
|
|
26
|
-
add_offense(node,
|
26
|
+
add_offense(node, args_location(args)) if args.length >= 2
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def
|
31
|
+
def args_location(args)
|
32
32
|
begin_pos = args.first.loc.begin.begin_pos
|
33
33
|
end_pos = args.last.loc.expression.end_pos
|
34
34
|
Parser::Source::Range.new(args.first.loc.expression.source_buffer, begin_pos, end_pos)
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemfile
|
6
|
+
# This cop makes sure that `gem` is sorted by ascending
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # TopGems: []
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# gem "sass-rails"
|
13
|
+
# gem "coffee-rails"
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# gem "coffee-rails"
|
17
|
+
# gem "sass-rails"
|
18
|
+
#
|
19
|
+
# # TopGems:
|
20
|
+
# # - rails
|
21
|
+
#
|
22
|
+
# # bad
|
23
|
+
# gem "coffee-rails"
|
24
|
+
# gem "rails"
|
25
|
+
# gem "sass-rails"
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# gem "rails"
|
29
|
+
# gem "coffee-rails"
|
30
|
+
# gem "sass-rails"
|
31
|
+
class SortGemAscending < Cop
|
32
|
+
MSG = "gem should be sorted by ascending".freeze
|
33
|
+
|
34
|
+
def on_begin(node)
|
35
|
+
gems = string_arg_gems(node)
|
36
|
+
|
37
|
+
gems.each_cons(2) do |gem1, gem2|
|
38
|
+
gem_name1 = gem_name(gem1)
|
39
|
+
gem_name2 = gem_name(gem2)
|
40
|
+
|
41
|
+
if !top_gem?(gem1) && top_gem?(gem2)
|
42
|
+
add_offense(node, gem2.loc.expression, "gem '#{gem_name2}' should be top of Gemfile")
|
43
|
+
elsif top_gem?(gem1) && !top_gem?(gem2)
|
44
|
+
# nop
|
45
|
+
else
|
46
|
+
add_offense(node, gem2.loc.expression) if gem_name1 > gem_name2
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def autocorrect(node)
|
52
|
+
lambda do |corrector|
|
53
|
+
gems = string_arg_gems(node)
|
54
|
+
sorted_gems = gems.sort_by do |gem|
|
55
|
+
sort_key = top_gem?(gem) ? 0 : 1
|
56
|
+
[sort_key, gem_name(gem)]
|
57
|
+
end
|
58
|
+
|
59
|
+
gems_enum = gems.to_enum
|
60
|
+
sorted_gems_enum = sorted_gems.to_enum
|
61
|
+
|
62
|
+
loop do
|
63
|
+
gem = gems_enum.next
|
64
|
+
sorted_gem = sorted_gems_enum.next
|
65
|
+
|
66
|
+
unless gem == sorted_gem
|
67
|
+
corrector.replace(gem.loc.expression, sorted_gem.source)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def string_arg_gems(node)
|
76
|
+
gems = node.children.select { |n| gem_type?(n) }
|
77
|
+
gems.select { |gem| gem_name(gem) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def gem_type?(node)
|
81
|
+
_, method_name, *_args = *node
|
82
|
+
method_name == :gem
|
83
|
+
end
|
84
|
+
|
85
|
+
def gem_name(node)
|
86
|
+
_, method_name, *args = *node
|
87
|
+
|
88
|
+
return nil unless method_name == :gem
|
89
|
+
|
90
|
+
arg = args.first
|
91
|
+
return nil unless arg
|
92
|
+
return nil unless arg.str_type?
|
93
|
+
|
94
|
+
arg.str_content
|
95
|
+
end
|
96
|
+
|
97
|
+
def top_gems
|
98
|
+
@top_gems ||= Array(cop_config["TopGems"])
|
99
|
+
end
|
100
|
+
|
101
|
+
def top_gem?(gem)
|
102
|
+
gem_name =
|
103
|
+
if gem.is_a?(RuboCop::Node)
|
104
|
+
gem_name(gem)
|
105
|
+
else
|
106
|
+
gem
|
107
|
+
end
|
108
|
+
|
109
|
+
top_gems.include?(gem_name)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/rubocop/gemfile.rb
CHANGED
data/lib/tasks/yard.rake
ADDED
data/rubocop-gemfile.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-gemfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sue445
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.5.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Code style checking for Gemfile
|
84
98
|
email:
|
85
99
|
- sue445@sue445.net
|
@@ -100,9 +114,11 @@ files:
|
|
100
114
|
- lib/rubocop-gemfile.rb
|
101
115
|
- lib/rubocop/cop/gemfile/group_type.rb
|
102
116
|
- lib/rubocop/cop/gemfile/single_group.rb
|
117
|
+
- lib/rubocop/cop/gemfile/sort_gem_ascending.rb
|
103
118
|
- lib/rubocop/gemfile.rb
|
104
119
|
- lib/rubocop/gemfile/inject.rb
|
105
120
|
- lib/rubocop/gemfile/version.rb
|
121
|
+
- lib/tasks/yard.rake
|
106
122
|
- rubocop-gemfile.gemspec
|
107
123
|
homepage:
|
108
124
|
licenses:
|