scss-lint 0.21.0 → 0.22.0

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: 0a7439d0611e864629c12a2f1e95c417b0e0615a
4
- data.tar.gz: 4ca3047aa3497339ee4dc9164764d229e38f9a27
3
+ metadata.gz: 70bae0144c5b9e28dc02a481787f9a59d6904829
4
+ data.tar.gz: 0ae51c9a6ab0cca63274d0026ad07c27acecad75
5
5
  SHA512:
6
- metadata.gz: 74cf4f6c5e8fcd106500db1a05ef37d311065cbd97ef4e120380d2d6c6c90ff252d9f6818a863708337b42cc24d352cd6ba5909a2216c987b7b1d07419f9aa79
7
- data.tar.gz: 04e23316befdbaf54f37f6004df3b5e93a9eab83ce00a5f36de107ec5176485092c1f22e965fc3f2617e4a7c7f536d171a8099a5c5ea50353b80cd86030aee0c
6
+ metadata.gz: a3040302bcde27b996f2f1bb0e3825c0173c6b965d5ffe41e50d7c9313de01ef00482a7c4b408837776882098c9a492c82fb1bd86a2f9eb9b8536c7db838e7c1
7
+ data.tar.gz: ded041dd16b6b836c21db252c2747acabe2be2296b321cbfc763a7cdd89f9c8232c00b76f37f11045deb4adbb30842316154a32670f7c29c831a94e4061f0943
data/config/default.yml CHANGED
@@ -28,6 +28,10 @@ linters:
28
28
  EmptyRule:
29
29
  enabled: true
30
30
 
31
+ FinalNewline:
32
+ enabled: true
33
+ present: true
34
+
31
35
  HexFormat:
32
36
  enabled: true
33
37
 
@@ -77,6 +81,7 @@ linters:
77
81
 
78
82
  SpaceBeforeBrace:
79
83
  enabled: true
84
+ allow_single_line_padding: false
80
85
 
81
86
  SpaceBetweenParens:
82
87
  enabled: true
@@ -20,11 +20,11 @@ module SCSSLint
20
20
  @contents = scss_or_filename
21
21
  end
22
22
 
23
- @lines = @contents.split("\n")
23
+ @lines = @contents.lines.to_a # Need `to_a` for Ruby 1.9.3
24
24
  @tree = @engine.to_tree
25
- rescue Encoding::UndefinedConversionError, ArgumentError => error
25
+ rescue Encoding::UndefinedConversionError, Sass::SyntaxError => error
26
26
  if error.is_a?(Encoding::UndefinedConversionError) ||
27
- error.message.include?('invalid byte sequence')
27
+ error.message.match(/invalid.*(byte sequence|character)/i)
28
28
  raise FileEncodingError,
29
29
  "Unable to parse SCSS file: #{error}",
30
30
  error.backtrace
@@ -80,19 +80,5 @@ module SCSSLint
80
80
  .children
81
81
  .select { |child| child.is_a?(Sass::Tree::Node) }
82
82
  end
83
-
84
- def node_on_single_line(node)
85
- return if node.source_range.start_pos.line != node.source_range.end_pos.line
86
-
87
- # The Sass parser reports an incorrect source range if the trailing curly
88
- # brace is on the next line, e.g.
89
- #
90
- # p {
91
- # }
92
- #
93
- # Since we don't want to count this as a single line node, check if the
94
- # last character on the first line is an opening curly brace.
95
- engine.lines[node.line - 1].strip[-1] != '{'
96
- end
97
83
  end
98
84
  end
@@ -0,0 +1,20 @@
1
+ module SCSSLint
2
+ # Checks for final newlines at the end of a file.
3
+ class Linter::FinalNewline < Linter
4
+ include LinterRegistry
5
+
6
+ def visit_root(node)
7
+ return if engine.lines.empty?
8
+
9
+ ends_with_newline = engine.lines[-1][-1] == "\n"
10
+
11
+ if config['present']
12
+ add_lint(engine.lines.count,
13
+ 'Files should end with a trailing newline') unless ends_with_newline
14
+ else
15
+ add_lint(engine.lines.count,
16
+ 'Files should not end with a trailing newline') if ends_with_newline
17
+ end
18
+ end
19
+ end
20
+ end
@@ -4,15 +4,20 @@ module SCSSLint
4
4
  class Linter::SpaceAfterPropertyColon < Linter
5
5
  include LinterRegistry
6
6
 
7
- EXPECTED_SPACES_AFTER_COLON = 1
7
+ MINIMUM_SPACES_AFTER_COLON = 1
8
8
 
9
9
  def visit_prop(node)
10
10
  spaces = spaces_after_colon(node)
11
11
 
12
- if spaces != EXPECTED_SPACES_AFTER_COLON
12
+ if config['allow_extra_spaces']
13
+ if spaces < MINIMUM_SPACES_AFTER_COLON
14
+ add_lint node, 'Colon after property should be followed by ' <<
15
+ "at least #{pluralize(MINIMUM_SPACES_AFTER_COLON, 'space')} "
16
+ end
17
+ elsif spaces != MINIMUM_SPACES_AFTER_COLON
13
18
  add_lint node, 'Colon after property should be followed by ' <<
14
- "#{pluralize(EXPECTED_SPACES_AFTER_COLON, 'space')} instead of " <<
15
- pluralize(spaces, 'space')
19
+ pluralize(MINIMUM_SPACES_AFTER_COLON, 'space') <<
20
+ " instead of #{pluralize(spaces, 'space')}"
16
21
  end
17
22
  end
18
23
 
@@ -5,8 +5,17 @@ module SCSSLint
5
5
 
6
6
  def visit_root(node)
7
7
  engine.lines.each_with_index do |line, index|
8
- line.scan /[^"#](?<![^ ] )\{/ do |match|
9
- add_lint(index + 1, 'Opening curly braces ({) should be preceded by one space')
8
+
9
+ if config['allow_single_line_padding'] && node_on_single_line(node)
10
+ line.scan(/[^"#' ]\{/) do |match|
11
+ add_lint(index + 1, 'Opening curly brace `{` should be ' <<
12
+ 'preceded by at least one space')
13
+ end
14
+ else
15
+ line.scan(/[^"#'](?<![^ ] )\{/) do |match|
16
+ add_lint(index + 1, 'Opening curly brace `{` should be ' <<
17
+ 'preceded by one space')
18
+ end
10
19
  end
11
20
  end
12
21
  end
@@ -7,8 +7,18 @@ module SCSSLint
7
7
  def visit_prop(node)
8
8
  has_nested_props = has_nested_properties?(node)
9
9
 
10
- if !has_nested_props && !ends_with_semicolon?(node)
11
- add_lint node.line, 'Property declaration should end with a semicolon'
10
+ unless has_nested_props
11
+ if has_space_before_semicolon?(node)
12
+ line = node.source_range.end_pos
13
+ add_lint line, 'Property declaration should be terminated by a semicolon'
14
+ elsif !ends_with_semicolon?(node)
15
+ # Adjust line since lack of semicolon results in end of source range
16
+ # being on the next line
17
+ line = node.source_range.end_pos.line - 1
18
+ add_lint line,
19
+ 'Property declaration should not have a space before ' <<
20
+ 'the terminating semicolon'
21
+ end
12
22
  end
13
23
 
14
24
  yield if has_nested_props
@@ -22,8 +32,11 @@ module SCSSLint
22
32
 
23
33
  # Checks that the property is ended by a semicolon (with no whitespace)
24
34
  def ends_with_semicolon?(node)
25
- character_at(node.source_range.end_pos) == ';' &&
26
- character_at(node.source_range.end_pos, -1) !~ /\s/
35
+ source_from_range(node.source_range) =~ /;$/
36
+ end
37
+
38
+ def has_space_before_semicolon?(node)
39
+ source_from_range(node.source_range) =~ /\s;$/
27
40
  end
28
41
  end
29
42
  end
@@ -43,6 +43,7 @@ module SCSSLint
43
43
  end
44
44
 
45
45
  def check_url(url, node)
46
+ return if url.match(/^data:/)
46
47
  uri = URI(url)
47
48
 
48
49
  if uri.scheme || uri.host
@@ -4,6 +4,8 @@ module SCSSLint
4
4
  include LinterRegistry
5
5
 
6
6
  def visit_script_string(node)
7
+ return unless node.type == :identifier
8
+
7
9
  node.value.scan(ZERO_UNIT_REGEX) do |match|
8
10
  add_lint(node, MESSAGE_FORMAT % match.first)
9
11
  end
@@ -37,9 +37,6 @@ module SCSSLint
37
37
  actual_line = source_position.line - 1
38
38
  actual_offset = source_position.offset + offset - 1
39
39
 
40
- # Return a newline if offset points at the very end of the line
41
- return "\n" if actual_offset == engine.lines[actual_line].length
42
-
43
40
  engine.lines[actual_line][actual_offset]
44
41
  end
45
42
 
@@ -60,20 +57,35 @@ module SCSSLint
60
57
 
61
58
  current_line += 1
62
59
  while current_line < last_line
63
- source += "#{engine.lines[current_line]}\n"
60
+ source += "#{engine.lines[current_line]}"
64
61
  current_line += 1
65
62
  end
66
63
 
67
- if source_range.start_pos.line != source_range.end_pos.line &&
68
- # Sometimes the parser reports ranges ending on the first column of the
69
- # line after the last line; don't include the last line in this case.
70
- engine.lines.count == current_line - 1
71
- source += "#{engine.lines[current_line][0...source_range.end_pos.offset]}\n"
64
+ if source_range.start_pos.line != source_range.end_pos.line
65
+ source += "#{(engine.lines[current_line] || '')[0...source_range.end_pos.offset]}"
72
66
  end
73
67
 
74
68
  source
75
69
  end
76
70
 
71
+ # Returns whether a given node spans only a single line.
72
+ #
73
+ # @param node [Sass::Tree::Node]
74
+ # @return [true,false] whether the node spans a single line
75
+ def node_on_single_line(node)
76
+ return if node.source_range.start_pos.line != node.source_range.end_pos.line
77
+
78
+ # The Sass parser reports an incorrect source range if the trailing curly
79
+ # brace is on the next line, e.g.
80
+ #
81
+ # p {
82
+ # }
83
+ #
84
+ # Since we don't want to count this as a single line node, check if the
85
+ # last character on the first line is an opening curly brace.
86
+ engine.lines[node.line - 1].strip[-1] != '{'
87
+ end
88
+
77
89
  # Modified so we can also visit selectors in linters
78
90
  #
79
91
  # @param node [Sass::Tree::Node, Sass::Script::Tree::Node,
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SCSSLint
3
- VERSION = '0.21.0'
3
+ VERSION = '0.22.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scss-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-30 00:00:00.000000000 Z
12
+ date: 2014-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -78,56 +78,57 @@ extra_rdoc_files: []
78
78
  files:
79
79
  - config/default.yml
80
80
  - data/properties.txt
81
- - lib/scss_lint/cli.rb
82
- - lib/scss_lint/config.rb
81
+ - lib/scss_lint/version.rb
83
82
  - lib/scss_lint/constants.rb
84
- - lib/scss_lint/engine.rb
83
+ - lib/scss_lint/utils.rb
84
+ - lib/scss_lint/reporter/files_reporter.rb
85
+ - lib/scss_lint/reporter/xml_reporter.rb
86
+ - lib/scss_lint/reporter/default_reporter.rb
87
+ - lib/scss_lint/runner.rb
88
+ - lib/scss_lint/reporter.rb
85
89
  - lib/scss_lint/lint.rb
86
- - lib/scss_lint/linter/border_zero.rb
87
- - lib/scss_lint/linter/capitalization_in_selector.rb
88
- - lib/scss_lint/linter/color_keyword.rb
89
- - lib/scss_lint/linter/comment.rb
90
- - lib/scss_lint/linter/compass/property_with_mixin.rb
90
+ - lib/scss_lint/linter.rb
91
+ - lib/scss_lint/rake_task.rb
92
+ - lib/scss_lint/selector_visitor.rb
93
+ - lib/scss_lint/sass/tree.rb
94
+ - lib/scss_lint/sass/script.rb
95
+ - lib/scss_lint/config.rb
91
96
  - lib/scss_lint/linter/compass.rb
92
- - lib/scss_lint/linter/debug_statement.rb
93
- - lib/scss_lint/linter/declaration_order.rb
94
- - lib/scss_lint/linter/duplicate_property.rb
95
- - lib/scss_lint/linter/empty_line_between_blocks.rb
96
- - lib/scss_lint/linter/empty_rule.rb
97
- - lib/scss_lint/linter/hex_format.rb
98
- - lib/scss_lint/linter/id_with_extraneous_selector.rb
97
+ - lib/scss_lint/linter/space_after_comma.rb
98
+ - lib/scss_lint/linter/space_before_brace.rb
99
+ - lib/scss_lint/linter/capitalization_in_selector.rb
99
100
  - lib/scss_lint/linter/indentation.rb
100
- - lib/scss_lint/linter/leading_zero.rb
101
- - lib/scss_lint/linter/name_format.rb
101
+ - lib/scss_lint/linter/trailing_semicolon_after_property_value.rb
102
+ - lib/scss_lint/linter/shorthand.rb
103
+ - lib/scss_lint/linter/final_newline.rb
104
+ - lib/scss_lint/linter/id_with_extraneous_selector.rb
105
+ - lib/scss_lint/linter/empty_line_between_blocks.rb
106
+ - lib/scss_lint/linter/declaration_order.rb
107
+ - lib/scss_lint/linter/zero_unit.rb
102
108
  - lib/scss_lint/linter/placeholder_in_extend.rb
103
- - lib/scss_lint/linter/property_sort_order.rb
104
- - lib/scss_lint/linter/property_spelling.rb
105
109
  - lib/scss_lint/linter/selector_depth.rb
106
- - lib/scss_lint/linter/shorthand.rb
107
- - lib/scss_lint/linter/single_line_per_selector.rb
108
- - lib/scss_lint/linter/space_after_comma.rb
109
- - lib/scss_lint/linter/space_after_property_colon.rb
110
+ - lib/scss_lint/linter/compass/property_with_mixin.rb
110
111
  - lib/scss_lint/linter/space_after_property_name.rb
111
- - lib/scss_lint/linter/space_before_brace.rb
112
+ - lib/scss_lint/linter/property_spelling.rb
113
+ - lib/scss_lint/linter/url_quotes.rb
114
+ - lib/scss_lint/linter/name_format.rb
112
115
  - lib/scss_lint/linter/space_between_parens.rb
116
+ - lib/scss_lint/linter/border_zero.rb
117
+ - lib/scss_lint/linter/space_after_property_colon.rb
118
+ - lib/scss_lint/linter/debug_statement.rb
119
+ - lib/scss_lint/linter/duplicate_property.rb
120
+ - lib/scss_lint/linter/property_sort_order.rb
121
+ - lib/scss_lint/linter/hex_format.rb
122
+ - lib/scss_lint/linter/color_keyword.rb
113
123
  - lib/scss_lint/linter/string_quotes.rb
114
- - lib/scss_lint/linter/trailing_semicolon_after_property_value.rb
124
+ - lib/scss_lint/linter/leading_zero.rb
125
+ - lib/scss_lint/linter/comment.rb
126
+ - lib/scss_lint/linter/empty_rule.rb
127
+ - lib/scss_lint/linter/single_line_per_selector.rb
115
128
  - lib/scss_lint/linter/url_format.rb
116
- - lib/scss_lint/linter/url_quotes.rb
117
- - lib/scss_lint/linter/zero_unit.rb
118
- - lib/scss_lint/linter.rb
129
+ - lib/scss_lint/cli.rb
130
+ - lib/scss_lint/engine.rb
119
131
  - lib/scss_lint/linter_registry.rb
120
- - lib/scss_lint/rake_task.rb
121
- - lib/scss_lint/reporter/default_reporter.rb
122
- - lib/scss_lint/reporter/files_reporter.rb
123
- - lib/scss_lint/reporter/xml_reporter.rb
124
- - lib/scss_lint/reporter.rb
125
- - lib/scss_lint/runner.rb
126
- - lib/scss_lint/sass/script.rb
127
- - lib/scss_lint/sass/tree.rb
128
- - lib/scss_lint/selector_visitor.rb
129
- - lib/scss_lint/utils.rb
130
- - lib/scss_lint/version.rb
131
132
  - lib/scss_lint.rb
132
133
  - bin/scss-lint
133
134
  homepage: https://github.com/causes/scss-lint