A Reload opinionated way of making sure our JS code is up to snuff.
Install eslint-plugin-reload
.
npm install eslint-plugin-reload --save-dev
If using npm before v7, install the required peer dependecies. v7 and beyond auto installs the peer dependencies.
Create these two files alongside your package.json
file.
{}
{
"extends": ["plugin:reload/recommended"]
}
Spin this badboy up and point eslint and prettier towards your JS files.
npx eslint "**/*.js" && npx prettier "**/*.js" --check
npx eslint "**/*.js" --fix && npx prettier "**/*.js" --write
Remember to define in your .eslintrc.json
configuration which environments
your code is supposed to support.
"extends": ["plugin:reload/recommended"],
"env": {
"browser": true,
"node": true
}
If not you will get a lot of no-undef
errors on ex. window
and console
variables.
Wanting to add additional rules is straightforward.
{
"extends": ["plugin:reload/recommended"],
"rules": {
"no-console": 1
}
}
If wanting to extend the eslint-plugin-reload
we need to re-apply
the prettier eslint-config-prettier
configuration that turns off all
eslint rules that is prettiers responsability.
Imagine we wanted to apply the Github JS guidelines we would have to install
their config, extend from it and then make sure to append eslint-config-prettier
.
npm install eslint-plugin-github eslint-config-prettier --save-dev
{
"extends": [
"plugin:reload/recommended",
"plugin:github/recommended",
"eslint-config-prettier"
]
}
All of the above applies but instead of recommended
we expose a specific
reload/typescript
config that also includes everything from reload/recommended
.
{
"extends": ["plugin:reload/typescript"]
}
There is some globals you would want to include when doing Drupal development.
This is done via. adding plugin:reload/drupal
at the end.
{
"extends": ["plugin:reload/recommended", "plugin:reload/drupal"]
}
The editor_integration
directory is an example of smart editor integration
that will help you with code quality and code style on save.
The equivelant can be configured for additional editors.
PR's are encouraged to broaden the example support.