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

Add new line at the end of file and missing white space #1153

Merged
merged 2 commits into from
Aug 18, 2017

Conversation

truongwp
Copy link
Contributor

@truongwp truongwp commented Jul 1, 2017

This PR add a missing white space between css selector and open brace, and add new line at the end of many files.

@szepeviktor
Copy link
Contributor

Maybe adding a PHPCS rule for that?

@jrfnl
Copy link
Contributor

jrfnl commented Jul 1, 2017

Maybe adding a PHPCS rule for that?

There already is one included ;-) The reason these files were not reported is that PHPCS is currently configured in phpcs.xml.dist to only check PHP files, not JS or CSS files.

@grappler
Copy link
Collaborator

I would like to see this being checked for in travis before the changes are made so that they do not get reversed by mistake in the future.

@truongwp
Copy link
Contributor Author

Hi @grappler,
How I can do that?

@grappler
Copy link
Collaborator

Add this to .travis.yml would check the CSS and JS files.
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs . --sniffs=Generic.Files.EndFileNewline --extensions=css,js; fi

The problem is that PHPCS would not not check the other files like scss.

We need to come up with another solution that could run in travis to check this.

@grappler
Copy link
Collaborator

Here is another way we could run this in bash https://stackoverflow.com/a/34944104/850651

@jrfnl
Copy link
Contributor

jrfnl commented Jul 10, 2017

The problem is that PHPCS would not not check the other files like scss.

You can pass scss as an additional extension to PHPCS to be checked as if it were CSS. --extensions=css,scss/css,js should do the trick.

You could also consider changing the extensions directive in the custom ruleset. There are not that many sniffs in WPCS which check CSS and JS any way, so - except for minified files - I don't really expect any problems.

@m-e-h m-e-h mentioned this pull request Jul 10, 2017
@grappler
Copy link
Collaborator

--extensions=css,scss/css,js does do the trick.

The only thing that is not checked are the "hidden" files .jshintignore & .jscsrc but they are not worked on a lot and they maybe replaced by package.json in the future.

If we enable PHPCS for JS then will need to fix the following warnings.


FILE: _s/js/customizer.js
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | ERROR | Missing @package tag in file comment
   |       | (Squiz.Commenting.FileComment.MissingPackageTag)
----------------------------------------------------------------------

FILE: _s/js/navigation.js
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
   6 | ERROR | There must be exactly one blank line after the file
     |       | comment (Squiz.Commenting.FileComment.SpacingAfterComment)
   6 | ERROR | Missing @package tag in file comment
     |       | (Squiz.Commenting.FileComment.MissingPackageTag)
  89 | ERROR | The use of object.length inside a loop condition is not
     |       | allowed; assign the return value to a variable and use the
     |       | variable in the loop condition instead
     |       | (Squiz.PHP.DisallowSizeFunctionsInLoops.Found)
 101 | ERROR | The use of object.length inside a loop condition is not
     |       | allowed; assign the return value to a variable and use the
     |       | variable in the loop condition instead
     |       | (Squiz.PHP.DisallowSizeFunctionsInLoops.Found)
----------------------------------------------------------------------

FILE: _s/js/skip-link-focus-fix.js
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | ERROR | There must be exactly one blank line after the file
   |       | comment (Squiz.Commenting.FileComment.SpacingAfterComment)
 7 | ERROR | Missing @package tag in file comment
   |       | (Squiz.Commenting.FileComment.MissingPackageTag)
----------------------------------------------------------------------

@jrfnl
Copy link
Contributor

jrfnl commented Jul 10, 2017

Those all look legitimate and easy enough to fix.

If the extensions directive in the custom ruleset will be changed, I'd suggest adding an exclude pattern for minified js and css files. Even though _s does not contain these, most derivative themes probably will, so setting an exclusion for the minified css/js files will save them some grief. I'm thinking along the lines of:

<exclude-pattern>*.min.(css|js)</exclude-pattern>

@grappler
Copy link
Collaborator

@truongwp I have had another look at this PR.

Could you add the CSS and SCSS files to the PHPCS check? Like this:

--- phpcs.xml.dist
+++ phpcs.xml.dist
@@ -17,7 +17,7 @@
    <arg value="psvn"/>

    <!-- Only check the PHP files. JS files are checked separately with JSCS and JSHint. -->
-   <arg name="extensions" value="php"/>
+   <arg name="extensions" value="php,css,scss/css"/>

    <!-- Check all files in this directory and the directories below it. -->
    <file>.</file>

When you run PHPCS you will notice that _s/sass/modules/_clearings.scss is still missing a newline at the end of the file.

@jrfnl I have created a separate pull request for the JavaScript file issues #1187. We can add the exclude-pattern once we have merged these two pull requests.

@truongwp
Copy link
Contributor Author

@grappler I updated the old commit to add newline at end of _clearing.scss, and added another commit to update the PHP ruleset.

Copy link
Collaborator

@grappler grappler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. It makes sense to have two commits here.

@davidakennedy davidakennedy merged commit 9bf12e5 into Automattic:master Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants