You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Squiz.CSS.ClassDefinitionOpeningBrace: add fixed file and various bug fixes
The sniff contains fixers, but didn't have a `fixed` file.
While I was add it, I've reviewed the sniff and applied any improvements I could think of:
* For the `Before` error code, the sniff would report on a `tab` being found if the whitespace length was 1, but not a space. This meant that for a "3 space" whitespace token, it would also report as `tab`.
I've now changed the `$length` determination to be more accurate.
* The fixer for the `Before` error will now fix the whitespace between in one go if there is more than one whitespace token.
Previously, it would replace the first preceding whitespace token with a space, which in effect left any additional new lines in place as the fixer would not be triggered again.
* While the `ContentBefore` error states "Opening brace should be the last content on the line", the way the code was, allowed for trailing comments on the line of the opening brace.
I've elected not to change this behaviour, but have documented it with a unit test.
* The fixer for the `AfterNesting` error would remove the first non-whitespace token after the opening brace if too many lines after the opener were found. This changes the meaning of the style declaration and/or could remove comments.
The existing unit test on line 33 demonstrates this, as well as the new unit tests on line 88 and 95.
* The fixer for `AfterNesting` would also inadvertently remove line indentation. Indentation is not the concern of this sniff, so should be left alone.
* The `AfterNesting` check would also **not** report an error if the line between the original opening brace and the nested style declaration, contained a comment.
* Lastly, the handling of trailing comments was inconsistent with the handling of these in the `ContentBefore` part, i.e. for `ContentBefore` they would be allowed, but if the `AfterNesting` error was triggered, the fixer would move them.
* Improved the resilience of the sniff against syntax/parse errors and during live coding. This prevents an `Undefined index: bracket_closer` error.
* Minor other defensive coding improvements.
In effect, this constitutes a complete rewrite of this sniff.
Includes additional unit tests covering all fixes.
0 commit comments