Skip to content

Commit

Permalink
Add SpaceAfterVariableName linter
Browse files Browse the repository at this point in the history
  • Loading branch information
cih authored and sds committed Jun 29, 2015
1 parent 40dfc22 commit bdc4521
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
via the `ignore_parent_selectors` configuration option
* Fix `PropertyUnits` for properties that have multiple unit-like values (e.g.
shorthand properties) and quoted values
* Add `SpaceAfterVariableName` linter which checks that there are no spaces
between a variable name and a colon

## 0.39.0

Expand Down
3 changes: 3 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ linters:
SpaceAfterPropertyName:
enabled: true

SpaceAfterVariableName:
enabled: true

SpaceBeforeBrace:
enabled: true
style: space # or 'new_line'
Expand Down
15 changes: 15 additions & 0 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Below is a list of linters supported by `scss-lint`, ordered alphabetically.
* [SpaceAfterComma](#spaceaftercomma)
* [SpaceAfterPropertyColon](#spaceafterpropertycolon)
* [SpaceAfterPropertyName](#spaceafterpropertyname)
* [SpaceAfterVariableName](#spaceaftervariablename)
* [SpaceBeforeBrace](#spacebeforebrace)
* [SpaceBetweenParens](#spacebetweenparens)
* [StringQuotes](#stringquotes)
Expand Down Expand Up @@ -1245,6 +1246,20 @@ margin : 0;
margin: 0;
```

## SpaceAfterVariableName

Variables should be formatted with no space between the name and the colon.

**Bad: space before colon**
```scss
$my-var : 0;
```

**Good**
```scss
$my-var: 0;
```

## SpaceBeforeBrace

Opening braces should be preceded by a single space.
Expand Down
18 changes: 18 additions & 0 deletions lib/scss_lint/linter/space_after_variable_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module SCSSLint
# Checks for spaces following the name of a variable and before the colon
# separating the variables's name from its value.
class SpaceAfterVariableName < Linter
include LinterRegistry

def visit_variable(node)
return unless spaces_before_colon?(node)
add_lint(node, 'Variable names should be followed immediately by a colon')
end

private

def spaces_before_colon?(node)
source_from_range(node.source_range) =~ /\s+:/
end
end
end
13 changes: 13 additions & 0 deletions spec/scss_lint/linter/space_after_variable_name_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe SCSSLint::SpaceAfterVariableName do
let(:scss) { <<-SCSS }
$none: #fff;
$one : #fff;
$two : #fff;
SCSS

it { should_not report_lint line: 1 }
it { should report_lint line: 2 }
it { should report_lint line: 3 }
end

0 comments on commit bdc4521

Please sign in to comment.