A collection of regular expressions to easily comply to scss-lint rules.
carview.php?tsp= Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
carview.php?tsp= README.md

README.md

SCSS-lint Regex

I got tired of cleaning Sass codebases by hand to make them compliant with SCSS-lint so I wrote a set of regular expressions to do just that.

The point is to be able to perform a quick search and replace to make the whole codebase compliant to a specific rule from SCSS-lint — when possible of course. Turned out to be extremely easy in Sublime Text for instance (see following screenshot).

Search and replace in Sublime Text

If you suspect a regular expression to be incorrect, dangerous or improvable, please by all mean open a new issue so we can discuss it!

BangFormat

  • Search: ([^\s])!important
  • Replace: \1 !important

BorderZero

  • Search: (border(-bottom|-left|-right|-top)?):\s*none
  • Replace: \1: 0

Comment

A bit complex, but could probably be done.

DebugStatement

  • Search: ^@debug.+$
  • Replace: nothing

DuplicateProperty

Hard, but could be done I suppose.

ElsePlacement

  • Search: }\s*@else
  • Replace: } @else

EmptyLineBetweenBlocks

Could be done.

EmptyRule

  • Search: ^([^\n{]+){(?:|\s+)}\n
  • Replace: nothing

FinalNewline

Could be done I suppose.

HexLength

  • Search: #(?:([a-fA-F0-9])\1)(?:([a-fA-F0-9])\2)(?:([a-fA-F0-9])\3)
  • Replace: #\1\2\3

HexNotation

  • Search: (#[a-zA-Z0-9]{6}|[a-zA-Z0-9]{3})
  • Replace: \L\1\E (to lowercase) or \U\1\E (to uppercase)

ImportPath

  • Search: ^@import\s+('|")_?(.*?)(?:.scss)?\1;
  • Replace: @import \1\2\1;

Indentation

Could theoretically be possible I guess.

LeadingZero

Remove zeros:

  • Search: \s+0\.(\d+)
  • Replace: \ .\1

Include zeros:

  • Search: \s+\.(\d+)
  • Replace: \ 0.\1

NameFormat

  • Search: ([a-z])([A-Z])
  • Replace: \1-\L\2\E

Note: remember to enable case sensitiveness.

Note: will also affect selectors. Could be optimised to only affect variables, placeholders, mixins and functions.

PseudoElement

  • Search: ([^:]):(after|backdrop|before|content|first-letter|first-line|placeholder|selection|shadow)
  • Replace: \1::\2

Shorthand

Could be doable.

SingleLinePerProperty

  • Search: ;(?!\n)\s*
  • Replace: ;\n

Note: currently does not apply indentation.

SingleLinePerSelector

Could be doable.

SpaceAfterComma

  • Search: ,([^\s])
  • Replace: , \1

SpaceAfterPropertyColon

  • Search: :(?:|\s{2,})([^\s])
  • Replace: : \1

SpaceAfterPropertyName

Could be doable.

SpaceAfterVariableColon

Could be doable.

SpaceAfterVariableName

Could be doable.

SpaceAroundOperator

Could be doable.

SpaceBeforeBrace

  • Search ([^\s]){
  • Replace: \1 {

SpaceBetweenParens

  • Search: \(\s+([^()]+)\s+\)
  • Replace: (\1)

Note: does not deal with nested parentheses.

StringQuotes

  • Search: "
  • Replace: '

TrailingSemicolon

Could be doable.

TrailingWhitespace

  • Search: [ \t]+$
  • Replace: nothing

TrailingZero

Could be doable.

TransitionAll

Could be doable.

UrlQuotes

  • Search: url\(([^\s'"]+)\)
  • Replace: url('\1') (or url("\1"))

VendorPrefix

Could be doable.

ZeroUnit

  • Search: 0(?!s|ms)(\w+)
  • Replace: 0