diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..3b35abf --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,96 @@ +{ + "rules": { + "curly": [ + 2, + "multi-line" + ], + "keyword-spacing": [ + 2, + {} + ], + "wrap-iife": 2, + "space-before-function-paren": [ + 2, + "never" + ], + "one-var": [ + 2, + "never" + ], + "array-bracket-spacing": [ + 2, + "never", + { + "singleValue": false + } + ], + "space-in-parens": [ + 2, + "never" + ], + "key-spacing": [ + 2, + { + "beforeColon": false, + "afterColon": true + } + ], + "comma-style": [ + 2, + "last" + ], + "operator-linebreak": [ + 2, + "after" + ], + "space-unary-ops": [ + 2, + { + "words": false, + "nonwords": false + } + ], + "camelcase": [ + 2, + { + "properties": "never" + } + ], + "no-with": 2, + "no-multi-str": 2, + "linebreak-style": [ + 2, + "unix" + ], + "indent": [ + 2, + "tab", + { + "SwitchCase": 1 + } + ], + "no-mixed-spaces-and-tabs": 2, + "no-trailing-spaces": 2, + "brace-style": [ + 2, + "stroustrup", + { + "allowSingleLine": true + } + ], + "eol-last": 2, + "max-len": [ + 2, + 140 + ], + "consistent-this": [ + 2, + "that" + ], + "dot-notation": 2, + "valid-jsdoc": [ + 2, + { "requireReturn": false, "requireReturnDescription": false, "requireParamDescription": false } + ] + } +} diff --git a/.jscs.json b/.jscs.json deleted file mode 100644 index 28ed857..0000000 --- a/.jscs.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "requireCurlyBraces": ["for", "while", "do"], - "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return"], - "requireParenthesesAroundIIFE": true, - "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, - "disallowSpacesInFunctionExpression": { "beforeOpeningRoundBrace": true }, - "disallowMultipleVarDecl": true, - "disallowSpacesInsideObjectBrackets": true, - "disallowSpacesInsideArrayBrackets": true, - "disallowSpacesInsideParentheses": true, - "disallowSpaceAfterObjectKeys": true, - "requireCommaBeforeLineBreak": true, - "requireOperatorBeforeLineBreak": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], - "disallowSpaceAfterBinaryOperators": ["!"], - "disallowSpaceBeforeBinaryOperators": [","], - "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], - "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], - "requireSpaceBeforeBinaryOperators": ["?", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], - "requireSpaceAfterBinaryOperators": ["?", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], - "requireCamelCaseOrUpperCaseIdentifiers": true, - "disallowKeywords": ["with"], - "disallowMultipleLineStrings": true, - "validateLineBreaks": "LF", - "validateIndentation": "\t", - "disallowMixedSpacesAndTabs": "smart", - "disallowTrailingWhitespace": true, - "requireKeywordsOnNewLine": ["else"], - "requireLineFeedAtFileEnd": true, - "maximumLineLength": 140, - "safeContextKeyword": "that", - "requireDotNotation": true, - "validateJSDoc": { - "checkParamNames": true, - "checkRedundantParams": true, - "requireParamTypes": true - }, - "excludeFiles": ["node_modules/**"] -} diff --git a/.travis.yml b/.travis.yml index 6cc8294..c0f4586 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,7 @@ language: node_js sudo: false node_js: - - "0.12" - - "4" - - "5" - - "6" + - "8" addons: apt: packages: diff --git a/Gruntfile.js b/Gruntfile.js index febecc5..62183ca 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -371,16 +371,16 @@ module.exports = function(grunt) { watch: { scripts: { files: '<%= jshint.all %>', - tasks: ['jshint', 'jscs'], + tasks: ['jshint', 'eslint'], options: { debounceDelay: 100, nospawn: true } }, }, - jscs: { + eslint: { options: { - config: ".jscs.json", + configFile: '.eslintrc.json' }, all: ['tasks/*.js'] }, @@ -390,6 +390,6 @@ module.exports = function(grunt) { grunt.loadTasks('tasks'); grunt.registerTask('test', ['nodeunit']); - grunt.registerTask('default', ['jshint', 'jscs', 'clean', 'webfont', 'test', 'clean']); + grunt.registerTask('default', ['jshint', 'eslint', 'clean', 'webfont', 'test', 'clean']); }; diff --git a/package.json b/package.json index 1d49b68..e2a757a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-webfont", "description": "Ultimate SVG to webfont converter for Grunt.", - "version": "1.7.2", + "version": "1.8.0", "homepage": "https://github.com/sapegin/grunt-webfont", "author": { "name": "Artem Sapegin", @@ -30,30 +30,30 @@ "dependencies": { "async": "~1.5.2", "chalk": "~1.1.1", - "glob": "~7.0.0", + "glob": "~7.1.4", "lodash": "~4.17.10", "memorystream": "~0.3.1", "mkdirp": "~0.5.1", - "svg2ttf": "~2.1.1", + "svg2ttf": "~4.3.0", "svgicons2svgfont": "~1.1.0", - "svgo": "~0.6.1", + "svgo": "~1.3.0", "temp": "~0.8.3", - "ttf2eot": "~1.3.0", - "ttf2woff": "~1.3.0", + "ttf2eot": "~2.0.0", + "ttf2woff": "~2.0.1", "ttf2woff2": "~2.0.3", - "underscore.string": "~3.2.3", + "underscore.string": "~3.3.5", "winston": "~2.1.1" }, "devDependencies": { - "grunt": "~0.4.5", - "grunt-cli": "~0.1.13", + "grunt": "~1.0.4", + "grunt-cli": "~1.3.2", "grunt-contrib-clean": "~1.0.0", - "grunt-contrib-jshint": "~0.11.3", - "grunt-contrib-nodeunit": "~0.4.1", - "grunt-contrib-watch": "~0.6.1", - "grunt-jscs": "~1.0.0", + "grunt-contrib-jshint": "~2.1.0", + "grunt-contrib-nodeunit": "~2.0.0", + "grunt-contrib-watch": "~1.1.0", + "grunt-eslint": "~22.0.0", "load-grunt-tasks": "~3.4.0", - "stylus": "~0.53.0", + "stylus": "~0.54.5", "xml2js": "~0.4.16" }, "peerDependencies": { diff --git a/tasks/engines/node.js b/tasks/engines/node.js index 8498928..2f1c72d 100644 --- a/tasks/engines/node.js +++ b/tasks/engines/node.js @@ -142,7 +142,7 @@ module.exports = function(o, allDone) { var svg = fs.readFileSync(file, 'utf8'); var svgo = new SVGO(); try { - svgo.optimize(svg, function(res) { + svgo.optimize(svg).then(res => { var stream = new MemoryStream(res.data, { writable: false }); diff --git a/tasks/webfont.js b/tasks/webfont.js index c198183..4d1fe41 100755 --- a/tasks/webfont.js +++ b/tasks/webfont.js @@ -54,8 +54,8 @@ module.exports = function(grunt) { * Check for `dest` param on either target config or global options object */ if (_.isUndefined(params.dest) && _.isUndefined(options.dest)) { - logger.warn('Required property ' + [this.name, this.target, 'dest'].join('.') - + ' or ' + [this.name, this.target, 'options.dest'].join('.') + ' missing.'); + logger.warn('Required property ' + [this.name, this.target, 'dest'].join('.') + + ' or ' + [this.name, this.target, 'options.dest'].join('.') + ' missing.'); } if (options.skip) { @@ -399,6 +399,7 @@ module.exports = function(grunt) { /** * Gets the codepoints from the set filepath in o.codepointsFile + * @returns {Object} the codepoints, or an empty object if not found */ function readCodepointsFromFile(){ if (!o.codepointsFile) return {}; @@ -420,7 +421,8 @@ module.exports = function(grunt) { try { fs.writeFileSync(o.codepointsFile, codepointsToString); logger.verbose('Codepoints saved to file "' + o.codepointsFile + '".'); - } catch (err) { + } + catch (err) { logger.error(err.message); } } @@ -741,12 +743,13 @@ module.exports = function(grunt) { * @param {String} template Template file path * @param {String} syntax Syntax (bem, bootstrap, etc.) * @param {String} ext Extention of the template + * @param {Boolean} optional If true, return `undefined` if the template file does not exist, otherwise fail * @return {Object} {filename: 'Template filename', template: 'Template code'} */ function readTemplate(template, syntax, ext, optional) { - var filename = template - ? path.resolve(template.replace(path.extname(template), ext)) - : path.join(__dirname, 'templates/' + syntax + ext) + var filename = template ? + path.resolve(template.replace(path.extname(template), ext)) : + path.join(__dirname, 'templates/' + syntax + ext) ; if (fs.existsSync(filename)) { return { @@ -823,6 +826,7 @@ module.exports = function(grunt) { /** * Return path of HTML demo file or `null` if feature was disabled + * @returns {String} path of the HTML demo file */ function getDemoPath() { if (!o.htmlDemo) return null;