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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ecb5464bb631a1ee5659093f896dc1b663d629
4
- data.tar.gz: 0bbb3860b3d1f424961bd2eeab4649cc0b51f462
3
+ metadata.gz: f02b59e2ba450a6240d4cc537f6829deb900e39d
4
+ data.tar.gz: 31f982e70b5573bf1109bd540d2c41f0245625c7
5
5
  SHA512:
6
- metadata.gz: f7ab60f764863fd5e1b9b61316c89da1d0f0e4a7b8a26d7f66eae4cbf16febc6f1a29202ba03d1e6cadcbeccb4cc77185be7f590a67b424c8f8cb9ce3e3a5fc3
7
- data.tar.gz: eede024f9f01d0658bd1260f4daf543f3b59b8b74aacc1c611dbd1c23d4f3680aa68edf1a0e0a6e6811df4f10ea8515a0feb70f0ecd8c2a9e8ec07b44c03b6c0
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
- @correctors.each do |c|
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 }
@@ -4,7 +4,7 @@ module SCSSLint::AutoCorrect
4
4
  ObjectSpace.
5
5
  each_object(Class).
6
6
  select { |klass| klass < Base }.
7
- sort_by(&:priority)
7
+ sort_by { |x| [x.priority.to_s.rjust(8, "0"), x.name].join }
8
8
  end
9
9
  end
10
10
  end
@@ -24,7 +24,7 @@ module SCSSLint::AutoCorrect::Correctors
24
24
  end
25
25
 
26
26
  def regexp
27
- @regexp ||= Regexp.new("#{self.class.data.keys.join('|')}")
27
+ @regexp ||= Regexp.new("(?<![$_-])\\b(#{self.class.data.keys.join('|')})\\b")
28
28
  end
29
29
 
30
30
  def self.data
@@ -13,7 +13,7 @@ module SCSSLint::AutoCorrect::Correctors
13
13
  end
14
14
 
15
15
  def visit_line(line)
16
- if line =~ /^\s*\/\//
16
+ if line =~ /^\s*\/\// || line =~ /^\s*$/
17
17
  @result << line
18
18
  return
19
19
  end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SCSSLint::AutoCorrect
3
- VERSION = '1.2.1'.freeze
3
+ VERSION = '1.2.2'.freeze
4
4
  end
@@ -0,0 +1,12 @@
1
+ .users-list {
2
+ margin-top: 1rem;
3
+ }
4
+
5
+ .new-membership {
6
+ select { width: 80%; }
7
+
8
+ select,
9
+ input {
10
+ display: inline-block;
11
+ }
12
+ }
@@ -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 "#fff", output
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.1
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-03 00:00:00.000000000 Z
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