rubocopfmt 0.1.0.beta7 → 0.1.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bf78c5ac751ef29855d0ef4d566c9960926173b
4
- data.tar.gz: de2da7fbe495d37d12dc79582c2a703084d42e6b
3
+ metadata.gz: 5f07e82e60b03c9b3d67b6e1eff442d92e1e7a03
4
+ data.tar.gz: 4109b54c44c6e189029eb8db10549ab27d57f945
5
5
  SHA512:
6
- metadata.gz: 2259350145f6eeb723038aa9eae4e0505fc737c275024951c9f249190e3dc666aea229d26bbbea391b36f46656988081ec4fa84bb009c0168b07f0ab42b76cee
7
- data.tar.gz: a8b3d02c97d42ff7e3f0e610c60a7d7693f653fc2cf013ab5e71d1044d064c4dcffddda1a9409f80ad1eaac5f2ccc81792dbf88434435a673b009b51f5b6fef0
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
- -F, --stdin-file=<s> Optionally provide file path when using STDIN.
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
@@ -17,15 +17,13 @@ module RuboCopFMT
17
17
  end
18
18
 
19
19
  def run
20
- formatter = Formatter.new(options)
21
- formatter.run
22
- @sources = formatter.sources
20
+ format_sources
23
21
 
24
- if @options.list
22
+ if options.list
25
23
  print_corrected_list
26
- elsif @options.diff
24
+ elsif options.diff
27
25
  print_diff_of_corrections
28
- elsif @options.write
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 diff_source(source)
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.options(args) do
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
- Trollop.die(opt, 'requires one or more paths to be specified')
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
- Trollop.die(:diff_format,
66
- "does not support \"#{opts[:diff_format]}\" format")
85
+ parser.die(
86
+ :diff_format,
87
+ "does not support \"#{opts[:diff_format]}\" format"
88
+ )
67
89
  end
68
90
  end
69
91
  end
@@ -12,6 +12,10 @@ module RuboCopFMT
12
12
 
13
13
  attr_reader :source
14
14
 
15
+ def self.render(source, format = nil)
16
+ new(source).render(format)
17
+ end
18
+
15
19
  def self.valid_format?(format)
16
20
  FORMATS.key?(format.downcase.to_sym)
17
21
  end
@@ -13,7 +13,9 @@ module RuboCopFMT
13
13
  end
14
14
 
15
15
  def run
16
- sources = build_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 build_sources
29
- if options.paths.empty?
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
- source = File.read(path, mode: 'rb')
46
- Source.new(source, path, options.src_dir)
37
+ input = File.read(path, mode: 'rb')
38
+ Source.new(input, path, options.src_dir)
47
39
  end
48
40
  end
49
41
  end
@@ -1,5 +1,6 @@
1
1
  module RuboCopFMT
2
2
  class Options
3
+ attr_accessor :input
3
4
  attr_accessor :src_dir
4
5
  attr_accessor :diff_format
5
6
 
@@ -1,3 +1,3 @@
1
1
  module RuboCopFMT
2
- VERSION = '0.1.0.beta7'.freeze
2
+ VERSION = '0.1.0.beta8'.freeze
3
3
  end
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', '~> 10.0'
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.beta7
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: '10.0'
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: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement