Skip to content

Commit cb21501

Browse files
committed
Set most of the methods in lint class to private and update the tests in rspec to access those methods
1 parent a5de0ac commit cb21501

File tree

3 files changed

+85
-83
lines changed

3 files changed

+85
-83
lines changed

lib/lint.rb

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,58 @@ def initialize(curr_file)
99
@inside_block = false
1010
end
1111

12+
def type_of_line
13+
return 'comment' if @curr_text.include?('/*')
14+
return 'block start' if @curr_text.include?('{')
15+
return 'block end' if @curr_text.include?('}')
16+
return 'empty line' if @curr_text.chomp.nil? || @curr_text.chomp.chars.all?(' ')
17+
18+
'regular'
19+
end
20+
21+
def run_linters(line_type)
22+
case line_type
23+
when 'comment'
24+
empty_reset
25+
comment_start_linter
26+
comment_end_linter
27+
trailing_white_linter
28+
when 'block start'
29+
empty_reset
30+
set_inside_block
31+
declaration_space_linter
32+
trailing_white_linter
33+
when 'block end'
34+
empty_reset
35+
unset_inside_block
36+
block_end_space_linter
37+
trailing_white_linter
38+
when 'empty line'
39+
empty_count
40+
trailing_white_linter
41+
empty_line_linter
42+
when 'regular'
43+
empty_reset
44+
trailing_white_linter
45+
empty_line_linter
46+
property_space_linter
47+
colors_lowercase_linter
48+
no_semicolon_linter
49+
indentation_linter
50+
end
51+
end
52+
53+
def report
54+
@report_log.rewind
55+
puts "\e[1;40m\e[1;36m #{@current_file_name} \e[1;32mNo Errors Found - Good Job \e[0m" if @report_log.gets.nil?
56+
@report_log.each do |error|
57+
puts error
58+
end
59+
@report_log.close
60+
end
61+
62+
private
63+
1264
def update_msg_header
1365
@message_header = "File: \e[1;40m\e[1;34m #{@current_file_name} \e[0m "
1466
@message_header += "Line: \e[1;40m\e[1;35m #{@curr_line + 1} \e[0m ====> "
@@ -95,54 +147,4 @@ def indentation_linter
95147
text_beginning = @curr_text.index(/\w/)
96148
return @report_log << msg if @inside_block && @curr_text[0...text_beginning].count(' ') != 2
97149
end
98-
99-
def type_of_line
100-
return 'comment' if @curr_text.include?('/*')
101-
return 'block start' if @curr_text.include?('{')
102-
return 'block end' if @curr_text.include?('}')
103-
return 'empty line' if @curr_text.chomp.nil? || @curr_text.chomp.chars.all?(' ')
104-
105-
'regular'
106-
end
107-
108-
def run_linters(line_type)
109-
case line_type
110-
when 'comment'
111-
empty_reset
112-
comment_start_linter
113-
comment_end_linter
114-
trailing_white_linter
115-
when 'block start'
116-
empty_reset
117-
set_inside_block
118-
declaration_space_linter
119-
trailing_white_linter
120-
when 'block end'
121-
empty_reset
122-
unset_inside_block
123-
block_end_space_linter
124-
trailing_white_linter
125-
when 'empty line'
126-
empty_count
127-
trailing_white_linter
128-
empty_line_linter
129-
when 'regular'
130-
empty_reset
131-
trailing_white_linter
132-
empty_line_linter
133-
property_space_linter
134-
colors_lowercase_linter
135-
no_semicolon_linter
136-
indentation_linter
137-
end
138-
end
139-
140-
def report
141-
@report_log.rewind
142-
puts "\e[1;40m\e[1;36m #{@current_file_name} \e[1;32mNo Errors Found - Good Job \e[0m" if @report_log.gets.nil?
143-
@report_log.each do |error|
144-
puts error
145-
end
146-
@report_log.close
147-
end
148150
end

spec/lint_spec.rb

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,163 +6,163 @@
66
it 'Checks the trailing white linter - FINDS AN ERROR' do
77
linter.curr_text = ' background-color: whitesmoke '
88
linter.curr_line = 4
9-
expect(linter.trailing_white_linter.is_a?(File)).to eql(true)
9+
expect(linter.send(:trailing_white_linter).is_a?(File)).to eql(true)
1010
end
1111

1212
it 'Checks the trailing white linter - NO ERROR' do
1313
linter.curr_text = ' margin: 0px;'
1414
linter.curr_line = 4
15-
expect(linter.trailing_white_linter).to eql(nil)
15+
expect(linter.send(:trailing_white_linter)).to eql(nil)
1616
end
1717

1818
it 'Checks the empty line linter outside block - FINDS AN ERROR' do
1919
linter.curr_text = ' '
2020
linter.curr_line = 4
21-
linter.unset_inside_block
21+
linter.send(:unset_inside_block)
2222
linter.empty_count = 2
23-
expect(linter.empty_line_linter.is_a?(File)).to eql(true)
23+
expect(linter.send(:empty_line_linter).is_a?(File)).to eql(true)
2424
end
2525

2626
it 'Checks the empty line linter outside block - NO ERROR' do
2727
linter.curr_text = ' '
2828
linter.curr_line = 4
29-
linter.unset_inside_block
29+
linter.send(:unset_inside_block)
3030
linter.empty_count = 1
31-
expect(linter.empty_line_linter).to eql(nil)
31+
expect(linter.send(:empty_line_linter)).to eql(nil)
3232
end
3333

3434
it 'Checks the empty line linter inside block - FINDS AN ERROR' do
3535
linter.curr_text = ' '
3636
linter.curr_line = 4
37-
linter.set_inside_block
37+
linter.send(:set_inside_block)
3838
linter.empty_count = 1
39-
expect(linter.empty_line_linter.is_a?(File)).to eql(true)
39+
expect(linter.send(:empty_line_linter).is_a?(File)).to eql(true)
4040
end
4141

4242
it 'Checks the empty line linter inside block - NO ERROR' do
4343
linter.curr_text = ' ;'
4444
linter.curr_line = 4
45-
linter.set_inside_block
45+
linter.send(:set_inside_block)
4646
linter.empty_count = 0
47-
expect(linter.empty_line_linter).to eql(nil)
47+
expect(linter.send(:empty_line_linter)).to eql(nil)
4848
end
4949

5050
it 'Checks the colon space linter - FINDS ERROR' do
5151
linter.curr_text = ' position:fixed;'
5252
linter.curr_line = 4
53-
expect(linter.property_space_linter.is_a?(File)).to eql(true)
53+
expect(linter.send(:property_space_linter).is_a?(File)).to eql(true)
5454
end
5555

5656
it 'Checks the colon space linter - NO ERROR' do
5757
linter.curr_text = 'background-color: white;'
5858
linter.curr_line = 4
59-
expect(linter.property_space_linter).to eql(nil)
59+
expect(linter.send(:property_space_linter)).to eql(nil)
6060
end
6161

6262
it 'Checks the color linter - FINDS ERROR' do
6363
linter.curr_text = 'color: #3344A8;'
6464
linter.curr_line = 4
65-
expect(linter.colors_lowercase_linter.is_a?(File)).to eql(true)
65+
expect(linter.send(:colors_lowercase_linter).is_a?(File)).to eql(true)
6666
end
6767

6868
it 'Checks the color linter - NO ERROR' do
6969
linter.curr_text = 'color: #3344a8;'
7070
linter.curr_line = 4
71-
expect(linter.colors_lowercase_linter).to eql(nil)
71+
expect(linter.send(:colors_lowercase_linter)).to eql(nil)
7272
end
7373

7474
it 'Checks the semicolon linter - FINDS ERROR' do
7575
linter.curr_text = 'background-color: whitesmoke '
7676
linter.curr_line = 4
77-
expect(linter.no_semicolon_linter.is_a?(File)).to eql(true)
77+
expect(linter.send(:no_semicolon_linter).is_a?(File)).to eql(true)
7878
end
7979

8080
it 'Checks the semicolon linter - NO ERROR' do
8181
linter.curr_text = 'max-width: 10vmin;'
8282
linter.curr_line = 4
83-
expect(linter.no_semicolon_linter).to eql(nil)
83+
expect(linter.send(:no_semicolon_linter)).to eql(nil)
8484
end
8585

8686
it 'Checks the comment start linter - FINDS ERROR' do
8787
linter.curr_text = '/*================= NAVBAR SECTION =================*/'
8888
linter.curr_line = 4
89-
expect(linter.comment_start_linter.is_a?(File)).to eql(true)
89+
expect(linter.send(:comment_start_linter).is_a?(File)).to eql(true)
9090
end
9191

9292
it 'Checks the comment start linter - NO ERROR' do
9393
linter.curr_text = '/* ================= CONTENT SECTION ================ */'
9494
linter.curr_line = 4
95-
expect(linter.comment_start_linter).to eql(nil)
95+
expect(linter.send(:comment_start_linter)).to eql(nil)
9696
end
9797

9898
it 'Checks the comment end linter - FINDS ERROR' do
9999
linter.curr_text = '/*================= NAVBAR SECTION =================*/'
100100
linter.curr_line = 4
101-
expect(linter.comment_end_linter.is_a?(File)).to eql(true)
101+
expect(linter.send(:comment_end_linter).is_a?(File)).to eql(true)
102102
end
103103

104104
it 'Checks the comment end linter - NO ERROR' do
105105
linter.curr_text = '/* ================= CONTENT SECTION ================ */'
106106
linter.curr_line = 4
107-
expect(linter.comment_end_linter).to eql(nil)
107+
expect(linter.send(:comment_end_linter)).to eql(nil)
108108
end
109109

110110
it 'Checks the declaration bracket linter - FINDS ERROR' do
111111
linter.curr_text = '#content{'
112112
linter.curr_line = 4
113-
expect(linter.declaration_space_linter.is_a?(File)).to eql(true)
113+
expect(linter.send(:declaration_space_linter).is_a?(File)).to eql(true)
114114
end
115115

116116
it 'Checks the declaration bracket linter - NO ERROR' do
117117
linter.curr_text = 'input#search {'
118118
linter.curr_line = 4
119-
expect(linter.declaration_space_linter).to eql(nil)
119+
expect(linter.send(:declaration_space_linter)).to eql(nil)
120120
end
121121

122122
it 'Checks closing block space linter - FINDS ERROR' do
123123
linter.curr_text = ' }'
124124
linter.curr_line = 4
125-
expect(linter.block_end_space_linter.is_a?(File)).to eql(true)
125+
expect(linter.send(:block_end_space_linter).is_a?(File)).to eql(true)
126126
end
127127

128128
it 'Checks closing block space linter - NO ERROR' do
129129
linter.curr_text = '}'
130130
linter.curr_line = 4
131-
expect(linter.block_end_space_linter).to eql(nil)
131+
expect(linter.send(:block_end_space_linter)).to eql(nil)
132132
end
133133

134134
it 'Checks closing block space linter - NO ERROR' do
135135
linter.curr_text = '} '
136136
linter.curr_line = 4
137-
expect(linter.block_end_space_linter).to eql(nil)
137+
expect(linter.send(:block_end_space_linter)).to eql(nil)
138138
end
139139

140140
it 'Checks the indentation linter - FINDS ERROR' do
141141
linter.curr_text = ' display: block;'
142142
linter.curr_line = 4
143-
linter.set_inside_block
144-
expect(linter.indentation_linter.is_a?(File)).to eql(true)
143+
linter.send(:set_inside_block)
144+
expect(linter.send(:indentation_linter).is_a?(File)).to eql(true)
145145
end
146146

147147
it 'Checks the indentation linter - FINDS ERROR' do
148148
linter.curr_text = ' display: block; '
149149
linter.curr_line = 4
150-
linter.set_inside_block
151-
expect(linter.indentation_linter.is_a?(File)).to eql(true)
150+
linter.send(:set_inside_block)
151+
expect(linter.send(:indentation_linter).is_a?(File)).to eql(true)
152152
end
153153

154154
it 'Checks the indentation linter - FINDS ERROR' do
155155
linter.curr_text = ' display: block;'
156156
linter.curr_line = 4
157-
linter.set_inside_block
158-
expect(linter.indentation_linter.is_a?(File)).to eql(true)
157+
linter.send(:set_inside_block)
158+
expect(linter.send(:indentation_linter).is_a?(File)).to eql(true)
159159
end
160160

161161
it 'Checks the indentation linter - NO ERROR' do
162162
linter.curr_text = ' display: block;'
163163
linter.curr_line = 4
164-
linter.set_inside_block
165-
expect(linter.indentation_linter).to eql(nil)
164+
linter.send(:set_inside_block)
165+
expect(linter.send(:indentation_linter)).to eql(nil)
166166
end
167167

168168
it 'Checks the line type method TYPE 1: Comment line' do
File renamed without changes.

0 commit comments

Comments
 (0)