rufo 0.9.0 → 0.10.0

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
  SHA256:
3
- metadata.gz: ea171b0f22404cea26bb2f1263b5787721a968bc4be3dccb96d258ca7ab1586a
4
- data.tar.gz: bdbafe76de95494aadff70e0183805dbe5a1734373b45d8fa5f6c4c8addb4e48
3
+ metadata.gz: 19befa300eb72a2de7c9f70a5df89a9d81520ae565ec28260eb78ccb8c6259a4
4
+ data.tar.gz: efa9c54a96d77df14c1ecdd9fd301942c73be0ec80ad1312b7a419007b7ad282
5
5
  SHA512:
6
- metadata.gz: 79279d81687a7137424100278d5fbc3727052317ad264bbf9b9379ec8f1902bf4e2a8239d6ba43b219149912372f9db78bc82288ff645889bd1333741c072b9d
7
- data.tar.gz: 604473d7682a92356a4e3fd9aa865f3a0cb5ee248e7bac2b237c8f917d5feffa7fc66597dfbd5a91101154cfdbd5f9adb4d402fad2e0fcf034b4a3be79452867
6
+ metadata.gz: c1c699f17a408b12d9e134869d9e9857c048a3d64c35daf06f3ab4ccd4880371c6940ca382aa90f92e91c86dc534e466cbc4ca7652e15f720c2d8ad13dcd985a
7
+ data.tar.gz: b07894fcad0897b000cf84aa6e664a276fb2bcd7bf1e228ed7b3f1d3c43a3352cd9c12f03926236e15b932fe099f82c32af20aa04f0246c066d44ad9e8b67224
data/.gitignore CHANGED
@@ -11,4 +11,8 @@
11
11
 
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
+ spec/examples.txt
15
+
14
16
  sample_code
17
+
18
+ .byebug_history
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
+ --require spec_helper
1
2
  --format documentation
2
- --color
@@ -12,6 +12,41 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
12
12
 
13
13
  ### Added
14
14
 
15
+ ## [0.10.0] - 2020-01-16
16
+
17
+ ### Fixed
18
+ - Squiggly heredoc closing tag indentation.
19
+ - Formatting .erb files from stdin.
20
+
21
+ ### Changed
22
+ - Method parameters are now no longer aligned with the method parenthesis. For example:
23
+ - ```ruby
24
+ def foo(
25
+ param
26
+ )
27
+ end
28
+
29
+ # Becomes:
30
+
31
+ def foo(
32
+ param
33
+ )
34
+ end
35
+ ```
36
+ - Multiline assignments are no longer aligned with variable indentation.
37
+ - ```ruby
38
+ a = if true
39
+ b
40
+ end
41
+
42
+ # Becomes:
43
+
44
+ a = if true
45
+ b
46
+ end
47
+ ```
48
+ ### Added
49
+
15
50
  ## [0.9.0] - 2020-01-11
16
51
 
17
52
  ### Added
@@ -35,17 +35,18 @@ class Rufo::Command
35
35
 
36
36
  def run(argv)
37
37
  status_code = if argv.empty?
38
- format_stdin
39
- else
40
- format_args argv
41
- end
38
+ format_stdin
39
+ else
40
+ format_args argv
41
+ end
42
42
  exit exit_code(status_code)
43
43
  end
44
44
 
45
45
  def format_stdin
46
46
  code = STDIN.read
47
47
 
48
- result = format(code, @filename_for_dot_rufo || Dir.getwd)
48
+ erb = @filename_for_dot_rufo && @filename_for_dot_rufo.end_with?(".erb")
49
+ result = format(code, @filename_for_dot_rufo || Dir.getwd, erb: erb)
49
50
 
50
51
  print(result) if !@want_check
51
52
 
@@ -53,10 +54,10 @@ class Rufo::Command
53
54
  rescue Rufo::SyntaxError => e
54
55
  logger.error("STDIN is invalid code. Error on line:#{e.lineno} #{e.message}")
55
56
  CODE_ERROR
56
- rescue => ex
57
+ rescue => e
57
58
  logger.error("You've found a bug!")
58
59
  logger.error("Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it\n")
59
- raise ex
60
+ raise e
60
61
  end
61
62
 
62
63
  def format_args(args)
@@ -121,11 +122,11 @@ class Rufo::Command
121
122
  rescue Rufo::SyntaxError => e
122
123
  logger.error("#{filename}:#{e.lineno} #{e.message}")
123
124
  CODE_ERROR
124
- rescue => ex
125
+ rescue => e
125
126
  logger.error("You've found a bug!")
126
127
  logger.error("It happened while trying to format the file #{filename}")
127
128
  logger.error("Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it\n")
128
- raise ex
129
+ raise e
129
130
  end
130
131
 
131
132
  def format(code, dir, erb: false)
@@ -887,19 +887,24 @@ class Rufo::Formatter
887
887
  def visit_assign_value(value)
888
888
  has_slash_newline, _first_space = skip_space_backslash
889
889
 
890
- sticky = indentable_value?(value)
891
-
892
890
  # Remove backslash after equal + newline (it's useless)
893
891
  if has_slash_newline
894
892
  skip_space_or_newline
895
- write_line
893
+ write_space
896
894
  indent(next_indent) do
897
- write_indent
898
895
  visit(value)
899
896
  end
900
897
  else
901
- indent_after_space value, sticky: sticky,
902
- want_space: true
898
+ if [:begin, :case, :if, :unless].include?(value.first)
899
+ skip_space_or_newline
900
+ write_space
901
+ indent(next_indent) do
902
+ visit value
903
+ end
904
+ else
905
+ indent_after_space value, sticky: false,
906
+ want_space: true
907
+ end
903
908
  end
904
909
  end
905
910
 
@@ -1195,9 +1200,6 @@ class Rufo::Formatter
1195
1200
  write current_token_value.rstrip
1196
1201
  next_token
1197
1202
  write_line
1198
- if @heredocs.last[1]
1199
- write_indent(next_indent)
1200
- end
1201
1203
  end
1202
1204
 
1203
1205
  printed = false
@@ -2031,6 +2033,7 @@ class Rufo::Formatter
2031
2033
  next_token
2032
2034
  skip_space
2033
2035
  skip_semicolons
2036
+ broken_across_line = false
2034
2037
 
2035
2038
  if empty_params?(params)
2036
2039
  skip_space_or_newline
@@ -2041,8 +2044,8 @@ class Rufo::Formatter
2041
2044
  write "("
2042
2045
 
2043
2046
  if newline? || comment?
2044
- column = @column
2045
- indent(column) do
2047
+ broken_across_line = true
2048
+ indent(next_indent) do
2046
2049
  consume_end_of_line
2047
2050
  write_indent
2048
2051
  visit params
@@ -2056,6 +2059,10 @@ class Rufo::Formatter
2056
2059
  skip_space_or_newline
2057
2060
  consume_keyword("nil") if current_token[1] == :on_kw
2058
2061
  check :on_rparen
2062
+ if broken_across_line
2063
+ write_line
2064
+ write_indent
2065
+ end
2059
2066
  write ")"
2060
2067
  next_token
2061
2068
  end
@@ -2737,8 +2744,9 @@ class Rufo::Formatter
2737
2744
  # We have to be careful not to aumatically write a heredoc on next_token,
2738
2745
  # because we miss the chance to write a comma to separate elements
2739
2746
  first_space = skip_space_no_heredoc_check
2740
- wrote_comma = check_heredocs_in_literal_elements(is_last, wrote_comma)
2741
-
2747
+ indent(needed_indent) do
2748
+ wrote_comma = check_heredocs_in_literal_elements(is_last, wrote_comma)
2749
+ end
2742
2750
  next unless comma?
2743
2751
 
2744
2752
  unless is_last
@@ -2751,7 +2759,9 @@ class Rufo::Formatter
2751
2759
  next_token_no_heredoc_check
2752
2760
 
2753
2761
  first_space = skip_space_no_heredoc_check
2754
- wrote_comma = check_heredocs_in_literal_elements(is_last, wrote_comma)
2762
+ indent(needed_indent) do
2763
+ wrote_comma = check_heredocs_in_literal_elements(is_last, wrote_comma)
2764
+ end
2755
2765
 
2756
2766
  if newline? || comment?
2757
2767
  if is_last
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rufo
4
- VERSION = "0.9.0"
4
+ VERSION = "0.10.0"
5
5
  end
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = ">= 2.4.5"
24
24
 
25
25
  spec.add_development_dependency "bundler", ">= 1.15"
26
- spec.add_development_dependency "byebug", "~> 10.0.2"
26
+ spec.add_development_dependency "byebug", "~> 11.0.1"
27
27
  spec.add_development_dependency "guard-rspec", "~> 4.0"
28
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
31
- spec.add_development_dependency "rubocop", "~> 0.63.1"
31
+ spec.add_development_dependency "rubocop", "~> 0.79.0"
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ary Borenszweig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-11 00:00:00.000000000 Z
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 10.0.2
33
+ version: 11.0.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 10.0.2
40
+ version: 11.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: guard-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.63.1
103
+ version: 0.79.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.63.1
110
+ version: 0.79.0
111
111
  description: Fast and unobtrusive Ruby code formatter
112
112
  email:
113
113
  - asterite@gmail.com