Skip to content

Commit 593258b

Browse files
Add ESLint and fix linting errors
1 parent 492bd07 commit 593258b

File tree

4 files changed

+243
-14
lines changed

4 files changed

+243
-14
lines changed

.eslintrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "airbnb-base",
3+
"rules": {
4+
"arrow-body-style": 0,
5+
"comma-dangle": ["error", "never"],
6+
"indent": ["error", 2],
7+
"linebreak-style": ["error", "unix"],
8+
"max-len": ["error", 120],
9+
"no-console": 0,
10+
"no-mixed-operators": 0,
11+
"no-param-reassign": 0,
12+
"no-tabs": 2,
13+
"no-undef": 1,
14+
"no-unused-vars": ["error"]
15+
}
16+
}

index.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22
const browserifyPreprocessor = require('@cypress/browserify-preprocessor');
3-
const CLIEngine = require('eslint').CLIEngine;
3+
const { CLIEngine } = require('eslint');
44
const chalk = require('chalk');
55

66
const cli = new CLIEngine();
@@ -12,8 +12,8 @@ const cli = new CLIEngine();
1212
const padString = (string, longest) => {
1313
if (string.length < longest) {
1414
Array(longest - string.length)
15-
.fill(null)
16-
.forEach(() => { string += ' '; });
15+
.fill(null)
16+
.forEach(() => { string += ' '; });
1717
}
1818
return string;
1919
};
@@ -32,11 +32,11 @@ const logResults = (filePath, messages, type, colour) => {
3232
return curr > prev ? curr : prev;
3333
};
3434
const longestLineChars = messages
35-
.map(message => `${message.line}:${message.column}`.length)
36-
.reduce(findLargestReducer, 0);
35+
.map(message => `${message.line}:${message.column}`.length)
36+
.reduce(findLargestReducer, 0);
3737
const longestMsgChars = messages
38-
.map(message => message.message.length)
39-
.reduce(findLargestReducer, 0);
38+
.map(message => message.message.length)
39+
.reduce(findLargestReducer, 0);
4040

4141
messages.forEach((message) => {
4242
const lineText = padString(`${message.line}:${message.column}`, longestLineChars);
@@ -50,6 +50,11 @@ const logResults = (filePath, messages, type, colour) => {
5050
});
5151
};
5252

53+
/**
54+
* Runs linting via ESLint on file
55+
* If preprocessor is provided will call this once linting is complete, otherwise will default to using
56+
* Cypress' @cypress/browserify-preprocessor
57+
*/
5358
const lint = preprocessor => (file) => {
5459
const report = cli.executeOnFiles([file.filePath]);
5560
if (report.errorCount > 0) {

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Cypress plugin that will run linting via ESLint on your spec files as they are loaded and display errors in console",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"lint": "eslint index.js"
88
},
99
"keywords": [
1010
"cypress",
@@ -20,5 +20,9 @@
2020
"@cypress/browserify-preprocessor": "^1.0.2",
2121
"chalk": "^2.3.2",
2222
"eslint": "^4.19.1"
23+
},
24+
"devDependencies": {
25+
"eslint-config-airbnb-base": "^12.1.0",
26+
"eslint-plugin-import": "^2.10.0"
2327
}
2428
}

0 commit comments

Comments
 (0)