Skip to content

Commit

Permalink
Don't lint pseudo-selectors in SelectorFormat
Browse files Browse the repository at this point in the history
The SelectorFormat linter shouldn't lint pseudo-selectors since these
must always use a hyphenated lowercase convention.

Change-Id: I1b3f65a8017d69c5f984b7721f626c9c27348e75
Reviewed-on: http://gerrit.causes.com/44887
Tested-by: jenkins <[email protected]>
Reviewed-by: Shane da Silva <[email protected]>
  • Loading branch information
sds committed Nov 30, 2014
1 parent cff05b9 commit 5ce6292
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 72 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Fix `DuplicateProperty` not reporting duplicate properties in nested rule
sets
* Fix `TrailingSemicolon` handling of comma-separated `@import`s
* Fix `SelectorFormat` to not allow format of pseudo-selectors to be defined,
as they are always hyphenated lowercase

## 0.30.0

Expand Down
3 changes: 1 addition & 2 deletions lib/scss_lint/linter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,11 @@ Configuration Option | Description
-------------------------|-----------------------------------------------------
`convention` | Name of convention to use (`hyphenated_lowercase` (default) or `snake_case`, `camel_case`, or `BEM`, or `hyphenated_BEM`), or a regex the name must match
`ignored_names` | Array of whitelisted names to not report lints for.
`ignored_types` | Array containing list of types of selectors to ignore (valid values are `attribute`, `class`, `element`, `id`, `placeholder`, or `pseudo-selector`)
`ignored_types` | Array containing list of types of selectors to ignore (valid values are `attribute`, `class`, `element`, `id`, `placeholder`)
`attribute_convention` | Convention for attribute selectors only. See the `convention` option for possible values.
`class_convention` | Convention for class selectors only. See the `convention` option for possible values.
`id_convention` | Convention for id selectors only. See the `convention` option for possible values.
`placeholder_convention` | Convention for placeholder selectors only. See the `convention` option for possible values.
`pseudo_convention` | Convention for pseudo-selectors only. See the `convention` option for possible values.

## Shorthand

Expand Down
4 changes: 0 additions & 4 deletions lib/scss_lint/linter/selector_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ def visit_placeholder(placeholder)
check(placeholder, 'placeholder') unless @ignored_types.include?('placeholder')
end

def visit_pseudo(pseudo)
check(pseudo, 'pseudo') unless @ignored_types.include?('pseudo-selector')
end

private

def check(node, type)
Expand Down
69 changes: 3 additions & 66 deletions spec/scss_lint/linter/selector_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
it { should_not report_lint }
end

context 'when pseudo-selector has alphanumeric chars and is separated by hyphens' do
let(:css) { <<-CSS }
[foo-bar-77=text] {
}
CSS

it { should_not report_lint }
end

context 'when selector has alphanumeric chars and is separated by underscores' do
let(:css) { <<-CSS }
.foo_bar {
Expand Down Expand Up @@ -73,15 +64,6 @@
it { should report_lint line: 1 }
end

context 'psuedo-selector has alphanumeric chars and is separated by underscores' do
let(:css) { <<-CSS }
:foo_bar {
}
CSS

it { should report_lint line: 1 }
end

context 'when attribute has alphanumeric chars and is separated by underscores' do
let(:css) { <<-CSS }
[data_text] {
Expand Down Expand Up @@ -121,7 +103,7 @@
it { should report_lint line: 1 }
end

context 'when selector has is in camelCase' do
context 'when selector is in camelCase' do
let(:css) { <<-CSS }
.fooBar77 {
}
Expand Down Expand Up @@ -219,9 +201,9 @@
end
end

context 'when ignored types is set to id, element, placeholder, pseudo-selector' do
context 'when ignored types is set to id, element, placeholder' do
let(:linter_config) do
{ 'ignored_types' => %w[id attribute element placeholder pseudo-selector] }
{ 'ignored_types' => %w[id attribute element placeholder] }
end

context 'it ignores all invalid ids' do
Expand Down Expand Up @@ -259,15 +241,6 @@

it { should_not report_lint }
end

context 'it ignores all invalid pseudo-selectors' do
let(:css) { <<-CSS }
:fooBar {
}
CSS

it { should_not report_lint }
end
end

context 'when using a unique `id_convention`' do
Expand Down Expand Up @@ -399,42 +372,6 @@
end
end

context 'when using a unique `pseudo_convention`' do
let(:linter_config) do
{
'convention' => 'camel_case',
'pseudo_convention' => 'hyphenated-lowercase'
}
end

context 'and actual pseudo is correct' do
let(:css) { <<-CSS }
:hyphenated-lowercase {}
#camelCase {}
CSS

it { should_not report_lint }
end

context 'and actual pseudo is incorrect' do
let(:css) { <<-CSS }
:camelCase {}
#camelCase {}
CSS

it { should report_lint line: 1 }
end

context 'and something else uses the `pseudo_convention`' do
let(:css) { <<-CSS }
:hyphenated-lowercase {}
#hyphenated-lowercase {}
CSS

it { should report_lint line: 2 }
end
end

context 'when using a unique `attribute_convention`' do
let(:linter_config) do
{
Expand Down

0 comments on commit 5ce6292

Please sign in to comment.