rubocopfmt 0.1.0.beta1 → 0.1.0.beta2

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: a012ee79b8442b495047743bacaa7638bd12f39e
4
- data.tar.gz: 0f68b98d269a76ea2a4049c1dc8ffc66f56e6653
3
+ metadata.gz: 5964e7d80d992e05a65799d94271249cfe563e36
4
+ data.tar.gz: 97623211f9bf546a16654aecda5117b2a3f9b1bd
5
5
  SHA512:
6
- metadata.gz: 2db966f9d9b1e13cc952dfa6121cec9e08c63e7774ac0c5bd86d90175c43acb0a4611ebdc3b9ea57c42106d6df59a06edc6846e89bc312078017db352e9cbfb6
7
- data.tar.gz: 4c957d666f21e30862be1b889659bcf36b6b9ab08cc2aa2307368e7673410dbb4b5eb8da074bbc5bcbf9a0526ba7963e08061baa8a1cce997cb9ad111426d6ab
6
+ metadata.gz: f38caac15512b59497dd4b07dda77beb1da67bd854cddd4e90c9b6f36dc82a9e84479f23c8ec4acdf79096926bf7c64e5266d2b042fe909bee8c268bfe55f753
7
+ data.tar.gz: 85d365454150441eb9cd9aea763e2ef9f7f7819086b47c5610eed1d769d9363129b7ff90882daf90696ee5d5ffde268c1a1e407b73a9967a27396894997369c3
data/.travis.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.1
5
+ - 2.2
4
6
  - 2.3.3
7
+ - 2.4.0
5
8
  before_install: gem install bundler -v 1.13.6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rubocopfmt
1
+ # rubocopfmt [![Build Status](https://api.travis-ci.org/jimeh/rubocopfmt.svg)](https://travis-ci.org/jimeh/rubocopfmt)
2
2
 
3
3
  Easy formatting of Ruby code
4
4
  using [RuboCop](https://github.com/bbatsov/rubocop). Analogous
@@ -7,7 +7,7 @@ to [`gofmt`](https://golang.org/cmd/gofmt/).
7
7
  ## Installation
8
8
 
9
9
  ```
10
- gem install rubocopfmt
10
+ gem install rubocopfmt --pre
11
11
  ```
12
12
 
13
13
  ## Usage
@@ -9,42 +9,59 @@ module RuboCopFMT
9
9
  'Lint/UnusedBlockArgument'
10
10
  ].freeze
11
11
 
12
- RUBOCOP_OPTS = [
12
+ RUBOCOP_ARGV = [
13
13
  '--auto-correct',
14
14
  '--cache', 'false',
15
15
  '--format', 'RuboCopFMT::Formatter',
16
- '--except', DISABLED_COPS.join(','),
17
- 'fake.rb'
16
+ '--except', DISABLED_COPS.join(',')
18
17
  ].freeze
19
18
 
20
19
  attr_reader :source
21
20
  attr_reader :runner
22
21
 
23
- def initialize(source)
22
+ def initialize(source, path = nil)
24
23
  @source = source
24
+ @path = path
25
25
  end
26
26
 
27
27
  def correct
28
- options, paths = RuboCop::Options.new.parse(RUBOCOP_OPTS)
29
- config_store = RuboCop::ConfigStore.new
30
-
31
- options[:stdin] = source
32
-
33
28
  Rainbow.enabled = false
34
- config_store.options_config = options[:config] if options[:config]
35
- config_store.force_default_config! if options[:force_default_config]
36
-
37
29
  @runner = RuboCop::Runner.new(options, config_store)
38
30
  @runner.run(paths)
39
31
  options[:stdin]
40
32
  end
41
33
 
42
- def warnings
43
- runner && runner.warnings
34
+ private
35
+
36
+ def config_store
37
+ return @config_store if @config_store
38
+
39
+ @config_store = RuboCop::ConfigStore.new
40
+ @config_store.options_config = options[:config] if options[:config]
41
+ @config_store.force_default_config! if options[:force_default_config]
42
+ @config_store
43
+ end
44
+
45
+ def options
46
+ return @options if @options
47
+
48
+ set_options_and_paths
49
+ @options
50
+ end
51
+
52
+ def paths
53
+ return @paths if @paths
54
+
55
+ set_options_and_paths
56
+ @paths
44
57
  end
45
58
 
46
- def errors
47
- runner && runner.errors
59
+ def set_options_and_paths
60
+ argv = RUBOCOP_ARGV + [@path || 'fake.rb']
61
+ @options, @paths = RuboCop::Options.new.parse(argv)
62
+ @options[:stdin] = source
63
+
64
+ [@options, @paths]
48
65
  end
49
66
  end
50
67
  end
@@ -37,7 +37,7 @@ module RuboCopFMT
37
37
  end
38
38
 
39
39
  def require_real_files(flag)
40
- return unless @options.files.empty?
40
+ return unless @options.paths.empty?
41
41
 
42
42
  $stderr.puts "ERROR: To use #{flag} you must specify one or more files"
43
43
  exit 1
@@ -78,10 +78,10 @@ module RuboCopFMT
78
78
  def sources
79
79
  return @sources if @sources
80
80
 
81
- if options.files.empty?
82
- @sources = [new_source_from_stdin]
81
+ if options.paths.empty?
82
+ @sources = [new_source_from_stdin(options.stdin_file)]
83
83
  else
84
- @sources = options.files.map do |path|
84
+ @sources = options.paths.map do |path|
85
85
  new_source_from_file(path)
86
86
  end
87
87
  end
@@ -97,8 +97,8 @@ module RuboCopFMT
97
97
  diff.to_s(:text)
98
98
  end
99
99
 
100
- def new_source_from_stdin
101
- Source.new($stdin.binmode.read)
100
+ def new_source_from_stdin(path = nil)
101
+ Source.new($stdin.binmode.read, path)
102
102
  end
103
103
 
104
104
  def new_source_from_file(path)
@@ -0,0 +1,5 @@
1
+ class String
2
+ def undent
3
+ gsub(/^.{#{slice(/^ +/).length}}/, '')
4
+ end
5
+ end
@@ -2,10 +2,12 @@ require 'rubocopfmt/options_parser'
2
2
 
3
3
  module RuboCopFMT
4
4
  class Options
5
- def files
6
- @files.nil? ? [] : @files
5
+ attr_accessor :stdin_file
6
+
7
+ def paths
8
+ @paths.nil? ? [] : @paths
7
9
  end
8
- attr_writer :files
10
+ attr_writer :paths
9
11
 
10
12
  def diff
11
13
  @diff.nil? ? false : @diff
@@ -1,6 +1,7 @@
1
- require 'optparse'
1
+ require 'trollop'
2
2
  require 'rubocop'
3
3
 
4
+ require 'rubocopfmt/core_ext/string'
4
5
  require 'rubocopfmt/options'
5
6
  require 'rubocopfmt/version'
6
7
 
@@ -12,7 +13,7 @@ module RuboCopFMT
12
13
  options ||= Options.new
13
14
 
14
15
  parse_flags(args, options)
15
- options.files = args unless args.empty?
16
+ options.paths = args unless args.empty?
16
17
 
17
18
  options
18
19
  end
@@ -20,45 +21,33 @@ module RuboCopFMT
20
21
  private
21
22
 
22
23
  def parse_flags(args, options)
23
- parser = OptionParser.new do |opts|
24
- opts.program_name = 'rubocopfmt'
25
- opts.version = RuboCopFMT::VERSION
24
+ opts = Trollop.options(args) do
25
+ banner <<-EOF.undent
26
+ Usage: rubocopfmt [options] [path ...]
26
27
 
27
- opts.banner = 'Usage: rubocopfmt [options] [path ...]'
28
- opts.separator ''
29
- opts.separator 'Reads from STDIN if no path is given.'
30
- opts.separator ''
31
- opts.separator 'Options:'
28
+ Reads from STDIN if no path is given.
32
29
 
33
- opts.on(
34
- '-d', '--diff',
35
- 'Display diffs instead of rewriting files.'
36
- ) { |v| options.diff = v }
30
+ Options:
31
+ EOF
37
32
 
38
- opts.on(
39
- '-l', '--list',
40
- 'List files whose formatting is incorrect.'
41
- ) { |v| options.list = v }
33
+ version "rubocopfmt #{RuboCopFMT::VERSION}" \
34
+ " (rubocop #{RuboCop::Version::STRING})"
42
35
 
43
- opts.on(
44
- '-w', '--write',
45
- 'Write result to (source) file instead of STDOUT.'
46
- ) { |v| options.write = v }
36
+ opt :diff, 'Display diffs instead of rewriting files.'
37
+ opt :list, 'List files whose formatting is incorrect.'
38
+ opt :write, 'Write result to (source) file instead of STDOUT.'
39
+ opt :stdin_file, 'Optionally provide file path when using STDIN.',
40
+ short: 'f', type: :string
41
+ banner ''
47
42
 
48
- opts.separator ''
49
-
50
- opts.on('-v', '--version', 'Show version.') do
51
- puts "#{opts.program_name} #{opts.version}" \
52
- " (rubocop #{RuboCop::Version::STRING})"
53
- exit
54
- end
55
-
56
- opts.on('-h', '--help', 'Show this message.') do
57
- puts opts
58
- exit
59
- end
43
+ conflicts :diff, :list, :write
60
44
  end
61
- parser.parse!(args)
45
+
46
+ options.diff = opts[:diff]
47
+ options.list = opts[:list]
48
+ options.write = opts[:write]
49
+ options.stdin_file = opts[:stdin_file]
50
+ options
62
51
  end
63
52
  end
64
53
  end
@@ -14,7 +14,7 @@ module RuboCopFMT
14
14
  def auto_correct
15
15
  return unless output.nil?
16
16
 
17
- @corrector = AutoCorrector.new(input)
17
+ @corrector = AutoCorrector.new(input, path)
18
18
  @output = @corrector.correct
19
19
  end
20
20
 
@@ -1,3 +1,3 @@
1
1
  module RuboCopFMT
2
- VERSION = '0.1.0.beta1'.freeze
2
+ VERSION = '0.1.0.beta2'.freeze
3
3
  end
data/rubocopfmt.gemspec CHANGED
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'byebug'
27
27
 
28
28
  spec.add_runtime_dependency 'rubocop', '~> 0.46'
29
+ spec.add_runtime_dependency 'trollop', '~> 2.1'
29
30
  spec.add_runtime_dependency 'diffy', '~> 3.1'
30
31
  end
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.beta1
4
+ version: 0.1.0.beta2
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-06 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.46'
83
+ - !ruby/object:Gem::Dependency
84
+ name: trollop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: diffy
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +129,7 @@ files:
115
129
  - lib/rubocopfmt.rb
116
130
  - lib/rubocopfmt/auto_corrector.rb
117
131
  - lib/rubocopfmt/cli.rb
132
+ - lib/rubocopfmt/core_ext/string.rb
118
133
  - lib/rubocopfmt/errors.rb
119
134
  - lib/rubocopfmt/formatter.rb
120
135
  - lib/rubocopfmt/options.rb