rubocopfmt 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/README.md +8 -6
- data/lib/rubocopfmt/auto_corrector.rb +3 -2
- data/lib/rubocopfmt/cli.rb +22 -26
- data/lib/rubocopfmt/diff.rb +40 -0
- data/lib/rubocopfmt/options.rb +1 -0
- data/lib/rubocopfmt/options_parser.rb +15 -5
- data/lib/rubocopfmt/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670799ba9de4c1e7446930905a3decb4212e6ae9
|
4
|
+
data.tar.gz: 2f02bc7f06cad9d23c8f74dc476d53d50cad8d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c64289852893568c1eefb3edff608ca6e70cfc84436e789dcbabd5f01ca2d7bbf9cc3adc7eede5973af4e0ded3559147afe51077045d10b881532fc8310b442
|
7
|
+
data.tar.gz: 580314ca1bb4c094313d002bc8d522f315c6bdb11831640358cd3696ca56f55f2e271c2374d7e1571a7ea72222ea3eacce3c1bbcc29c967b2278cec6a9f8b07c
|
data/README.md
CHANGED
@@ -18,12 +18,14 @@ Usage: rubocopfmt [options] [path ...]
|
|
18
18
|
Reads from STDIN if no path is given.
|
19
19
|
|
20
20
|
Options:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
-d, --diff Display diffs instead of rewriting files.
|
22
|
+
-l, --list List files whose formatting is incorrect.
|
23
|
+
-w, --write Write result to (source) file instead of STDOUT.
|
24
|
+
-F, --stdin-file=<s> Optionally provide file path when using STDIN.
|
25
|
+
-D, --diff-format=<s> Display diffs using format: unified, rcs, context
|
26
|
+
|
27
|
+
-v, --version Print version and exit
|
28
|
+
-h, --help Show this message
|
27
29
|
```
|
28
30
|
|
29
31
|
## Configure
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubocop'
|
2
|
+
|
2
3
|
require 'rubocopfmt/formatter'
|
3
4
|
|
4
5
|
module RuboCopFMT
|
@@ -25,7 +26,7 @@ module RuboCopFMT
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def correct
|
28
|
-
Rainbow.enabled = false
|
29
|
+
Rainbow.enabled = false if defined?(Rainbow)
|
29
30
|
@runner = RuboCop::Runner.new(options, config_store)
|
30
31
|
@runner.run(paths)
|
31
32
|
options[:stdin]
|
data/lib/rubocopfmt/cli.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'rubocop'
|
3
|
-
|
1
|
+
require 'rubocopfmt/diff'
|
4
2
|
require 'rubocopfmt/errors'
|
3
|
+
require 'rubocopfmt/options_parser'
|
5
4
|
require 'rubocopfmt/source'
|
6
5
|
|
7
6
|
module RuboCopFMT
|
@@ -32,10 +31,6 @@ module RuboCopFMT
|
|
32
31
|
|
33
32
|
private
|
34
33
|
|
35
|
-
def auto_correct_sources
|
36
|
-
sources.map(&:auto_correct)
|
37
|
-
end
|
38
|
-
|
39
34
|
def require_real_files(flag)
|
40
35
|
return unless @options.paths.empty?
|
41
36
|
|
@@ -45,16 +40,14 @@ module RuboCopFMT
|
|
45
40
|
|
46
41
|
def print_corrected_list
|
47
42
|
require_real_files('--list')
|
48
|
-
auto_correct_sources
|
49
43
|
|
50
|
-
|
44
|
+
for_corrected_source do |source|
|
45
|
+
puts source.path
|
46
|
+
end
|
51
47
|
end
|
52
48
|
|
53
49
|
def print_diff_of_corrections
|
54
|
-
|
55
|
-
|
56
|
-
sources.each do |source|
|
57
|
-
next unless source.corrected?
|
50
|
+
for_corrected_source do |source|
|
58
51
|
puts "diff #{source.path} rubocopfmt/#{source.path}" if source.path
|
59
52
|
puts diff_source(source)
|
60
53
|
end
|
@@ -62,17 +55,16 @@ module RuboCopFMT
|
|
62
55
|
|
63
56
|
def write_corrected_source
|
64
57
|
require_real_files('--write')
|
65
|
-
auto_correct_sources
|
66
58
|
|
67
|
-
|
68
|
-
File.write(source.path, source.output)
|
59
|
+
for_corrected_source do |source|
|
60
|
+
File.write(source.path, source.output)
|
69
61
|
end
|
70
62
|
end
|
71
63
|
|
72
64
|
def print_corrected_source
|
73
|
-
|
74
|
-
|
75
|
-
|
65
|
+
for_corrected_source(skip_unchanged: false) do |source|
|
66
|
+
print source.output
|
67
|
+
end
|
76
68
|
end
|
77
69
|
|
78
70
|
def sources
|
@@ -87,14 +79,18 @@ module RuboCopFMT
|
|
87
79
|
end
|
88
80
|
end
|
89
81
|
|
90
|
-
def
|
91
|
-
|
92
|
-
source.
|
93
|
-
|
94
|
-
diff: '-U 3'
|
95
|
-
)
|
82
|
+
def for_corrected_source(skip_unchanged: true)
|
83
|
+
sources.each do |source|
|
84
|
+
source.auto_correct
|
85
|
+
next if skip_unchanged && !source.corrected?
|
96
86
|
|
97
|
-
|
87
|
+
yield(source)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def diff_source(source)
|
92
|
+
diff = Diff.new(source)
|
93
|
+
diff.render(options.diff_format)
|
98
94
|
end
|
99
95
|
|
100
96
|
def new_source_from_stdin(path = nil)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'diffy'
|
2
|
+
|
3
|
+
module RuboCopFMT
|
4
|
+
class Diff
|
5
|
+
FORMATS = {
|
6
|
+
unified: '-U 3',
|
7
|
+
rcs: '-n',
|
8
|
+
context: '-C 3'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
DEFAULT_FORMAT = :unified
|
12
|
+
|
13
|
+
attr_reader :source
|
14
|
+
|
15
|
+
def self.valid_format?(format)
|
16
|
+
FORMATS.key?(format.downcase.to_sym)
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(source)
|
20
|
+
@source = source
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(format = nil)
|
24
|
+
diff = Diffy::Diff.new(
|
25
|
+
source.input, source.output,
|
26
|
+
include_diff_info: true,
|
27
|
+
diff: diff_opts(format)
|
28
|
+
)
|
29
|
+
|
30
|
+
diff.to_s(:text)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def diff_opts(format = nil)
|
36
|
+
return FORMATS[format.downcase.to_sym] if format
|
37
|
+
FORMATS[DEFAULT_FORMAT]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/rubocopfmt/options.rb
CHANGED
@@ -37,16 +37,26 @@ module RuboCopFMT
|
|
37
37
|
opt :list, 'List files whose formatting is incorrect.'
|
38
38
|
opt :write, 'Write result to (source) file instead of STDOUT.'
|
39
39
|
opt :stdin_file, 'Optionally provide file path when using STDIN.',
|
40
|
-
short: '
|
40
|
+
short: 'F', type: :string
|
41
|
+
opt :diff_format, 'Display diffs using format: unified, rcs, context',
|
42
|
+
short: 'D', type: :string
|
41
43
|
banner ''
|
42
44
|
|
43
45
|
conflicts :diff, :list, :write
|
46
|
+
conflicts :diff_format, :list, :write
|
47
|
+
end
|
48
|
+
|
49
|
+
if opts[:diff_format] && !Diff.valid_format?(opts[:diff_format])
|
50
|
+
Trollop.die :diff_format,
|
51
|
+
"does not support \"#{opts[:diff_format]}\" format"
|
52
|
+
end
|
53
|
+
|
54
|
+
opts[:diff] = true if opts[:diff_format] && !opts[:diff]
|
55
|
+
|
56
|
+
opts.each do |k, v|
|
57
|
+
options.send("#{k}=", v) if options.respond_to?("#{k}=")
|
44
58
|
end
|
45
59
|
|
46
|
-
options.diff = opts[:diff]
|
47
|
-
options.list = opts[:list]
|
48
|
-
options.write = opts[:write]
|
49
|
-
options.stdin_file = opts[:stdin_file]
|
50
60
|
options
|
51
61
|
end
|
52
62
|
end
|
data/lib/rubocopfmt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocopfmt
|
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
|
- Jim Myhrberg
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/rubocopfmt/auto_corrector.rb
|
131
131
|
- lib/rubocopfmt/cli.rb
|
132
132
|
- lib/rubocopfmt/core_ext/string.rb
|
133
|
+
- lib/rubocopfmt/diff.rb
|
133
134
|
- lib/rubocopfmt/errors.rb
|
134
135
|
- lib/rubocopfmt/formatter.rb
|
135
136
|
- lib/rubocopfmt/options.rb
|