We're going to use the newer version of JS (ES6) in core #2809281: Use ES6 for core JavaScript development, that comes with some pretty significant language improvements that we need to have standards for. Instead of making up our own we should make use of an existing established standard close to ours.
One of the most well known and used standard similar to ours is airbnb JavaScript Style Guide. They have rules for new ES6 features, they also use react hence have react rules ready. Won't help core but might be helpful to contrib and projects. Their rules are more strict than ours, it's a good move for our codebase.
The only significant whitespace change that will impact us are the config for brace-style
and object-curly-spacing
.
Current drupal style
if (this.model.get('isActive')) {
// …
this.model.set({isActive: true, activeTour: $tour});
// …
}
else {
// …
}
Airbnb style
if (this.model.get('isActive')) {
// …
this.model.set({ isActive: true, activeTour: $tour });
// …
} else {
// …
}
People might complain but it's a really minor thing in the grand scheme of things. And if we really have to, we can override those 2 rules. The rest of the rules enforce good practices.
Right now running coding standard on our codebase, after eslint auto-fix of some rules (and without the whitepace rules discussed above) there are 2061 problems, 95% of which come from the following rules:
"camelcase""no-param-reassign""func-names""comma-dangle""max-len""no-underscore-dangle""no-unused-vars""no-plusplus""newline-per-chained-call""no-restricted-syntax""new-cap""no-new""padded-blocks""prefer-const""no-use-before-define""consistent-return""no-prototype-builtins""no-else-return""default-case""no-shadow"
Attaching a patch since adopting this means changing some eslint files.
Some projects using this standard:
- React
- Evernote
And it seems ember.js coding standards are extremely similar.
Previous discussions
#1778828-51: [policy, no patch] Update JS coding standards
#1778828-59: [policy, no patch] Update JS coding standards
#2746807-2: Consider standard js coding standard