1
1
const path = require ( 'path' ) ;
2
2
const browserifyPreprocessor = require ( '@cypress/browserify-preprocessor' ) ;
3
- const CLIEngine = require ( 'eslint' ) . CLIEngine ;
3
+ const { CLIEngine } = require ( 'eslint' ) ;
4
4
const chalk = require ( 'chalk' ) ;
5
5
6
6
const cli = new CLIEngine ( ) ;
@@ -12,8 +12,8 @@ const cli = new CLIEngine();
12
12
const padString = ( string , longest ) => {
13
13
if ( string . length < longest ) {
14
14
Array ( longest - string . length )
15
- . fill ( null )
16
- . forEach ( ( ) => { string += ' ' ; } ) ;
15
+ . fill ( null )
16
+ . forEach ( ( ) => { string += ' ' ; } ) ;
17
17
}
18
18
return string ;
19
19
} ;
@@ -32,11 +32,11 @@ const logResults = (filePath, messages, type, colour) => {
32
32
return curr > prev ? curr : prev ;
33
33
} ;
34
34
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 ) ;
37
37
const longestMsgChars = messages
38
- . map ( message => message . message . length )
39
- . reduce ( findLargestReducer , 0 ) ;
38
+ . map ( message => message . message . length )
39
+ . reduce ( findLargestReducer , 0 ) ;
40
40
41
41
messages . forEach ( ( message ) => {
42
42
const lineText = padString ( `${ message . line } :${ message . column } ` , longestLineChars ) ;
@@ -50,6 +50,11 @@ const logResults = (filePath, messages, type, colour) => {
50
50
} ) ;
51
51
} ;
52
52
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
+ */
53
58
const lint = preprocessor => ( file ) => {
54
59
const report = cli . executeOnFiles ( [ file . filePath ] ) ;
55
60
if ( report . errorCount > 0 ) {
0 commit comments