rubocop-git 0.0.2 → 0.0.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/README.md +5 -1
- data/hound.yml +12 -0
- data/lib/rubocop/git.rb +1 -10
- data/lib/rubocop/git/cli.rb +5 -2
- data/lib/rubocop/git/commit.rb +22 -0
- data/lib/rubocop/git/commit_file.rb +11 -5
- data/lib/rubocop/git/file_violation.rb +1 -1
- data/lib/rubocop/git/line.rb +1 -1
- data/lib/rubocop/git/options.rb +1 -4
- data/lib/rubocop/git/patch.rb +1 -1
- data/lib/rubocop/git/pseudo_pull_request.rb +4 -12
- data/lib/rubocop/git/runner.rb +2 -2
- data/lib/rubocop/git/style_checker.rb +4 -4
- data/lib/rubocop/git/style_guide.rb +33 -22
- data/lib/rubocop/git/version.rb +1 -1
- data/rubocop-git.gemspec +1 -1
- metadata +5 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 090d9d83c07e1a98d759e498718d4180934d4dc9
|
4
|
+
data.tar.gz: b79390241bb3f9634f2502ec1ec7a462cae02883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d588673e5a7ea69326a0f1783b24a2a08cd24eadb8194046a58e885433a6fa4c570032331c6856f938ac8abaf3f5e8e8cf28028ea4967803dfae460457fe810
|
7
|
+
data.tar.gz: b88912a13cdf6414d8127dd4561789c99dd01965ad5cbdb8c2fc50c129e819b9a1582aae2058b22505e554d88919ac99a1f69800b70c4570fb76a498bfa22cac
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
RuboCop for git diff.
|
4
4
|
|
5
|
+
[](http://badge.fury.io/rb/rubocop-git)
|
6
|
+
[](https://codeclimate.com/github/m4i/rubocop-git)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -20,10 +23,11 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
Usage: rubocop-git [options] [[commit] commit]
|
22
25
|
-c, --config FILE Specify configuration file
|
26
|
+
-d, --debug Display debug info
|
23
27
|
-D, --display-cop-names Display cop names in offense messages
|
24
28
|
--cached git diff --cached
|
25
29
|
--staged synonym of --cached
|
26
|
-
--hound Hound compatibility mode
|
30
|
+
--hound Hound compatibility mode
|
27
31
|
|
28
32
|
## Contributing
|
29
33
|
|
data/hound.yml
CHANGED
@@ -5,6 +5,9 @@ AllCops:
|
|
5
5
|
AccessorMethodName:
|
6
6
|
Enabled: false
|
7
7
|
|
8
|
+
ActionFilter:
|
9
|
+
Enabled: false
|
10
|
+
|
8
11
|
Alias:
|
9
12
|
Enabled: false
|
10
13
|
|
@@ -29,6 +32,9 @@ CaseEquality:
|
|
29
32
|
CharacterLiteral:
|
30
33
|
Enabled: false
|
31
34
|
|
35
|
+
ClassAndModuleChildren:
|
36
|
+
Enabled: false
|
37
|
+
|
32
38
|
ClassLength:
|
33
39
|
Enabled: false
|
34
40
|
|
@@ -66,6 +72,9 @@ DotPosition:
|
|
66
72
|
DoubleNegation:
|
67
73
|
Enabled: false
|
68
74
|
|
75
|
+
EachWithObject:
|
76
|
+
Enabled: false
|
77
|
+
|
69
78
|
EmptyLiteral:
|
70
79
|
Enabled: false
|
71
80
|
|
@@ -87,6 +96,9 @@ FormatString:
|
|
87
96
|
GlobalVars:
|
88
97
|
Enabled: false
|
89
98
|
|
99
|
+
GuardClause:
|
100
|
+
Enabled: false
|
101
|
+
|
90
102
|
IfUnlessModifier:
|
91
103
|
Enabled: false
|
92
104
|
|
data/lib/rubocop/git.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
require 'rubocop/git/version'
|
2
2
|
require 'rubocop'
|
3
3
|
|
4
|
-
if defined?(Rubocop)
|
5
|
-
# rubocop 0.22.0
|
6
|
-
RuboCop::ConfigLoader = Rubocop::ConfigLoader
|
7
|
-
RuboCop::Formatter = Rubocop::Formatter
|
8
|
-
RuboCop::Version = Rubocop::Version
|
9
|
-
else
|
10
|
-
# rubocop >= 0.23.0
|
11
|
-
Rubocop = RuboCop
|
12
|
-
end
|
13
|
-
|
14
4
|
module RuboCop
|
15
5
|
module Git
|
6
|
+
autoload :Commit, 'rubocop/git/commit'
|
16
7
|
autoload :CommitFile, 'rubocop/git/commit_file'
|
17
8
|
autoload :DiffParser, 'rubocop/git/diff_parser'
|
18
9
|
autoload :FileViolation, 'rubocop/git/file_violation'
|
data/lib/rubocop/git/cli.rb
CHANGED
@@ -30,6 +30,10 @@ module RuboCop
|
|
30
30
|
@options.config = config
|
31
31
|
end
|
32
32
|
|
33
|
+
opt.on('-d', '--debug', 'Display debug info') do
|
34
|
+
@options.rubocop[:debug] = true
|
35
|
+
end
|
36
|
+
|
33
37
|
opt.on('-D', '--display-cop-names',
|
34
38
|
'Display cop names in offense messages') do
|
35
39
|
@options.rubocop[:display_cop_names] = true
|
@@ -43,8 +47,7 @@ module RuboCop
|
|
43
47
|
@options.cached = true
|
44
48
|
end
|
45
49
|
|
46
|
-
opt.on('--hound',
|
47
|
-
'Hound compatibility mode (require rubocop 0.22.0)') do
|
50
|
+
opt.on('--hound', 'Hound compatibility mode') do
|
48
51
|
@options.hound = true
|
49
52
|
end
|
50
53
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Git
|
5
|
+
# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/models/commit.rb
|
6
|
+
class Commit
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_content(filename)
|
12
|
+
if @options.cached
|
13
|
+
`git show :#{filename.shellescape}`
|
14
|
+
elsif @options.commit_last
|
15
|
+
`git show #{@options.commit_last.shellescape}:#{filename.shellescape}`
|
16
|
+
else
|
17
|
+
File.read(filename)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,17 +1,23 @@
|
|
1
1
|
module RuboCop::Git
|
2
|
-
# copy from https://github.com/thoughtbot/hound/blob/
|
2
|
+
# copy from https://github.com/thoughtbot/hound/blob/d2f3933/app/models/commit_file.rb
|
3
3
|
class CommitFile
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(file, contents)
|
4
|
+
def initialize(file, commit)
|
7
5
|
@file = file
|
8
|
-
@
|
6
|
+
@commit = commit
|
9
7
|
end
|
10
8
|
|
11
9
|
def filename
|
12
10
|
@file.filename
|
13
11
|
end
|
14
12
|
|
13
|
+
def content
|
14
|
+
@content ||= begin
|
15
|
+
unless removed?
|
16
|
+
@commit.file_content(filename)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
def relevant_line?(line_number)
|
16
22
|
modified_lines.detect do |modified_line|
|
17
23
|
modified_line.line_number == line_number
|
data/lib/rubocop/git/line.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RuboCop::Git
|
2
|
-
# copy from https://github.com/thoughtbot/hound/blob/
|
2
|
+
# copy from https://github.com/thoughtbot/hound/blob/d2f3933/app/models/line.rb
|
3
3
|
class Line < Struct.new(:content, :line_number, :patch_position)
|
4
4
|
def ==(other_line)
|
5
5
|
content == other_line.content
|
data/lib/rubocop/git/options.rb
CHANGED
@@ -27,9 +27,6 @@ module RuboCop
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def hound=(hound_)
|
30
|
-
if hound_ && RuboCop::Version.version != '0.22.0'
|
31
|
-
fail Invalid, 'Hound compatibility mode requires rubocop 0.22.0'
|
32
|
-
end
|
33
30
|
@hound = !!hound_
|
34
31
|
end
|
35
32
|
|
@@ -50,7 +47,7 @@ module RuboCop
|
|
50
47
|
@commits = commits
|
51
48
|
end
|
52
49
|
|
53
|
-
def
|
50
|
+
def config_file
|
54
51
|
if hound
|
55
52
|
HOUND_DEFAULT_CONFIG_FILE
|
56
53
|
elsif config
|
data/lib/rubocop/git/patch.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RuboCop::Git
|
2
|
-
# copy from https://github.com/thoughtbot/hound/blob/
|
2
|
+
# copy from https://github.com/thoughtbot/hound/blob/d2f3933/app/models/patch.rb
|
3
3
|
class Patch
|
4
4
|
RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
|
5
5
|
MODIFIED_LINE = /^\+(?!\+|\+)/
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'shellwords'
|
2
|
-
|
3
1
|
module RuboCop
|
4
2
|
module Git
|
5
|
-
# ref. https://github.com/thoughtbot/hound/blob/
|
3
|
+
# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/models/pull_request.rb
|
6
4
|
class PseudoPullRequest
|
7
5
|
HOUND_CONFIG_FILE = '.hound.yml'
|
8
6
|
|
@@ -27,17 +25,11 @@ module RuboCop
|
|
27
25
|
private
|
28
26
|
|
29
27
|
def build_commit_file(file)
|
30
|
-
CommitFile.new(file,
|
28
|
+
CommitFile.new(file, head_commit)
|
31
29
|
end
|
32
30
|
|
33
|
-
def
|
34
|
-
|
35
|
-
`git show :#{filename.shellescape}`
|
36
|
-
elsif @options.commit_last
|
37
|
-
`git show #{@options.commit_last.shellescape}:#{filename.shellescape}`
|
38
|
-
else
|
39
|
-
File.read(filename)
|
40
|
-
end
|
31
|
+
def head_commit
|
32
|
+
@head_commit ||= Commit.new(@options)
|
41
33
|
end
|
42
34
|
end
|
43
35
|
end
|
data/lib/rubocop/git/runner.rb
CHANGED
@@ -2,7 +2,7 @@ require 'shellwords'
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Git
|
5
|
-
# ref. https://github.com/thoughtbot/hound/blob/
|
5
|
+
# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/services/build_runner.rb
|
6
6
|
class Runner
|
7
7
|
def run(options)
|
8
8
|
options = Options.new(options) unless options.is_a?(Options)
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
def style_checker
|
23
23
|
StyleChecker.new(pull_request.pull_request_files,
|
24
24
|
@options.rubocop,
|
25
|
-
@options.
|
25
|
+
@options.config_file,
|
26
26
|
pull_request.config)
|
27
27
|
end
|
28
28
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module RuboCop::Git
|
2
|
-
# ref. https://github.com/thoughtbot/hound/blob/
|
2
|
+
# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/models/style_checker.rb
|
3
3
|
class StyleChecker
|
4
4
|
def initialize(modified_files,
|
5
5
|
rubocop_options,
|
6
|
-
|
6
|
+
config_file,
|
7
7
|
custom_config = nil)
|
8
8
|
@modified_files = modified_files
|
9
9
|
@rubocop_options = rubocop_options
|
10
|
-
@
|
10
|
+
@config_file = config_file
|
11
11
|
@custom_config = custom_config
|
12
12
|
end
|
13
13
|
|
@@ -36,7 +36,7 @@ class StyleChecker
|
|
36
36
|
|
37
37
|
def style_guide
|
38
38
|
@style_guide ||= StyleGuide.new(@rubocop_options,
|
39
|
-
@
|
39
|
+
@config_file,
|
40
40
|
@custom_config)
|
41
41
|
end
|
42
42
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RuboCop::Git
|
2
|
-
# ref. https://github.com/thoughtbot/hound/blob/
|
2
|
+
# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/models/style_guide.rb
|
3
3
|
class StyleGuide
|
4
|
-
def initialize(rubocop_options,
|
4
|
+
def initialize(rubocop_options, config_file, override_config_content = nil)
|
5
5
|
@rubocop_options = rubocop_options
|
6
|
-
@
|
6
|
+
@config_file = config_file
|
7
7
|
@override_config_content = override_config_content
|
8
8
|
end
|
9
9
|
|
@@ -12,42 +12,53 @@ class StyleGuide
|
|
12
12
|
[]
|
13
13
|
else
|
14
14
|
parsed_source = parse_source(file)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
commissioner.investigate(parsed_source)
|
15
|
+
cops = RuboCop::Cop::Cop.all
|
16
|
+
team = RuboCop::Cop::Team.new(cops, config, rubocop_options)
|
17
|
+
team.inspect_file(parsed_source)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
21
|
private
|
23
22
|
|
24
23
|
def ignored_file?(file)
|
25
|
-
!file.ruby? ||
|
26
|
-
file.removed? ||
|
27
|
-
configuration.file_to_exclude?(file.filename)
|
24
|
+
!file.ruby? || file.removed? || excluded_file?(file)
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
31
|
-
|
27
|
+
def excluded_file?(file)
|
28
|
+
config.file_to_exclude?(file.filename)
|
32
29
|
end
|
33
30
|
|
34
|
-
def
|
35
|
-
|
31
|
+
def parse_source(file)
|
32
|
+
RuboCop::ProcessedSource.new(file.content)
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
)
|
42
|
-
config.make_excludes_absolute
|
35
|
+
def config
|
36
|
+
if @config.nil?
|
37
|
+
config = RuboCop::ConfigLoader.configuration_from_file(@config_file)
|
38
|
+
combined_config = RuboCop::ConfigLoader.merge(config, override_config)
|
39
|
+
@config = RuboCop::Config.new(combined_config, "")
|
43
40
|
end
|
44
41
|
|
45
|
-
config
|
42
|
+
@config
|
43
|
+
end
|
44
|
+
|
45
|
+
def rubocop_options
|
46
|
+
if config["ShowCopNames"]
|
47
|
+
{ debug: true }
|
48
|
+
else
|
49
|
+
{}
|
50
|
+
end.merge(@rubocop_options)
|
46
51
|
end
|
47
52
|
|
48
53
|
def override_config
|
49
54
|
if @override_config_content
|
50
|
-
|
55
|
+
config_content = YAML.load(@override_config_content)
|
56
|
+
override_config = RuboCop::Config.new(config_content, "")
|
57
|
+
override_config.add_missing_namespaces
|
58
|
+
override_config.make_excludes_absolute
|
59
|
+
override_config
|
60
|
+
else
|
61
|
+
{}
|
51
62
|
end
|
52
63
|
end
|
53
64
|
end
|
data/lib/rubocop/git/version.rb
CHANGED
data/rubocop-git.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaki Takeuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,20 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
48
|
-
- - "<"
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.24.0
|
47
|
+
version: 0.24.1
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - ">="
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.
|
58
|
-
- - "<"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.24.0
|
54
|
+
version: 0.24.1
|
61
55
|
description: RuboCop for git diff.
|
62
56
|
email:
|
63
57
|
- m.ishihara@gmail.com
|
@@ -75,6 +69,7 @@ files:
|
|
75
69
|
- hound.yml
|
76
70
|
- lib/rubocop/git.rb
|
77
71
|
- lib/rubocop/git/cli.rb
|
72
|
+
- lib/rubocop/git/commit.rb
|
78
73
|
- lib/rubocop/git/commit_file.rb
|
79
74
|
- lib/rubocop/git/diff_parser.rb
|
80
75
|
- lib/rubocop/git/file_violation.rb
|