rubocopfmt 0.1.0.beta9 → 0.1.0.beta10

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: ba8786eb7c1bdd55ed396f709f087a429429d92b
4
- data.tar.gz: 48d71ff1a78aeb97b949522cdfbec764b7f2ac09
3
+ metadata.gz: '0499af5d4df26074ce977b4ea3b342a4fee80f01'
4
+ data.tar.gz: 69f4c237faf44139cdeea5e55016ddba7b9e030c
5
5
  SHA512:
6
- metadata.gz: 3011db0eae54d67284643febd3a73a27eb730d5713c263876664a6ea2d9004b13cf485302c374ec3c728e857f826cb324f255804e77ffbec082605f70589489f
7
- data.tar.gz: 9bc6f35aab4deddfca561b25f101bcc7b3a506b20355af0fb60e897f5c53b8024e790e031de545432a8569ad3f15e225ff0e36b30f69b7e61f3de3ee1d2606ea
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
- _Coming Soon!_
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
- @runner = ::RuboCop::Runner.new(options, config_store)
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 || 'fake.rb']
36
+ @paths ||= [@path || '__fake__.rb']
28
37
  end
29
38
 
30
- def options
31
- @options ||= {
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
@@ -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
- @sources = formatter.sources
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',
@@ -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(&:auto_correct)
19
+ sources.map { |s| s.auto_correct(options.interactive) }
20
20
 
21
21
  @sources = sources
22
22
  end
@@ -23,5 +23,10 @@ module RuboCopFMT
23
23
  @write.nil? ? false : @write
24
24
  end
25
25
  attr_writer :write
26
+
27
+ def interactive
28
+ @interactive.nil? ? false : @interactive
29
+ end
30
+ attr_writer :interactive
26
31
  end
27
32
  end
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module RuboCopFMT
2
- VERSION = '0.1.0.beta9'.freeze
2
+ VERSION = '0.1.0.beta10'.freeze
3
3
  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.beta9
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-20 00:00:00.000000000 Z
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler