Skip to content

Commit

Permalink
Conservatively process control commands
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Sep 2, 2015
1 parent c5be783 commit 033a2b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/scss_lint/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FileEncodingError < StandardError; end
class Engine
ENGINE_OPTIONS = { cache: false, syntax: :scss }

attr_reader :contents, :filename, :lines, :tree
attr_reader :contents, :filename, :lines, :tree, :any_control_commands

# Creates a parsed representation of an SCSS document from the given string
# or file.
Expand All @@ -27,7 +27,8 @@ def initialize(options = {})
# Need `to_a` for Ruby 1.9.3.
@lines = @contents.force_encoding('UTF-8').lines.to_a
@tree = @engine.to_tree
rescue Encoding::UndefinedConversionError, Sass::SyntaxError => error
find_any_control_commands
rescue Encoding::UndefinedConversionError, Sass::SyntaxError, ArgumentError => error
if error.is_a?(Encoding::UndefinedConversionError) ||
error.message.match(/invalid.*(byte sequence|character)/i)
raise FileEncodingError,
Expand All @@ -52,5 +53,10 @@ def build_from_string(scss)
@engine = Sass::Engine.new(scss, ENGINE_OPTIONS)
@contents = scss
end

def find_any_control_commands
@any_control_commands =
@lines.any? { |line| line['scss-lint:disable'] || line['scss-line:enable'] }
end
end
end
4 changes: 2 additions & 2 deletions lib/scss_lint/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def visit(node)
visit_selector(node.parsed_rules)
end

@comment_processor.before_node_visit(node)
@comment_processor.before_node_visit(node) if @engine.any_control_commands
super
@comment_processor.after_node_visit(node)
@comment_processor.after_node_visit(node) if @engine.any_control_commands
end

# Redefine so we can set the `node_parent` of each node
Expand Down

0 comments on commit 033a2b8

Please sign in to comment.