Class: SCSSLint::Linter::UnnecessaryMantissa
- Inherits:
-
SCSSLint::Linter
- Object
- Sass::Tree::Visitors::Base
- SCSSLint::Linter
- SCSSLint::Linter::UnnecessaryMantissa
- Includes:
- SCSSLint::LinterRegistry
- Defined in:
- lib/scss_lint/linter/unnecessary_mantissa.rb
Overview
Checks for the unnecessary inclusion of a zero-value mantissa in numbers. (e.g. ‘4.0` could be written as just `4`)
Instance Attribute Summary
Attributes inherited from SCSSLint::Linter
Instance Method Summary collapse
Methods included from SCSSLint::LinterRegistry
extract_linters_from, included
Methods inherited from SCSSLint::Linter
#add_lint, #character_at, #initialize, #location_from_range, #node_on_single_line?, #run, #source_from_range, #visit, #visit_children
Methods included from Utils
#can_be_condensed?, #extract_string_selectors, #pluralize, #previous_node, #remove_quoted_strings, #shortest_hex_form
Methods included from SelectorVisitor
Constructor Details
This class inherits a constructor from SCSSLint::Linter
Instance Method Details
#visit_script_number(node) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/scss_lint/linter/unnecessary_mantissa.rb', line 17 def visit_script_number(node) return unless match = REAL_NUMBER_REGEX.match(source_from_range(node.source_range)) if unnecessary_mantissa?(match[:mantissa]) add_lint(node, MESSAGE_FORMAT % [match[:number], match[:integer], match[:units]]) end end |
#visit_script_string(node) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/scss_lint/linter/unnecessary_mantissa.rb', line 7 def visit_script_string(node) return unless node.type == :identifier node.value.scan(REAL_NUMBER_REGEX) do |number, integer, mantissa, units| if unnecessary_mantissa?(mantissa) add_lint(node, MESSAGE_FORMAT % [number, integer, units]) end end end |