Skip to content

Commit 00edfe6

Browse files
committed
Update the report method to give a no errors message
1 parent 7cef06d commit 00edfe6

File tree

4 files changed

+62
-86
lines changed

4 files changed

+62
-86
lines changed

.results.mm

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +0,0 @@
1-
File:  styles.css  Line:  1  ====> Missing space before the opening bracket
2-
File:  styles.css  Line:  12  ====> Missing space before the opening bracket
3-
File:  styles.css  Line:  18  ====> Missing space before the opening bracket
4-
File:  styles.css  Line:  29  ====> Missing space before the opening bracket
5-
File:  styles.css  Line:  33  ====> Missing space before the opening bracket
6-
File:  styles.css  Line:  36  ====> Missing space before the opening bracket
7-
File:  styles.css  Line:  40  ====> Missing space before the opening bracket
8-
File:  styles.css  Line:  47  ====> Missing space before the opening bracket
9-
File:  styles.css  Line:  52  ====> Missing space before the opening bracket
10-
File:  styles.css  Line:  55  ====> Missing space before the opening bracket
11-
File:  styles.css  Line:  62  ====> Missing space before the opening bracket
12-
File:  styles.css  Line:  75  ====> Missing space before the opening bracket
13-
File:  styles.css  Line:  88  ====> Missing space before the opening bracket
14-
File:  styles.css  Line:  99  ====> Missing space before the opening bracket
15-
File:  styles.css  Line:  106  ====> Missing space before the opening bracket
16-
File:  styles.css  Line:  110  ====> Missing space before the opening bracket
17-
File:  styles.css  Line:  117  ====> Missing space before the opening bracket
18-
File:  styles.css  Line:  124  ====> Missing space before the opening bracket
19-
File:  styles.css  Line:  130  ====> Missing space before the opening bracket
20-
File:  styles.css  Line:  143  ====> Missing space before the opening bracket
21-
File:  styles.css  Line:  156  ====> Missing space before the opening bracket
22-
File:  styles.css  Line:  166  ====> Missing space before the opening bracket
23-
File:  styles.css  Line:  171  ====> Missing space before the opening bracket
24-
File:  styles.css  Line:  184  ====> Missing space before the opening bracket
25-
File:  styles.css  Line:  187  ====> Missing space before the opening bracket
26-
File:  styles.css  Line:  193  ====> Missing space before the opening bracket

lib/lint.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def initialize(curr_file)
88
end
99

1010
def update_msg_header
11-
@message_header = "File: \e[1;40m\e[1;34m #{@current_file_name} \e[0m Line: \e[1;40m\e[1;35m #{@curr_line + 1} \e[0m ====> "
11+
@message_header = "File: \e[1;40m\e[1;34m #{@current_file_name} \e[0m "
12+
@message_header += "Line: \e[1;40m\e[1;35m #{@curr_line + 1} \e[0m ====> "
1213
end
1314

1415
def trailing_white_linter
@@ -41,7 +42,7 @@ def colors_lowercase_linter
4142

4243
def no_semicolon_linter
4344
update_msg_header
44-
msg = @message_header + "Missing semicolor\n"
45+
msg = @message_header + "Missing semicolon\n"
4546
@report_log << msg if !@curr_text.match?(/[{};]/) && !@curr_text.chomp.chars.all?(' ')
4647
end
4748

@@ -53,6 +54,7 @@ def comment_start_linter
5354

5455
def declaration_space_linter
5556
update_msg_header
57+
p @curr_text
5658
msg = @message_header + "Missing space before the opening bracket\n"
5759
@report_log << msg if @curr_text.include?('{') && !@curr_text.include?(' {')
5860
end
@@ -74,6 +76,7 @@ def type_of_line
7476

7577
def report
7678
@report_log.rewind
79+
puts "\e[1;40m\e[1;32m No Errors Found - Good Job \e[0m" if @report_log.gets.nil?
7780
@report_log.each do |error|
7881
puts error
7982
end

main.rb

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,88 +35,87 @@
3535
# linter.colors_lowercase_linter
3636
# linter.no_semicolon_linter
3737
# linter.comment_start_linter
38-
linter.declaration_space_linter
39-
# puts "\e[1;40m \e[1;33mThis is red text \e[0m other text"
38+
# linter.declaration_space_linter
4039
end
4140
linter.report
4241

4342
exit(0)
4443

4544
# Checks for trailing white spaces
4645

47-
# current_file.each_with_index do |text, line|
48-
# if text.chomp[-1] == ' '
49-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Trailing whitespace detected\n"
50-
# end
51-
# end
46+
current_file.each_with_index do |text, line|
47+
if text.chomp[-1] == ' '
48+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Trailing whitespace detected\n"
49+
end
50+
end
5251

5352
# Checks for empty lines
5453

55-
# current_file.rewind
56-
# current_file.each_with_index do |text, line|
57-
# if text.chomp.count(' ') == text.chomp.length || text.chomp.nil?
58-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Empty line detected\n"
59-
# end
60-
# end
54+
current_file.rewind
55+
current_file.each_with_index do |text, line|
56+
if text.chomp.count(' ') == text.chomp.length || text.chomp.nil?
57+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Empty line detected\n"
58+
end
59+
end
6160

6261
# Checks for the space after the property
6362

64-
# current_file.rewind
65-
# current_file.each_with_index do |text, line|
66-
# text_array = text.chomp.chars
67-
# if text_array.include?(':')
68-
# if text_array[text_array.index(':')+1] != ' '
69-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> No space after colon\n"
70-
# end
71-
# end
72-
# end
63+
current_file.rewind
64+
current_file.each_with_index do |text, line|
65+
text_array = text.chomp.chars
66+
if text_array.include?(':')
67+
if text_array[text_array.index(':')+1] != ' '
68+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> No space after colon\n"
69+
end
70+
end
71+
end
7372

7473
# Checks for colors lower case
7574

76-
# current_file.rewind
77-
# current_file.each_with_index do |text, line|
78-
# pound_index = text.index('#')
79-
# if pound_index != nil
80-
# semicolon_index = text.index(';')
81-
# if semicolon_index != nil
82-
# color = text[pound_index...semicolon_index]
83-
# if color != color.downcase
84-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Colors should be all lower case\n"
85-
# end
86-
# end
87-
# end
88-
# end
75+
current_file.rewind
76+
current_file.each_with_index do |text, line|
77+
pound_index = text.index('#')
78+
if pound_index != nil
79+
semicolon_index = text.index(';')
80+
if semicolon_index != nil
81+
color = text[pound_index...semicolon_index]
82+
if color != color.downcase
83+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Colors should be all lower case\n"
84+
end
85+
end
86+
end
87+
end
8988

9089
# Checks for semicolon missing
9190

92-
# current_file.rewind
93-
# current_file.each_with_index do |text, line|
94-
# if text.index(';').nil? && text.index('{').nil? && text.index('}').nil?
95-
# if !text.chomp.chars.all?(' ')
96-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Missing semicolor\n"
97-
# end
98-
# end
99-
# end
91+
current_file.rewind
92+
current_file.each_with_index do |text, line|
93+
if text.index(';').nil? && text.index('{').nil? && text.index('}').nil?
94+
if !text.chomp.chars.all?(' ')
95+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Missing semicolor\n"
96+
end
97+
end
98+
end
10099

101100
# Checks for space between the comment start and the content
102101

103-
# current_file.rewind
104-
# current_file.each_with_index do |text, line|
105-
# comment_index = text.index('/')
106-
# if !comment_index.nil? && text[comment_index+2] != ' '
107-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Missing space after between /* and content\n"
108-
# end
109-
# end
102+
current_file.rewind
103+
current_file.each_with_index do |text, line|
104+
comment_index = text.index('/')
105+
if !comment_index.nil? && text[comment_index+2] != ' '
106+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Missing space after between /* and content\n"
107+
end
108+
end
110109

111110
# Checks for space between the declaration and the {
112111

113-
# current_file.rewind
114-
# current_file.each_with_index do |text, line|
115-
# bracket_index = text.index('{')
116-
# if !bracket_index.nil? && text[bracket_index-1] != ' '
117-
# results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Missing space before the opening bracket\n"
118-
# end
119-
# end
112+
current_file.rewind
113+
current_file.each_with_index do |text, line|
114+
bracket_index = text.index('{')
115+
if !bracket_index.nil? && text[bracket_index-1] != ' '
116+
results_log << "File: #{File.basename(current_file)} Line: #{line+1} ====> Missing space before the opening bracket\n"
117+
end
118+
end
120119

121120
# Type of line
122121

test_files/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
body{
1+
body {
22
margin: 0px;
33
background-color: whitesmoke
44
}

0 commit comments

Comments
 (0)