rubocopfmt 0.1.0.beta9 → 0.1.0.beta10
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 +23 -1
- data/lib/rubocopfmt/auto_corrector.rb +15 -24
- data/lib/rubocopfmt/cli.rb +2 -2
- data/lib/rubocopfmt/cli_options.rb +1 -0
- data/lib/rubocopfmt/formatter.rb +1 -1
- data/lib/rubocopfmt/options.rb +5 -0
- data/lib/rubocopfmt/source.rb +2 -2
- data/lib/rubocopfmt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0499af5d4df26074ce977b4ea3b342a4fee80f01'
|
4
|
+
data.tar.gz: 69f4c237faf44139cdeea5e55016ddba7b9e030c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9085840c6e9be2546e22c685ae294f1515baa74b8884ce961cc9386190b2b14199f6c84efed555e0ba66444abcd1266de88f7304040b9b6780511c9fc4d83a62
|
7
|
+
data.tar.gz: 9961b01ba0dbd6fd1aa406556d20f178c4beba1a76c90ef49f53944229ea67b4ebd4c0f112c01e554bc13febdbaac99ea758b71e7860bedae1af6e4c0ba13430
|
data/README.md
CHANGED
@@ -4,6 +4,9 @@ Easy formatting of Ruby code
|
|
4
4
|
using [RuboCop](https://github.com/bbatsov/rubocop). Analogous
|
5
5
|
to [`gofmt`](https://golang.org/cmd/gofmt/).
|
6
6
|
|
7
|
+
Currently the main focus is to provide a simple way to format Ruby code on save
|
8
|
+
in various editors. As such the feature set is very minimal for the time being.
|
9
|
+
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
```
|
@@ -21,6 +24,7 @@ Options:
|
|
21
24
|
-d, --diff Display diffs instead of rewriting files
|
22
25
|
-l, --list List files whose formatting is incorrect
|
23
26
|
-w, --write Write result to (source) file instead of STDOUT
|
27
|
+
-i, --interactive Disable cops that cause confusion in text editors
|
24
28
|
-S, --src-dir=<s> Operate as if code resides in specified directory
|
25
29
|
-D, --diff-format=<s> Display diffs using format: unified, rcs, context
|
26
30
|
|
@@ -35,7 +39,25 @@ RuboCop's [Documentation](http://rubocop.readthedocs.io/en/latest/).
|
|
35
39
|
|
36
40
|
## Editor Integration
|
37
41
|
|
38
|
-
|
42
|
+
- Emacs: https://github.com/jimeh/rubocopfmt-emacs
|
43
|
+
- _More coming soon!_
|
44
|
+
|
45
|
+
## Interactive Mode
|
46
|
+
|
47
|
+
When called from an editor on save, there's a few of Cops that causes
|
48
|
+
confusion when run against half-finished code. Interactive mode disables those
|
49
|
+
cops and should be used by all editor plugins.
|
50
|
+
|
51
|
+
Cops disabled in Interactive mode:
|
52
|
+
|
53
|
+
- `Lint/Debugger`: Removes `debugger` statements. Not helpful when you need to
|
54
|
+
debug something.
|
55
|
+
- `Lint/UnusedBlockArgument`: Don't prefix unused block variable names with
|
56
|
+
`_`. This causes issues if you save after defining a block, but before you use
|
57
|
+
all arguments of the block.
|
58
|
+
- `Lint/UnusedMethodArgument`: Don't prefix unused method variable names with
|
59
|
+
`_`. This causes issues if you save after defining a method, but before you
|
60
|
+
use all arguments of the method.
|
39
61
|
|
40
62
|
## Todo
|
41
63
|
|
@@ -4,6 +4,12 @@ require 'rubocopfmt/rubocop_formatter'
|
|
4
4
|
|
5
5
|
module RuboCopFMT
|
6
6
|
class AutoCorrector
|
7
|
+
BAD_INTERACTIVE_COPS = [
|
8
|
+
'Lint/Debugger',
|
9
|
+
'Lint/UnusedBlockArgument',
|
10
|
+
'Lint/UnusedMethodArgument'
|
11
|
+
].freeze
|
12
|
+
|
7
13
|
attr_reader :input
|
8
14
|
attr_reader :runner
|
9
15
|
|
@@ -12,10 +18,13 @@ module RuboCopFMT
|
|
12
18
|
@path = path
|
13
19
|
end
|
14
20
|
|
15
|
-
def correct
|
21
|
+
def correct(interactive = false)
|
16
22
|
Rainbow.enabled = false if defined?(Rainbow)
|
17
23
|
|
18
|
-
|
24
|
+
options = default_options.clone
|
25
|
+
options[:except] = BAD_INTERACTIVE_COPS if interactive
|
26
|
+
|
27
|
+
@runner = ::RuboCop::Runner.new(options, ::RuboCop::ConfigStore.new)
|
19
28
|
@runner.run(paths)
|
20
29
|
|
21
30
|
options[:stdin]
|
@@ -24,34 +33,16 @@ module RuboCopFMT
|
|
24
33
|
private
|
25
34
|
|
26
35
|
def paths
|
27
|
-
@paths ||= [@path || '
|
36
|
+
@paths ||= [@path || '__fake__.rb']
|
28
37
|
end
|
29
38
|
|
30
|
-
def
|
31
|
-
|
39
|
+
def default_options
|
40
|
+
{
|
32
41
|
stdin: @input,
|
33
42
|
auto_correct: true,
|
34
43
|
cache: 'false',
|
35
|
-
formatters: [['RuboCopFMT::RubocopFormatter']]
|
36
|
-
except: disabled_cops
|
44
|
+
formatters: [['RuboCopFMT::RubocopFormatter']]
|
37
45
|
}
|
38
46
|
end
|
39
|
-
|
40
|
-
def disabled_cops
|
41
|
-
[
|
42
|
-
'Lint/Debugger',
|
43
|
-
'Lint/UnusedMethodArgument',
|
44
|
-
'Lint/UnusedBlockArgument'
|
45
|
-
]
|
46
|
-
end
|
47
|
-
|
48
|
-
def config_store
|
49
|
-
return @config_store if @config_store
|
50
|
-
|
51
|
-
@config_store = ::RuboCop::ConfigStore.new
|
52
|
-
@config_store.options_config = options[:config] if options[:config]
|
53
|
-
@config_store.force_default_config! if options[:force_default_config]
|
54
|
-
@config_store
|
55
|
-
end
|
56
47
|
end
|
57
48
|
end
|
data/lib/rubocopfmt/cli.rb
CHANGED
@@ -17,7 +17,7 @@ module RuboCopFMT
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def run
|
20
|
-
format_sources
|
20
|
+
@sources = format_sources
|
21
21
|
|
22
22
|
if options.list
|
23
23
|
print_corrected_list
|
@@ -37,7 +37,7 @@ module RuboCopFMT
|
|
37
37
|
def format_sources
|
38
38
|
formatter = Formatter.new(options)
|
39
39
|
formatter.run
|
40
|
-
|
40
|
+
formatter.sources
|
41
41
|
end
|
42
42
|
|
43
43
|
def print_corrected_list
|
@@ -46,6 +46,7 @@ module RuboCopFMT
|
|
46
46
|
opt :diff, 'Display diffs instead of rewriting files'
|
47
47
|
opt :list, 'List files whose formatting is incorrect'
|
48
48
|
opt :write, 'Write result to (source) file instead of STDOUT'
|
49
|
+
opt :interactive, 'Disable cops that cause confusion in text editors'
|
49
50
|
opt :src_dir, 'Operate as if code resides in specified directory',
|
50
51
|
short: 'S', type: :string
|
51
52
|
opt :diff_format, 'Display diffs using format: unified, rcs, context',
|
data/lib/rubocopfmt/formatter.rb
CHANGED
@@ -16,7 +16,7 @@ module RuboCopFMT
|
|
16
16
|
sources = []
|
17
17
|
sources << new_source_from_str(options.input) if options.input
|
18
18
|
sources += options.paths.map { |path| new_source_from_file(path) }
|
19
|
-
sources.map(
|
19
|
+
sources.map { |s| s.auto_correct(options.interactive) }
|
20
20
|
|
21
21
|
@sources = sources
|
22
22
|
end
|
data/lib/rubocopfmt/options.rb
CHANGED
data/lib/rubocopfmt/source.rb
CHANGED
@@ -13,11 +13,11 @@ module RuboCopFMT
|
|
13
13
|
@src_dir = src_dir
|
14
14
|
end
|
15
15
|
|
16
|
-
def auto_correct
|
16
|
+
def auto_correct(interactive = false)
|
17
17
|
return unless output.nil?
|
18
18
|
|
19
19
|
@corrector = AutoCorrector.new(input, full_path)
|
20
|
-
@output = @corrector.correct
|
20
|
+
@output = @corrector.correct(interactive)
|
21
21
|
end
|
22
22
|
|
23
23
|
def corrected?
|
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.beta10
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|