tailor 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tailor (1.1.1)
4
+ tailor (1.1.2)
5
5
  log_switch (>= 0.3.0)
6
6
  term-ansicolor (>= 1.0.5)
7
7
  text-table (>= 1.2.2)
@@ -1,3 +1,17 @@
1
+ === 1.1.2 2012-06-01
2
+
3
+ * gh-101[https://github.com/turboladen/tailor/issues/101]
4
+ * Tailor now handles code that uses backslashes to break up statements to
5
+ multiple lines. Note that this is somewhat of a hack, since Ripper does not
6
+ tokenize these backslashes--it actually just treats what we see as 2 lines
7
+ of code as a single line of code. In order to preserve line numbering and
8
+ indentation tracking, tailor replaces the backslash with a special comment
9
+ that it can detect and handle accordingly. While this isn't ideal, given
10
+ the current design, it seemed like the way to deal with this.
11
+ * gh-103[https://github.com/turboladen/tailor/issues/103]
12
+ * Tailor now properly handles string interpolation inside string
13
+ interpolation.
14
+
1
15
  === 1.1.1 2012-05-31
2
16
 
3
17
  * gh-110[https://github.com/turboladen/tailor/issues/110]
@@ -39,8 +53,8 @@
39
53
 
40
54
  === 1.0.1 2012-04-23
41
55
 
42
- * gh-104: Fixed incorrect rendering of config file when using
43
- `tailor --create-config`.
56
+ * gh-104[https://github.com/turboladen/tailor/issues/104]:
57
+ * Fixed incorrect rendering of config file when using `tailor --create-config`.
44
58
 
45
59
  === 1.0.0 2012-04-17
46
60
 
@@ -28,6 +28,7 @@ class Tailor
28
28
  end
29
29
 
30
30
  @file_text = ensure_trailing_newline(@original_file_text)
31
+ @file_text = sub_line_ending_backslashes(@file_text)
31
32
  super @file_text
32
33
  @added_newline = @file_text != @original_file_text
33
34
  end
@@ -553,6 +554,18 @@ class Tailor
553
554
  #---------------------------------------------------------------------------
554
555
  private
555
556
 
557
+ # Used internally as part of the hack to deal with Ripper's lack of dealing
558
+ # with line-ending backslashes that break up statements.
559
+ #
560
+ # @param [String] file_text The file test to check.
561
+ # @param [String] The altered file text.
562
+ def sub_line_ending_backslashes(file_text)
563
+ backslash_replacement = "# TAILOR REMOVED BACKSLASH"
564
+ file_text.gsub!(/\\\s*\n?$/, backslash_replacement)
565
+
566
+ file_text
567
+ end
568
+
556
569
  def log(*args)
557
570
  l = begin; lineno; rescue; "<EOF>"; end
558
571
  c = begin; column; rescue; "<EOF>"; end
@@ -102,6 +102,11 @@ class Tailor
102
102
 
103
103
  result
104
104
  end
105
+
106
+ # @return [Boolean]
107
+ def fake_backslash_line_end?
108
+ self =~ /^# TAILOR REMOVED BACKSLASH\n?$/
109
+ end
105
110
  end
106
111
  end
107
112
  end
@@ -25,11 +25,17 @@ class Tailor
25
25
  :tstring_end
26
26
  )
27
27
  @manager = IndentationManager.new(@config)
28
- @embexpr_beg = false
28
+ @embexpr_nesting = []
29
29
  @tstring_nesting = []
30
30
  end
31
31
 
32
32
  def comment_update(token, lexed_line, file_text, lineno, column)
33
+ if token.fake_backslash_line_end?
34
+ log "Line was altered by tailor to accommodate trailing backslash"
35
+ @manager.add_indent_reason(:trailing_backslash, :trailing_backslash,
36
+ lineno)
37
+ end
38
+
33
39
  # trailing comment?
34
40
  if token.ends_with_newline?
35
41
  log "Comment ends with newline. Removing comment..."
@@ -50,14 +56,14 @@ class Tailor
50
56
  end
51
57
 
52
58
  def embexpr_beg_update
53
- @embexpr_beg = true
59
+ @embexpr_nesting << true
54
60
  end
55
61
 
56
62
  # Due to a Ripper bug (depending on which Ruby version you have), this may
57
63
  # or may not get triggered.
58
64
  # More info: https://bugs.ruby-lang.org/issues/6211
59
65
  def embexpr_end_update
60
- @embexpr_beg = false
66
+ @embexpr_nesting.pop
61
67
  end
62
68
 
63
69
  def ignored_nl_update(current_lexed_line, lineno, column)
@@ -167,7 +173,7 @@ class Tailor
167
173
  #
168
174
  # @return [Boolean]
169
175
  def in_embexpr?
170
- @embexpr_beg == true
176
+ !@embexpr_nesting.empty?
171
177
  end
172
178
 
173
179
  def rbrace_update(current_lexed_line, lineno, column)
@@ -175,7 +181,7 @@ class Tailor
175
181
  msg = "Got :rbrace and @embexpr_beg is true. "
176
182
  msg << " Must be at an @embexpr_end."
177
183
  log msg
178
- @embexpr_beg = false
184
+ @embexpr_nesting.pop
179
185
  return
180
186
  end
181
187
 
@@ -333,8 +333,7 @@ class Tailor
333
333
  return nil if @indent_reasons.empty?
334
334
 
335
335
  @indent_reasons.reverse.find do |r|
336
- !ENCLOSERS.include? r[:event_type] &&
337
- r[:event_type] != :on_kw
336
+ !ENCLOSERS.include?(r[:event_type]) && r[:event_type] != :on_kw
338
337
  end
339
338
  end
340
339
 
@@ -1,3 +1,3 @@
1
1
  class Tailor
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
@@ -36,24 +36,49 @@ describe "Horizontal Space problem detection" do
36
36
  context "line ends with a backslash" do
37
37
  let(:file_name) { :line_split_by_backslash }
38
38
 
39
- let(:contents) do
40
- %Q{execute 'myscript' do
41
- command \\
42
- '/some/really/long/path/that/would/be/over/eighty/chars.sh'
43
- only_if { something }
44
- end}
45
- end
46
-
47
39
  before do
48
40
  FileUtils.touch file_name.to_s
49
41
  File.open(file_name.to_s, 'w') { |f| f.write contents }
50
42
  end
51
43
 
52
- it "is OK" do
53
- pending "Fix of gh-101"
44
+ context "no problems" do
45
+ let(:contents) do
46
+ %Q{execute 'myscript' do
47
+ command \\
48
+ '/some/line/that/is/not/over/eighty/chars.sh'
49
+ only_if { something }
50
+ end}
51
+ end
54
52
 
55
- critic.check_file(file_name.to_s, style.to_hash)
56
- critic.problems.should == { file_name.to_s => [] }
53
+ it "is OK" do
54
+ critic.check_file(file_name.to_s, style.to_hash)
55
+ critic.problems.should == { file_name.to_s => [] }
56
+ end
57
+ end
58
+
59
+ context "line after backslash is too long" do
60
+ let(:contents) do
61
+ %Q{execute 'myscript' do
62
+ command \\
63
+ '#{'*' * 75}'
64
+ only_if { something }
65
+ end}
66
+ end
67
+
68
+ it "is OK" do
69
+ critic.check_file(file_name.to_s, style.to_hash)
70
+ critic.problems.should == {
71
+ file_name.to_s => [
72
+ {
73
+ :type => "max_line_length",
74
+ :line => 3,
75
+ :column => 81,
76
+ :message => "Line is 81 chars long, but should be 80.",
77
+ :level=>:error
78
+ }
79
+ ]
80
+ }
81
+ end
57
82
  end
58
83
  end
59
84
  end
@@ -103,16 +103,14 @@ describe "Detection of method length" do
103
103
 
104
104
  context "class method outdented, in a class" do
105
105
  let(:file_name) { :class_method_def_using_self_outdented }
106
+
106
107
  specify do
107
- pending "Fix of gh-109"
108
108
  critic.problems[file_name.to_s].size.should be 1
109
109
  end
110
- =begin
111
110
  specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
112
111
  specify { critic.problems[file_name.to_s].first[:line].should be 2 }
113
112
  specify { critic.problems[file_name.to_s].first[:column].should be 1 }
114
113
  specify { critic.problems[file_name.to_s].first[:level].should be :error }
115
- =end
116
114
  end
117
115
  end
118
116
 
@@ -47,7 +47,7 @@ end}
47
47
 
48
48
  INDENT_1[:class_method_def_using_self_outdented] =
49
49
  %Q{class A
50
- self.my_method
50
+ def self.my_method
51
51
  puts 'stuff'
52
52
  end
53
53
  end}
@@ -440,6 +440,17 @@ INDENT_OK[:deep_hash_with_rockets] =
440
440
  "e" => "E",
441
441
  "f" => "F" } } }]
442
442
 
443
+ INDENT_OK[:embedded_strings_in_embedded_strings] =
444
+ %q[def friendly_time(time)
445
+ if hours < 24
446
+ "#{(hours > 0) ? "#{hours} hour" : '' }#{(hours > 1) ? 's' : ''}" +
447
+ " #{(mins > 0) ? "#{mins} minute" : '' }#{(mins > 1) ? 's' : ''}" +
448
+ " #{seconds} second#{(seconds > 1) ? "s" : ''} ago"
449
+ else
450
+ time.to_s
451
+ end
452
+ end]
453
+
443
454
  #----------- Brackets ----------#
444
455
  INDENT_OK[:single_line_brackets] =
445
456
  %Q{['one', 'two', 'three']}
@@ -122,4 +122,22 @@ describe Tailor::Lexer do
122
122
  end
123
123
  end
124
124
  end
125
+
126
+ describe "#sub_line_ending_backslashes" do
127
+ let!(:text) do
128
+ %Q{command \\
129
+ 'something'}
130
+ end
131
+
132
+ before do
133
+ def subject.sub_publicly(file_text)
134
+ sub_line_ending_backslashes(file_text)
135
+ end
136
+ end
137
+
138
+ it "replaces all line-ending backslashes with a comment" do
139
+ subject.sub_publicly(text).should == %Q{command # TAILOR REMOVED BACKSLASH
140
+ 'something'}
141
+ end
142
+ end
125
143
  end
@@ -35,19 +35,18 @@ describe Tailor::Rulers::IndentationSpacesRuler do
35
35
  end
36
36
 
37
37
  describe "#embexpr_beg_update" do
38
- it "sets @embexpr_beg to true" do
39
- subject.instance_variable_set(:@embexpr_beg, false)
38
+ it "sets @embexpr_nesting to [true]" do
39
+ subject.instance_variable_set(:@embexpr_nesting, [])
40
40
  subject.embexpr_beg_update
41
- subject.instance_variable_get(:@embexpr_beg).should be_true
41
+ subject.instance_variable_get(:@embexpr_nesting).should == [true]
42
42
  end
43
43
  end
44
44
 
45
-
46
45
  describe "#embexpr_end_update" do
47
- it "sets @embexpr_beg to false" do
48
- subject.instance_variable_set(:@embexpr_beg, true)
46
+ it "pops @embexpr_nesting" do
47
+ subject.instance_variable_set(:@embexpr_nesting, [true])
49
48
  subject.embexpr_end_update
50
- subject.instance_variable_get(:@embexpr_beg).should be_false
49
+ subject.instance_variable_get(:@embexpr_nesting).should == []
51
50
  end
52
51
  end
53
52
 
@@ -2,5 +2,5 @@ require_relative '../../spec_helper'
2
2
  require 'tailor/version'
3
3
 
4
4
  describe Tailor::VERSION do
5
- it { should == "1.1.1" }
5
+ it { should == "1.1.2" }
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-31 00:00:00.000000000 Z
12
+ date: 2012-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log_switch