rubocopfmt 0.1.0.beta7 → 0.1.0.beta8
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 +4 -4
- data/lib/rubocopfmt/cli.rb +11 -12
- data/lib/rubocopfmt/cli_options.rb +26 -4
- data/lib/rubocopfmt/diff.rb +4 -0
- data/lib/rubocopfmt/formatter.rb +7 -15
- data/lib/rubocopfmt/options.rb +1 -0
- data/lib/rubocopfmt/version.rb +1 -1
- data/rubocopfmt.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f07e82e60b03c9b3d67b6e1eff442d92e1e7a03
|
4
|
+
data.tar.gz: 4109b54c44c6e189029eb8db10549ab27d57f945
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed13ead3cded942a7a3e917b86af9f60932985efaf12af950311ba9148ced9dc9e6611e2daaf4a3f583e82553b1d43461f848c23111eeb9c168e40507874ec88
|
7
|
+
data.tar.gz: dc096d32c927b0740b87e92ee730f17d555e43149098d05d62f748d8452d067c4f0d8d8da1a7aa477b3a0ed260a60f027e82611047d360f7db68f13241df8eb0
|
data/README.md
CHANGED
@@ -18,10 +18,10 @@ Usage: rubocopfmt [options] [path ...]
|
|
18
18
|
Reads from STDIN if no path is given.
|
19
19
|
|
20
20
|
Options:
|
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
|
-
-
|
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
|
+
-S, --src-dir=<s> Operate as if code resides in specified directory
|
25
25
|
-D, --diff-format=<s> Display diffs using format: unified, rcs, context
|
26
26
|
|
27
27
|
-v, --version Print version and exit
|
data/lib/rubocopfmt/cli.rb
CHANGED
@@ -17,15 +17,13 @@ module RuboCopFMT
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def run
|
20
|
-
|
21
|
-
formatter.run
|
22
|
-
@sources = formatter.sources
|
20
|
+
format_sources
|
23
21
|
|
24
|
-
if
|
22
|
+
if options.list
|
25
23
|
print_corrected_list
|
26
|
-
elsif
|
24
|
+
elsif options.diff
|
27
25
|
print_diff_of_corrections
|
28
|
-
elsif
|
26
|
+
elsif options.write
|
29
27
|
write_corrected_source
|
30
28
|
else
|
31
29
|
print_corrected_source
|
@@ -36,6 +34,12 @@ module RuboCopFMT
|
|
36
34
|
|
37
35
|
private
|
38
36
|
|
37
|
+
def format_sources
|
38
|
+
formatter = Formatter.new(options)
|
39
|
+
formatter.run
|
40
|
+
@sources = formatter.sources
|
41
|
+
end
|
42
|
+
|
39
43
|
def print_corrected_list
|
40
44
|
sources.each do |source|
|
41
45
|
puts source.path if source.corrected?
|
@@ -49,7 +53,7 @@ module RuboCopFMT
|
|
49
53
|
if source.path && sources.size > 1
|
50
54
|
puts "diff #{source.path} rubocopfmt/#{source.path}"
|
51
55
|
end
|
52
|
-
puts
|
56
|
+
puts Diff.render(source, options.diff_format)
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
@@ -64,10 +68,5 @@ module RuboCopFMT
|
|
64
68
|
print source.output
|
65
69
|
end
|
66
70
|
end
|
67
|
-
|
68
|
-
def diff_source(source)
|
69
|
-
diff = Diff.new(source)
|
70
|
-
diff.render(options.diff_format)
|
71
|
-
end
|
72
71
|
end
|
73
72
|
end
|
@@ -18,13 +18,20 @@ module RuboCopFMT
|
|
18
18
|
validate_diff_format(opts)
|
19
19
|
validate_paths(opts)
|
20
20
|
|
21
|
+
opts[:input] = read_stdin if opts[:paths].empty?
|
21
22
|
opts
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
27
|
def parse_args(args)
|
27
|
-
Trollop.
|
28
|
+
Trollop.with_standard_exception_handling(parser) do
|
29
|
+
parser.parse(args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parser
|
34
|
+
@parser ||= Trollop::Parser.new do
|
28
35
|
banner <<-EOF.undent
|
29
36
|
Usage: rubocopfmt [options] [path ...]
|
30
37
|
|
@@ -50,10 +57,23 @@ module RuboCopFMT
|
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
60
|
+
def read_stdin
|
61
|
+
tries = 0
|
62
|
+
begin
|
63
|
+
str = $stdin.binmode.read_nonblock(1)
|
64
|
+
rescue IO::WaitReadable, EOFError
|
65
|
+
IO.select([$stdin.binmode], nil, nil, 0.2)
|
66
|
+
retry if (tries += 1) <= 1
|
67
|
+
end
|
68
|
+
|
69
|
+
parser.die('Failed to read from STDIN', nil) if str.nil?
|
70
|
+
str + $stdin.binmode.read
|
71
|
+
end
|
72
|
+
|
53
73
|
def validate_paths(opts)
|
54
74
|
[:list, :write].each do |opt|
|
55
75
|
if opts[opt] && opts[:paths].empty?
|
56
|
-
|
76
|
+
parser.die(opt, 'requires one or more paths to be specified')
|
57
77
|
end
|
58
78
|
end
|
59
79
|
end
|
@@ -62,8 +82,10 @@ module RuboCopFMT
|
|
62
82
|
return if opts[:diff_format].nil? \
|
63
83
|
|| Diff.valid_format?(opts[:diff_format])
|
64
84
|
|
65
|
-
|
66
|
-
|
85
|
+
parser.die(
|
86
|
+
:diff_format,
|
87
|
+
"does not support \"#{opts[:diff_format]}\" format"
|
88
|
+
)
|
67
89
|
end
|
68
90
|
end
|
69
91
|
end
|
data/lib/rubocopfmt/diff.rb
CHANGED
data/lib/rubocopfmt/formatter.rb
CHANGED
@@ -13,7 +13,9 @@ module RuboCopFMT
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
16
|
-
sources =
|
16
|
+
sources = []
|
17
|
+
sources << new_source_from_str(options.input) if options.input
|
18
|
+
sources += options.paths.map { |path| new_source_from_file(path) }
|
17
19
|
sources.map(&:auto_correct)
|
18
20
|
|
19
21
|
@sources = sources
|
@@ -25,25 +27,15 @@ module RuboCopFMT
|
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
def
|
29
|
-
|
30
|
-
[new_source_from_stdin]
|
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
|
39
|
-
Source.new($stdin.binmode.read, nil, options.src_dir)
|
30
|
+
def new_source_from_str(str)
|
31
|
+
Source.new(str, nil, options.src_dir)
|
40
32
|
end
|
41
33
|
|
42
34
|
def new_source_from_file(path)
|
43
35
|
raise FileNotFound, "File not found: #{path}" unless File.exist?(path)
|
44
36
|
|
45
|
-
|
46
|
-
Source.new(
|
37
|
+
input = File.read(path, mode: 'rb')
|
38
|
+
Source.new(input, path, options.src_dir)
|
47
39
|
end
|
48
40
|
end
|
49
41
|
end
|
data/lib/rubocopfmt/options.rb
CHANGED
data/lib/rubocopfmt/version.rb
CHANGED
data/rubocopfmt.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
24
|
-
spec.add_development_dependency 'rake', '~>
|
24
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
26
|
spec.add_development_dependency 'byebug'
|
27
27
|
|
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.beta8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Myhrberg
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|