-
Notifications
You must be signed in to change notification settings - Fork 43
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
Set up SCSS and JS linting #291
Conversation
Calypso linting issueThis PR started as a an attempt to match Calypso linting configuration. Because Calypso pulls this code into their repo, they also lint it - and get a bunch of warnings. Calypso uses custom configs for both SCSS and JS lintingNevertheless, this project did not have SCSS and JS linting set up - and that's that this PR evolved to be. It introduces following changes:
One important thing 🚨After this lands on your machine, run |
3816ca4
to
c36902a
Compare
c36902a
to
3a8def0
Compare
daec4b6
to
38ad557
Compare
38ad557
to
70ffbb6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice. Thanks for getting it set up. There is one small issue I noticed that would be good to solve if possible:
- With this branch, if you edit a PHP or JS file and something doesn't pass linting, the error will be output but the commit will still go through:
## ESLint
src/blocks/homepage-articles/index.js: line 24, col 7, Error - A space is required after '{'. (object-curly-spacing)
src/blocks/homepage-articles/index.js: line 24, col 34, Error - A space is required before '}'. (object-curly-spacing)
No staged files match any of provided globs.
[detached HEAD af529b7] Test commit <<< The commit went through here.
- If you check out the master branch or newspack-plugin, edit a PHP file and something doesn't pass linting, the commit will abort:
## PHP_CodeSniffer
E 1 / 1 (100%)
Time: 231ms; Memory: 12MB
src/blocks/homepage-articles/view.php:20:10: error - Expected 1 spaces before closing bracket; 0 found (PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket)
Claudius-MacBook-Pro:newspack-blocks claudiulodro$ <<< The commit was aborted.
Since the linter should prevent people from pushing "bad" code, it would be nice to maintain the behavior where it only lets you commit when the linter passes.
To test this out I tried comparing the linting warnings from Calypso to the warnings in It looks like there might be some rules that are in direct conflict. For example in .scss files in |
- add react plugin - add import plugin - add JSDoc plugin - add missing npm deps
to match wp-calypso's style
@claudiulodro That's fixed now with a33fa5e @jeffersonrabb I've taken another look at it and updated the configs, trying to limit the warnings thrown on wp-calypso: JS (eslint)Linting errors (in
CSS (stylelint)Linting errors (in |
# Conflicts: # package-lock.json # package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there are a couple tiny tweaks left, but this is almost there!
package.json
Outdated
"lint": "npm-run-all --parallel lint:*", | ||
"lint:js": "eslint --ext .js,.jsx src", | ||
"lint:scss:all": "stylelint \"**/*.scss\" --syntax scss", | ||
"lint:scss": "stylelint --syntax scss", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but I don't think this usage is correct. If you run npm run lint:scss
the stylelint options are output, nothing is linted, and npm throws an error:
Claudius-MacBook-Pro:newspack-blocks claudiulodro$ npm run lint:scss
> [email protected] lint:scss /Users/claudiulodro/Documents/Projects/VVV/www/newspack/public_html/wp-content/plugins/newspack-blocks
> stylelint --syntax scss
A mighty, modern CSS linter.
Usage: stylelint [input] [options]
Input: Files(s), glob(s), or nothing to use stdin.
If an input argument is wrapped in quotation marks, it will be passed to
globby for cross-platform glob support. node_modules are always ignored.
You can also pass no input and use stdin, instead.
Options:
--config
Path to a specific configuration file (JSON, YAML, or CommonJS), or the
name of a module in node_modules that points to one. If no --config
argument is provided, stylelint will search for configuration files in
the following places, in this order:
- a stylelint property in package.json
{...ETC MORE OPTION OUTPUT HERE...}
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] lint:scss: `stylelint --syntax scss`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] lint:scss script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/claudiulodro/.npm/_logs/2020-01-08T20_28_04_855Z-debug.log
From the documentation that is conveniently output when this script is run :) :
Usage: stylelint [input] [options]
Input: Files(s), glob(s), or nothing to use stdin.
It looks like it's looking for the files in stdin; it should have something for [input]
?
SCSS: that's on me, the npm script names were not descriptive enough. Fixed in 8473b98 Other problem is JS. This project already uses If not, we can always run JS linting using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest version work great! Thanks for making the revisions and taking the initiative to contribute a PR back to wp-dev-lib. 👍
It was not updated after e70f346
🎉 This PR is included in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes proposed in this Pull Request:
Match
wp-calypso
linting, so synced files no longer raise warnings.What I've done so far:
@wordpress/eslint-plugin
,stylelint
,stylelint-config-wordpress
..eslintrc
as described in https://github.com/WordPress/gutenberg/tree/4786c14803859a046b14e5eb324b1041b8fbfff3/packages/eslint-plugin.stylelintrc
from Calypso (https://github.com/Automattic/wp-calypso/blob/46a9eafeda1d2d74871b527b25765fd7a9f7ae1e/.stylelintrc)npm run lint
correctly reports linting issues but errors out.