wdio-eslint-service
v0.0.3
Published
WDIO service to use ESLint
Downloads
274
Maintainers
Readme
wdio-eslint-service
WDIO service to use ESLint
This service makes a lot of sense when your tests and code are placed independently.
Installation
npm install wdio-eslint-service --save
Usage
wdio.config.js
{
services: [
'eslint'
],
eslintOptions: {
files: ['**/*.js']
}
}
Options
Custom options
- cache — Only check changed files. In additional, we see your diff (for Git repositories).
- files — This option allows you to specify which files will be used.
- fix — True indicates that fixes should be included with the output report, and that errors and warnings should not be listed if they can be fixed. Your files on disk will be changed!
Standard options
- extensions — Specify JavaScript / Typescript file extensions. Default:
.js
. - format — Use a specific output format. Default:
node_modules/eslint-friendly-formatter
- ...
In additional you can use all options and rules are available in ESLint.
TypeScript
Make sure you already have the following dependencies:
package.json
{
"typescript": "^2.1.5",
"eslint-plugin-typescript": "^0.1.0",
"typescript-eslint-parser": "^1.0.3"
}
wdio.config.js
{
services: [
'eslint'
],
eslintOptions: {
extensions: ['.js', '.ts']
}
}
eslintrc.js
{
parser: 'typescript-eslint-parser',
plugins: [ 'typescript' ],
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true
}
}
}
These options can be added to wdio.config.js
as well.
Rationale
Before:
package.json
{
"scripts": {
"test": "wdio wdio.conf.js",
"lint": "eslint . --cache --format node_modules/eslint-friendly-formatter --ext .js"
},
"pre-commit": {
"silent": true,
"run": [
"lint"
]
}
}
Or:
{
"scripts": {
"test": "eslint . --cache --format node_modules/eslint-friendly-formatter --ext .js && wdio wdio.conf.js"
}
}
What if you want to run your ESLint task only locally? In this case, you should care about some environment variables on your server:
CI
SERVER_SIDE_ENV=npm test
utils/test.sh
#!/usr/bin/env bash
if [ -z $SERVER_SIDE_ENV ]
then eslint . --cache --format node_modules/eslint-friendly-formatter --ext .js
fi
wdio wdio.conf.js
{
"scripts": {
"test": "source ./utils/test.sh"
}
}
Do you like it? I don't think so.
After
.gitignore
wdio.conf.local.js
package.json
{
"scripts": {
"test": "test wdio.conf.local.js && wdio wdio.conf.local.js || wdio wdio.conf.js"
}
}
wdio.conf.local.js
{
services: [
'eslint'
],
eslintOptions: {
files: ['**/*.js']
}
}
So, you can have several configuration files for different environments and preferences.
That's why wdio-eslint-service
is so actual.
License
MIT