Skip to content

Commit

Permalink
Conservatively process control commands
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored and sds committed Sep 4, 2015
1 parent e29cc40 commit 33cf2bc
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 33cf2bc

Please sign in to comment.