rubocop-gemfile 0.1.0.beta2 → 0.1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +24 -2
- data/Gemfile +1 -0
- data/README.md +23 -5
- data/Rakefile +5 -4
- data/bin/console +4 -3
- data/config/default.yml +1 -0
- data/lib/rubocop-gemfile.rb +2 -1
- data/lib/rubocop/cop/gemfile/concerns/group_type/autocorrect.rb +51 -0
- data/lib/rubocop/cop/gemfile/concerns/group_type/on_send.rb +29 -0
- data/lib/rubocop/cop/gemfile/concerns/sort_gem_ascending/autocorrect.rb +87 -0
- data/lib/rubocop/cop/gemfile/concerns/sort_gem_ascending/on_begin.rb +29 -0
- data/lib/rubocop/cop/gemfile/group_type.rb +54 -39
- data/lib/rubocop/cop/gemfile/single_group.rb +2 -1
- data/lib/rubocop/cop/gemfile/sort_gem_ascending.rb +10 -23
- data/lib/rubocop/gemfile.rb +7 -6
- data/lib/rubocop/gemfile/inject.rb +1 -0
- data/lib/rubocop/gemfile/version.rb +2 -1
- data/lib/tasks/yard.rake +4 -5
- data/rubocop-gemfile.gemspec +22 -17
- metadata +51 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 296889335d1d22241595424e4eeb26a63c8ac986
|
4
|
+
data.tar.gz: 2de481849d3d7eb3996ee75df8e53196e9dcf394
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894957c96dd30e230159b32752e1ae308c7c224a13e0d968b58852876a5d6dab10c2ac1ad93da3eb97705d392732aed0eb68ddd7bcc7da145981e4408effd4b0
|
7
|
+
data.tar.gz: 5ff3a2a22f2b724bdce2e6658a7f530dc15d4b8acecdf271576c7defda6a2c873d8e267bb88e55975c3918c2b79bde5b4a9b891f0926d4f85a8d6617687e6d23
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: D4zrX3740AuzEhmB3Xh5si0GkEjp00NLP
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
|
5
|
-
|
4
|
+
- 2.2
|
5
|
+
- 2.3.1
|
6
|
+
- ruby-head
|
7
|
+
before_install:
|
8
|
+
- gem update --system
|
9
|
+
- gem install bundler -v 1.12.5
|
10
|
+
bundler_args: "--jobs=2"
|
11
|
+
cache: bundler
|
12
|
+
before_script:
|
13
|
+
- export CODECLIMATE_REPO_TOKEN=6e639271e2b71c8d880f7449a0d56a7029f75cf9f468abcae63b66f48e61d249
|
14
|
+
- export CI=true
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
- bundle exec rubocop
|
18
|
+
branches:
|
19
|
+
only:
|
20
|
+
- master
|
21
|
+
notifications:
|
22
|
+
email: false
|
23
|
+
slack:
|
24
|
+
secure: isiRJb/vgIL7NwiunQGsZMOdOPiKGPRl6KqC65RkYKc89bhXnDf/70oZsLYCgRrsM5ClEL/QnNivvohdjWwvxPQgNbHmoXh5egZ2/19nh0tb0x7DWyQ3uIslUWRBsu9GAugKK0JSUiBi5iK3NqipI/GQgGtN+gxD98IXMqkD29V+YO3Ysfa9vKEnS1ijy8KVhMOASj+9+5HEOXOPVWIvZ+Gjgx9D/MOaz/ALJ6xUuVAesc2XqSrYqOqseKArRq4qeslqb3RE4kWUmw0QGJG77hryyVw2oI5sXcfKOzeqduV/GzOq7eP1A0GDd7DgIkWnW0T+hiCG789fUA91g09F9ln9IdDBnJ/1M4UKf0Nj+AmWwGUG2JmRUsjVns5buyCduKcxkCr82NxDH27O/jU+KvXHTjjWByd7ABuIaWHs5Y9SkP7JMeyiqzIanhnuo0wgh/O1p9uEjpF0vS70qAkib9ph9HC6ZbfIp8lAoUNiQkrqlrbB624d8QVgqX9X9vTFVBmeRUVEWq3cBg99D+Ryemhzcfakq1PesoKuzsemV2E0mhxW6hOdZKAiIucvY8vEIPkpTKaZ6hjQBRoGKyMPRbwhVkRo3J+sHrGweWTjFT53C1lVDgC2s7ZYfrMOXi/Jf8AGJqCl0aTzIsn29IUwhDJR7sNixufLkU4ioSra8t0=
|
25
|
+
matrix:
|
26
|
+
allow_failures:
|
27
|
+
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
# RuboCop::Gemfile
|
2
2
|
|
3
|
-
|
3
|
+
Code style checking for Gemfile, as an extension to [Rubocop](https://github.com/bbatsov/rubocop)
|
4
4
|
|
5
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/rubocop-gemfile.svg)](https://badge.fury.io/rb/rubocop-gemfile)
|
6
|
+
[![Build Status](https://travis-ci.org/sue445/rubocop-gemfile.svg?branch=master)](https://travis-ci.org/sue445/rubocop-gemfile)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/sue445/rubocop-gemfile/badges/gpa.svg)](https://codeclimate.com/github/sue445/rubocop-gemfile)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/github/sue445/rubocop-gemfile/badge.svg?branch=master)](https://coveralls.io/github/sue445/rubocop-gemfile?branch=master)
|
9
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/sue445/rubocop-gemfile.svg)](https://gemnasium.com/github.com/sue445/rubocop-gemfile)
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application's Gemfile:
|
10
14
|
|
11
15
|
```ruby
|
12
|
-
|
16
|
+
group :development do
|
17
|
+
gem 'rubocop-gemfile', require: false
|
18
|
+
end
|
13
19
|
```
|
14
20
|
|
15
21
|
And then execute:
|
@@ -22,7 +28,19 @@ Or install it yourself as:
|
|
22
28
|
|
23
29
|
## Usage
|
24
30
|
|
25
|
-
|
31
|
+
### RuboCop configuration file
|
32
|
+
|
33
|
+
Put this into your `.rubocop.yml`.
|
34
|
+
|
35
|
+
```
|
36
|
+
require: rubocop-gemfile
|
37
|
+
```
|
38
|
+
|
39
|
+
## The Cops
|
40
|
+
see these.
|
41
|
+
|
42
|
+
* [config/default.yml](config/default.yml)
|
43
|
+
* [lib/rubocop/cop/gemfile/](lib/rubocop/cop/gemfile/)
|
26
44
|
|
27
45
|
## Development
|
28
46
|
|
@@ -32,7 +50,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
50
|
|
33
51
|
## Contributing
|
34
52
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/rubocop-gemfile.
|
36
54
|
|
37
55
|
|
38
56
|
## License
|
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
|
-
task :
|
7
|
+
task default: :spec
|
7
8
|
|
8
|
-
Dir[
|
9
|
+
Dir['lib/tasks/*.rake'].each { |f| load f }
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'rubocop/gemfile'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "rubocop/gemfile"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/config/default.yml
CHANGED
data/lib/rubocop-gemfile.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rubocop/gemfile'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemfile
|
6
|
+
module Concerns
|
7
|
+
module GroupType
|
8
|
+
module Autocorrect # rubocop:disable Style/Documentation
|
9
|
+
private
|
10
|
+
|
11
|
+
def correct_symbol_group(args)
|
12
|
+
lambda do |corrector|
|
13
|
+
args.each do |arg|
|
14
|
+
content = arg_content(arg)
|
15
|
+
if content
|
16
|
+
corrector.replace(arg_location(arg),
|
17
|
+
to_symbol_literal(content))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def correct_double_quote_group(args)
|
24
|
+
lambda do |corrector|
|
25
|
+
args.each do |arg|
|
26
|
+
content = arg_content(arg)
|
27
|
+
if content
|
28
|
+
corrector.replace(arg_location(arg),
|
29
|
+
content.inspect)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def correct_symbol_quote_group(args)
|
36
|
+
lambda do |corrector|
|
37
|
+
args.each do |arg|
|
38
|
+
content = arg_content(arg)
|
39
|
+
if content
|
40
|
+
corrector.replace(arg_location(arg),
|
41
|
+
to_string_literal(content))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module RuboCop
|
3
|
+
module Cop
|
4
|
+
module Gemfile
|
5
|
+
module Concerns
|
6
|
+
module GroupType
|
7
|
+
module OnSend # rubocop:disable Style/Documentation
|
8
|
+
private
|
9
|
+
|
10
|
+
def check_symbol_group(arg, node, message)
|
11
|
+
return if exclude_type?(arg) || arg.sym_type?
|
12
|
+
add_offense(node, arg.loc.expression, message)
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_double_quotes_group(arg, node, message)
|
16
|
+
return if exclude_type?(arg) || double_quotes?(arg)
|
17
|
+
add_offense(node, arg.loc.expression, message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_single_quotes_group(arg, node, message)
|
21
|
+
return if exclude_type?(arg) || single_quotes?(arg)
|
22
|
+
add_offense(node, arg.loc.expression, message)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module RuboCop
|
3
|
+
module Cop
|
4
|
+
module Gemfile
|
5
|
+
module Concerns
|
6
|
+
module SortGemAscending
|
7
|
+
module Autocorrect # rubocop:disable Style/Documentation
|
8
|
+
private
|
9
|
+
|
10
|
+
def correct_gems(corrector, gems, sorted_gems)
|
11
|
+
gems_enum = gems.to_enum
|
12
|
+
sorted_gems_enum = sorted_gems.to_enum
|
13
|
+
|
14
|
+
loop do
|
15
|
+
gem = gems_enum.next
|
16
|
+
sorted_gem = sorted_gems_enum.next
|
17
|
+
|
18
|
+
next if gem == sorted_gem
|
19
|
+
|
20
|
+
range = range_with_prev_comment(gem)
|
21
|
+
source = source_with_prev_comment(sorted_gem)
|
22
|
+
corrector.replace(range, source)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def source_with_prev_comment(gem)
|
27
|
+
comments = line_comments[gem.loc.line - 1]
|
28
|
+
return gem.source unless comments
|
29
|
+
|
30
|
+
lines = comments.map(&:text)
|
31
|
+
lines << gem.source
|
32
|
+
lines.join("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def range_with_prev_comment(gem)
|
36
|
+
comments = line_comments[gem.loc.line - 1]
|
37
|
+
return gem.loc.expression unless comments
|
38
|
+
|
39
|
+
Parser::Source::Range.new(
|
40
|
+
gem.loc.expression.source_buffer,
|
41
|
+
begin_pos(comments.first), end_pos(gem)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def begin_pos(node)
|
46
|
+
node.loc.expression.begin.begin_pos
|
47
|
+
end
|
48
|
+
|
49
|
+
def end_pos(node)
|
50
|
+
node.loc.expression.end_pos
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Hash{Integer, Array<Parser::Source::Comment>}]
|
54
|
+
def line_comments
|
55
|
+
return @line_comments if @line_comments
|
56
|
+
|
57
|
+
@line_comments =
|
58
|
+
comment_groups.each_with_object({}) do |comments, hash|
|
59
|
+
comment_end_line = comments.last.loc.line
|
60
|
+
hash[comment_end_line] = comments
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def comment_groups
|
65
|
+
comment_groups = []
|
66
|
+
work = []
|
67
|
+
processed_source.comments.each do |comment|
|
68
|
+
if work.empty? || continuously_line?(work.last, comment)
|
69
|
+
work << comment
|
70
|
+
else
|
71
|
+
comment_groups << work
|
72
|
+
work = [comment]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
comment_groups << work unless work.empty?
|
76
|
+
comment_groups
|
77
|
+
end
|
78
|
+
|
79
|
+
def continuously_line?(first, second)
|
80
|
+
first.loc.line + 1 == second.loc.line
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module RuboCop
|
3
|
+
module Cop
|
4
|
+
module Gemfile
|
5
|
+
module Concerns
|
6
|
+
module SortGemAscending
|
7
|
+
module OnBegin # rubocop:disable Style/Documentation
|
8
|
+
private
|
9
|
+
|
10
|
+
def check_gems_order(node, gem1, gem2)
|
11
|
+
if top_gem?(gem1) == top_gem?(gem2)
|
12
|
+
check_gems_order_in_same_priority(node, gem1, gem2)
|
13
|
+
elsif !top_gem?(gem1) && top_gem?(gem2)
|
14
|
+
add_offense(node, gem2.loc.expression,
|
15
|
+
"gem '#{gem_name(gem2)}' should be top of Gemfile")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_gems_order_in_same_priority(node, gem1, gem2)
|
20
|
+
gem_name1 = gem_name(gem1)
|
21
|
+
gem_name2 = gem_name(gem2)
|
22
|
+
add_offense(node, gem2.loc.expression) if gem_name1 > gem_name2
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rubocop/cop/gemfile/concerns/group_type/on_send'
|
4
|
+
require 'rubocop/cop/gemfile/concerns/group_type/autocorrect'
|
5
|
+
|
3
6
|
module RuboCop
|
4
7
|
module Cop
|
5
8
|
module Gemfile
|
@@ -56,64 +59,66 @@ module RuboCop
|
|
56
59
|
class GroupType < Cop
|
57
60
|
MSG = 'Use %s group'.freeze
|
58
61
|
|
59
|
-
ENFORCED_STYLE_SYMBOL =
|
60
|
-
ENFORCED_STYLE_DOUBLE_QUOTES =
|
61
|
-
ENFORCED_STYLE_SINGLE_QUOTES =
|
62
|
+
ENFORCED_STYLE_SYMBOL = 'symbol'.freeze
|
63
|
+
ENFORCED_STYLE_DOUBLE_QUOTES = 'double_quotes'.freeze
|
64
|
+
ENFORCED_STYLE_SINGLE_QUOTES = 'single_quotes'.freeze
|
65
|
+
|
66
|
+
VALIDATION_ENFORCED_STYLE_MSG = '%s is not unsupport'.freeze
|
67
|
+
|
68
|
+
include Concerns::GroupType::OnSend
|
69
|
+
include Concerns::GroupType::Autocorrect
|
62
70
|
|
63
71
|
def on_send(node)
|
64
72
|
_, method_name, *args = *node
|
65
73
|
|
66
74
|
return unless method_name == :group
|
67
75
|
|
68
|
-
enforced_style = cop_config["EnforcedStyle"]
|
69
|
-
unless cop_config["SupportedStyles"].include?(enforced_style)
|
70
|
-
raise ValidationError, "EnforcedStyle(#{enforced_style}) is not neither double_quotes, single_quotes or symbol"
|
71
|
-
end
|
72
|
-
|
73
|
-
message = MSG % enforced_style
|
74
|
-
|
75
76
|
args.each do |arg|
|
76
|
-
|
77
|
-
when ENFORCED_STYLE_SYMBOL
|
78
|
-
add_offense(node, arg.loc.expression, message) if arg.str_type?
|
79
|
-
when ENFORCED_STYLE_DOUBLE_QUOTES
|
80
|
-
add_offense(node, arg.loc.expression, message) if arg.sym_type? || single_quotes?(arg)
|
81
|
-
when ENFORCED_STYLE_SINGLE_QUOTES
|
82
|
-
add_offense(node, arg.loc.expression, message) if arg.sym_type? || double_quotes?(arg)
|
83
|
-
end
|
77
|
+
check_group_argument(arg, node)
|
84
78
|
end
|
85
79
|
end
|
86
80
|
|
87
81
|
def autocorrect(node)
|
88
82
|
_receiver, _method_name, *args = *node
|
89
83
|
|
90
|
-
case
|
84
|
+
case enforced_style
|
91
85
|
when ENFORCED_STYLE_SYMBOL
|
92
|
-
|
93
|
-
args.each do |arg|
|
94
|
-
content = arg_content(arg)
|
95
|
-
corrector.replace(arg_location(arg), to_symbol_literal(content)) if content
|
96
|
-
end
|
97
|
-
end
|
86
|
+
correct_symbol_group(args)
|
98
87
|
when ENFORCED_STYLE_DOUBLE_QUOTES
|
99
|
-
|
100
|
-
args.each do |arg|
|
101
|
-
content = arg_content(arg)
|
102
|
-
corrector.replace(arg_location(arg), content.inspect) if content
|
103
|
-
end
|
104
|
-
end
|
88
|
+
correct_double_quote_group(args)
|
105
89
|
when ENFORCED_STYLE_SINGLE_QUOTES
|
106
|
-
|
107
|
-
args.each do |arg|
|
108
|
-
content = arg_content(arg)
|
109
|
-
corrector.replace(arg_location(arg), to_string_literal(content)) if content
|
110
|
-
end
|
111
|
-
end
|
90
|
+
correct_symbol_quote_group(args)
|
112
91
|
end
|
113
92
|
end
|
114
93
|
|
115
94
|
private
|
116
95
|
|
96
|
+
def check_group_argument(arg, node)
|
97
|
+
message = MSG % enforced_style
|
98
|
+
|
99
|
+
case enforced_style
|
100
|
+
when ENFORCED_STYLE_SYMBOL
|
101
|
+
check_symbol_group(arg, node, message)
|
102
|
+
when ENFORCED_STYLE_DOUBLE_QUOTES
|
103
|
+
check_double_quotes_group(arg, node, message)
|
104
|
+
when ENFORCED_STYLE_SINGLE_QUOTES
|
105
|
+
check_single_quotes_group(arg, node, message)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def enforced_style
|
110
|
+
return @enforced_style if @enforced_style
|
111
|
+
|
112
|
+
@enforced_style = cop_config['EnforcedStyle']
|
113
|
+
|
114
|
+
unless cop_config['SupportedStyles'].include?(@enforced_style)
|
115
|
+
message = VALIDATION_ENFORCED_STYLE_MSG % @enforced_style
|
116
|
+
raise ValidationError, message
|
117
|
+
end
|
118
|
+
|
119
|
+
@enforced_style
|
120
|
+
end
|
121
|
+
|
117
122
|
def single_quotes?(arg)
|
118
123
|
quotes?(arg, "'")
|
119
124
|
end
|
@@ -123,13 +128,23 @@ module RuboCop
|
|
123
128
|
end
|
124
129
|
|
125
130
|
def quotes?(arg, quote)
|
126
|
-
arg.str_type?
|
131
|
+
return false unless arg.str_type?
|
132
|
+
|
133
|
+
arg_prev_position = arg.loc.begin.begin_pos
|
134
|
+
arg.loc.expression.source_buffer.source[arg_prev_position] == quote
|
135
|
+
end
|
136
|
+
|
137
|
+
def exclude_type?(arg)
|
138
|
+
return false if arg.str_type? || arg.sym_type?
|
139
|
+
true
|
127
140
|
end
|
128
141
|
|
129
142
|
def arg_location(arg)
|
130
143
|
begin_pos = arg.loc.begin.begin_pos
|
131
144
|
end_pos = arg.loc.expression.end_pos
|
132
|
-
|
145
|
+
|
146
|
+
Parser::Source::Range.new(arg.loc.expression.source_buffer,
|
147
|
+
begin_pos, end_pos)
|
133
148
|
end
|
134
149
|
|
135
150
|
def arg_content(arg)
|
@@ -31,7 +31,8 @@ module RuboCop
|
|
31
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
|
-
Parser::Source::Range.new(args.first.loc.expression.source_buffer,
|
34
|
+
Parser::Source::Range.new(args.first.loc.expression.source_buffer,
|
35
|
+
begin_pos, end_pos)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rubocop/cop/gemfile/concerns/sort_gem_ascending/autocorrect'
|
4
|
+
require 'rubocop/cop/gemfile/concerns/sort_gem_ascending/on_begin'
|
5
|
+
|
3
6
|
module RuboCop
|
4
7
|
module Cop
|
5
8
|
module Gemfile
|
@@ -29,22 +32,16 @@ module RuboCop
|
|
29
32
|
# gem "coffee-rails"
|
30
33
|
# gem "sass-rails"
|
31
34
|
class SortGemAscending < Cop
|
32
|
-
MSG =
|
35
|
+
MSG = 'gem should be sorted by ascending'.freeze
|
36
|
+
|
37
|
+
include RuboCop::Cop::Gemfile::Concerns::SortGemAscending::Autocorrect
|
38
|
+
include RuboCop::Cop::Gemfile::Concerns::SortGemAscending::OnBegin
|
33
39
|
|
34
40
|
def on_begin(node)
|
35
41
|
gems = string_arg_gems(node)
|
36
42
|
|
37
43
|
gems.each_cons(2) do |gem1, gem2|
|
38
|
-
|
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
|
44
|
+
check_gems_order(node, gem1, gem2)
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
@@ -56,17 +53,7 @@ module RuboCop
|
|
56
53
|
[sort_key, gem_name(gem)]
|
57
54
|
end
|
58
55
|
|
59
|
-
|
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
|
56
|
+
correct_gems(corrector, gems, sorted_gems)
|
70
57
|
end
|
71
58
|
end
|
72
59
|
|
@@ -95,7 +82,7 @@ module RuboCop
|
|
95
82
|
end
|
96
83
|
|
97
84
|
def top_gems
|
98
|
-
@top_gems ||= Array(cop_config[
|
85
|
+
@top_gems ||= Array(cop_config['TopGems'])
|
99
86
|
end
|
100
87
|
|
101
88
|
def top_gem?(gem)
|
data/lib/rubocop/gemfile.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rubocop'
|
3
|
+
require 'rubocop/gemfile/version'
|
4
|
+
require 'rubocop/gemfile/inject'
|
4
5
|
|
5
6
|
RuboCop::Gemfile::Inject.defaults!
|
6
7
|
|
7
8
|
# cops
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
9
|
+
require 'rubocop/cop/gemfile/single_group'
|
10
|
+
require 'rubocop/cop/gemfile/group_type'
|
11
|
+
require 'rubocop/cop/gemfile/sort_gem_ascending'
|
data/lib/tasks/yard.rake
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yard'
|
3
|
+
require 'yard/rake/yardoc_task'
|
3
4
|
YARD::Rake::YardocTask.new do |t|
|
4
|
-
t.files
|
5
|
-
t.options = []
|
6
|
-
t.options << '--debug' << '--verbose' if $trace
|
5
|
+
t.files = ['lib/**/*.rb']
|
7
6
|
end
|
data/rubocop-gemfile.gemspec
CHANGED
@@ -1,30 +1,35 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'rubocop/gemfile/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'rubocop-gemfile'
|
8
9
|
spec.version = RuboCop::Gemfile::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['sue445']
|
11
|
+
spec.email = ['sue445@sue445.net']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
|
15
|
-
|
16
|
-
spec.license = "MIT"
|
13
|
+
spec.summary = 'Code style checking for Gemfile'
|
14
|
+
spec.description = 'Code style checking for Gemfile'
|
15
|
+
spec.homepage = 'https://github.com/sue445/rubocop-gemfile'
|
16
|
+
spec.license = 'MIT'
|
17
17
|
|
18
|
-
spec.files
|
19
|
-
|
18
|
+
spec.files =
|
19
|
+
`git ls-files -z`
|
20
|
+
.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = 'exe'
|
20
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
22
24
|
|
23
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency 'rubocop', '>= 0.35.0'
|
24
26
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
28
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
29
|
+
spec.add_development_dependency 'coveralls'
|
30
|
+
spec.add_development_dependency 'pry-byebug'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.5.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '0.44.1'
|
34
|
+
spec.add_development_dependency 'yard'
|
30
35
|
end
|
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.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sue445
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: pry-byebug
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +108,20 @@ dependencies:
|
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: 3.5.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.44.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.44.1
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: yard
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,8 +143,10 @@ executables: []
|
|
101
143
|
extensions: []
|
102
144
|
extra_rdoc_files: []
|
103
145
|
files:
|
146
|
+
- ".coveralls.yml"
|
104
147
|
- ".gitignore"
|
105
148
|
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
106
150
|
- ".travis.yml"
|
107
151
|
- Gemfile
|
108
152
|
- LICENSE.txt
|
@@ -112,6 +156,10 @@ files:
|
|
112
156
|
- bin/setup
|
113
157
|
- config/default.yml
|
114
158
|
- lib/rubocop-gemfile.rb
|
159
|
+
- lib/rubocop/cop/gemfile/concerns/group_type/autocorrect.rb
|
160
|
+
- lib/rubocop/cop/gemfile/concerns/group_type/on_send.rb
|
161
|
+
- lib/rubocop/cop/gemfile/concerns/sort_gem_ascending/autocorrect.rb
|
162
|
+
- lib/rubocop/cop/gemfile/concerns/sort_gem_ascending/on_begin.rb
|
115
163
|
- lib/rubocop/cop/gemfile/group_type.rb
|
116
164
|
- lib/rubocop/cop/gemfile/single_group.rb
|
117
165
|
- lib/rubocop/cop/gemfile/sort_gem_ascending.rb
|
@@ -120,7 +168,7 @@ files:
|
|
120
168
|
- lib/rubocop/gemfile/version.rb
|
121
169
|
- lib/tasks/yard.rake
|
122
170
|
- rubocop-gemfile.gemspec
|
123
|
-
homepage:
|
171
|
+
homepage: https://github.com/sue445/rubocop-gemfile
|
124
172
|
licenses:
|
125
173
|
- MIT
|
126
174
|
metadata: {}
|