-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix.js
52 lines (47 loc) · 1.1 KB
/
fix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
// npm install -D eslint@8 gulp gulp-eslint-new
const { src } = require('gulp');
const gulpESLintNew = require('gulp-eslint-new');
const { join } = require('path');
function lintNFix()
{
return src('demo/**/*.js')
.pipe
(
gulpESLintNew
(
{
cwd: join(__dirname, 'demo'),
fix: true,
},
),
)
.pipe(gulpESLintNew.format())
// If a file has a fix, overwrite it.
.pipe(gulpESLintNew.fix());
}
function flagNFix()
{
// Fix only when the option "--fix" is specified in the command line.
const hasFixFlag = process.argv.slice(2).includes('--fix');
return src('demo/**/*.js')
.pipe
(
gulpESLintNew
(
{
cwd: join(__dirname, 'demo'),
fix: hasFixFlag,
},
),
)
.pipe(gulpESLintNew.format())
// If a file has a fix, overwrite it.
.pipe(gulpESLintNew.fix());
}
module.exports =
{
'default': lintNFix,
'lint-n-fix': lintNFix,
'flag-n-fix': flagNFix,
};