From: Jukka Kurkela Date: Sun, 9 Feb 2020 16:50:11 +0000 (+0200) Subject: Fix lint issues in gulpfile.js (#7076) X-Git-Tag: v3.0.0-alpha~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92b2f7908e3a84c3f34f0c1574206d137284e086;p=thirdparty%2FChart.js.git Fix lint issues in gulpfile.js (#7076) * Fix lint issues in gulpfile.js * .eslintignore update --- diff --git a/.eslintignore b/.eslintignore index 96212a359..5f985010b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -**/*{.,-}min.js +dist/*.js diff --git a/gulpfile.js b/gulpfile.js index 0c2cfb045..1f009d1b6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,4 @@ +/* eslint-disable no-use-before-define */ const gulp = require('gulp'); const eslint = require('gulp-eslint'); const file = require('gulp-file'); @@ -13,14 +14,14 @@ const yargs = require('yargs'); const path = require('path'); const htmllint = require('gulp-htmllint'); const typescript = require('gulp-typescript'); -const typedoc = require("gulp-typedoc"); +const typedoc = require('gulp-typedoc'); const pkg = require('./package.json'); const tsProject = typescript.createProject('./tsconfig.json'); const argv = yargs - .option('verbose', {default: false}) - .argv; + .option('verbose', {default: false}) + .argv; const srcDir = './src/'; const outDir = './dist/'; @@ -40,23 +41,23 @@ gulp.task('module-sizes', moduleSizesTask); gulp.task('size', gulp.parallel('library-size', 'module-sizes')); gulp.task('default', gulp.parallel('build')); -function run(bin, args, done) { - return new Promise(function(resolve, reject) { - const exe = '"' + process.execPath + '"'; - const src = require.resolve(bin); - const cmd = [exe, src].concat(args || []).join(' '); - const ps = exec(cmd); - - ps.stdout.pipe(process.stdout); - ps.stderr.pipe(process.stderr); - ps.on('close', function(error) { - if (error) { - reject(error); - } else { - resolve(); - } - }); - }); +function run(bin, args) { + return new Promise(function(resolve, reject) { + const exe = '"' + process.execPath + '"'; + const src = require.resolve(bin); + const cmd = [exe, src].concat(args || []).join(' '); + const ps = exec(cmd); + + ps.stdout.pipe(process.stdout); + ps.stderr.pipe(process.stderr); + ps.on('close', function(error) { + if (error) { + reject(error); + } else { + resolve(); + } + }); + }); } /** @@ -64,132 +65,132 @@ function run(bin, args, done) { * Specs: https://github.com/bower/spec/blob/master/json.md */ function bowerTask() { - const json = JSON.stringify({ - name: pkg.name, - description: pkg.description, - homepage: pkg.homepage, - license: pkg.license, - version: pkg.version, - main: outDir + 'Chart.js', - ignore: [ - '.github', - '.codeclimate.yml', - '.gitignore', - '.npmignore', - '.travis.yml', - 'scripts' - ] - }, null, 2); - - return file('bower.json', json, { src: true }) - .pipe(gulp.dest('./')); + const json = JSON.stringify({ + name: pkg.name, + description: pkg.description, + homepage: pkg.homepage, + license: pkg.license, + version: pkg.version, + main: outDir + 'Chart.js', + ignore: [ + '.github', + '.codeclimate.yml', + '.gitignore', + '.npmignore', + '.travis.yml', + 'scripts' + ] + }, null, 2); + + return file('bower.json', json, {src: true}) + .pipe(gulp.dest('./')); } function buildTask() { - return run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']); + return run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']); } function packageTask() { - return merge( - // gather "regular" files landing in the package root - gulp.src([outDir + '*.js', outDir + '*.css', 'LICENSE.md']), - - // since we moved the dist files one folder up (package root), we need to rewrite - // samples src="../dist/ to src="../ and then copy them in the /samples directory. - gulp.src('./samples/**/*', { base: '.' }) - .pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1'))) - ) - // finally, create the zip archive - .pipe(zip('Chart.js.zip')) - .pipe(gulp.dest(outDir)); + return merge( + // gather "regular" files landing in the package root + gulp.src([outDir + '*.js', outDir + '*.css', 'LICENSE.md']), + + // since we moved the dist files one folder up (package root), we need to rewrite + // samples src="../dist/ to src="../ and then copy them in the /samples directory. + gulp.src('./samples/**/*', {base: '.'}) + .pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1'))) + ) + // finally, create the zip archive + .pipe(zip('Chart.js.zip')) + .pipe(gulp.dest(outDir)); } function lintJsTask() { - const files = [ - 'samples/**/*.html', - 'samples/**/*.js', - 'src/**/*.js', - 'test/**/*.js' - ]; - - // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict - // compare to what the current codebase can support, and since it's not straightforward - // to fix, let's turn them as warnings and rewrite code later progressively. - const options = { - rules: { - 'complexity': [1, 10], - 'max-statements': [1, 30] - } - }; - - return gulp.src(files) - .pipe(eslint(options)) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + const files = [ + 'samples/**/*.html', + 'samples/**/*.js', + 'src/**/*.js', + 'test/**/*.js' + ]; + + // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict + // compare to what the current codebase can support, and since it's not straightforward + // to fix, let's turn them as warnings and rewrite code later progressively. + const options = { + rules: { + complexity: [1, 10], + 'max-statements': [1, 30] + } + }; + + return gulp.src(files) + .pipe(eslint(options)) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); } function typescriptTask() { - return tsProject.src() - .pipe(tsProject()) - .js.pipe(gulp.dest('dist')); + return tsProject.src() + .pipe(tsProject()) + .js.pipe(gulp.dest('dist')); } function lintHtmlTask() { - return gulp.src('samples/**/*.html') - .pipe(htmllint({ - failOnError: true, - })); + return gulp.src('samples/**/*.html') + .pipe(htmllint({ + failOnError: true, + })); } function docsTask(done) { - const bin = require.resolve('gitbook-cli/bin/gitbook.js'); - const cmd = argv.watch ? 'serve' : 'build'; - - return run(bin, ['install', './']) - .then(() => run(bin, [cmd, './', './dist/docs'])) - .then(() => { - const config = { - moduleResolution: "Node", - target: "ES6", - out: "./dist/docs/typedoc" - }; - gulp.src(['./src/**/*.js'], {read: false}) - .pipe(typedoc(config, done)); - }).catch((err) => { - done(new Error(err.stdout || err)); - }); + const bin = require.resolve('gitbook-cli/bin/gitbook.js'); + const cmd = argv.watch ? 'serve' : 'build'; + + return run(bin, ['install', './']) + .then(() => run(bin, [cmd, './', './dist/docs'])) + .then(() => { + const config = { + moduleResolution: 'Node', + target: 'ES6', + out: './dist/docs/typedoc' + }; + gulp.src(['./src/**/*.js'], {read: false}) + .pipe(typedoc(config, done)); + }).catch((err) => { + done(new Error(err.stdout || err)); + }); } function unittestTask(done) { - new karma.Server({ - configFile: path.join(__dirname, 'karma.conf.js'), - singleRun: !argv.watch, - args: { - coverage: !!argv.coverage, - inputs: argv.inputs, - browsers: argv.browsers, - watch: argv.watch - } - }, - // https://github.com/karma-runner/gulp-karma/issues/18 - function(error) { - error = error ? new Error('Karma returned with the error code: ' + error) : undefined; - done(error); - }).start(); + new karma.Server({ + configFile: path.join(__dirname, 'karma.conf.js'), + singleRun: !argv.watch, + args: { + coverage: !!argv.coverage, + inputs: argv.inputs, + browsers: argv.browsers, + watch: argv.watch + } + }, + // https://github.com/karma-runner/gulp-karma/issues/18 + function(error) { + error = error ? new Error('Karma returned with the error code: ' + error) : undefined; + done(error); + }).start(); } function librarySizeTask() { - return gulp.src('dist/Chart.bundle.min.js') - .pipe(size({ - gzip: true - })); + return gulp.src('dist/Chart.bundle.min.js') + .pipe(size({ + gzip: true + })); } function moduleSizesTask() { - return gulp.src(srcDir + '**/*.js') - .pipe(terser()) - .pipe(size({ - showFiles: true, - gzip: true - })); + return gulp.src(srcDir + '**/*.js') + .pipe(terser()) + .pipe(size({ + showFiles: true, + gzip: true + })); }