lib/scss_lint/engine.rb in scss_lint-0.41.0 vs lib/scss_lint/engine.rb in scss_lint-0.42.0

- old
+ new

@@ -6,11 +6,11 @@ # Contains all information for a parsed SCSS file, including its name, # contents, and parse tree. 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. # # @param options [Hash] @@ -25,11 +25,12 @@ # Need to force encoding to avoid Windows-related bugs. # 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, "Unable to parse SCSS file: #{error}", error.backtrace @@ -49,8 +50,13 @@ # @param scss [String] 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