Hello,
I have a .css file with media query. Drupal CodeSniffer considers it as normal css class and shows errors.

Test 1:

PHP CodeSniffer version : 2.3.1
Drupal Code Sniffer version : 8.x-2.1
in css

@media (min-width: 320px) and (max-width: 961px) {
  .tooltipsrt:hover span.tltp,
  .tooltipstp:hover span.tltp {
    visibility: hidden;
  }
}

and the error generates as :

 2 | ERROR | [ ] Style definitions must end with a semicolon
 2 | ERROR | [x] Expected 1 space after colon in style definition; 0
   |       |     found
 3 | ERROR | [ ] Style definitions must end with a semicolon
 3 | ERROR | [x] Expected 1 space after colon in style definition; 0
   |       |     found

Test 2:

PHP CodeSniffer version : 2.3.1
Drupal Code Sniffer version : 7.x-1.0

The error generates as:

Fatal error: Uncaught exception 'PHP_CodeSniffer_Exception' with message 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found' in C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer\Standards\Drupal\Sniffs\Commenting\FileCommentSniff.php on line 13

PHP_CodeSniffer_Exception: Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found in C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer\Standards\Drupal\Sniffs\Commenting\FileCommentSniff.php on line 13

Call Stack:
    0.0002     123664   1. {main}() C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\scripts\phpcs:0
    0.0125    1057816   2. PHP_CodeSniffer_CLI->runphpcs() C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\scripts\phpcs:25
    0.0132    1098816   3. PHP_CodeSniffer_CLI->process() C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer\CLI.php:95
    0.0161    1106496   4. PHP_CodeSniffer->initStandard() C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer\CLI.php:830
    0.0972    1141904   5. PHP_CodeSniffer->registerSniffs() C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer.php:560
    0.1026    1218960   6. include_once('C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer\Standards\Drupal\Sniffs\Commenting\FileCommentSniff.php') C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer.php:1318

Test 3:

I have followed the steps in the link: https://www.drupal.org/node/1431428#comment-9893517
Clonnned the code from http://cgit.drupalcode.org/drupalcs/commit/?id=905fa01 using the command: git://git.drupal.org/project/drupalcs.git

Now, it shows the following error in the Test 2.

Thanks in advance,
How can I fix this issue?

Comments

Saneesh’s picture

Issue summary: View changes
klausi’s picture

Category: Bug report » Support request
Status: Active » Fixed

If you use Cdoer 7.x-2. you need to use PHPCS 1.x (not 2.x).

I would recommend that you use Coder 8.x-2.x which works with PHPCS 2 and can also be used to check Drupal 7 code.

Saneesh’s picture

Priority: Normal » Critical
klausi’s picture

Title: media quey issue (@media) » CSS media quey with colon throws false positives
Version: 7.x-2.5 » 8.x-2.x-dev
Category: Support request » Bug report
Priority: Critical » Normal
Status: Fixed » Active

Oh sorry, just saw that there is a CSS snippet in the issue summary that throws false positives.

Saneesh’s picture

Hello klausi,

Thank you very much for your reply!

CodeSniffer 2.3.1
Coder 8.x-2.2

I'm still gets the same error. Let me explain what are the steps I did.
1. Downloaded Coder 8.x-2.2
2. Copied the folders Drupal and DrupalPractice to 'C:\wamp\bin\php\php5.5.12\PHP_CodeSniffer\CodeSniffer\Standards'
3. Executed the command
phpcs --standard=Drupal main-latest.css > cssError.txt

Content of main-latest.css

@media (min-width: 320px) and (max-width: 961px) {
  .tooltipsrt:hover span.tltp,
  .tooltipstp:hover span.tltp {
    visibility: hidden;
  }
}

Output of codesniffer in cssError.txt

 2 | ERROR | [ ] Style definitions must end with a semicolon
 2 | ERROR | [x] Expected 1 space after colon in style definition; 0
   |       |     found
 3 | ERROR | [ ] Style definitions must end with a semicolon
 3 | ERROR | [x] Expected 1 space after colon in style definition; 0
   |       |     found

What should I do now?

klausi’s picture

  • klausi committed da7dec3 on 8.x-2.x
    Issue #2483849: Fixed CSS media query with colon throws false positives
    
klausi’s picture

Status: Active » Fixed

The bug got merged upstream, I updated the composer dependency and added a test case.

We will update the PHPCS dependency to a proper version when the next release is made.

Saneesh’s picture

Thank you very much klausi! It works fine! :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.