scss_lint-auto_correct 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scss_lint/auto_correct/correctors/base.rb +1 -0
- data/lib/scss_lint/auto_correct/correctors/color_keyword.rb +44 -0
- data/lib/scss_lint/auto_correct/correctors/{format_newlines.rb → empty_line_between_blocks.rb} +2 -2
- data/lib/scss_lint/auto_correct/correctors/{shorter_versions_of_colors.rb → hex_length.rb} +2 -5
- data/lib/scss_lint/auto_correct/correctors/hex_notation.rb +16 -0
- data/lib/scss_lint/auto_correct/correctors/indentation.rb +35 -0
- data/lib/scss_lint/auto_correct/correctors/leading_zero.rb +37 -0
- data/lib/scss_lint/auto_correct/correctors/property_sort_order.rb +0 -4
- data/lib/scss_lint/auto_correct/correctors/{newlines_for_each_selector.rb → single_line_per_selector.rb} +2 -2
- data/lib/scss_lint/auto_correct/correctors/{spacing_before_selectors.rb → space_before_brace.rb} +1 -1
- data/lib/scss_lint/auto_correct/correctors/string_quotes.rb +16 -0
- data/lib/scss_lint/auto_correct/correctors/{lines_end_with_semicolons.rb → trailing_semicolon.rb} +5 -2
- data/lib/scss_lint/auto_correct/correctors/{variable_names.rb → variable_name.rb} +5 -1
- data/lib/scss_lint/auto_correct/version.rb +1 -1
- data/test/fixtures/double_semicolon.scss +3 -0
- data/test/fixtures/double_semicolon_corrected.scss +3 -0
- data/test/fixtures/empty_line_between_blocks.scss +14 -0
- data/test/fixtures/empty_line_between_blocks_corrected.scss +17 -0
- data/test/fixtures/has_leading_zero.scss +3 -0
- data/test/fixtures/has_leading_zero_corrected.scss +3 -0
- data/test/fixtures/has_leading_zero_with_comments.scss +5 -0
- data/test/fixtures/has_underscores_for_variable_names.scss +5 -0
- data/test/fixtures/has_underscores_for_variable_names_corrected.scss +5 -0
- data/test/fixtures/indentation.scss +6 -0
- data/test/fixtures/indentation_corrected.scss +6 -0
- data/test/fixtures/indentation_with_comments.scss +6 -0
- data/test/fixtures/missing_semicolon.scss +3 -0
- data/test/fixtures/missing_semicolon_corrected.scss +3 -0
- data/test/fixtures/multiple_selectors_on_same_line.scss +3 -0
- data/test/fixtures/multiple_selectors_on_same_line_corrected.scss +4 -0
- data/test/fixtures/space_before_opening_brace.scss +3 -0
- data/test/fixtures/space_before_opening_brace_corrected.scss +3 -0
- data/test/fixtures/space_before_semicolon.scss +3 -0
- data/test/fixtures/space_before_semicolon_corrected.scss +3 -0
- data/test/unit/cli_test.rb +2 -2
- data/test/unit/color_keyword.rb +16 -0
- data/test/unit/empty_line_between_blocks_test.rb +18 -0
- data/test/unit/hex_length_test.rb +26 -0
- data/test/unit/{downcase_colors_test.rb → hex_notation_test.rb} +3 -3
- data/test/unit/indentation_test.rb +24 -0
- data/test/unit/leading_zero_test.rb +34 -0
- data/test/unit/single_line_per_selector_test.rb +18 -0
- data/test/unit/space_before_brace_test.rb +18 -0
- data/test/unit/string_quotes_test.rb +24 -0
- data/test/unit/trailing_semicolon_test.rb +32 -0
- data/test/unit/variable_name_test.rb +18 -0
- metadata +74 -14
- data/lib/scss_lint/auto_correct/correctors/double_quoting.rb +0 -11
- data/lib/scss_lint/auto_correct/correctors/downcase_colors.rb +0 -11
- data/lib/scss_lint/auto_correct/correctors/no_spaces_before_semicolons.rb +0 -11
- data/lib/scss_lint/auto_correct/correctors/short_versions_of_numbers.rb +0 -13
- data/lib/scss_lint/auto_correct/correctors/use_hex_instead_of_color_keywords.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf50c2002cc599f3886207b12128de2325f98ad9
|
4
|
+
data.tar.gz: 0004de322f5480f32b27c5998a739a01d53ddbd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 881227252dc98f9b52ec053948fa0cab2e09d6098894a51848cea90df688a257f304e4c1ed09cc18790d1e430e32c9547c838e4f17b90c7a0d00709607bdff3c
|
7
|
+
data.tar.gz: a292ee51dffcf338af613c4990efd162cb762afb622b004c88ce1862b12accf70f2fc7717c209f28371ede1ad56479136b0515f8deeccfa4111fafca26cc72ef
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SCSSLint::AutoCorrect::Correctors
|
2
|
+
class ColorKeyword < Base
|
3
|
+
def call(contents)
|
4
|
+
result = []
|
5
|
+
contents.lines.each do |line|
|
6
|
+
if line =~ /\s*\/\// # skip comments
|
7
|
+
result << line
|
8
|
+
next
|
9
|
+
end
|
10
|
+
mm = line.match(/(.+:)([\s\S]*)$/)
|
11
|
+
if mm
|
12
|
+
result << mm[1] + correct_values(mm[2])
|
13
|
+
else
|
14
|
+
result << line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
result.join
|
18
|
+
end
|
19
|
+
|
20
|
+
def correct_values(str)
|
21
|
+
str.gsub(regexp) do |color|
|
22
|
+
self.class.data[color]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def regexp
|
27
|
+
@regexp ||= Regexp.new("#{self.class.data.keys.join('|')}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.data
|
31
|
+
return @data if @data
|
32
|
+
colors_file = File.expand_path(File.join(File.dirname(__FILE__), "color-keywords.csv"))
|
33
|
+
@data = Hash[File.read(colors_file).lines.map { |l| l.gsub("\n", '').split(',') }]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.description
|
37
|
+
"Replace named colors with their hex values"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.priority
|
41
|
+
5
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/scss_lint/auto_correct/correctors/{format_newlines.rb → empty_line_between_blocks.rb}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class
|
2
|
+
class EmptyLineBetweenBlocks < Base
|
3
3
|
def call(contents)
|
4
4
|
contents.gsub(/}\n( *[\.a-zA-Z0-9=\-:&\[\]]+) {/m) do
|
5
5
|
"}\n\n#{Regexp.last_match[1]} {"
|
@@ -7,7 +7,7 @@ module SCSSLint::AutoCorrect::Correctors
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.description
|
10
|
-
""
|
10
|
+
"Ensures empty lines between block defintions"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class
|
2
|
+
class HexLength < Base
|
3
3
|
def call(contents)
|
4
|
+
# TODO: config['style'] == 'short'
|
4
5
|
contents.gsub(/#(([A-Za-z0-9])\2){3}/) { |m| "##{m[1]}#{m[3]}#{m[5]}" }
|
5
6
|
end
|
6
7
|
|
7
|
-
def self.linter_name
|
8
|
-
"HexLength"
|
9
|
-
end
|
10
|
-
|
11
8
|
def self.description
|
12
9
|
"Shortens hex color codes to 3 letters, when possible"
|
13
10
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SCSSLint::AutoCorrect::Correctors
|
2
|
+
class HexNotation < Base
|
3
|
+
def call(contents)
|
4
|
+
contents.gsub(/#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/) { |m| correct_case(m) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def correct_case(str)
|
8
|
+
return str.downcase if config['style'] == 'lowercase' || config['style'].nil?
|
9
|
+
str.upcase
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.description
|
13
|
+
"Downcase hex color values"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module SCSSLint::AutoCorrect::Correctors
|
2
|
+
class Indentation < Base
|
3
|
+
def initialize(config = {})
|
4
|
+
super
|
5
|
+
@result = []
|
6
|
+
@level = 0
|
7
|
+
@indentation_symbol = " "
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(source)
|
11
|
+
source.lines.each { |line| visit_line(line) }
|
12
|
+
@result.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def visit_line(line)
|
16
|
+
if line =~ /^\s*\/\//
|
17
|
+
@result << line
|
18
|
+
return
|
19
|
+
end
|
20
|
+
opening = line.include? "{"
|
21
|
+
closing = line.include? "}"
|
22
|
+
@level -= 1 if closing && !opening
|
23
|
+
@result << apply_indentation(line, @level)
|
24
|
+
@level += 1 if opening && !closing
|
25
|
+
end
|
26
|
+
|
27
|
+
def apply_indentation(line, level)
|
28
|
+
(@indentation_symbol * level) + line.lstrip
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.description
|
32
|
+
"Fixes indentation"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module SCSSLint::AutoCorrect::Correctors
|
2
|
+
class LeadingZero < Base
|
3
|
+
def call(contents)
|
4
|
+
result = []
|
5
|
+
contents.lines.each do |line|
|
6
|
+
if line =~ /\s*\/\// # skip comments
|
7
|
+
result << line
|
8
|
+
next
|
9
|
+
end
|
10
|
+
mm = line.match(/(.+:)([\s\S]*)$/)
|
11
|
+
if mm
|
12
|
+
result << mm[1] + correct_values(mm[2])
|
13
|
+
else
|
14
|
+
result << line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
result.join
|
18
|
+
end
|
19
|
+
|
20
|
+
def correct_values(str)
|
21
|
+
should_include = config.fetch('style', nil) == 'include_zero'
|
22
|
+
str.gsub(/-?(0?\.\d+)/) do |number|
|
23
|
+
if number[0] == "0" && !should_include
|
24
|
+
number[1..-1]
|
25
|
+
elsif number[0] != "0" && should_include
|
26
|
+
"0#{number}"
|
27
|
+
else
|
28
|
+
number
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.description
|
34
|
+
"Checks for unnecessary leading zeros in numeric values with decimal points"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class
|
2
|
+
class SingleLinePerSelector < Base
|
3
3
|
def call(contents)
|
4
|
-
contents.gsub(/([a-zA-Z0-9\[\]=~* ]+,){
|
4
|
+
contents.gsub(/([a-zA-Z0-9\[\]=~* ]+,){1,}.+{/) do |m|
|
5
5
|
selectors = m.split(",")
|
6
6
|
first = selectors.first.rstrip
|
7
7
|
rest = selectors[1..-1].map { |s| " " * first.count(" ") + s.strip }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SCSSLint::AutoCorrect::Correctors
|
2
|
+
class StringQuotes < Base
|
3
|
+
def call(contents)
|
4
|
+
# contents.gsub("'", '"')
|
5
|
+
linter = SCSSLint::Linter::StringQuotes.new
|
6
|
+
contents.gsub(/"[^"]*"|'[^']*'/) do |mm|
|
7
|
+
unescaped = linter.__send__ :extract_string_without_quotes, mm
|
8
|
+
unescaped.dump
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.description
|
13
|
+
"Use double quotes, rather than single quotes"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/scss_lint/auto_correct/correctors/{lines_end_with_semicolons.rb → trailing_semicolon.rb}
RENAMED
@@ -1,9 +1,12 @@
|
|
1
1
|
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class
|
2
|
+
class TrailingSemicolon < Base
|
3
3
|
def call(contents)
|
4
4
|
# if a line ends with a letter, it means it should end with a semicolon
|
5
5
|
# (and it contains a : but no comments (// and *) and some buggy expressions (&))
|
6
|
-
contents.
|
6
|
+
contents.
|
7
|
+
gsub(/^[^\/*&]+:[^\/*&]+[A-Za-z0-9-]$/, '\0;').
|
8
|
+
gsub(/ +;/, ';').
|
9
|
+
gsub(/;+/, ';')
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.description
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class
|
2
|
+
class VariableName < Base
|
3
3
|
def call(contents)
|
4
4
|
contents.gsub(/\$[a-z_-]+/) { |m| m.gsub('_', '-') }
|
5
5
|
end
|
6
6
|
|
7
|
+
def self.linter_name
|
8
|
+
"NameFormat"
|
9
|
+
end
|
10
|
+
|
7
11
|
def self.description
|
8
12
|
"Use dashes instead of underscores in variable names"
|
9
13
|
end
|
data/test/unit/cli_test.rb
CHANGED
@@ -23,14 +23,14 @@ class CliTest < Minitest::Test
|
|
23
23
|
|
24
24
|
it "allows running a specific correctors only" do
|
25
25
|
instance = cli.new
|
26
|
-
instance.parse_args! ["--
|
26
|
+
instance.parse_args! ["--hex-notation", "--empty-line-between-blocks"]
|
27
27
|
assert_equal 2, instance.selected_correctors.count
|
28
28
|
end
|
29
29
|
|
30
30
|
it "allows skipping a specific corrector" do
|
31
31
|
instance = cli.new
|
32
32
|
all = instance.selected_correctors.count
|
33
|
-
instance.parse_args! ["--no-
|
33
|
+
instance.parse_args! ["--no-hex-notation"]
|
34
34
|
assert_equal all - 1, instance.selected_correctors.count
|
35
35
|
end
|
36
36
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class ColorKeywordTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::ColorKeyword" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::ColorKeyword }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "transforms name to hex" do
|
12
|
+
output = corrector.new.call "white"
|
13
|
+
assert_equal "#fff", output
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class EmptyLineBetweenBlocksTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::EmptyLineBetweenBlocks" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::EmptyLineBetweenBlocks }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "process input" do
|
12
|
+
input = load_file "empty_line_between_blocks.scss"
|
13
|
+
expected = load_file "empty_line_between_blocks_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class HexLengthTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::HexLength" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::HexLength }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "shortens long hex" do
|
12
|
+
output = corrector.new.call "#ffffff"
|
13
|
+
assert_equal "#fff", output
|
14
|
+
end
|
15
|
+
|
16
|
+
it "ignores unshortable hex" do
|
17
|
+
output = corrector.new.call "#fedeabe"
|
18
|
+
assert_equal "#fedeabe", output
|
19
|
+
end
|
20
|
+
|
21
|
+
it "ignores partially unshortable hex" do
|
22
|
+
output = corrector.new.call "#ffdeabe"
|
23
|
+
assert_equal "#ffdeabe", output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative "../test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
describe "SCSSLint::AutoCorrect::Correctors::
|
5
|
-
let(:corrector) { SCSSLint::AutoCorrect::Correctors::
|
3
|
+
class HexNotationTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::HexNotation" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::HexNotation }
|
6
6
|
|
7
7
|
it "basically works" do
|
8
8
|
corrector.new
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class IndentationTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::Indentation" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::Indentation }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "process input" do
|
12
|
+
input = load_file "indentation.scss"
|
13
|
+
expected = load_file "indentation_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
|
18
|
+
it "ignores commented lines" do
|
19
|
+
input = load_file "indentation_with_comments.scss"
|
20
|
+
output = corrector.new.call input
|
21
|
+
assert_equal input, output
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class LeadingZeroTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::LeadingZero" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::LeadingZero }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "removes leading zeros" do
|
12
|
+
input = load_file "has_leading_zero.scss"
|
13
|
+
expected = load_file "has_leading_zero_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
|
18
|
+
it "appends leading zeros, if configured" do
|
19
|
+
config = {
|
20
|
+
'style' => 'include_zero'
|
21
|
+
}
|
22
|
+
input = load_file "has_leading_zero_corrected.scss"
|
23
|
+
expected = load_file "has_leading_zero.scss"
|
24
|
+
output = corrector.new(config).call input
|
25
|
+
assert_equal expected, output
|
26
|
+
end
|
27
|
+
|
28
|
+
it "skips over tasty comments" do
|
29
|
+
input = load_file "has_leading_zero_with_comments.scss"
|
30
|
+
output = corrector.new.call input
|
31
|
+
assert_equal input, output
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class SingleLinePerSelectorTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::SingleLinePerSelector" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::SingleLinePerSelector }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "puts each selector on its own line" do
|
12
|
+
input = load_file "multiple_selectors_on_same_line.scss"
|
13
|
+
expected = load_file "multiple_selectors_on_same_line_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class SpaceBeforeBraceTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::SpaceBeforeBrace" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::SpaceBeforeBrace }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "puts each selector on its own line" do
|
12
|
+
input = load_file "space_before_opening_brace.scss"
|
13
|
+
expected = load_file "space_before_opening_brace_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class StringQuotesTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::StringQuotes" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::StringQuotes }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "converts sigle quotes to doubles" do
|
12
|
+
input = ".lorem { color: 'foo'; }"
|
13
|
+
expected = '.lorem { color: "foo"; }'
|
14
|
+
output = corrector.new.call(input)
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
|
18
|
+
it "respectfully deals with nested quotes" do
|
19
|
+
input = ".lorem { color: \"foo 'bar'\"; }"
|
20
|
+
output = corrector.new.call(input)
|
21
|
+
assert_equal input, output
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class TrailingSemicolonTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::TrailingSemicolon" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::TrailingSemicolon }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "adds missing semicolons" do
|
12
|
+
input = load_file "missing_semicolon.scss"
|
13
|
+
expected = load_file "missing_semicolon_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
|
18
|
+
it "removes extra space before semicolon" do
|
19
|
+
input = load_file "space_before_semicolon.scss"
|
20
|
+
expected = load_file "space_before_semicolon_corrected.scss"
|
21
|
+
output = corrector.new.call input
|
22
|
+
assert_equal expected, output
|
23
|
+
end
|
24
|
+
|
25
|
+
it "removes double semicolon" do
|
26
|
+
input = load_file "double_semicolon.scss"
|
27
|
+
expected = load_file "double_semicolon_corrected.scss"
|
28
|
+
output = corrector.new.call input
|
29
|
+
assert_equal expected, output
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class VariableNameTest < Minitest::Test
|
4
|
+
describe "SCSSLint::AutoCorrect::Correctors::VariableName" do
|
5
|
+
let(:corrector) { SCSSLint::AutoCorrect::Correctors::VariableName }
|
6
|
+
|
7
|
+
it "basically works" do
|
8
|
+
corrector.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does its duty" do
|
12
|
+
input = load_file "has_underscores_for_variable_names.scss"
|
13
|
+
expected = load_file "has_underscores_for_variable_names_corrected.scss"
|
14
|
+
output = corrector.new.call input
|
15
|
+
assert_equal expected, output
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scss_lint-auto_correct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
@@ -40,28 +40,58 @@ files:
|
|
40
40
|
- lib/scss_lint/auto_correct/cli.rb
|
41
41
|
- lib/scss_lint/auto_correct/correctors.rb
|
42
42
|
- lib/scss_lint/auto_correct/correctors/base.rb
|
43
|
-
- lib/scss_lint/auto_correct/correctors/
|
44
|
-
- lib/scss_lint/auto_correct/correctors/
|
45
|
-
- lib/scss_lint/auto_correct/correctors/
|
46
|
-
- lib/scss_lint/auto_correct/correctors/
|
47
|
-
- lib/scss_lint/auto_correct/correctors/
|
48
|
-
- lib/scss_lint/auto_correct/correctors/
|
43
|
+
- lib/scss_lint/auto_correct/correctors/color_keyword.rb
|
44
|
+
- lib/scss_lint/auto_correct/correctors/empty_line_between_blocks.rb
|
45
|
+
- lib/scss_lint/auto_correct/correctors/hex_length.rb
|
46
|
+
- lib/scss_lint/auto_correct/correctors/hex_notation.rb
|
47
|
+
- lib/scss_lint/auto_correct/correctors/indentation.rb
|
48
|
+
- lib/scss_lint/auto_correct/correctors/leading_zero.rb
|
49
49
|
- lib/scss_lint/auto_correct/correctors/property_sort_order.rb
|
50
|
-
- lib/scss_lint/auto_correct/correctors/
|
51
|
-
- lib/scss_lint/auto_correct/correctors/
|
52
|
-
- lib/scss_lint/auto_correct/correctors/
|
53
|
-
- lib/scss_lint/auto_correct/correctors/
|
54
|
-
- lib/scss_lint/auto_correct/correctors/
|
50
|
+
- lib/scss_lint/auto_correct/correctors/single_line_per_selector.rb
|
51
|
+
- lib/scss_lint/auto_correct/correctors/space_before_brace.rb
|
52
|
+
- lib/scss_lint/auto_correct/correctors/string_quotes.rb
|
53
|
+
- lib/scss_lint/auto_correct/correctors/trailing_semicolon.rb
|
54
|
+
- lib/scss_lint/auto_correct/correctors/variable_name.rb
|
55
55
|
- lib/scss_lint/auto_correct/property_sorter.rb
|
56
56
|
- lib/scss_lint/auto_correct/version.rb
|
57
|
+
- test/fixtures/double_semicolon.scss
|
58
|
+
- test/fixtures/double_semicolon_corrected.scss
|
59
|
+
- test/fixtures/empty_line_between_blocks.scss
|
60
|
+
- test/fixtures/empty_line_between_blocks_corrected.scss
|
61
|
+
- test/fixtures/has_leading_zero.scss
|
62
|
+
- test/fixtures/has_leading_zero_corrected.scss
|
63
|
+
- test/fixtures/has_leading_zero_with_comments.scss
|
64
|
+
- test/fixtures/has_underscores_for_variable_names.scss
|
65
|
+
- test/fixtures/has_underscores_for_variable_names_corrected.scss
|
57
66
|
- test/fixtures/has_uppercase_colors.scss
|
67
|
+
- test/fixtures/indentation.scss
|
68
|
+
- test/fixtures/indentation_corrected.scss
|
69
|
+
- test/fixtures/indentation_with_comments.scss
|
70
|
+
- test/fixtures/missing_semicolon.scss
|
71
|
+
- test/fixtures/missing_semicolon_corrected.scss
|
72
|
+
- test/fixtures/multiple_selectors_on_same_line.scss
|
73
|
+
- test/fixtures/multiple_selectors_on_same_line_corrected.scss
|
74
|
+
- test/fixtures/space_before_opening_brace.scss
|
75
|
+
- test/fixtures/space_before_opening_brace_corrected.scss
|
76
|
+
- test/fixtures/space_before_semicolon.scss
|
77
|
+
- test/fixtures/space_before_semicolon_corrected.scss
|
58
78
|
- test/fixtures/unsorted_properties.scss
|
59
79
|
- test/fixtures/unsorted_properties_corrected.scss
|
60
80
|
- test/fixtures/unsorted_properties_disable_rule.scss
|
61
81
|
- test/test_helper.rb
|
62
82
|
- test/unit/cli_test.rb
|
63
|
-
- test/unit/
|
83
|
+
- test/unit/color_keyword.rb
|
84
|
+
- test/unit/empty_line_between_blocks_test.rb
|
85
|
+
- test/unit/hex_length_test.rb
|
86
|
+
- test/unit/hex_notation_test.rb
|
87
|
+
- test/unit/indentation_test.rb
|
88
|
+
- test/unit/leading_zero_test.rb
|
64
89
|
- test/unit/property_sort_order_test.rb
|
90
|
+
- test/unit/single_line_per_selector_test.rb
|
91
|
+
- test/unit/space_before_brace_test.rb
|
92
|
+
- test/unit/string_quotes_test.rb
|
93
|
+
- test/unit/trailing_semicolon_test.rb
|
94
|
+
- test/unit/variable_name_test.rb
|
65
95
|
homepage: https://github.com/Dorian/scss-lint-auto-correct
|
66
96
|
licenses:
|
67
97
|
- MIT
|
@@ -87,11 +117,41 @@ signing_key:
|
|
87
117
|
specification_version: 4
|
88
118
|
summary: Auto corrections for SCSS lint tool
|
89
119
|
test_files:
|
120
|
+
- test/fixtures/double_semicolon.scss
|
121
|
+
- test/fixtures/double_semicolon_corrected.scss
|
122
|
+
- test/fixtures/empty_line_between_blocks.scss
|
123
|
+
- test/fixtures/empty_line_between_blocks_corrected.scss
|
124
|
+
- test/fixtures/has_leading_zero.scss
|
125
|
+
- test/fixtures/has_leading_zero_corrected.scss
|
126
|
+
- test/fixtures/has_leading_zero_with_comments.scss
|
127
|
+
- test/fixtures/has_underscores_for_variable_names.scss
|
128
|
+
- test/fixtures/has_underscores_for_variable_names_corrected.scss
|
90
129
|
- test/fixtures/has_uppercase_colors.scss
|
130
|
+
- test/fixtures/indentation.scss
|
131
|
+
- test/fixtures/indentation_corrected.scss
|
132
|
+
- test/fixtures/indentation_with_comments.scss
|
133
|
+
- test/fixtures/missing_semicolon.scss
|
134
|
+
- test/fixtures/missing_semicolon_corrected.scss
|
135
|
+
- test/fixtures/multiple_selectors_on_same_line.scss
|
136
|
+
- test/fixtures/multiple_selectors_on_same_line_corrected.scss
|
137
|
+
- test/fixtures/space_before_opening_brace.scss
|
138
|
+
- test/fixtures/space_before_opening_brace_corrected.scss
|
139
|
+
- test/fixtures/space_before_semicolon.scss
|
140
|
+
- test/fixtures/space_before_semicolon_corrected.scss
|
91
141
|
- test/fixtures/unsorted_properties.scss
|
92
142
|
- test/fixtures/unsorted_properties_corrected.scss
|
93
143
|
- test/fixtures/unsorted_properties_disable_rule.scss
|
94
144
|
- test/test_helper.rb
|
95
145
|
- test/unit/cli_test.rb
|
96
|
-
- test/unit/
|
146
|
+
- test/unit/color_keyword.rb
|
147
|
+
- test/unit/empty_line_between_blocks_test.rb
|
148
|
+
- test/unit/hex_length_test.rb
|
149
|
+
- test/unit/hex_notation_test.rb
|
150
|
+
- test/unit/indentation_test.rb
|
151
|
+
- test/unit/leading_zero_test.rb
|
97
152
|
- test/unit/property_sort_order_test.rb
|
153
|
+
- test/unit/single_line_per_selector_test.rb
|
154
|
+
- test/unit/space_before_brace_test.rb
|
155
|
+
- test/unit/string_quotes_test.rb
|
156
|
+
- test/unit/trailing_semicolon_test.rb
|
157
|
+
- test/unit/variable_name_test.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class ShortVersionsOfNumbers < Base
|
3
|
-
def call(contents)
|
4
|
-
# do not match 1.04 or v1.0.0 or LICENSE-2.0
|
5
|
-
# (this is pure dark magic)
|
6
|
-
contents.gsub(/([^-v[0-9]?\.?)])([0-9])\.0+([^0-9])/, '\1\2\3')
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.description
|
10
|
-
""
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module SCSSLint::AutoCorrect::Correctors
|
2
|
-
class UseHexInsteadOfColorKeywords < Base
|
3
|
-
def call(contents)
|
4
|
-
colors = self.class.data
|
5
|
-
regexp = Regexp.new("^([^\/]+ )(#{colors.keys.join('|')})([\) ;].*)$")
|
6
|
-
|
7
|
-
contents.gsub(regexp) do
|
8
|
-
Regexp.last_match[1] + colors[Regexp.last_match[2]] + Regexp.last_match[3]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.data
|
13
|
-
return @data if @data
|
14
|
-
colors_file = File.expand_path(File.join(File.dirname(__FILE__), "color-keywords.csv"))
|
15
|
-
@data = Hash[File.read(colors_file).lines.map { |l| l.gsub("\n", '').split(',') }]
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.description
|
19
|
-
"Replace named colors with their hex values"
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.priority
|
23
|
-
5
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.linter_name
|
27
|
-
"ColorKeyword"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|