-
Notifications
You must be signed in to change notification settings - Fork 28
Conversation
package.json
Outdated
"lerna": "^2.0.0-rc.5", | ||
"mkdirp": "^0.5.1" | ||
}, | ||
"eslintConfig": { |
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.
Curious why you included the eslint config here instead of a .eslintrc
. More precisely, I wonder if IDEs can read the config from here?
In this PR I've pinned p.s. @youknowriad I've included the |
package.json
Outdated
"babel-preset-env": "^1.5.2", | ||
"chalk": "^1.1.3", | ||
"eslint": "~4.1.0", | ||
"eslint-plugin-wordpress": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#d8abe35765088dcf138d8698cf5b0c4428d575cc", |
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.
Can we publish this package to npm instead?
As a follow-up task, we could move this package inside this repository (Jest has an eslint-jest-plugin
package built and used inside the repository itself)
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.
It is published to npm, it's just out of date, there's a couple more outstanding issues to be resolved before I push a new release to npm.
The package is part of the WordPress Coding Standards GitHub Organization
Inlcudes a `package.json` and `.gitignore`
@ntwb I took the liberty to rebase and fix some linting issues (not all of them). Since we're starting a new way to do JS for WordPress with this repository, I think we're in a good position to discuss these linting rules and maybe update them (only for this repository now and maybe Core later). Here are the rules I'd like us to reconsider for this repository:
I'm sure I will discover more issues as I add code but these are the ones I'd like us to reconsider now. Just noting we've already forked the rules this way in Gutenberg. |
(Looks like travis is not running |
The next #core-js chat scheduled for Tuesday has coding standards on the agenda, I think we should discuss this then rather than here in the ticket as a way to get everyone on the same page. • I'm +1 on the • The "spacing in parens" consistency is a legacy decision I believe to match/mimic the PHP coding standards, will need to do a bit of research on this one and then raise questions for both the PHP & JS in regard to changing the standard. • Babel, I've avoided Babel, getting the current ESLint shared plugin and config up and running against what JavaScript WordPress currently uses has been my focus, so another topic for the upcoming #core-cs chat. |
Have you considered using prettier? It doesn't play nicely with all additionsl spaces that are used in WordPress coding conventions, but otherwise helps to keep one style of code formatting across all files. It would be highly helpful in the context of WordPress. |
@gziolo Thanks, yes, the use of Prettier is currently being considered I plan on bringing this up for further discussion in this coming weeks #core-js Slack chat |
That would be awesome :) We were considering using prettier at Automattic with Calypso, related discussion: Automattic/wp-calypso#12260. We put it on hold, because we didn't want to deviate from WordPress JS conventions. @samouri forked prettier at some point (https://github.com/Automattic/calypso-prettier) and he added a few tweaks to enforce spaces around parenthesis. Some people use it with CLI or IDE to simplify formatting, but to use it on a larger scale we would have to update conventions or convince Prettier maintainers to add flag for spaces around parenthesis :) |
Prettier is not terribly hard to implement: it's just as AST-to-code converter. I have work underway to implement a version of it for WP coding standards (although it may be worth seeing what the Calypso team has there). That said, it may be worth adopting a wider coding standard. This would deviate somewhat significantly from WP though, so we should discuss it first. |
It might be worth reaching out to Prettier team and ask if we they would be fine to enable flag for spaces in parentheses. It would be much easier to contribute there than to maintain yet another tool. Given the number of WordPress installations, they should at least seriously consider such change. |
In a somewhat related manner, Prettier now includes support for CSS, the team over at stylelint are considering creating some prettier printers for formatting stylistic rules, in particular whitespace, so Prettier will inherit and print the CSS per the applicable stylelint whitespace rule configurations:
It's a long discussion there over the past few months (including Prettier's author). I think many of the concepts discussed there would work the same for JS with ESLint, to have whitespace around parenthesis we create a custom prettier printer such as
If creating a p.s. I didn't want to ping said Prettier author here, we should create a P2 post or a new issue to discuss this rather than hijack this issue 😏 |
(FWIW, I think it's possible to use prettier almost as-is, and simply insert an extra step that alters the intermediate representation ("doc"). Something I plan on exploring in any case.) |
I'm fine with both approaches as long as they allow us to make Prettier default for WordPress JS code :) It would be nice if Prettier would be pluggable as much as Eslint is, then we could pipe our own transforms and make sure max-length setting is applied as a last one and takes into account additional spaces. It may be a challenge to setup it properly with additional spaces. Imagine a use case where you have max lenght 80 chars, and line is properly formatted with Prettier and contains exactly 80 chars. We run
Yes, good idea. We should definitely ping him when we have some proposal how to tackle prettier integration. |
Just a small note on prettier. Actually, I'd have preferred if prettier didn't have any option and I encourage using it without options at all. As noted above may be it's worth considering wider coding standards :) |
{ | ||
"env": { | ||
"es6": true, | ||
"jest": true, |
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.
We can also add eslint-plugin-jest setup. You can check here, how I did it for Gutenberg: https://github.com/WordPress/gutenberg/pull/1382/files#diff-df39304d828831c44a2b9f38cd45289cR8.
Here we wouldn't need to turn off jest/valid-expect
, because tests don't use chai
.
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.
Will push up ESLint for Jest in the morning, I ran out of time today because real life got in the way of coding 😝
@@ -17,5 +17,5 @@ export function addQueryArgs( url, args ) { | |||
const query = { ...parsedURL.query, ...args }; | |||
delete parsedURL.search; | |||
|
|||
return format( { ...parsedURL, query } ); | |||
return format({ ...parsedURL, query }); |
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.
Please, no :(
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'd like to see us standardize on something closer to the Gutenberg lint config. It's time for these standards to get a major refresh - the rules around things like someFunction( arg1, {})
are just nonsensical.
} ); | ||
} ); | ||
}); | ||
}); |
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.
Please, no :(
const destPath = getBuildPath( file, buildDir ); | ||
const babelOptions = babelConfigs[ environment ]; | ||
const babelOptions = babelConfigs[environment]; |
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.
:(
scripts/build.js
Outdated
@@ -137,7 +138,7 @@ function buildFileFor( file, silent, environment ) { | |||
function buildPackage( packagePath ) { | |||
const srcDir = path.resolve( packagePath, SRC_DIR ); | |||
const pattern = path.resolve( srcDir, '**/*' ); | |||
const files = glob.sync( pattern, { nodir: true } ); | |||
const files = glob.sync( pattern, { nodir: true }); |
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.
:(
@@ -34,24 +34,25 @@ const babelDefaultConfig = JSON.parse( | |||
fs.readFileSync( path.resolve( __dirname, '..', '.babelrc' ), 'utf8' ) | |||
); | |||
babelDefaultConfig.babelrc = false; | |||
const presetEnvConfig = babelDefaultConfig.presets[ 0 ][ 1 ]; | |||
const presetEnvConfig = babelDefaultConfig.presets[0][1]; |
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.
Debatable, but overall :(
# Conflicts: # .travis.yml # package.json # scripts/build.js
@ntwb, should we close this one? It is very out of date and we are tackling it a bit differently than initially started. |
Includes a
package.json
and.gitignore