8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/obcd/checks/header_style.rb', line 8
def check!
if head.select { |line| line.start_with?('//') }.count != 7
violations << Obcd::Violations::Violation.new(1, "Number of lines in header doesn't match.")
elsif head.select { |line| (line.start_with?('//') || line.start_with?('// ')) && !line.start_with?('// ') }.count != 7
violations << Obcd::Violations::Violation.new(1, "Header text alignment or number of spaces in header doesn't match.")
elsif head[7].strip != ''
violations << Obcd::Violations::Violation.new(1, 'Missing empty line after header.')
else
violations << Obcd::Violations::Violation.new(1, 'Expected header to start with a //.') unless head[0] == '//'
if head[1] != "// #{File.basename(filename)}"
if head[1].downcase == "// #{File.basename(filename).downcase}"
violations << Obcd::Violations::Violation.new(2, "Filename case doesn't match, expected #{File.basename(filename)}, got #{head[1]}.")
elsif (extension = File.extname(head[1].split('//').last)) != File.extname(filename)
violations << Obcd::Violations::Violation.new(2, "Filename extension doesn't match, expected #{File.extname(filename)}, got #{extension}.")
else
violations << Obcd::Violations::Violation.new(2, "Expected header to include file name, instead got #{head[1]}.") unless head[1] == "// #{File.basename(filename)}"
end
end
violations << Obcd::Violations::Violation.new(4, 'Expected a blank // after company name.') unless head[3] == '//'
violations << Obcd::Violations::Violation.new(7, 'Expected a blank // after copyright.') unless head[3] == '//'
end
end
|