rails5-spec-converter 1.0.9 → 1.0.10

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: d5bf0eb89b52036356b4302e4ac69ce3b55b7736
4
- data.tar.gz: 5a1af9450f8b860194ef3fbf3a81248a1747219f
3
+ metadata.gz: decc1a2e5df2d25320f01d2bbcb93e03054382e3
4
+ data.tar.gz: e26b4a67c196eb1dde0240d5bcb4a2dbc9bf1036
5
5
  SHA512:
6
- metadata.gz: 4eb378462e4741677c8f55eeaad228c4b8b028f7087bddc7240e47fa851c37c0fe7e1a4a868d64d6660fa8c7149934783a2194b939dbb3cce02c425a212181e0
7
- data.tar.gz: 6e1715037451e0cba49b3d3c4c618f29382df4b0a45e296bebc929f46d2d437a69bf1359272f149d1acdbe058b1ba71f2eb20ef19f024343109f6c997502dc82
6
+ metadata.gz: b42d4eb6bf97ad55b37885c6d9778e3060847b3c9a8d81a2e1ad230f12de02f16b5fff07dc20c97afeea320041b7440203544580de7591355bdf30786ea9d4d9
7
+ data.tar.gz: d7756ca27cf33f234175a33fb9b8569adbcf123cbce411cab9164a382bb105e616a9d41a09ad87ed78f749235112933cce2ffd4ca6a39c9d43c9fbc6352a847b
data/README.md CHANGED
@@ -41,6 +41,8 @@ By default it will make some noise, run with `rails5-spec-converter --quiet` if
41
41
 
42
42
  ### Whitespace
43
43
 
44
+ #### Indentation
45
+
44
46
  The tool will attempt to indent the newly-added "params" hash in situations when the arguments are on newlines, e.g.:
45
47
 
46
48
  ```
@@ -65,6 +67,24 @@ Since the extra spaces in front of 'params' are brand-new whitespace, you may wa
65
67
 
66
68
  `rails5-spec-converter --indent '\t'`
67
69
 
70
+ #### Hash Spacing
71
+
72
+ By default, for single-line hashes, a single space will be added after the opening curly brace and before the ending curly brace. The space will be omitted if the new params hash will contain any hash literals that do not have surrounding whitespace, ex:
73
+
74
+ ```
75
+ post :users, user: {name: 'bayleef'}
76
+ ```
77
+
78
+ becomes
79
+
80
+ ```
81
+ post :users, params: {user: {name: 'bayleef'}}
82
+ ```
83
+
84
+ To force hashes to be written without extra whitespace in all files regardless of context, use the argument `--no-hash-spacing`.
85
+
86
+ To force hashes to be written WITH extra whitespace in all files regardless of context, use the argument `--hash-spacing`.
87
+
68
88
  ## Development
69
89
 
70
90
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -22,6 +22,10 @@ module Rails5
22
22
  opts.on("-i", "--indent INDENT", "Use specified string for indentation (default is two spaces)") do |indent|
23
23
  @options[:indent] = indent.gsub("\\t", "\t")
24
24
  end
25
+
26
+ opts.on("--[no-]hash-spacing", "Always/never add space around hashes ({foo: 'bar'} vs { foo: 'bar' })") do |hash_spacing|
27
+ @options[:hash_spacing] = hash_spacing
28
+ end
25
29
  end.parse!
26
30
 
27
31
  @files = ARGV
@@ -10,6 +10,7 @@ module Rails5
10
10
  class TextTransformer
11
11
  def initialize(content, options = {})
12
12
  @indent = options[:indent] || ' '
13
+ @hash_spacing = options[:hash_spacing]
13
14
  @quiet = options[:quiet]
14
15
  @content = content
15
16
 
@@ -152,7 +153,7 @@ module Rails5
152
153
  extract_indent(joiner) || ''
153
154
  end
154
155
 
155
- def has_space_after_curly?(hash_node)
156
+ def no_space_after_curly?(hash_node)
156
157
  hash_node.parent.loc.expression.source.match(/{\S/)
157
158
  end
158
159
 
@@ -194,11 +195,18 @@ module Rails5
194
195
  end
195
196
  "{\n#{restrung_hash}\n#{final_brace_indent}}"
196
197
  else
197
- curly_sep = has_space_after_curly?(hash_node) ? '' : ' '
198
+ curly_sep = determine_curly_sep(hash_node)
198
199
  "{#{curly_sep}#{restring_hash(pairs)}#{curly_sep}}"
199
200
  end
200
201
  end
201
202
 
203
+ def determine_curly_sep(hash_node)
204
+ return ' ' if @hash_spacing == true
205
+ return '' if @hash_spacing == false
206
+
207
+ no_space_after_curly?(hash_node) ? '' : ' '
208
+ end
209
+
202
210
  def wrap_arg(node, key)
203
211
  node_loc = node.loc.expression
204
212
  node_source = node_loc.source
@@ -1,5 +1,5 @@
1
1
  module Rails5
2
2
  module SpecConverter
3
- VERSION = "1.0.9"
3
+ VERSION = "1.0.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails5-spec-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Grathwell