scss_lint-auto_correct 1.2.1 → 1.2.2
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/cli.rb +29 -2
- data/lib/scss_lint/auto_correct/correctors.rb +1 -1
- data/lib/scss_lint/auto_correct/correctors/color_keyword.rb +1 -1
- data/lib/scss_lint/auto_correct/correctors/indentation.rb +1 -1
- data/lib/scss_lint/auto_correct/version.rb +1 -1
- data/test/fixtures/indentation_with_blanks.scss +12 -0
- data/test/unit/color_keyword.rb +20 -2
- data/test/unit/indentation_test.rb +7 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f02b59e2ba450a6240d4cc537f6829deb900e39d
|
4
|
+
data.tar.gz: 31f982e70b5573bf1109bd540d2c41f0245625c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de3ebef2afc22be17b0bdbc59d0ad3f0cc32bd973192d30813a559e0b38c844c130f6b661349e684c24bba7925739b413145881e1eafd6b52615369e912eaba
|
7
|
+
data.tar.gz: c1fa01797cb26f47f7efbbf77509a1489c9f092b99460eb0ee58d44ea1425f52da31898d31d08d9b161443193c6414b46110c237ba683017a83b8c54b4efacf6
|
@@ -49,6 +49,7 @@ module SCSSLint::AutoCorrect
|
|
49
49
|
puts "Nothing to process"
|
50
50
|
return 1
|
51
51
|
end
|
52
|
+
puts "Dry run. Nothing written" if option? :dry
|
52
53
|
process_all @paths
|
53
54
|
0
|
54
55
|
end
|
@@ -59,6 +60,7 @@ module SCSSLint::AutoCorrect
|
|
59
60
|
puts "OPTIONS are:"
|
60
61
|
puts " --help, -h"
|
61
62
|
puts " --verbose, -v"
|
63
|
+
puts " --debug Prints extended debugging information"
|
62
64
|
puts " --dry"
|
63
65
|
puts " --list"
|
64
66
|
puts " --force Ignore config disabling of corrector"
|
@@ -108,13 +110,13 @@ module SCSSLint::AutoCorrect
|
|
108
110
|
|
109
111
|
def write_file(path, contents)
|
110
112
|
puts "Writing file #{path}" if option? :verbose, :v
|
111
|
-
writer.write_file(path, contents)
|
113
|
+
writer.write_file(path, contents) unless option? :dry
|
112
114
|
end
|
113
115
|
|
114
116
|
def selected_correctors
|
115
117
|
selected = []
|
116
118
|
unselected = []
|
117
|
-
|
119
|
+
selected_correctors.each do |c|
|
118
120
|
selected << c if option? c.short_name
|
119
121
|
unselected << c if option? "no-#{c.short_name}"
|
120
122
|
end
|
@@ -126,11 +128,36 @@ module SCSSLint::AutoCorrect
|
|
126
128
|
@correctors.each do |corrector|
|
127
129
|
config = corrector.linter_name ? @config.options['linters'].fetch(corrector.linter_name) : {}
|
128
130
|
instance = corrector.new(config)
|
131
|
+
contents_was = contents
|
129
132
|
contents = instance.call(contents) if instance.enabled? || option?(:force)
|
133
|
+
if option?(:debug) && contents != contents_was
|
134
|
+
puts "* #{corrector.name} applied"
|
135
|
+
print_diff contents_was, contents
|
136
|
+
end
|
130
137
|
end
|
131
138
|
contents
|
132
139
|
end
|
133
140
|
|
141
|
+
def print_diff(before, after)
|
142
|
+
@has_diff = `[ -x "$(command -v diff)" ] && echo "yay"`.strip == "yay" if @has_diff.nil?
|
143
|
+
return puts after unless @has_diff
|
144
|
+
require "tempfile"
|
145
|
+
files = []
|
146
|
+
file_before = Tempfile.new("before")
|
147
|
+
files << file_before
|
148
|
+
file_before.write before
|
149
|
+
file_before.close
|
150
|
+
file_after = Tempfile.new("after")
|
151
|
+
files << file_after
|
152
|
+
file_after.write after
|
153
|
+
file_after.close
|
154
|
+
cmd = "diff -u #{file_before.path} #{file_after.path}"
|
155
|
+
output = `#{cmd}`
|
156
|
+
puts output.lines[2..-1].join
|
157
|
+
ensure
|
158
|
+
files.each(&:unlink)
|
159
|
+
end
|
160
|
+
|
134
161
|
class FilesystemWriter
|
135
162
|
def write_file(path, contents)
|
136
163
|
File.open(path, "w+") { |f| f.write contents }
|
data/test/unit/color_keyword.rb
CHANGED
@@ -9,8 +9,26 @@ class ColorKeywordTest < Minitest::Test
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "transforms name to hex" do
|
12
|
-
output = corrector.new.call "white"
|
13
|
-
assert_equal "#
|
12
|
+
output = corrector.new.call "color: white"
|
13
|
+
assert_equal "color: #ffffff", output
|
14
|
+
end
|
15
|
+
|
16
|
+
it "doesnt mess replace into variable names" do
|
17
|
+
input = "color: $white"
|
18
|
+
output = corrector.new.call input
|
19
|
+
assert_equal input, output
|
20
|
+
end
|
21
|
+
|
22
|
+
it "respects dashes as non-boundaries" do
|
23
|
+
input = "color: $pale-red"
|
24
|
+
output = corrector.new.call input
|
25
|
+
assert_equal input, output
|
26
|
+
end
|
27
|
+
|
28
|
+
it "respects underscores as non-boundaries" do
|
29
|
+
input = "color: $pale_red"
|
30
|
+
output = corrector.new.call input
|
31
|
+
assert_equal input, output
|
14
32
|
end
|
15
33
|
end
|
16
34
|
end
|
@@ -20,5 +20,12 @@ class IndentationTest < Minitest::Test
|
|
20
20
|
output = corrector.new.call input
|
21
21
|
assert_equal input, output
|
22
22
|
end
|
23
|
+
|
24
|
+
it "doesnt remove blank lines" do
|
25
|
+
input = load_file "indentation_with_blanks.scss"
|
26
|
+
expected = input
|
27
|
+
output = corrector.new.call input
|
28
|
+
assert_equal expected, output
|
29
|
+
end
|
23
30
|
end
|
24
31
|
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.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-01-
|
12
|
+
date: 2018-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: scss_lint
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- test/fixtures/has_uppercase_colors.scss
|
68
68
|
- test/fixtures/indentation.scss
|
69
69
|
- test/fixtures/indentation_corrected.scss
|
70
|
+
- test/fixtures/indentation_with_blanks.scss
|
70
71
|
- test/fixtures/indentation_with_comments.scss
|
71
72
|
- test/fixtures/missing_semicolon.scss
|
72
73
|
- test/fixtures/missing_semicolon_corrected.scss
|
@@ -130,6 +131,7 @@ test_files:
|
|
130
131
|
- test/fixtures/has_uppercase_colors.scss
|
131
132
|
- test/fixtures/indentation.scss
|
132
133
|
- test/fixtures/indentation_corrected.scss
|
134
|
+
- test/fixtures/indentation_with_blanks.scss
|
133
135
|
- test/fixtures/indentation_with_comments.scss
|
134
136
|
- test/fixtures/missing_semicolon.scss
|
135
137
|
- test/fixtures/missing_semicolon_corrected.scss
|