Class: SCSSLint::AutoCorrect::Correctors::HexLength

Inherits:
Base
  • Object
show all
Defined in:
lib/scss_lint/auto_correct/correctors/hex_length.rb

Instance Attribute Summary

Attributes inherited from Base

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#enabled?, #initialize, linter_name, priority, short_name

Constructor Details

This class inherits a constructor from SCSSLint::AutoCorrect::Correctors::Base

Class Method Details

.descriptionObject



8
9
10
# File 'lib/scss_lint/auto_correct/correctors/hex_length.rb', line 8

def self.description
  "Shortens hex color codes to 3 letters, when possible"
end

Instance Method Details

#call(contents) ⇒ Object



3
4
5
6
# File 'lib/scss_lint/auto_correct/correctors/hex_length.rb', line 3

def call(contents)
  # TODO: config['style'] == 'short'
  contents.gsub(/#(([A-Za-z0-9])\2){3}/) { |m| "##{m[1]}#{m[3]}#{m[5]}" }
end