Skip to content

Commit

Permalink
Improve messages for SelectorFormat
Browse files Browse the repository at this point in the history
I was getting the message that my selector 'should be written must match
regex ...'; so I looked into the file and tidied up those strings, in
order to output consistently grammatical messages.

Change-Id: I862ad36ce2365ac3492252b229c4014505d983eb
Reviewed-on: http://gerrit.causes.com/45265
Tested-by: jenkins <[email protected]>
Reviewed-by: Shane da Silva <[email protected]>
  • Loading branch information
davidtheclark authored and sds committed Dec 13, 2014
1 parent 171addb commit 7d6f8a2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/scss_lint/linter/selector_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,28 @@ def check(node, type)
return if @ignored_names.include?(name)
return unless violation = violated_convention(name, type)

add_lint(node, "Selector `#{name}` should be " \
"written #{violation[:explanation]}")
add_lint(node, "Selector `#{name}` #{violation[:explanation]}")
end

CONVENTIONS = {
'hyphenated_lowercase' => {
explanation: 'in lowercase with hyphens',
explanation: 'should be written in lowercase with hyphens',
validator: ->(name) { name !~ /[^\-a-z0-9]/ },
},
'snake_case' => {
explanation: 'in lowercase with underscores',
explanation: 'should be written in lowercase with underscores',
validator: ->(name) { name !~ /[^_a-z0-9]/ },
},
'camel_case' => {
explanation: 'has no spaces with capitalized words except first',
explanation: 'should be written in camelCase format',
validator: ->(name) { name =~ /^[a-z][a-zA-Z0-9]*$/ },
},
'hyphenated_BEM' => {
explanation: 'in hyphenated BEM (Block Element Modifier) format',
explanation: 'should be written in hyphenated BEM (Block Element Modifier) format',
validator: ->(name) { name !~ /[A-Z]|-{3}|_{3}|[^_]_[^_]/ },
},
'BEM' => {
explanation: 'in BEM (Block Element Modifier) format',
explanation: 'should be written in BEM (Block Element Modifier) format',
validator: lambda do |name|
name =~ /
^[a-z]([-]?[a-z0-9]+)*
Expand All @@ -77,7 +76,7 @@ def violated_convention(name_string, type)
'hyphenated_lowercase'

convention = CONVENTIONS[convention_name] || {
explanation: "must match regex /#{convention_name}/",
explanation: "should match regex /#{convention_name}/",
validator: ->(name) { name =~ /#{convention_name}/ }
}

Expand Down

0 comments on commit 7d6f8a2

Please sign in to comment.