rubocopfmt 0.1.0.beta4 → 0.1.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocopfmt/auto_corrector.rb +5 -5
- data/lib/rubocopfmt/cli.rb +16 -52
- data/lib/rubocopfmt/{options_parser.rb → cli_options.rb} +25 -19
- data/lib/rubocopfmt/diff.rb +7 -1
- data/lib/rubocopfmt/formatter.rb +46 -3
- data/lib/rubocopfmt/options.rb +0 -2
- data/lib/rubocopfmt/rubocop_formatter.rb +6 -0
- data/lib/rubocopfmt/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fa9af7cf679b86a5ef27cf338e97c13b8bda718
|
4
|
+
data.tar.gz: bc0456f52025e46daa569daa4c6057a38c95f853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a761e3295527c8d8f39ce6e31b6ddd29263cd5d79ebba0bb9616e5765be22957c87ea428a3a7f022f77945fd780a55c121aeb029c3ecdad22467bb780c64ba5
|
7
|
+
data.tar.gz: 717eeb9ee0c8134293c07876f8c7e2eac7e729ab75d2ad611f87858627317d7c6cd7e4f9bbe161aa60392d05896d41ff3fac8354e4d2618df0d3d1a49b2567d1
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubocop'
|
2
2
|
|
3
|
-
require 'rubocopfmt/
|
3
|
+
require 'rubocopfmt/rubocop_formatter'
|
4
4
|
|
5
5
|
module RuboCopFMT
|
6
6
|
class AutoCorrector
|
@@ -13,7 +13,7 @@ module RuboCopFMT
|
|
13
13
|
RUBOCOP_ARGV = [
|
14
14
|
'--auto-correct',
|
15
15
|
'--cache', 'false',
|
16
|
-
'--format', 'RuboCopFMT::
|
16
|
+
'--format', 'RuboCopFMT::RubocopFormatter',
|
17
17
|
'--except', DISABLED_COPS.join(',')
|
18
18
|
].freeze
|
19
19
|
|
@@ -27,7 +27,7 @@ module RuboCopFMT
|
|
27
27
|
|
28
28
|
def correct
|
29
29
|
Rainbow.enabled = false if defined?(Rainbow)
|
30
|
-
@runner = RuboCop::Runner.new(options, config_store)
|
30
|
+
@runner = ::RuboCop::Runner.new(options, config_store)
|
31
31
|
@runner.run(paths)
|
32
32
|
options[:stdin]
|
33
33
|
end
|
@@ -37,7 +37,7 @@ module RuboCopFMT
|
|
37
37
|
def config_store
|
38
38
|
return @config_store if @config_store
|
39
39
|
|
40
|
-
@config_store = RuboCop::ConfigStore.new
|
40
|
+
@config_store = ::RuboCop::ConfigStore.new
|
41
41
|
@config_store.options_config = options[:config] if options[:config]
|
42
42
|
@config_store.force_default_config! if options[:force_default_config]
|
43
43
|
@config_store
|
@@ -59,7 +59,7 @@ module RuboCopFMT
|
|
59
59
|
|
60
60
|
def set_options_and_paths
|
61
61
|
argv = RUBOCOP_ARGV + [@path || 'fake.rb']
|
62
|
-
@options, @paths = RuboCop::Options.new.parse(argv)
|
62
|
+
@options, @paths = ::RuboCop::Options.new.parse(argv)
|
63
63
|
@options[:stdin] = source
|
64
64
|
|
65
65
|
[@options, @paths]
|
data/lib/rubocopfmt/cli.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubocopfmt/diff'
|
2
2
|
require 'rubocopfmt/errors'
|
3
|
-
require 'rubocopfmt/
|
4
|
-
require 'rubocopfmt/
|
3
|
+
require 'rubocopfmt/cli_options'
|
4
|
+
require 'rubocopfmt/formatter'
|
5
5
|
|
6
6
|
module RuboCopFMT
|
7
7
|
class CLI
|
@@ -10,12 +10,17 @@ module RuboCopFMT
|
|
10
10
|
end
|
11
11
|
|
12
12
|
attr_reader :options
|
13
|
+
attr_reader :sources
|
13
14
|
|
14
15
|
def initialize(args)
|
15
|
-
@options =
|
16
|
+
@options = CLIOptions.parse(args)
|
16
17
|
end
|
17
18
|
|
18
19
|
def run
|
20
|
+
runner = Formatter.new(options)
|
21
|
+
runner.run
|
22
|
+
@sources = runner.sources
|
23
|
+
|
19
24
|
if @options.list
|
20
25
|
print_corrected_list
|
21
26
|
elsif @options.diff
|
@@ -31,23 +36,16 @@ module RuboCopFMT
|
|
31
36
|
|
32
37
|
private
|
33
38
|
|
34
|
-
def require_real_files(flag)
|
35
|
-
return unless @options.paths.empty?
|
36
|
-
|
37
|
-
$stderr.puts "ERROR: To use #{flag} you must specify one or more files"
|
38
|
-
exit 1
|
39
|
-
end
|
40
|
-
|
41
39
|
def print_corrected_list
|
42
|
-
|
43
|
-
|
44
|
-
for_corrected_source do |source|
|
45
|
-
puts source.path
|
40
|
+
sources.each do |source|
|
41
|
+
puts source.path if source.corrected?
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
49
45
|
def print_diff_of_corrections
|
50
|
-
|
46
|
+
sources.each do |source|
|
47
|
+
next unless source.corrected?
|
48
|
+
|
51
49
|
if source.path && sources.size > 1
|
52
50
|
puts "diff #{source.path} rubocopfmt/#{source.path}"
|
53
51
|
end
|
@@ -56,37 +54,14 @@ module RuboCopFMT
|
|
56
54
|
end
|
57
55
|
|
58
56
|
def write_corrected_source
|
59
|
-
|
60
|
-
|
61
|
-
for_corrected_source do |source|
|
62
|
-
File.write(source.path, source.output)
|
57
|
+
sources.each do |source|
|
58
|
+
File.write(source.path, source.output) if source.corrected?
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
62
|
def print_corrected_source
|
67
|
-
for_corrected_source(skip_unchanged: false) do |source|
|
68
|
-
print source.output
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def sources
|
73
|
-
return @sources if @sources
|
74
|
-
|
75
|
-
if options.paths.empty?
|
76
|
-
@sources = [new_source_from_stdin(options.stdin_file)]
|
77
|
-
else
|
78
|
-
@sources = options.paths.map do |path|
|
79
|
-
new_source_from_file(path)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def for_corrected_source(skip_unchanged: true)
|
85
63
|
sources.each do |source|
|
86
|
-
source.
|
87
|
-
next if skip_unchanged && !source.corrected?
|
88
|
-
|
89
|
-
yield(source)
|
64
|
+
print source.output
|
90
65
|
end
|
91
66
|
end
|
92
67
|
|
@@ -94,16 +69,5 @@ module RuboCopFMT
|
|
94
69
|
diff = Diff.new(source)
|
95
70
|
diff.render(options.diff_format)
|
96
71
|
end
|
97
|
-
|
98
|
-
def new_source_from_stdin(path = nil)
|
99
|
-
Source.new($stdin.binmode.read, path)
|
100
|
-
end
|
101
|
-
|
102
|
-
def new_source_from_file(path)
|
103
|
-
raise FileNotFound, "File not found: #{path}" unless File.exist?(path)
|
104
|
-
|
105
|
-
source = File.read(path, mode: 'rb')
|
106
|
-
Source.new(source, path)
|
107
|
-
end
|
108
72
|
end
|
109
73
|
end
|
@@ -6,22 +6,25 @@ require 'rubocopfmt/options'
|
|
6
6
|
require 'rubocopfmt/version'
|
7
7
|
|
8
8
|
module RuboCopFMT
|
9
|
-
class
|
9
|
+
class CLIOptions
|
10
10
|
class << self
|
11
|
-
def parse(args
|
11
|
+
def parse(args)
|
12
12
|
args = args.clone
|
13
|
-
options ||= Options.new
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
opts = parse_args(args)
|
15
|
+
opts[:paths] = args
|
16
|
+
opts[:diff] = true if opts[:diff_format] && !opts[:diff]
|
17
|
+
|
18
|
+
validate_diff_format(opts)
|
19
|
+
validate_paths(opts)
|
17
20
|
|
18
|
-
|
21
|
+
opts
|
19
22
|
end
|
20
23
|
|
21
24
|
private
|
22
25
|
|
23
|
-
def
|
24
|
-
|
26
|
+
def parse_args(args)
|
27
|
+
Trollop.options(args) do
|
25
28
|
banner <<-EOF.undent
|
26
29
|
Usage: rubocopfmt [options] [path ...]
|
27
30
|
|
@@ -30,8 +33,8 @@ module RuboCopFMT
|
|
30
33
|
Options:
|
31
34
|
EOF
|
32
35
|
|
33
|
-
version "rubocopfmt #{RuboCopFMT::VERSION}" \
|
34
|
-
"
|
36
|
+
version "rubocopfmt #{RuboCopFMT::VERSION} " \
|
37
|
+
"(rubocop #{::RuboCop::Version::STRING})"
|
35
38
|
|
36
39
|
opt :diff, 'Display diffs instead of rewriting files.'
|
37
40
|
opt :list, 'List files whose formatting is incorrect.'
|
@@ -45,19 +48,22 @@ module RuboCopFMT
|
|
45
48
|
conflicts :diff, :list, :write
|
46
49
|
conflicts :diff_format, :list, :write
|
47
50
|
end
|
51
|
+
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
def validate_paths(opts)
|
54
|
+
[:list, :write].each do |opt|
|
55
|
+
if opts[opt] && opts[:paths].empty?
|
56
|
+
Trollop.die(opt, 'requires one or more paths to be specified')
|
57
|
+
end
|
52
58
|
end
|
59
|
+
end
|
53
60
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
options.send("#{k}=", v) if options.respond_to?("#{k}=")
|
58
|
-
end
|
61
|
+
def validate_diff_format(opts)
|
62
|
+
return if opts[:diff_format].nil? \
|
63
|
+
|| Diff.valid_format?(opts[:diff_format])
|
59
64
|
|
60
|
-
|
65
|
+
Trollop.die(:diff_format,
|
66
|
+
"does not support \"#{opts[:diff_format]}\" format")
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
data/lib/rubocopfmt/diff.rb
CHANGED
@@ -27,11 +27,17 @@ module RuboCopFMT
|
|
27
27
|
diff: diff_opts(format)
|
28
28
|
)
|
29
29
|
|
30
|
-
diff.to_s(:text)
|
30
|
+
out = diff.to_s(:text)
|
31
|
+
out << "\n" if rcs?(format)
|
32
|
+
out
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
34
36
|
|
37
|
+
def rcs?(format)
|
38
|
+
diff_opts(format) == FORMATS[:rcs]
|
39
|
+
end
|
40
|
+
|
35
41
|
def diff_opts(format = nil)
|
36
42
|
format ? FORMATS[format.downcase.to_sym] : DEFAULT_FORMAT
|
37
43
|
end
|
data/lib/rubocopfmt/formatter.rb
CHANGED
@@ -1,6 +1,49 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubocopfmt/errors'
|
2
|
+
require 'rubocopfmt/options'
|
3
|
+
require 'rubocopfmt/source'
|
2
4
|
|
3
5
|
module RuboCopFMT
|
4
|
-
|
5
|
-
|
6
|
+
class Formatter
|
7
|
+
attr_reader :sources
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
opts.each do |k, v|
|
11
|
+
options.send("#{k}=", v) if options.respond_to?("#{k}=")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
sources = build_sources
|
17
|
+
sources.map(&:auto_correct)
|
18
|
+
|
19
|
+
@sources = sources
|
20
|
+
end
|
21
|
+
|
22
|
+
def options
|
23
|
+
@options ||= Options.new
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_sources
|
29
|
+
if options.paths.empty?
|
30
|
+
[new_source_from_stdin(options.stdin_file)]
|
31
|
+
else
|
32
|
+
options.paths.map do |path|
|
33
|
+
new_source_from_file(path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_source_from_stdin(path = nil)
|
39
|
+
Source.new($stdin.binmode.read, path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def new_source_from_file(path)
|
43
|
+
raise FileNotFound, "File not found: #{path}" unless File.exist?(path)
|
44
|
+
|
45
|
+
source = File.read(path, mode: 'rb')
|
46
|
+
Source.new(source, path)
|
47
|
+
end
|
48
|
+
end
|
6
49
|
end
|
data/lib/rubocopfmt/options.rb
CHANGED
data/lib/rubocopfmt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.beta5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Myhrberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,12 +130,13 @@ files:
|
|
130
130
|
- lib/rubocopfmt.rb
|
131
131
|
- lib/rubocopfmt/auto_corrector.rb
|
132
132
|
- lib/rubocopfmt/cli.rb
|
133
|
+
- lib/rubocopfmt/cli_options.rb
|
133
134
|
- lib/rubocopfmt/core_ext/string.rb
|
134
135
|
- lib/rubocopfmt/diff.rb
|
135
136
|
- lib/rubocopfmt/errors.rb
|
136
137
|
- lib/rubocopfmt/formatter.rb
|
137
138
|
- lib/rubocopfmt/options.rb
|
138
|
-
- lib/rubocopfmt/
|
139
|
+
- lib/rubocopfmt/rubocop_formatter.rb
|
139
140
|
- lib/rubocopfmt/source.rb
|
140
141
|
- lib/rubocopfmt/version.rb
|
141
142
|
- rubocopfmt.gemspec
|