Skip to content

Commit 92b2f79

Browse files
authored
Fix lint issues in gulpfile.js (chartjs#7076)
* Fix lint issues in gulpfile.js * .eslintignore update
1 parent 25002f2 commit 92b2f79

File tree

2 files changed

+123
-122
lines changed

2 files changed

+123
-122
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
**/*{.,-}min.js
1+
dist/*.js

gulpfile.js

Lines changed: 122 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-use-before-define */
12
const gulp = require('gulp');
23
const eslint = require('gulp-eslint');
34
const file = require('gulp-file');
@@ -13,14 +14,14 @@ const yargs = require('yargs');
1314
const path = require('path');
1415
const htmllint = require('gulp-htmllint');
1516
const typescript = require('gulp-typescript');
16-
const typedoc = require("gulp-typedoc");
17+
const typedoc = require('gulp-typedoc');
1718

1819
const pkg = require('./package.json');
1920
const tsProject = typescript.createProject('./tsconfig.json');
2021

2122
const argv = yargs
22-
.option('verbose', {default: false})
23-
.argv;
23+
.option('verbose', {default: false})
24+
.argv;
2425

2526
const srcDir = './src/';
2627
const outDir = './dist/';
@@ -40,156 +41,156 @@ gulp.task('module-sizes', moduleSizesTask);
4041
gulp.task('size', gulp.parallel('library-size', 'module-sizes'));
4142
gulp.task('default', gulp.parallel('build'));
4243

43-
function run(bin, args, done) {
44-
return new Promise(function(resolve, reject) {
45-
const exe = '"' + process.execPath + '"';
46-
const src = require.resolve(bin);
47-
const cmd = [exe, src].concat(args || []).join(' ');
48-
const ps = exec(cmd);
49-
50-
ps.stdout.pipe(process.stdout);
51-
ps.stderr.pipe(process.stderr);
52-
ps.on('close', function(error) {
53-
if (error) {
54-
reject(error);
55-
} else {
56-
resolve();
57-
}
58-
});
59-
});
44+
function run(bin, args) {
45+
return new Promise(function(resolve, reject) {
46+
const exe = '"' + process.execPath + '"';
47+
const src = require.resolve(bin);
48+
const cmd = [exe, src].concat(args || []).join(' ');
49+
const ps = exec(cmd);
50+
51+
ps.stdout.pipe(process.stdout);
52+
ps.stderr.pipe(process.stderr);
53+
ps.on('close', function(error) {
54+
if (error) {
55+
reject(error);
56+
} else {
57+
resolve();
58+
}
59+
});
60+
});
6061
}
6162

6263
/**
6364
* Generates the bower.json manifest file which will be pushed along release tags.
6465
* Specs: https://github.com/bower/spec/blob/master/json.md
6566
*/
6667
function bowerTask() {
67-
const json = JSON.stringify({
68-
name: pkg.name,
69-
description: pkg.description,
70-
homepage: pkg.homepage,
71-
license: pkg.license,
72-
version: pkg.version,
73-
main: outDir + 'Chart.js',
74-
ignore: [
75-
'.github',
76-
'.codeclimate.yml',
77-
'.gitignore',
78-
'.npmignore',
79-
'.travis.yml',
80-
'scripts'
81-
]
82-
}, null, 2);
83-
84-
return file('bower.json', json, { src: true })
85-
.pipe(gulp.dest('./'));
68+
const json = JSON.stringify({
69+
name: pkg.name,
70+
description: pkg.description,
71+
homepage: pkg.homepage,
72+
license: pkg.license,
73+
version: pkg.version,
74+
main: outDir + 'Chart.js',
75+
ignore: [
76+
'.github',
77+
'.codeclimate.yml',
78+
'.gitignore',
79+
'.npmignore',
80+
'.travis.yml',
81+
'scripts'
82+
]
83+
}, null, 2);
84+
85+
return file('bower.json', json, {src: true})
86+
.pipe(gulp.dest('./'));
8687
}
8788

8889
function buildTask() {
89-
return run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']);
90+
return run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']);
9091
}
9192

9293
function packageTask() {
93-
return merge(
94-
// gather "regular" files landing in the package root
95-
gulp.src([outDir + '*.js', outDir + '*.css', 'LICENSE.md']),
96-
97-
// since we moved the dist files one folder up (package root), we need to rewrite
98-
// samples src="../dist/ to src="../ and then copy them in the /samples directory.
99-
gulp.src('./samples/**/*', { base: '.' })
100-
.pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1')))
101-
)
102-
// finally, create the zip archive
103-
.pipe(zip('Chart.js.zip'))
104-
.pipe(gulp.dest(outDir));
94+
return merge(
95+
// gather "regular" files landing in the package root
96+
gulp.src([outDir + '*.js', outDir + '*.css', 'LICENSE.md']),
97+
98+
// since we moved the dist files one folder up (package root), we need to rewrite
99+
// samples src="../dist/ to src="../ and then copy them in the /samples directory.
100+
gulp.src('./samples/**/*', {base: '.'})
101+
.pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1')))
102+
)
103+
// finally, create the zip archive
104+
.pipe(zip('Chart.js.zip'))
105+
.pipe(gulp.dest(outDir));
105106
}
106107

107108
function lintJsTask() {
108-
const files = [
109-
'samples/**/*.html',
110-
'samples/**/*.js',
111-
'src/**/*.js',
112-
'test/**/*.js'
113-
];
114-
115-
// NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
116-
// compare to what the current codebase can support, and since it's not straightforward
117-
// to fix, let's turn them as warnings and rewrite code later progressively.
118-
const options = {
119-
rules: {
120-
'complexity': [1, 10],
121-
'max-statements': [1, 30]
122-
}
123-
};
124-
125-
return gulp.src(files)
126-
.pipe(eslint(options))
127-
.pipe(eslint.format())
128-
.pipe(eslint.failAfterError());
109+
const files = [
110+
'samples/**/*.html',
111+
'samples/**/*.js',
112+
'src/**/*.js',
113+
'test/**/*.js'
114+
];
115+
116+
// NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
117+
// compare to what the current codebase can support, and since it's not straightforward
118+
// to fix, let's turn them as warnings and rewrite code later progressively.
119+
const options = {
120+
rules: {
121+
complexity: [1, 10],
122+
'max-statements': [1, 30]
123+
}
124+
};
125+
126+
return gulp.src(files)
127+
.pipe(eslint(options))
128+
.pipe(eslint.format())
129+
.pipe(eslint.failAfterError());
129130
}
130131

131132
function typescriptTask() {
132-
return tsProject.src()
133-
.pipe(tsProject())
134-
.js.pipe(gulp.dest('dist'));
133+
return tsProject.src()
134+
.pipe(tsProject())
135+
.js.pipe(gulp.dest('dist'));
135136
}
136137

137138
function lintHtmlTask() {
138-
return gulp.src('samples/**/*.html')
139-
.pipe(htmllint({
140-
failOnError: true,
141-
}));
139+
return gulp.src('samples/**/*.html')
140+
.pipe(htmllint({
141+
failOnError: true,
142+
}));
142143
}
143144

144145
function docsTask(done) {
145-
const bin = require.resolve('gitbook-cli/bin/gitbook.js');
146-
const cmd = argv.watch ? 'serve' : 'build';
147-
148-
return run(bin, ['install', './'])
149-
.then(() => run(bin, [cmd, './', './dist/docs']))
150-
.then(() => {
151-
const config = {
152-
moduleResolution: "Node",
153-
target: "ES6",
154-
out: "./dist/docs/typedoc"
155-
};
156-
gulp.src(['./src/**/*.js'], {read: false})
157-
.pipe(typedoc(config, done));
158-
}).catch((err) => {
159-
done(new Error(err.stdout || err));
160-
});
146+
const bin = require.resolve('gitbook-cli/bin/gitbook.js');
147+
const cmd = argv.watch ? 'serve' : 'build';
148+
149+
return run(bin, ['install', './'])
150+
.then(() => run(bin, [cmd, './', './dist/docs']))
151+
.then(() => {
152+
const config = {
153+
moduleResolution: 'Node',
154+
target: 'ES6',
155+
out: './dist/docs/typedoc'
156+
};
157+
gulp.src(['./src/**/*.js'], {read: false})
158+
.pipe(typedoc(config, done));
159+
}).catch((err) => {
160+
done(new Error(err.stdout || err));
161+
});
161162
}
162163

163164
function unittestTask(done) {
164-
new karma.Server({
165-
configFile: path.join(__dirname, 'karma.conf.js'),
166-
singleRun: !argv.watch,
167-
args: {
168-
coverage: !!argv.coverage,
169-
inputs: argv.inputs,
170-
browsers: argv.browsers,
171-
watch: argv.watch
172-
}
173-
},
174-
// https://github.com/karma-runner/gulp-karma/issues/18
175-
function(error) {
176-
error = error ? new Error('Karma returned with the error code: ' + error) : undefined;
177-
done(error);
178-
}).start();
165+
new karma.Server({
166+
configFile: path.join(__dirname, 'karma.conf.js'),
167+
singleRun: !argv.watch,
168+
args: {
169+
coverage: !!argv.coverage,
170+
inputs: argv.inputs,
171+
browsers: argv.browsers,
172+
watch: argv.watch
173+
}
174+
},
175+
// https://github.com/karma-runner/gulp-karma/issues/18
176+
function(error) {
177+
error = error ? new Error('Karma returned with the error code: ' + error) : undefined;
178+
done(error);
179+
}).start();
179180
}
180181

181182
function librarySizeTask() {
182-
return gulp.src('dist/Chart.bundle.min.js')
183-
.pipe(size({
184-
gzip: true
185-
}));
183+
return gulp.src('dist/Chart.bundle.min.js')
184+
.pipe(size({
185+
gzip: true
186+
}));
186187
}
187188

188189
function moduleSizesTask() {
189-
return gulp.src(srcDir + '**/*.js')
190-
.pipe(terser())
191-
.pipe(size({
192-
showFiles: true,
193-
gzip: true
194-
}));
190+
return gulp.src(srcDir + '**/*.js')
191+
.pipe(terser())
192+
.pipe(size({
193+
showFiles: true,
194+
gzip: true
195+
}));
195196
}

0 commit comments

Comments
 (0)