rubocop-git-kjanoudi 0.1.2 → 0.1.3
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 +4 -4
- data/lib/rubocop/git/patch.rb +1 -28
- data/lib/rubocop/git/runner.rb +1 -8
- data/lib/rubocop/git/version.rb +1 -1
- data/lib/rubocop/git.rb +0 -3
- data/rubocop-git-kjanoudi.gemspec +1 -1
- metadata +2 -3
- data/lib/rubocop/git/rubo_comment.rb +0 -92
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac9436a5b688315f427ddfaa6113a1762e64f289
|
|
4
|
+
data.tar.gz: 9c55dba14255f08dbc001a8003d0457afd20d590
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58a87e93b2977dff8a00f3b6ce16811fa2977b1c97c752d431f550933e0ef6948366d22c646b8ed2e6ce6dcd2dbec7bc5021b2dcf3986146c6be64a48b5915df
|
|
7
|
+
data.tar.gz: ed977b0168c8cf8bca7ceee01911785bfcc4d97ce75be97acaa84e7705786aa486ba077d92be3bd6f326bef2d6bbdb066b6f4e70094a0981b33f72da03729e67
|
data/lib/rubocop/git/patch.rb
CHANGED
|
@@ -4,17 +4,15 @@ class Patch
|
|
|
4
4
|
RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
|
|
5
5
|
MODIFIED_LINE = /^\+(?!\+|\+)/
|
|
6
6
|
NOT_REMOVED_LINE = /^[^-]/
|
|
7
|
-
PATCH_INFO_LINE = /\+([0-9,]+)/
|
|
8
7
|
|
|
9
8
|
def initialize(body)
|
|
10
9
|
@body = body || ''
|
|
11
|
-
@changes = []
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
def additions
|
|
15
13
|
line_number = 0
|
|
16
14
|
|
|
17
|
-
lines.each_with_index.inject(
|
|
15
|
+
lines.each_with_index.inject([]) do |additions, (content, patch_position)|
|
|
18
16
|
case content
|
|
19
17
|
when RANGE_INFORMATION_LINE
|
|
20
18
|
line_number = Regexp.last_match[:line_number].to_i
|
|
@@ -29,31 +27,6 @@ class Patch
|
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
# maps out additions line numbers to indicate start and end of code changes
|
|
33
|
-
# [[5,7], [11,11]] indicates changes from line 5, 6, 7 and then
|
|
34
|
-
# another one at 11
|
|
35
|
-
def additions_map
|
|
36
|
-
if @changes.empty?
|
|
37
|
-
self.additions
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
map = []
|
|
41
|
-
starting_line = ending_line = 0
|
|
42
|
-
|
|
43
|
-
@changes.each do |addition|
|
|
44
|
-
if starting_line == 0
|
|
45
|
-
starting_line = ending_line = addition.line_number
|
|
46
|
-
elsif addition.line_number == ( ending_line + 1 )
|
|
47
|
-
ending_line = addition.line_number
|
|
48
|
-
else # this row is not part of the last rows "group"
|
|
49
|
-
map.push([starting_line, ending_line])
|
|
50
|
-
starting_line = ending_line = addition.line_number
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
map.push([starting_line, ending_line])
|
|
54
|
-
map
|
|
55
|
-
end
|
|
56
|
-
|
|
57
30
|
private
|
|
58
31
|
|
|
59
32
|
def lines
|
data/lib/rubocop/git/runner.rb
CHANGED
|
@@ -9,15 +9,8 @@ module RuboCop
|
|
|
9
9
|
|
|
10
10
|
@options = options
|
|
11
11
|
@files = DiffParser.parse(git_diff(options))
|
|
12
|
-
rubo_comment = RuboComment.new(@files)
|
|
13
|
-
|
|
14
|
-
#adds comments to files and reparses diff after changes are made
|
|
15
|
-
rubo_comment.add_comments
|
|
16
|
-
@files = DiffParser.parse(git_diff(options))
|
|
17
12
|
|
|
18
13
|
display_violations($stdout)
|
|
19
|
-
#removes comments after rubocop processing
|
|
20
|
-
rubo_comment.remove_comments
|
|
21
14
|
|
|
22
15
|
exit(1) if violations.any?
|
|
23
16
|
end
|
|
@@ -52,7 +45,7 @@ module RuboCop
|
|
|
52
45
|
def display_violations(io)
|
|
53
46
|
formatter = RuboCop::Formatter::ClangStyleFormatter.new(io)
|
|
54
47
|
formatter.started(nil)
|
|
55
|
-
|
|
48
|
+
|
|
56
49
|
violations.map do |violation|
|
|
57
50
|
formatter.file_finished(
|
|
58
51
|
violation.filename,
|
data/lib/rubocop/git/version.rb
CHANGED
data/lib/rubocop/git.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
require 'rubocop/git/version'
|
|
2
2
|
require 'rubocop'
|
|
3
|
-
require 'tempfile'
|
|
4
|
-
require 'fileutils'
|
|
5
3
|
|
|
6
4
|
module RuboCop
|
|
7
5
|
module Git
|
|
@@ -17,6 +15,5 @@ module RuboCop
|
|
|
17
15
|
autoload :Runner, 'rubocop/git/runner'
|
|
18
16
|
autoload :StyleChecker, 'rubocop/git/style_checker'
|
|
19
17
|
autoload :StyleGuide, 'rubocop/git/style_guide'
|
|
20
|
-
autoload :RuboComment, 'rubocop/git/rubo_comment'
|
|
21
18
|
end
|
|
22
19
|
end
|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.email = ['m.ishihara@gmail.com']
|
|
11
11
|
spec.summary = %q{RuboCop for git diff.}
|
|
12
12
|
spec.description = %q{RuboCop for git diff.}
|
|
13
|
-
spec.homepage = 'https://github.com/
|
|
13
|
+
spec.homepage = 'https://github.com/m4i/rubocop-git'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
15
|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-git-kjanoudi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Masaki Takeuchi
|
|
@@ -132,7 +132,6 @@ files:
|
|
|
132
132
|
- lib/rubocop/git/patch.rb
|
|
133
133
|
- lib/rubocop/git/pseudo_pull_request.rb
|
|
134
134
|
- lib/rubocop/git/pseudo_resource.rb
|
|
135
|
-
- lib/rubocop/git/rubo_comment.rb
|
|
136
135
|
- lib/rubocop/git/runner.rb
|
|
137
136
|
- lib/rubocop/git/style_checker.rb
|
|
138
137
|
- lib/rubocop/git/style_guide.rb
|
|
@@ -142,7 +141,7 @@ files:
|
|
|
142
141
|
- test/rubocop/git/options_test.rb
|
|
143
142
|
- test/rubocop/git/runner_test.rb
|
|
144
143
|
- test/test_helper.rb
|
|
145
|
-
homepage: https://github.com/
|
|
144
|
+
homepage: https://github.com/m4i/rubocop-git
|
|
146
145
|
licenses:
|
|
147
146
|
- MIT
|
|
148
147
|
metadata: {}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module RuboCop::Git
|
|
2
|
-
class RuboComment
|
|
3
|
-
RUBOCOP_DISABLE = "# rubocop:disable all\n"
|
|
4
|
-
RUBOCOP_ENABLE = "# rubocop:enable all\n"
|
|
5
|
-
WHITE_SPACE = /^\s*/
|
|
6
|
-
|
|
7
|
-
def initialize(files)
|
|
8
|
-
@edit_map = {}
|
|
9
|
-
@files = files
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# adds rubocop enable and disabled comments to files
|
|
13
|
-
# making sure only edited lines are processed by rubocop
|
|
14
|
-
def add_comments
|
|
15
|
-
@files.each do |file|
|
|
16
|
-
patch_info = Patch.new(file.patch).additions_map
|
|
17
|
-
temp_file = Tempfile.new('temp')
|
|
18
|
-
|
|
19
|
-
line_count = edited_line_count = current_patch = 0
|
|
20
|
-
in_patch = false
|
|
21
|
-
edit_locations = []
|
|
22
|
-
|
|
23
|
-
begin
|
|
24
|
-
File.open(file.filename, "r").each_line do |line|
|
|
25
|
-
line_count += 1
|
|
26
|
-
edited_line_count += 1
|
|
27
|
-
|
|
28
|
-
if line_count == patch_info[current_patch].first
|
|
29
|
-
temp_file.puts generate_spaces(line) + RUBOCOP_ENABLE
|
|
30
|
-
in_patch = true
|
|
31
|
-
edit_locations.push edited_line_count
|
|
32
|
-
edited_line_count += 1
|
|
33
|
-
|
|
34
|
-
elsif in_patch && patch_info[current_patch].last + 1 == line_count
|
|
35
|
-
temp_file.puts generate_spaces(line) + RUBOCOP_DISABLE
|
|
36
|
-
in_patch = false
|
|
37
|
-
edit_locations.push edited_line_count
|
|
38
|
-
edited_line_count += 1
|
|
39
|
-
current_patch += 1 unless (current_patch + 1) >= patch_info.size
|
|
40
|
-
|
|
41
|
-
elsif line_count == 1 #adds disable at top of file
|
|
42
|
-
temp_file.puts generate_spaces(line) + RUBOCOP_DISABLE
|
|
43
|
-
edit_locations.push edited_line_count
|
|
44
|
-
edited_line_count += 1
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
temp_file.puts line
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
temp_file.close
|
|
51
|
-
FileUtils.mv(temp_file.path, file.filename)
|
|
52
|
-
@edit_map[file.filename] = edit_locations
|
|
53
|
-
ensure
|
|
54
|
-
temp_file.close
|
|
55
|
-
temp_file.unlink
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# removes all added comments that where added from add_comments
|
|
61
|
-
def remove_comments
|
|
62
|
-
@files.each do |file|
|
|
63
|
-
temp_file = Tempfile.new('temp')
|
|
64
|
-
line_count = 0
|
|
65
|
-
|
|
66
|
-
begin
|
|
67
|
-
File.open(file.filename, "r").each_line do |line|
|
|
68
|
-
line_count += 1
|
|
69
|
-
temp_file.puts line unless @edit_map[file.filename].find_index line_count
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
temp_file.close
|
|
73
|
-
FileUtils.mv(temp_file.path, file.filename)
|
|
74
|
-
ensure
|
|
75
|
-
temp_file.close
|
|
76
|
-
temp_file.unlink
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
private
|
|
82
|
-
|
|
83
|
-
# generates whitespaces to make en/disable comments match line indent
|
|
84
|
-
# preventing rubocop errors
|
|
85
|
-
def generate_spaces(line)
|
|
86
|
-
whitespaces = ""
|
|
87
|
-
WHITE_SPACE.match(line).to_s.split('').size.times { whitespaces << " " }
|
|
88
|
-
whitespaces
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
end
|