From: Iskren Chernev Date: Sun, 22 Mar 2015 22:17:26 +0000 (-0700) Subject: Fix jscs warnings in grunt tasks X-Git-Tag: 2.10.2~15^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5819ee845b1141cb3ad490fde72974e12c5e608;p=thirdparty%2Fmoment.git Fix jscs warnings in grunt tasks --- diff --git a/tasks/check_sauce_creds.js b/tasks/check_sauce_creds.js index dd9de91c5..e56951d47 100644 --- a/tasks/check_sauce_creds.js +++ b/tasks/check_sauce_creds.js @@ -1,5 +1,4 @@ module.exports = function (grunt) { - // Pull requests do not have secure variables enabled for security reasons. // Use this task before launching travis-sauce-browser task, so it would // exit early and won't try connecting to SauceLabs without credentials. diff --git a/tasks/embed_locales.js b/tasks/embed_locales.js index 7583bf803..5027af10c 100644 --- a/tasks/embed_locales.js +++ b/tasks/embed_locales.js @@ -1,6 +1,5 @@ module.exports = function (grunt) { - grunt.registerTask('embedLocales', function () { var config = grunt.config('embedLocales'); @@ -44,6 +43,5 @@ module.exports = function (grunt) { return fileContents.replace(reTransform, replaceWith); } - }; diff --git a/tasks/history.js b/tasks/history.js index fc6d3ffac..85e83338f 100644 --- a/tasks/history.js +++ b/tasks/history.js @@ -29,11 +29,11 @@ function normalize() { var i, max = 0, max2 = 0; - for (i = 0; i < count; i ++) { + for (i = 0; i < count; i++) { max = Math.max(max, outputs[i].gzip); max2 = Math.max(max2, outputs[i].original); } - for (i = 0; i < count; i ++) { + for (i = 0; i < count; i++) { outputs[i].bargraph = makeBar((outputs[i].gzip / max) * 80); outputs[i].bargraph2 = makeBar((outputs[i].original / max2) * 80); } @@ -41,7 +41,7 @@ function normalize() { function display() { var i; - for (i = 0; i < count; i ++) { + for (i = 0; i < count; i++) { console.log(outputs[i].version + ' ' + outputs[i].gzip + ' ' + outputs[i].original); console.log('gzip ' + outputs[i].bargraph); console.log('orig ' + outputs[i].bargraph2); @@ -67,7 +67,7 @@ function getSizeAtVersion(version, path) { op.version = version; op.gzip = result.length; op.original = data.length; - resolved ++; + resolved++; check(); }); }); @@ -95,7 +95,7 @@ function getRemote() { } function getLocal() { - count ++; + count++; var op = {}; outputs.push(op); fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function (err, data) { @@ -106,7 +106,7 @@ function getLocal() { op.version = '.next'; op.gzip = result.length; op.original = data.length; - resolved ++; + resolved++; check(); }); }); diff --git a/tasks/nuget.js b/tasks/nuget.js index f5b8cedfa..7827b2400 100644 --- a/tasks/nuget.js +++ b/tasks/nuget.js @@ -11,12 +11,12 @@ module.exports = function (grunt) { grunt.config('nugetpack', { dist: { src: 'Moment.js.nuspec', - dest: './', + dest: './' } }); grunt.config('nugetpush', { dist: { - src: 'Moment.js.*.nupkg', + src: 'Moment.js.*.nupkg' } }); grunt.config('clean.nuget', { diff --git a/tasks/qtest.js b/tasks/qtest.js index 99f78c0a4..bff9a8fe2 100644 --- a/tasks/qtest.js +++ b/tasks/qtest.js @@ -1,9 +1,8 @@ module.exports = function (grunt) { - grunt.task.registerTask("qtest", "run tests locally", function () { - + grunt.task.registerTask('qtest', 'run tests locally', function () { var done = this.async(); - var testrunner = require("qunit"); + var testrunner = require('qunit'); testrunner.options.log.assertions = false; testrunner.options.log.tests = false; @@ -12,10 +11,10 @@ module.exports = function (grunt) { testrunner.options.maxBlockDuration = 10000; testrunner.run({ - code: "build/umd/moment.js", - tests: grunt.file.expand("build/umd/test/moment/*.js", - "build/umd/test/locale/*.js"), - }, function(err, report) { + code: 'build/umd/moment.js', + tests: grunt.file.expand('build/umd/test/moment/*.js', + 'build/umd/test/locale/*.js') + }, function (err, report) { if (err) { console.log('woot', err, report); done(err); @@ -23,10 +22,9 @@ module.exports = function (grunt) { } err = null; if (report.failed !== 0) { - err = new Error(report.failed + " tests failed"); + err = new Error(report.failed + ' tests failed'); } done(err); }); - }); }; diff --git a/tasks/size.js b/tasks/size.js index 35d08ebe8..2ab380e9f 100644 --- a/tasks/size.js +++ b/tasks/size.js @@ -8,7 +8,6 @@ var stable = '1.7.1', function getVersion(path, cb) { var data = '', - req = https.request({ host: 'raw.github.com', port: 443, @@ -57,4 +56,4 @@ module.exports = function (grunt) { }); }); }); -}; \ No newline at end of file +}; diff --git a/tasks/transpile.js b/tasks/transpile.js index 97b8ead2f..8dcb1524e 100644 --- a/tasks/transpile.js +++ b/tasks/transpile.js @@ -2,7 +2,7 @@ module.exports = function (grunt) { var esperanto = require('esperanto'); var path = require('path'); var Promise = require('es6-promise').Promise; - var TMP_DIR = "build/tmp"; + var TMP_DIR = 'build/tmp'; function moveComments(code) { var comments = [], rest = []; @@ -26,17 +26,17 @@ module.exports = function (grunt) { } function transpile(opts) { - grunt.log.writeln("transpile", opts); + grunt.log.writeln('transpile', opts); // base, entry, skip, headerFile, skipLines, target - var umdName = opts.headerFile ? "not_used" : opts.umdName, + var umdName = opts.headerFile ? 'not_used' : opts.umdName, header = opts.headerFile ? getHeaderByFile(opts.headerFile) : '', skipLines = opts.skipLines ? opts.skipLines : 0; return esperanto.bundle({ base: opts.base, entry: opts.entry, - skip: opts.skip || [], - }).then(function(bundle) { + skip: opts.skip || [] + }).then(function (bundle) { var umd = bundle.toUmd({name: umdName}), fixed = header + umd.code.split('\n').slice(skipLines).join('\n'); if (opts.moveComments) { @@ -52,10 +52,10 @@ module.exports = function (grunt) { files = grunt.file.expand({cwd: opts.base}, opts.pattern), i, transpileOne = function (i) { - promise = promise.then(function() { - grunt.log.writeln("transpiling from", opts.pattern, i); - return Promise.all(files.slice(i, i + batchSize).map(function(file) { - grunt.log.writeln("transpiling", file); + promise = promise.then(function () { + grunt.log.writeln('transpiling from', opts.pattern, i); + return Promise.all(files.slice(i, i + batchSize).map(function (file) { + grunt.log.writeln('transpiling', file); return transpile({ base: opts.base, entry: file, @@ -63,7 +63,7 @@ module.exports = function (grunt) { skip: opts.skip, skipLines: opts.skipLines, moveComments: opts.moveComments, - target: path.join(opts.targetDir, file), + target: path.join(opts.targetDir, file) }); })); }); @@ -77,9 +77,9 @@ module.exports = function (grunt) { } function prepareTemp(base) { - var files = grunt.file.expand({cwd: base}, "**/*.js"), + var files = grunt.file.expand({cwd: base}, '**/*.js'), tmpDir = TMP_DIR; - grunt.log.writeln("preparint temp", base); + grunt.log.writeln('preparint temp', base); if (grunt.file.exists(tmpDir)) { return; } @@ -95,20 +95,20 @@ module.exports = function (grunt) { return transpile({ base: TMP_DIR, entry: entry, - umdName: opts.umdName || "not_used", + umdName: opts.umdName || 'not_used', headerFile: opts.headerFile, skipLines: opts.skipLines, moveComments: opts.moveComments, target: opts.target, - skip: opts.skip, + skip: opts.skip }); } grunt.task.registerTask('transpile', 'convert es6 to umd', function () { var done = this.async(); - grunt.log.writeln("cleaning up build"); - grunt.file.delete("build"); + grunt.log.writeln('cleaning up build'); + grunt.file.delete('build'); transpile({ base: 'src', @@ -116,20 +116,20 @@ module.exports = function (grunt) { umdName: 'moment', target: 'build/umd/moment.js', moveComments: true - }).then(function() { + }).then(function () { return transpileMany({ base: 'src', - pattern: "locale/*.js", + pattern: 'locale/*.js', headerFile: 'templates/locale-header.js', skipLines: 5, moveComments: true, targetDir: 'build/umd', skip: ['moment'] }); - }).then(function() { + }).then(function () { return transpileMany({ base: 'src', - pattern: "test/moment/*.js", + pattern: 'test/moment/*.js', headerFile: 'templates/test-header.js', skipLines: 5, moveComments: true, @@ -139,34 +139,34 @@ module.exports = function (grunt) { }).then(function () { return transpileMany({ base: 'src', - pattern: "test/locale/*.js", - headerFile: "templates/test-header.js", + pattern: 'test/locale/*.js', + headerFile: 'templates/test-header.js', skipLines: 5, moveComments: true, - targetDir: "build/umd", + targetDir: 'build/umd', skip: ['moment'] }); }).then(function () { - var files = grunt.file.expand({cwd: "src"}, "locale/*.js"), + var files = grunt.file.expand({cwd: 'src'}, 'locale/*.js'), code = files.map(function (file) { var identifier = path.basename(file, '.js').replace('-', '_'); return 'import ' + identifier + ' from "./' + file + '";'; - }).join("\n"); + }).join('\n'); return transpileCode({ base: 'src', code: code, target: 'build/umd/min/locales.js', skip: ['moment'], headerFile: 'templates/locale-header.js', - skipLines: 5, + skipLines: 5 }); - }).then(function() { - var files = grunt.file.expand({cwd: "src"}, "locale/*.js"), + }).then(function () { + var files = grunt.file.expand({cwd: 'src'}, 'locale/*.js'), importCode = files.map(function (file) { var identifier = path.basename(file, '.js').replace('-', '_'); var fileNoExt = file.replace('.js', ''); return 'import ' + identifier + ' from "./' + fileNoExt + '";'; - }).join("\n"), + }).join('\n'), code = 'import * as moment_export from "./moment";\n\n' + importCode + '\n\n' + 'export default moment_export;'; @@ -175,15 +175,15 @@ module.exports = function (grunt) { base: 'src', code: code, umdName: 'moment', - target: 'build/umd/min/moment-with-locales.js', - }).then(function() { + target: 'build/umd/min/moment-with-locales.js' + }).then(function () { var code = grunt.file.read('build/umd/min/moment-with-locales.js'); code = code.replace(' var moment = {\n get default () { return moment__default; }\n };', ''); code = code.replace('var moment_with_locales = moment', 'var moment_with_locales = moment__default'); grunt.file.write('build/umd/min/moment-with-locales.js', code); }); - }).then(done, function(e) { - grunt.log.error("error transpiling", e); + }).then(done, function (e) { + grunt.log.error('error transpiling', e); done(e); }); }); diff --git a/tasks/update_index.js b/tasks/update_index.js index a9322b27f..2a6447e90 100644 --- a/tasks/update_index.js +++ b/tasks/update_index.js @@ -7,7 +7,7 @@ module.exports = function (grunt) { 'min/locales.js', 'min/moment-with-locales.js' ], - dest: '.', + dest: '.' }); grunt.registerTask('update-index', ['copy:index-files']); diff --git a/tasks/zones.js b/tasks/zones.js index 72629274a..7aa88b1f6 100644 --- a/tasks/zones.js +++ b/tasks/zones.js @@ -19,7 +19,7 @@ module.exports = function (grunt) { if (err != null) { throw err; } - iterator(i+1); + iterator(i + 1); }); }(0)); }); @@ -32,9 +32,13 @@ module.exports = function (grunt) { } callback(null, content.split(/\r\n|\r|\n/) // remove empty and commented lines - .filter(function (line) { return line && !/^#/.test(line); }) + .filter(function (line) { + return line && !/^#/.test(line); + }) // country code TAB coordinates TAB timezone - .map(function (line) { return line.split('\t')[2]; })); + .map(function (line) { + return line.split('\t')[2]; + })); }); } @@ -42,16 +46,22 @@ module.exports = function (grunt) { grunt.log.ok('Running tests in zone ' + zone); grunt.util.spawn({ cmd: 'grunt', - opts: { env: { - 'PATH': process.env.PATH, - 'TZ': zone - } }, + opts: { + env: { + 'PATH': process.env.PATH, + 'TZ': zone + } + }, args: ['--no-color', 'nodeunit'] }, function (err, result, code) { if (code !== 0) { grunt.log.error(result.stdout.split(/\r\n|\r|\n/) - .filter(function (line) { return /^(>>|Warning:|$)/.test(line); }) - .map(function (line) { return (line.substr(0, 3) === '>> ' ? line.substr(3) : line); }) + .filter(function (line) { + return /^(>>|Warning:|$)/.test(line); + }) + .map(function (line) { + return (line.substr(0, 3) === '>> ' ? line.substr(3) : line); + }) .join('\n')); } next();