Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double dash in CSS class name can lead to "Named colours are forbidden" false positives #1257

Closed
InvisibleSmiley opened this issue Jan 2, 2017 · 1 comment

Comments

@InvisibleSmiley
Copy link

We got some "Named colours are forbidden" (Squiz.CSS.NamedColours.Forbidden) errors from using named colours such as "white" in CSS class names. Turn out this is due to double dashes, which are recognized as T_DEC. Hence the "previous token was hash or string concat" check fails.

Should be easy to fix. :-)

Example:

.something--white {
    border: 0;
}
[CSS => 18 tokens in 4 lines]...
        *** START TOKEN PROCESSING ***
                Process token 0: T_OPEN_TAG =>
                        Processing Generic_Sniffs_Files_LineEndingsSniff... DONE in 0 seconds
                        Processing Squiz_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff... DONE in 0 seconds
                        Processing Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff... DONE in 0 seconds
                        Processing Squiz_Sniffs_CSS_IndentationSniff... DONE in 0 seconds
                        Processing Squiz_Sniffs_CSS_DuplicateClassDefinitionSniff... DONE in 0.0001 seconds
                Process token 1: T_STRING_CONCAT => .
                Process token 2: T_STRING => something
                        Processing Squiz_Sniffs_CSS_NamedColoursSniff... DONE in 0 seconds
                Process token 3: T_DEC => --
                Process token 4: T_STRING => white
                        Processing Squiz_Sniffs_CSS_NamedColoursSniff... DONE in 0 seconds
                Process token 5: T_WHITESPACE => ·
                        Processing Squiz_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff... DONE in 0 seconds
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------
 1 | ERROR | Named colours are forbidden; use hex, rgb, or rgba values instead (Squiz.CSS.NamedColours.Forbidden)
gsherwood added a commit that referenced this issue Jan 3, 2017
@gsherwood
Copy link
Member

Thanks for the bug report. I've fixed this now.

I had to change the way the file was tokenized to ensure all sniffs would work. Previously, the file was tokenized like this:

	Process token 0 on line 1 [col:1;len:0;lvl:0;]: T_OPEN_TAG => 
	Process token 1 on line 1 [col:1;len:1;lvl:0;]: T_STRING_CONCAT => .
	Process token 2 on line 1 [col:2;len:9;lvl:0;]: T_STRING => something
	Process token 3 on line 1 [col:11;len:2;lvl:0;]: T_DEC => --
	Process token 4 on line 1 [col:13;len:5;lvl:0;]: T_STRING => white
	Process token 5 on line 1 [col:18;len:1;lvl:0;]: T_WHITESPACE => ·
	Process token 6 on line 1 [col:19;len:1;lvl:0;]: T_OPEN_CURLY_BRACKET => {
	Process token 7 on line 1 [col:20;len:0;lvl:0;]: T_WHITESPACE => \n
	Process token 8 on line 2 [col:1;len:4;lvl:0;]: T_WHITESPACE => ····
	Process token 9 on line 2 [col:5;len:6;lvl:0;]: T_STYLE => border
	Process token 10 on line 2 [col:11;len:1;lvl:0;]: T_COLON => :
	Process token 11 on line 2 [col:12;len:1;lvl:0;]: T_WHITESPACE => ·
	Process token 12 on line 2 [col:13;len:1;lvl:0;]: T_LNUMBER => 0
	Process token 13 on line 2 [col:14;len:1;lvl:0;]: T_SEMICOLON => ;
	Process token 14 on line 2 [col:15;len:0;lvl:0;]: T_WHITESPACE => \n
	Process token 15 on line 3 [col:1;len:1;lvl:0;]: T_CLOSE_CURLY_BRACKET => }
	Process token 16 on line 3 [col:2;len:0;lvl:0;]: T_WHITESPACE => \n
	Process token 17 on line 4 [col:1;len:0;lvl:0;]: T_CLOSE_TAG => 

Now it is tokenized like this:

	Process token 0 on line 1 [col:1;len:0;lvl:0;]: T_OPEN_TAG => 
	Process token 1 on line 1 [col:1;len:1;lvl:0;]: T_STRING_CONCAT => .
	Process token 2 on line 1 [col:2;len:16;lvl:0;]: T_STRING => something--white
	Process token 3 on line 1 [col:18;len:1;lvl:0;]: T_WHITESPACE => ·
	Process token 4 on line 1 [col:19;len:1;lvl:0;]: T_OPEN_CURLY_BRACKET => {
	Process token 5 on line 1 [col:20;len:0;lvl:0;]: T_WHITESPACE => \n
	Process token 6 on line 2 [col:1;len:4;lvl:0;]: T_WHITESPACE => ····
	Process token 7 on line 2 [col:5;len:6;lvl:0;]: T_STYLE => border
	Process token 8 on line 2 [col:11;len:1;lvl:0;]: T_COLON => :
	Process token 9 on line 2 [col:12;len:1;lvl:0;]: T_WHITESPACE => ·
	Process token 10 on line 2 [col:13;len:1;lvl:0;]: T_LNUMBER => 0
	Process token 11 on line 2 [col:14;len:1;lvl:0;]: T_SEMICOLON => ;
	Process token 12 on line 2 [col:15;len:0;lvl:0;]: T_WHITESPACE => \n
	Process token 13 on line 3 [col:1;len:1;lvl:0;]: T_CLOSE_CURLY_BRACKET => }
	Process token 14 on line 3 [col:2;len:0;lvl:0;]: T_WHITESPACE => \n
	Process token 15 on line 4 [col:1;len:0;lvl:0;]: T_CLOSE_TAG => 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants