Class: SCSSLint::AutoCorrect::Correctors::PropertySortOrder
- Inherits:
-
Base
- Object
- Base
- SCSSLint::AutoCorrect::Correctors::PropertySortOrder
show all
- Defined in:
- lib/scss_lint/auto_correct/correctors/property_sort_order.rb
Instance Attribute Summary
Attributes inherited from Base
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#enabled?, linter_name, priority, short_name
Constructor Details
Returns a new instance of PropertySortOrder.
3
4
5
6
7
8
9
|
# File 'lib/scss_lint/auto_correct/correctors/property_sort_order.rb', line 3
def initialize(config = {})
super
@result = []
@buffer = []
@enabled = true
@sorter = SCSSLint::AutoCorrect::PropertySorter.new rules: @config["order"]
end
|
Class Method Details
.description ⇒ Object
45
46
47
|
# File 'lib/scss_lint/auto_correct/correctors/property_sort_order.rb', line 45
def self.description
"Sorts properties correctly"
end
|
Instance Method Details
#call(source) ⇒ Object
11
12
13
14
15
|
# File 'lib/scss_lint/auto_correct/correctors/property_sort_order.rb', line 11
def call(source)
source.lines.each { |line| visit_line(line) }
flush_buffer!
@result.join
end
|
#flush_buffer! ⇒ Object
36
37
38
39
|
# File 'lib/scss_lint/auto_correct/correctors/property_sort_order.rb', line 36
def flush_buffer!
@result += reduce_buffer(@buffer)
@buffer = []
end
|
#reduce_buffer(lines) ⇒ Object
41
42
43
|
# File 'lib/scss_lint/auto_correct/correctors/property_sort_order.rb', line 41
def reduce_buffer(lines)
@sorter.sort_lines(lines)
end
|
#visit_line(line) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/scss_lint/auto_correct/correctors/property_sort_order.rb', line 17
def visit_line(line)
if line =~ /scss-lint:disable.*PropertySortOrder/
@result << line
@enabled = false
return
end
if line =~ /scss-lint:enable.*PropertySortOrder/
@result << line
@enabled = true
return
end
if @enabled && @sorter.property?(line)
@buffer << line
else
flush_buffer!
@result << line
end
end
|