In this blog post, I’ll talk about the second External Pull Request I’ve done for OSD600 Release 0.4.
For this PR, I decided to work on issues that have to do with ESLint, particularly setting it up. So ESLint is a pluggable linting utility for Javascript and JSX. More information and documentation can be read on eslint.org.
The repo that I was working on is Kentico Developer Community Site. The issue that they had is that their project code is full of comments to disable eslint check, and they would like someone to create eslint configuration files for two of their projects’ directories.
After I skim through the configuring ESLint user guide provided, and similar issues, I was able to successfully create a PR.
So there are many ways to create an eslint configuration files:
- JavaScript – use
.eslintrc.js
and export an object containing your configuration. - YAML – use
.eslintrc.yaml
or.eslintrc.yml
to define the configuration structure. - JSON – use
.eslintrc.json
to define the configuration structure. ESLint’s JSON files also allow JavaScript-style comments. - Deprecated – use
.eslintrc
, which can be either JSON or YAML. - package.json – create an
eslintConfig
property in yourpackage.json
file and define your configuration there.
Taken from eslint user guide.
And they also have order of precedence if placed in the same directory, the priority is:
.eslintrc.js
.eslintrc.yaml
.eslintrc.yml
.eslintrc.json
.eslintrc
package.json
Then I had to look up how to disable rules for a group of files in configuration files instead of using in-file comments.
{
"rules": {...},
"overrides": [
{
"files": ["*-test.js","*.spec.js"],
"rules": {
"no-unused-expressions": "off"
}
}
]
}
Taken from the user-guide.
For my purpose, I changed the no-undef
rule to “off”. I also had to figure out how to select all the .js
files in the directories. Then I came across this:
**/*.js
This RegEx will include all JavaScript Files looking forwards from the location of the eslint configuration file.
The last step is just to remove all unnecessary eslint-disable comments from every files.
To make it easy, I just need to use Visual Studio Code search and replace feature.