Class: SCSSLint::AutoCorrect::Correctors::LeadingZero
- Inherits:
-
Base
- Object
- Base
- SCSSLint::AutoCorrect::Correctors::LeadingZero
show all
- Defined in:
- lib/scss_lint/auto_correct/correctors/leading_zero.rb
Instance Attribute Summary
Attributes inherited from Base
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#enabled?, #initialize, linter_name, priority, short_name
Class Method Details
.description ⇒ Object
33
34
35
|
# File 'lib/scss_lint/auto_correct/correctors/leading_zero.rb', line 33
def self.description
"Checks for unnecessary leading zeros in numeric values with decimal points"
end
|
Instance Method Details
#call(contents) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/scss_lint/auto_correct/correctors/leading_zero.rb', line 3
def call(contents)
result = []
contents.lines.each do |line|
if line =~ /\s*\/\// result << line
next
end
mm = line.match(/(.+:)([\s\S]*)$/)
if mm
result << mm[1] + correct_values(mm[2])
else
result << line
end
end
result.join
end
|
#correct_values(str) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/scss_lint/auto_correct/correctors/leading_zero.rb', line 20
def correct_values(str)
should_include = config.fetch('style', nil) == 'include_zero'
str.gsub(/-?(0?\.\d+)/) do |number|
if number[0] == "0" && !should_include
number[1..-1]
elsif number[0] != "0" && should_include
"0#{number}"
else
number
end
end
end
|