WordPress JavaScript Coding Standards shareable config for ESLint.
If you do not have npm installed on your computer, follow the instructions here.
Next you will need to have npm set up for your JavaScript project. If you do not see a package.json
file in your project's directory, run npm init
within that directory and follow the prompts to create one. You do not need to answer all the questions if you do not plan to be publishing your project to npm, so accepting the defaults is usually fine. You can also edit the configuration later by editing your package.json
file.
After that you will need to have eslint installed for your project. If it is not installed already, run the following command:
$ npm install --save-dev eslint
If the requirements are satisfied, you can install this plugin as follows:
$ npm install --save-dev eslint-config-wordpress
To use this plugin, you must have an eslint configuration file for your project. There are several different formats for this config file. In your config file you will need to find or create a section called "extends" and add "wordpress" to that section.
For example, if you are using the JSON file .eslintrc.json
, it should look something like this:
{
"extends": "wordpress"
}
There may be other sections in your config file as well. Read more about configuring eslint here.