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 +4 -4
- data/.travis.yml +3 -0
- data/README.md +2 -2
- data/lib/rubocopfmt/auto_corrector.rb +33 -16
- data/lib/rubocopfmt/cli.rb +6 -6
- data/lib/rubocopfmt/core_ext/string.rb +5 -0
- data/lib/rubocopfmt/options.rb +5 -3
- data/lib/rubocopfmt/options_parser.rb +24 -35
- data/lib/rubocopfmt/source.rb +1 -1
- data/lib/rubocopfmt/version.rb +1 -1
- data/rubocopfmt.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5964e7d80d992e05a65799d94271249cfe563e36
|
4
|
+
data.tar.gz: 97623211f9bf546a16654aecda5117b2a3f9b1bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f38caac15512b59497dd4b07dda77beb1da67bd854cddd4e90c9b6f36dc82a9e84479f23c8ec4acdf79096926bf7c64e5266d2b042fe909bee8c268bfe55f753
|
7
|
+
data.tar.gz: 85d365454150441eb9cd9aea763e2ef9f7f7819086b47c5610eed1d769d9363129b7ff90882daf90696ee5d5ffde268c1a1e407b73a9967a27396894997369c3
|
data/.travis.yml
CHANGED
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
|
-
|
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
|
-
|
43
|
-
|
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
|
47
|
-
|
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
|
data/lib/rubocopfmt/cli.rb
CHANGED
@@ -37,7 +37,7 @@ module RuboCopFMT
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def require_real_files(flag)
|
40
|
-
return unless @options.
|
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.
|
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.
|
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)
|
data/lib/rubocopfmt/options.rb
CHANGED
@@ -2,10 +2,12 @@ require 'rubocopfmt/options_parser'
|
|
2
2
|
|
3
3
|
module RuboCopFMT
|
4
4
|
class Options
|
5
|
-
|
6
|
-
|
5
|
+
attr_accessor :stdin_file
|
6
|
+
|
7
|
+
def paths
|
8
|
+
@paths.nil? ? [] : @paths
|
7
9
|
end
|
8
|
-
attr_writer :
|
10
|
+
attr_writer :paths
|
9
11
|
|
10
12
|
def diff
|
11
13
|
@diff.nil? ? false : @diff
|
@@ -1,6 +1,7 @@
|
|
1
|
-
require '
|
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.
|
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
|
-
|
24
|
-
|
25
|
-
|
24
|
+
opts = Trollop.options(args) do
|
25
|
+
banner <<-EOF.undent
|
26
|
+
Usage: rubocopfmt [options] [path ...]
|
26
27
|
|
27
|
-
|
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
|
-
|
34
|
-
|
35
|
-
'Display diffs instead of rewriting files.'
|
36
|
-
) { |v| options.diff = v }
|
30
|
+
Options:
|
31
|
+
EOF
|
37
32
|
|
38
|
-
|
39
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/rubocopfmt/source.rb
CHANGED
data/lib/rubocopfmt/version.rb
CHANGED
data/rubocopfmt.gemspec
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.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-
|
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
|