rubocop-git 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +26 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/bin/rubocop-git +5 -0
- data/hound.yml +242 -0
- data/lib/rubocop/git.rb +24 -0
- data/lib/rubocop/git/cli.rb +49 -0
- data/lib/rubocop/git/commit_file.rb +45 -0
- data/lib/rubocop/git/file_violation.rb +5 -0
- data/lib/rubocop/git/line.rb +8 -0
- data/lib/rubocop/git/patch.rb +36 -0
- data/lib/rubocop/git/pseudo_pull_request.rb +42 -0
- data/lib/rubocop/git/pseudo_resource.rb +6 -0
- data/lib/rubocop/git/runner.rb +89 -0
- data/lib/rubocop/git/style_checker.rb +43 -0
- data/lib/rubocop/git/style_guide.rb +54 -0
- data/lib/rubocop/git/version.rb +5 -0
- data/rubocop-git.gemspec +25 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e847268b1ab1d8961bb6afed3402f75cbc1abf60
|
4
|
+
data.tar.gz: 713c38e0742d3793d6234ab0ac8d971b3b821cae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ab7b0885da47ed39deb523fa5dbd7daac6b406b9ebf260982120fa071b8c340eca530e032a04ad959cd61cf1a4ae9d98913d0bb0126fcd87b4d0df5c93508f5
|
7
|
+
data.tar.gz: c3016b240f51a4645938202dc43c955ef91e95847d6881742bce4baca3ef7c6e9c11068ea005f94d6772f7266ebe7b6ad32f44315b85e5e8ad65afd5259e4f38
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2014 Masaki Takeuchi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
Some code is:
|
25
|
+
Copyright (c) 2014 thoughtbot, inc.
|
26
|
+
Released under the MIT License in Hound, https://github.com/thoughtbot/hound
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# RuboCop::Git
|
2
|
+
|
3
|
+
RuboCop for git diff.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubocop-git'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubocop-git
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Usage: rubocop-git [options]
|
22
|
+
-c, --config FILE Specify configuration file
|
23
|
+
-D, --display-cop-names Display cop names in offense messages
|
24
|
+
--cached git diff --cached
|
25
|
+
--staged synonym of --cached
|
26
|
+
--hound Hound compatibility mode (require rubocop 0.22.0)
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it ( https://github.com/m4i/rubocop-git/fork )
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/rubocop-git
ADDED
data/hound.yml
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- db/schema.rb
|
4
|
+
|
5
|
+
AccessorMethodName:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Alias:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
ArrayJoin:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
AsciiComments:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
AsciiIdentifiers:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Attr:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
BlockNesting:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
CaseEquality:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
CharacterLiteral:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
ClassLength:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
ClassVars:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
CollectionMethods:
|
39
|
+
PreferredMethods:
|
40
|
+
find: detect
|
41
|
+
reduce: inject
|
42
|
+
collect: map
|
43
|
+
find_all: select
|
44
|
+
|
45
|
+
ColonMethodCall:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
CommentAnnotation:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
CyclomaticComplexity:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Delegate:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
DeprecatedHashMethods:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Documentation:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
DotPosition:
|
64
|
+
EnforcedStyle: trailing
|
65
|
+
|
66
|
+
DoubleNegation:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
EmptyLiteral:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Encoding:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
EvenOdd:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
FileName:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
FlipFlop:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
FormatString:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
GlobalVars:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
IfUnlessModifier:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
IfWithSemicolon:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
Lambda:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
LambdaCall:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
LineEndConcatenation:
|
103
|
+
Enabled: false
|
104
|
+
|
105
|
+
LineLength:
|
106
|
+
Max: 80
|
107
|
+
|
108
|
+
MethodLength:
|
109
|
+
Enabled: false
|
110
|
+
|
111
|
+
ModuleFunction:
|
112
|
+
Enabled: false
|
113
|
+
|
114
|
+
NegatedIf:
|
115
|
+
Enabled: false
|
116
|
+
|
117
|
+
NegatedWhile:
|
118
|
+
Enabled: false
|
119
|
+
|
120
|
+
NilComparison:
|
121
|
+
Enabled: false
|
122
|
+
|
123
|
+
Not:
|
124
|
+
Enabled: false
|
125
|
+
|
126
|
+
NumericLiterals:
|
127
|
+
Enabled: false
|
128
|
+
|
129
|
+
OneLineConditional:
|
130
|
+
Enabled: false
|
131
|
+
|
132
|
+
OpMethod:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
ParameterLists:
|
136
|
+
Enabled: false
|
137
|
+
|
138
|
+
PercentLiteralDelimiters:
|
139
|
+
PreferredDelimiters:
|
140
|
+
'%': '{}'
|
141
|
+
|
142
|
+
PerlBackrefs:
|
143
|
+
Enabled: false
|
144
|
+
|
145
|
+
PredicateName:
|
146
|
+
NamePrefixBlacklist:
|
147
|
+
- is_
|
148
|
+
|
149
|
+
Proc:
|
150
|
+
Enabled: false
|
151
|
+
|
152
|
+
RaiseArgs:
|
153
|
+
Enabled: false
|
154
|
+
|
155
|
+
RegexpLiteral:
|
156
|
+
Enabled: false
|
157
|
+
|
158
|
+
SelfAssignment:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
SingleLineBlockParams:
|
162
|
+
Enabled: false
|
163
|
+
|
164
|
+
SingleLineMethods:
|
165
|
+
Enabled: false
|
166
|
+
|
167
|
+
SignalException:
|
168
|
+
Enabled: false
|
169
|
+
|
170
|
+
SpecialGlobalVars:
|
171
|
+
Enabled: false
|
172
|
+
|
173
|
+
StringLiterals:
|
174
|
+
EnforcedStyle: double_quotes
|
175
|
+
|
176
|
+
VariableInterpolation:
|
177
|
+
Enabled: false
|
178
|
+
|
179
|
+
TrailingComma:
|
180
|
+
Enabled: false
|
181
|
+
|
182
|
+
TrivialAccessors:
|
183
|
+
Enabled: false
|
184
|
+
|
185
|
+
VariableInterpolation:
|
186
|
+
Enabled: false
|
187
|
+
|
188
|
+
WhenThen:
|
189
|
+
Enabled: false
|
190
|
+
|
191
|
+
WhileUntilModifier:
|
192
|
+
Enabled: false
|
193
|
+
|
194
|
+
WordArray:
|
195
|
+
Enabled: false
|
196
|
+
|
197
|
+
# Lint
|
198
|
+
|
199
|
+
AmbiguousOperator:
|
200
|
+
Enabled: false
|
201
|
+
|
202
|
+
AmbiguousRegexpLiteral:
|
203
|
+
Enabled: false
|
204
|
+
|
205
|
+
AssignmentInCondition:
|
206
|
+
Enabled: false
|
207
|
+
|
208
|
+
ConditionPosition:
|
209
|
+
Enabled: false
|
210
|
+
|
211
|
+
DeprecatedClassMethods:
|
212
|
+
Enabled: false
|
213
|
+
|
214
|
+
ElseLayout:
|
215
|
+
Enabled: false
|
216
|
+
|
217
|
+
HandleExceptions:
|
218
|
+
Enabled: false
|
219
|
+
|
220
|
+
InvalidCharacterLiteral:
|
221
|
+
Enabled: false
|
222
|
+
|
223
|
+
LiteralInCondition:
|
224
|
+
Enabled: false
|
225
|
+
|
226
|
+
LiteralInInterpolation:
|
227
|
+
Enabled: false
|
228
|
+
|
229
|
+
Loop:
|
230
|
+
Enabled: false
|
231
|
+
|
232
|
+
ParenthesesAsGroupedExpression:
|
233
|
+
Enabled: false
|
234
|
+
|
235
|
+
RequireParentheses:
|
236
|
+
Enabled: false
|
237
|
+
|
238
|
+
UnderscorePrefixedVariableName:
|
239
|
+
Enabled: false
|
240
|
+
|
241
|
+
Void:
|
242
|
+
Enabled: false
|
data/lib/rubocop/git.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubocop/git/version'
|
2
|
+
require 'rubocop'
|
3
|
+
|
4
|
+
if defined?(Rubocop)
|
5
|
+
# rubocop 0.22.0
|
6
|
+
RuboCop::Formatter = Rubocop::Formatter
|
7
|
+
else
|
8
|
+
# rubocop >= 0.23.0
|
9
|
+
Rubocop = RuboCop
|
10
|
+
end
|
11
|
+
|
12
|
+
module RuboCop
|
13
|
+
module Git
|
14
|
+
autoload :CommitFile, 'rubocop/git/commit_file'
|
15
|
+
autoload :FileViolation, 'rubocop/git/file_violation'
|
16
|
+
autoload :Line, 'rubocop/git/line'
|
17
|
+
autoload :Patch, 'rubocop/git/patch'
|
18
|
+
autoload :PseudoPullRequest, 'rubocop/git/pseudo_pull_request'
|
19
|
+
autoload :PseudoResource, 'rubocop/git/pseudo_resource'
|
20
|
+
autoload :Runner, 'rubocop/git/runner'
|
21
|
+
autoload :StyleChecker, 'rubocop/git/style_checker'
|
22
|
+
autoload :StyleGuide, 'rubocop/git/style_guide'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubocop/git'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Git
|
6
|
+
class CLI
|
7
|
+
def run(args = ARGV)
|
8
|
+
options = parse_arguments(args)
|
9
|
+
Runner.new.run(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def parse_arguments(args)
|
15
|
+
options = {}
|
16
|
+
|
17
|
+
OptionParser.new do |opt|
|
18
|
+
opt.on('-c', '--config FILE',
|
19
|
+
'Specify configuration file') do |config|
|
20
|
+
options[:config] = config
|
21
|
+
end
|
22
|
+
|
23
|
+
opt.on('-D', '--display-cop-names',
|
24
|
+
'Display cop names in offense messages') do
|
25
|
+
options[:rubocop] ||= {}
|
26
|
+
options[:rubocop][:display_cop_names] = true
|
27
|
+
end
|
28
|
+
|
29
|
+
opt.on('--cached', 'git diff --cached') do
|
30
|
+
options[:cached] = true
|
31
|
+
end
|
32
|
+
|
33
|
+
opt.on('--staged', 'synonym of --cached') do
|
34
|
+
options[:cached] = true
|
35
|
+
end
|
36
|
+
|
37
|
+
opt.on('--hound',
|
38
|
+
'Hound compatibility mode (require rubocop 0.22.0)') do
|
39
|
+
options[:hound] = true
|
40
|
+
end
|
41
|
+
|
42
|
+
opt.parse(args)
|
43
|
+
end
|
44
|
+
|
45
|
+
options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RuboCop::Git
|
2
|
+
# copy from https://github.com/thoughtbot/hound/blob/be2dd34/app/models/commit_file.rb
|
3
|
+
class CommitFile
|
4
|
+
attr_reader :contents
|
5
|
+
|
6
|
+
def initialize(file, contents)
|
7
|
+
@file = file
|
8
|
+
@contents = contents
|
9
|
+
end
|
10
|
+
|
11
|
+
def filename
|
12
|
+
@file.filename
|
13
|
+
end
|
14
|
+
|
15
|
+
def relevant_line?(line_number)
|
16
|
+
modified_lines.detect do |modified_line|
|
17
|
+
modified_line.line_number == line_number
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def removed?
|
22
|
+
@file.status == 'removed'
|
23
|
+
end
|
24
|
+
|
25
|
+
def ruby?
|
26
|
+
filename.match(/.*\.rb$/)
|
27
|
+
end
|
28
|
+
|
29
|
+
def modified_lines
|
30
|
+
@modified_lines ||= patch.additions
|
31
|
+
end
|
32
|
+
|
33
|
+
def modified_line_at(line_number)
|
34
|
+
modified_lines.detect do |modified_line|
|
35
|
+
modified_line.line_number == line_number
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def patch
|
42
|
+
Patch.new(@file.patch)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RuboCop::Git
|
2
|
+
# copy from https://github.com/thoughtbot/hound/blob/be2dd34/app/models/patch.rb
|
3
|
+
class Patch
|
4
|
+
RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
|
5
|
+
MODIFIED_LINE = /^\+(?!\+|\+)/
|
6
|
+
NOT_REMOVED_LINE = /^[^-]/
|
7
|
+
|
8
|
+
def initialize(body)
|
9
|
+
@body = body || ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def additions
|
13
|
+
line_number = 0
|
14
|
+
|
15
|
+
lines.each_with_index.inject([]) do |additions, (content, patch_position)|
|
16
|
+
case content
|
17
|
+
when RANGE_INFORMATION_LINE
|
18
|
+
line_number = Regexp.last_match[:line_number].to_i
|
19
|
+
when MODIFIED_LINE
|
20
|
+
additions << Line.new(content, line_number, patch_position)
|
21
|
+
line_number += 1
|
22
|
+
when NOT_REMOVED_LINE
|
23
|
+
line_number += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
additions
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def lines
|
33
|
+
@body.lines
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Git
|
5
|
+
# ref. https://github.com/thoughtbot/hound/blob/be2dd34/app/models/pull_request.rb
|
6
|
+
class PseudoPullRequest
|
7
|
+
HOUND_CONFIG_FILE = '.hound.yml'
|
8
|
+
|
9
|
+
def initialize(files, options)
|
10
|
+
@files = files
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def pull_request_files
|
15
|
+
@files.map do |file|
|
16
|
+
build_commit_file(file)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
return unless @options[:hound]
|
22
|
+
File.read(HOUND_CONFIG_FILE)
|
23
|
+
rescue Errno::ENOENT
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_commit_file(file)
|
30
|
+
CommitFile.new(file, file_contents(file.filename))
|
31
|
+
end
|
32
|
+
|
33
|
+
def file_contents(filename)
|
34
|
+
if @options[:cached]
|
35
|
+
`git show :#{filename.shellescape}`
|
36
|
+
else
|
37
|
+
File.read(filename)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Git
|
3
|
+
# ref. https://github.com/thoughtbot/hound/blob/be2dd34/app/services/build_runner.rb
|
4
|
+
class Runner
|
5
|
+
DEFAULT_CONFIG_FILE = '.rubocop.yml'
|
6
|
+
HOUND_DEFAULT_CONFIG_FILE =
|
7
|
+
File.expand_path('../../../../hound.yml', __FILE__)
|
8
|
+
|
9
|
+
def run(options)
|
10
|
+
if options[:hound] && RuboCop::Version.version != '0.22.0'
|
11
|
+
warn 'Hound compatibility mode require rubocop 0.22.0'
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
@options = options
|
16
|
+
@files = parse_diff(git_diff(options[:cached]))
|
17
|
+
|
18
|
+
display_violations($stdout)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def violations
|
24
|
+
@violations ||= style_checker.violations
|
25
|
+
end
|
26
|
+
|
27
|
+
def style_checker
|
28
|
+
StyleChecker.new(pull_request.pull_request_files,
|
29
|
+
@options[:rubocop],
|
30
|
+
config_path,
|
31
|
+
pull_request.config)
|
32
|
+
end
|
33
|
+
|
34
|
+
def pull_request
|
35
|
+
@pull_request ||= PseudoPullRequest.new(@files, @options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def git_diff(cached)
|
39
|
+
if cached
|
40
|
+
`git diff --diff-filter=AMCR --cached --find-renames --find-copies`
|
41
|
+
else
|
42
|
+
`git diff --diff-filter=AM`
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_diff(diff)
|
47
|
+
files = []
|
48
|
+
in_patch = false
|
49
|
+
|
50
|
+
diff.each_line do |line|
|
51
|
+
case line
|
52
|
+
when /^diff --git/
|
53
|
+
in_patch = false
|
54
|
+
when %r{^\+{3} b/([^\t\n\r]+)}
|
55
|
+
files << PseudoResource.new($1, 'modified', '')
|
56
|
+
when /^@@/
|
57
|
+
in_patch = true
|
58
|
+
end
|
59
|
+
|
60
|
+
files.last.patch << line if in_patch
|
61
|
+
end
|
62
|
+
|
63
|
+
files
|
64
|
+
end
|
65
|
+
|
66
|
+
def config_path
|
67
|
+
if @options[:hound]
|
68
|
+
HOUND_DEFAULT_CONFIG_FILE
|
69
|
+
else
|
70
|
+
@options[:config] || DEFAULT_CONFIG_FILE
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def display_violations(io)
|
75
|
+
formatter = RuboCop::Formatter::ClangStyleFormatter.new(io)
|
76
|
+
formatter.started(nil)
|
77
|
+
|
78
|
+
violations.map do |violation|
|
79
|
+
formatter.file_finished(
|
80
|
+
violation.filename,
|
81
|
+
violation.offenses.compact.sort.freeze
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
formatter.finished(@files.map(&:filename).freeze)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module RuboCop::Git
|
2
|
+
# ref. https://github.com/thoughtbot/hound/blob/be2dd34/app/models/style_checker.rb
|
3
|
+
class StyleChecker
|
4
|
+
def initialize(modified_files,
|
5
|
+
rubocop_options,
|
6
|
+
config_path,
|
7
|
+
custom_config = nil)
|
8
|
+
@modified_files = modified_files
|
9
|
+
@rubocop_options = rubocop_options
|
10
|
+
@config_path = config_path
|
11
|
+
@custom_config = custom_config
|
12
|
+
end
|
13
|
+
|
14
|
+
def violations
|
15
|
+
file_violations = @modified_files.map do |modified_file|
|
16
|
+
FileViolation.new(modified_file.filename, offenses(modified_file))
|
17
|
+
end
|
18
|
+
|
19
|
+
file_violations.select do |file_violation|
|
20
|
+
file_violation.offenses.any?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def offenses(modified_file)
|
27
|
+
violations = style_guide.violations(modified_file)
|
28
|
+
violations_on_changed_lines(modified_file, violations)
|
29
|
+
end
|
30
|
+
|
31
|
+
def violations_on_changed_lines(modified_file, violations)
|
32
|
+
violations.select do |violation|
|
33
|
+
modified_file.relevant_line?(violation.line)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def style_guide
|
38
|
+
@style_guide ||= StyleGuide.new(@rubocop_options,
|
39
|
+
@config_path,
|
40
|
+
@custom_config)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module RuboCop::Git
|
2
|
+
# ref. https://github.com/thoughtbot/hound/blob/be2dd34/app/models/style_guide.rb
|
3
|
+
class StyleGuide
|
4
|
+
def initialize(rubocop_options, config_path, override_config_content = nil)
|
5
|
+
@rubocop_options = rubocop_options
|
6
|
+
@config_path = config_path
|
7
|
+
@override_config_content = override_config_content
|
8
|
+
end
|
9
|
+
|
10
|
+
def violations(file)
|
11
|
+
if ignored_file?(file)
|
12
|
+
[]
|
13
|
+
else
|
14
|
+
parsed_source = parse_source(file)
|
15
|
+
team = Rubocop::Cop::Team.new(
|
16
|
+
Rubocop::Cop::Cop.all, configuration, @rubocop_options)
|
17
|
+
commissioner = Rubocop::Cop::Commissioner.new(team.cops, [])
|
18
|
+
commissioner.investigate(parsed_source)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def ignored_file?(file)
|
25
|
+
!file.ruby? ||
|
26
|
+
file.removed? ||
|
27
|
+
configuration.file_to_exclude?(file.filename)
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_source(file)
|
31
|
+
Rubocop::SourceParser.parse(file.contents, file.filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
def configuration
|
35
|
+
config = Rubocop::ConfigLoader.configuration_from_file(@config_path)
|
36
|
+
|
37
|
+
if override_config
|
38
|
+
config = Rubocop::Config.new(
|
39
|
+
Rubocop::ConfigLoader.merge(config, override_config),
|
40
|
+
''
|
41
|
+
)
|
42
|
+
config.make_excludes_absolute
|
43
|
+
end
|
44
|
+
|
45
|
+
config
|
46
|
+
end
|
47
|
+
|
48
|
+
def override_config
|
49
|
+
if @override_config_content
|
50
|
+
Rubocop::Config.new(YAML.load(@override_config_content))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/rubocop-git.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubocop/git/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rubocop-git'
|
8
|
+
spec.version = RuboCop::Git::VERSION
|
9
|
+
spec.authors = ['Masaki Takeuchi']
|
10
|
+
spec.email = ['m.ishihara@gmail.com']
|
11
|
+
spec.summary = %q{RuboCop for git diff.}
|
12
|
+
spec.description = %q{RuboCop for git diff.}
|
13
|
+
spec.homepage = 'https://github.com/m4i/rubocop-git'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_dependency 'rubocop', ['>= 0.22.0', '< 0.24.0']
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masaki Takeuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.22.0
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.24.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.22.0
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.24.0
|
61
|
+
description: RuboCop for git diff.
|
62
|
+
email:
|
63
|
+
- m.ishihara@gmail.com
|
64
|
+
executables:
|
65
|
+
- rubocop-git
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bin/rubocop-git
|
75
|
+
- hound.yml
|
76
|
+
- lib/rubocop/git.rb
|
77
|
+
- lib/rubocop/git/cli.rb
|
78
|
+
- lib/rubocop/git/commit_file.rb
|
79
|
+
- lib/rubocop/git/file_violation.rb
|
80
|
+
- lib/rubocop/git/line.rb
|
81
|
+
- lib/rubocop/git/patch.rb
|
82
|
+
- lib/rubocop/git/pseudo_pull_request.rb
|
83
|
+
- lib/rubocop/git/pseudo_resource.rb
|
84
|
+
- lib/rubocop/git/runner.rb
|
85
|
+
- lib/rubocop/git/style_checker.rb
|
86
|
+
- lib/rubocop/git/style_guide.rb
|
87
|
+
- lib/rubocop/git/version.rb
|
88
|
+
- rubocop-git.gemspec
|
89
|
+
homepage: https://github.com/m4i/rubocop-git
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: RuboCop for git diff.
|
113
|
+
test_files: []
|