From: XhmikosR Date: Wed, 24 Dec 2014 16:17:14 +0000 (+0200) Subject: Update JSCS config. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=798e451eb0b6b2ea20d1f19b298d4e057bc533f9;p=html-minifier.git Update JSCS config. --- diff --git a/.jscsrc b/.jscsrc index 1429c95..a7ce4ee 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,9 +1,11 @@ { - "requireCurlyBraces": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], + "requireCurlyBraces": ["if", "else", "for", "while", "do", "switch", "try", "catch"], "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="], "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="], "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, + //"requireOperatorBeforeLineBreak": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="], + "requireSpacesInConditionalExpression": true, "requireCapitalizedConstructors": true, "requireCommaBeforeLineBreak": true, @@ -17,8 +19,7 @@ "disallowQuotedKeysInObjects": "allButReserved", "disallowSpaceAfterObjectKeys": true, - "disallowSpaceAfterPrefixUnaryOperators": ["!"], - "disallowSpaceBeforeBinaryOperators": [","], + //"disallowSpaceBeforeBinaryOperators": [","], "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], @@ -26,10 +27,13 @@ "disallowMixedSpacesAndTabs": true, //"disallowMultipleLineBreaks": true, "disallowMultipleLineStrings": true, + //"disallowMultipleVarDecl": true, + "disallowSpacesInCallExpression": true, "disallowTrailingWhitespace": true, "validateIndentation": 2, "validateLineBreaks": "LF", + "validateParameterSeparator": ", ", "validateQuoteMarks": "'", "safeContextKeyword": "_this" diff --git a/cli.js b/cli.js index 361268e..2e1c62f 100755 --- a/cli.js +++ b/cli.js @@ -223,7 +223,9 @@ cli.main(function(args, options) { process.stderr.write('Error: Minification error'); } - minifyOptions.lint && minifyOptions.lint.populate(); + if (minifyOptions.lint) { + minifyOptions.lint.populate(); + } if (minified !== null) { // Write the output diff --git a/dist/htmlminifier.js b/dist/htmlminifier.js index 1eb4f72..c51146a 100644 --- a/dist/htmlminifier.js +++ b/dist/htmlminifier.js @@ -622,12 +622,12 @@ lineBreakStamp = 'htmlmincollapsedlinebreak'; if (prevTag && prevTag !== 'img' && prevTag !== 'input' && (prevTag.substr(0, 1) !== '/' - || ( prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) { + || (prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) { str = str.replace(/^\s+/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveBefore : ''); } if (nextTag && nextTag !== 'img' && nextTag !== 'input' && (nextTag.substr(0, 1) === '/' - || ( nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) { + || (nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) { str = str.replace(/\s+$/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveAfter : ''); } @@ -673,13 +673,13 @@ function canRemoveAttributeQuotes(value) { // http://mathiasbynens.be/notes/unquoted-attribute-values - return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/ ).test(value) && + return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/).test(value) && // make sure trailing slash is not interpreted as HTML self-closing tag !(/\/$/).test(value); } function attributesInclude(attributes, attribute) { - for (var i = attributes.length; i--; ) { + for (var i = attributes.length; i--;) { if (attributes[i].name.toLowerCase() === attribute) { return true; } @@ -1144,7 +1144,7 @@ new HTMLParser(value, { html5: typeof options.html5 !== 'undefined' ? options.html5 : true, - start: function( tag, attrs, unary, unarySlash ) { + start: function(tag, attrs, unary, unarySlash) { if (isIgnoring) { buffer.push('<' + tag, attrsToMarkup(attrs), unarySlash ? '/' : '', '>'); return; @@ -1181,25 +1181,29 @@ var openTag = '<' + tag; var closeTag = ((unarySlash && options.keepClosingSlash) ? '/' : '') + '>'; - if ( attrs.length === 0) { + if (attrs.length === 0) { openTag += closeTag; } buffer.push(openTag); - lint && lint.testElement(tag); + if (lint) { + lint.testElement(tag); + } var token; - for ( var i = 0, len = attrs.length; i < len; i++ ) { - lint && lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped); + for (var i = 0, len = attrs.length; i < len; i++) { + if (lint) { + lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped); + } token = normalizeAttribute(attrs[i], attrs, tag, unarySlash, i, options); - if ( i === len - 1 ) { + if (i === len - 1) { token += closeTag; } buffer.push(token); } }, - end: function( tag, attrs ) { + end: function(tag, attrs) { if (isIgnoring) { buffer.push(''); @@ -1226,8 +1230,8 @@ var isElementEmpty = currentChars === '' && tag === currentTag; if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs))) { // remove last "element" from buffer, return - for ( var i = buffer.length - 1; i >= 0; i-- ) { - if ( /^<[^\/!]/.test(buffer[i]) ) { + for (var i = buffer.length - 1; i >= 0; i--) { + if (/^<[^\/!]/.test(buffer[i])) { buffer.splice(i); break; } @@ -1247,7 +1251,7 @@ buffer.length = 0; currentChars = ''; }, - chars: function( text, prevTag, nextTag ) { + chars: function(text, prevTag, nextTag) { prevTag = prevTag === '' ? 'comment' : prevTag; nextTag = nextTag === '' ? 'comment' : nextTag; @@ -1284,10 +1288,12 @@ } } currentChars = text; - lint && lint.testChars(text); + if (lint) { + lint.testChars(text); + } buffer.push(text); }, - comment: function( text, nonStandard ) { + comment: function(text, nonStandard) { var prefix = nonStandard ? '' : '-->'; @@ -1328,16 +1334,16 @@ return str; } - function joinResultSegments( results, options ) { + function joinResultSegments(results, options) { var str; var maxLineLength = options.maxLineLength; - if ( maxLineLength ) { + if (maxLineLength) { var token; var lines = []; var line = ''; - for ( var i = 0, len = results.length; i < len; i++ ) { + for (var i = 0, len = results.length; i < len; i++) { token = results[i]; - if ( line.length + token.length < maxLineLength ) { + if (line.length + token.length < maxLineLength) { line += token; } else { @@ -1357,7 +1363,7 @@ } // for CommonJS enviroments, export everything - if ( typeof exports !== 'undefined' ) { + if (typeof exports !== 'undefined') { exports.minify = minify; } else { diff --git a/src/htmlminifier.js b/src/htmlminifier.js index d49387f..de6abd4 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -56,12 +56,12 @@ lineBreakStamp = 'htmlmincollapsedlinebreak'; if (prevTag && prevTag !== 'img' && prevTag !== 'input' && (prevTag.substr(0, 1) !== '/' - || ( prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) { + || (prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) { str = str.replace(/^\s+/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveBefore : ''); } if (nextTag && nextTag !== 'img' && nextTag !== 'input' && (nextTag.substr(0, 1) === '/' - || ( nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) { + || (nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) { str = str.replace(/\s+$/, options.conservativeCollapse ? ' ' : options.preserveLineBreaks ? preserveAfter : ''); } @@ -107,13 +107,13 @@ function canRemoveAttributeQuotes(value) { // http://mathiasbynens.be/notes/unquoted-attribute-values - return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/ ).test(value) && + return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value) && !(/\/$/).test(value) && // make sure trailing slash is not interpreted as HTML self-closing tag !(/\/$/).test(value); } function attributesInclude(attributes, attribute) { - for (var i = attributes.length; i--; ) { + for (var i = attributes.length; i--;) { if (attributes[i].name.toLowerCase() === attribute) { return true; } @@ -578,7 +578,7 @@ new HTMLParser(value, { html5: typeof options.html5 !== 'undefined' ? options.html5 : true, - start: function( tag, attrs, unary, unarySlash ) { + start: function(tag, attrs, unary, unarySlash) { if (isIgnoring) { buffer.push('<' + tag, attrsToMarkup(attrs), unarySlash ? '/' : '', '>'); return; @@ -615,25 +615,29 @@ var openTag = '<' + tag; var closeTag = ((unarySlash && options.keepClosingSlash) ? '/' : '') + '>'; - if ( attrs.length === 0) { + if (attrs.length === 0) { openTag += closeTag; } buffer.push(openTag); - lint && lint.testElement(tag); + if (lint) { + lint.testElement(tag); + } var token; - for ( var i = 0, len = attrs.length; i < len; i++ ) { - lint && lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped); + for (var i = 0, len = attrs.length; i < len; i++) { + if (lint) { + lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].escaped); + } token = normalizeAttribute(attrs[i], attrs, tag, unarySlash, i, options); - if ( i === len - 1 ) { + if (i === len - 1) { token += closeTag; } buffer.push(token); } }, - end: function( tag, attrs ) { + end: function(tag, attrs) { if (isIgnoring) { buffer.push(''); @@ -660,8 +664,8 @@ var isElementEmpty = currentChars === '' && tag === currentTag; if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs))) { // remove last "element" from buffer, return - for ( var i = buffer.length - 1; i >= 0; i-- ) { - if ( /^<[^\/!]/.test(buffer[i]) ) { + for (var i = buffer.length - 1; i >= 0; i--) { + if (/^<[^\/!]/.test(buffer[i])) { buffer.splice(i); break; } @@ -681,7 +685,7 @@ buffer.length = 0; currentChars = ''; }, - chars: function( text, prevTag, nextTag ) { + chars: function(text, prevTag, nextTag) { prevTag = prevTag === '' ? 'comment' : prevTag; nextTag = nextTag === '' ? 'comment' : nextTag; @@ -718,10 +722,12 @@ } } currentChars = text; - lint && lint.testChars(text); + if (lint) { + lint.testChars(text); + } buffer.push(text); }, - comment: function( text, nonStandard ) { + comment: function(text, nonStandard) { var prefix = nonStandard ? '' : '-->'; @@ -762,16 +768,16 @@ return str; } - function joinResultSegments( results, options ) { + function joinResultSegments(results, options) { var str; var maxLineLength = options.maxLineLength; - if ( maxLineLength ) { + if (maxLineLength) { var token; var lines = []; var line = ''; - for ( var i = 0, len = results.length; i < len; i++ ) { + for (var i = 0, len = results.length; i < len; i++) { token = results[i]; - if ( line.length + token.length < maxLineLength ) { + if (line.length + token.length < maxLineLength) { line += token; } else { @@ -791,7 +797,7 @@ } // for CommonJS enviroments, export everything - if ( typeof exports !== 'undefined' ) { + if (typeof exports !== 'undefined') { exports.minify = minify; } else { diff --git a/tests/minifier.js b/tests/minifier.js index 5f278b7..5cfc86d 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -270,7 +270,7 @@ }); test('cleaning class/style attributes', function() { - input = '

foo bar baz

', output; + input = '

foo bar baz

'; equal(minify(input, { cleanAttributes: true }), '

foo bar baz

'); input = '

foo bar baz

';