From c48c397bddef718760a52aeac119a4d589bbd6aa Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 9 Mar 2014 09:49:35 +0200 Subject: [PATCH] Fix JSCS warnings. --- Gruntfile.js | 5 +-- master.js | 2 +- src/htmllint.js | 20 ++++++---- src/htmlminifier.js | 15 ++++---- src/htmlparser.js | 34 +++++++++++------ tests/minifier.js | 91 +++++++++++++++++++++++---------------------- 6 files changed, 92 insertions(+), 75 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 07675a4..ba89a53 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -60,9 +60,7 @@ module.exports = function(grunt) { banner: '<%= banner %>' }, dist: { - src: ['src/htmlparser.js', - 'src/htmlminifier.js', - 'src/htmllint.js'], + src: ['src/htmlparser.js', 'src/htmlminifier.js', 'src/htmllint.js'], dest: 'dist/htmlminifier.js' } }, @@ -82,7 +80,6 @@ module.exports = function(grunt) { } } - }); require('load-grunt-tasks')(grunt, { scope: 'devDependencies' }); diff --git a/master.js b/master.js index 2ac8845..b8b51ff 100644 --- a/master.js +++ b/master.js @@ -60,7 +60,7 @@ lint.populate(byId('report')); } } - catch(err) { + catch (err) { byId('output').value = ''; byId('stats').innerHTML = '' + escapeHTML(err) + ''; } diff --git a/src/htmllint.js b/src/htmllint.js index cbcf925..dd3d0b6 100644 --- a/src/htmllint.js +++ b/src/htmllint.js @@ -74,12 +74,14 @@ if (isDeprecatedElement(tag)) { this.log.push( '
  • Found deprecated <' + - tag + '> element
  • '); + tag + '> element' + ); } else if (isPresentationalElement(tag)) { this.log.push( '
  • Found presentational <' + - tag + '> element
  • '); + tag + '> element' + ); } else { this.checkRepeatingElement(tag); @@ -105,21 +107,25 @@ if (isEventAttribute(attrName)) { this.log.push( '
  • Found event attribute (', - attrName, ') on <' + tag + '> element
  • '); + attrName, ') on <' + tag + '> element' + ); } else if (isDeprecatedAttribute(tag, attrName)) { this.log.push( '
  • Found deprecated ' + - attrName + ' attribute on <', tag, '> element
  • '); + attrName + ' attribute on <', tag, '> element' + ); } else if (isStyleAttribute(attrName)) { this.log.push( - '
  • Found style attribute on <', tag, '> element
  • '); + '
  • Found style attribute on <', tag, '> element
  • ' + ); } else if (isInaccessibleAttribute(attrName, attrValue)) { this.log.push( - '
  • Found inaccessible attribute '+ - '(on <', tag, '> element)
  • '); + '
  • Found inaccessible attribute ' + + '(on <', tag, '> element)
  • ' + ); } }; diff --git a/src/htmlminifier.js b/src/htmlminifier.js index f8272bd..858caa9 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -190,12 +190,12 @@ var reStartDelimiter = { // account for js + html comments (e.g.: //\s*$/, - 'style': /\s*-->\s*$/ + script: /\s*(?:\/\/)?\s*-->\s*$/, + style: /\s*-->\s*$/ }; function removeComments(text, tag) { return text.replace(reStartDelimiter[tag], '').replace(reEndDelimiter[tag], ''); @@ -271,7 +271,6 @@ return (' ' + attrFragment); } - function setDefaultTesters(options) { var defaultTesters = ['canCollapseWhitespace','canTrimWhitespace']; @@ -395,7 +394,8 @@ if (options.removeComments) { if (isConditionalComment(text)) { text = ''; - } else if (isIgnoredComment(text)) { + } + else if (isIgnoredComment(text)) { text = ''; } else { @@ -425,7 +425,8 @@ // for CommonJS enviroments, export everything if ( typeof exports !== 'undefined' ) { exports.minify = minify; - } else { + } + else { global.minify = minify; } diff --git a/src/htmlparser.js b/src/htmlparser.js index 7814360..6225ebe 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -113,12 +113,13 @@ if ( match ) { html = html.substring( match[0].length ); match[0].replace( endTag, parseEndTag ); - prevTag = '/'+match[1]; + prevTag = '/' + match[1]; chars = false; } // Start tag: - } else if ( html.indexOf('<') === 0 ) { + } + else if ( html.indexOf('<') === 0 ) { match = html.match( startTag ); if ( match ) { @@ -139,11 +140,13 @@ tagMatch = html.match( startTag ); if (tagMatch) { nextTag = tagMatch[1]; - } else { + } + else { tagMatch = html.match( endTag ); if (tagMatch) { - nextTag = '/'+tagMatch[1]; - } else { + nextTag = '/' + tagMatch[1]; + } + else { nextTag = ''; } } @@ -154,7 +157,8 @@ } - } else { + } + else { stackedTag = stack.last().toLowerCase(); reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)<\/' + stackedTag + '[^>]*>', 'i')); @@ -200,7 +204,8 @@ if ( !unary ) { stack.push( tagName ); - } else { + } + else { unarySlash = tag.match( endingSlash ); } @@ -231,7 +236,8 @@ // If no tag name is provided, clean shop if ( !tagName ) { pos = 0; - } else { // Find the closest opened tag of the same type + } + else { // Find the closest opened tag of the same type for ( pos = stack.length - 1; pos >= 0; pos-- ) { if ( stack[ pos ] === tagName ) { break; @@ -296,13 +302,16 @@ if ( !doc ) { if ( typeof DOMDocument !== 'undefined' ) { doc = new DOMDocument(); - } else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) { + } + else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) { doc = document.implementation.createDocument('', '', null); - } else if ( typeof ActiveX !== 'undefined' ) { + } + else if ( typeof ActiveX !== 'undefined' ) { doc = new ActiveXObject('Msxml.DOMDocument'); } - } else { + } + else { doc = doc.ownerDocument || doc.getOwnerDocument && doc.getOwnerDocument() || doc; @@ -353,7 +362,8 @@ if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) { one[ structure[ tagName ] ].appendChild( elem ); - } else if ( curParentNode && curParentNode.appendChild ) { + } + else if ( curParentNode && curParentNode.appendChild ) { curParentNode.appendChild( elem ); } diff --git a/tests/minifier.js b/tests/minifier.js index 8e5343c..5f52892 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -13,8 +13,8 @@ equal(minify('

    xxx

    '), '

    xxx

    '); equal(minify('

    xxx

    '), '

    xxx

    '); - input = '
    '+ - 'i\'m 10 levels deep'+ + input = '
    ' + + 'i\'m 10 levels deep' + '
    '; equal(minify(input), input); @@ -29,16 +29,19 @@ equal(minify('

    Click me

    '), '

    Click me

    '); equal(minify(''), ''); equal(minify('
    [fallback image]
    '), - '
    [fallback image]
    '); + '
    [fallback image]
    ' + ); equal(minify(''), ''); equal(minify(''), ''); equal(minify('
    '), - '
    '); + '
    ' + ); // https://github.com/kangax/html-minifier/issues/41 equal(minify(''), - ''); + '' + ); // https://github.com/kangax/html-minifier/issues/40 equal(minify('[\']["]'), '[\']["]'); @@ -82,19 +85,19 @@ equal(minify('

    blah

    \n\n\n '), '

    blah

    '); // tags from collapseWhitespaceSmart() ['a', 'b', 'big', 'button', 'code', 'em', 'font', 'i', 'kbd', 'mark', 'q', 's', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u'].forEach(function(el){ - equal(minify('

    foo <'+el+'>baz bar

    ', {collapseWhitespace: true}), '

    foo <'+el+'>baz bar

    '); - equal(minify('

    foo<'+el+'>bazbar

    ', {collapseWhitespace: true}), '

    foo<'+el+'>bazbar

    '); - equal(minify('

    foo <'+el+'>bazbar

    ', {collapseWhitespace: true}), '

    foo <'+el+'>bazbar

    '); - equal(minify('

    foo<'+el+'>baz bar

    ', {collapseWhitespace: true}), '

    foo<'+el+'>baz bar

    '); - equal(minify('

    foo <'+el+'> baz bar

    ', {collapseWhitespace: true}), '

    foo <'+el+'>baz bar

    '); - equal(minify('

    foo<'+el+'> baz bar

    ', {collapseWhitespace: true}), '

    foo<'+el+'>bazbar

    '); - equal(minify('

    foo <'+el+'> baz bar

    ', {collapseWhitespace: true}), '

    foo <'+el+'>bazbar

    '); - equal(minify('

    foo<'+el+'> baz bar

    ', {collapseWhitespace: true}), '

    foo<'+el+'>baz bar

    '); + equal(minify('

    foo <' + el + '>baz bar

    ', { collapseWhitespace: true }), '

    foo <' + el + '>baz bar

    '); + equal(minify('

    foo<' + el + '>bazbar

    ', { collapseWhitespace: true }), '

    foo<' + el + '>bazbar

    '); + equal(minify('

    foo <' + el + '>bazbar

    ', { collapseWhitespace: true }), '

    foo <' + el + '>bazbar

    '); + equal(minify('

    foo<' + el + '>baz bar

    ', { collapseWhitespace: true }), '

    foo<' + el + '>baz bar

    '); + equal(minify('

    foo <' + el + '> baz bar

    ', { collapseWhitespace: true }), '

    foo <' + el + '>baz bar

    '); + equal(minify('

    foo<' + el + '> baz bar

    ', { collapseWhitespace: true }), '

    foo<' + el + '>bazbar

    '); + equal(minify('

    foo <' + el + '> baz bar

    ', { collapseWhitespace: true }), '

    foo <' + el + '>bazbar

    '); + equal(minify('

    foo<' + el + '> baz bar

    ', { collapseWhitespace: true }), '

    foo<' + el + '>baz bar

    '); }); - equal(minify('

    foo bar

    ', {collapseWhitespace: true}), '

    foo bar

    '); - equal(minify('

    foobar

    ', {collapseWhitespace: true}), '

    foobar

    '); - equal(minify('

    foo bar

    ', {collapseWhitespace: true}), '

    foo bar

    '); - equal(minify('

    foo bar

    ', {collapseWhitespace: true}), '

    foo bar

    '); + equal(minify('

    foo bar

    ', { collapseWhitespace: true }), '

    foo bar

    '); + equal(minify('

    foobar

    ', { collapseWhitespace: true }), '

    foobar

    '); + equal(minify('

    foo bar

    ', { collapseWhitespace: true }), '

    foo bar

    '); + equal(minify('

    foo bar

    ', { collapseWhitespace: true }), '

    foo bar

    '); }); test('doctype normalization', function() { @@ -169,8 +172,8 @@ input = ''; - output = ''; equal(minify(input, { removeComments: true }), output); @@ -237,7 +240,7 @@ input = '

    x

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

    x

    '); - input = '

    x

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

    x

    '); @@ -634,16 +637,16 @@ test('removing optional tags in tables', function(){ - input = ''+ - ''+ - ''+ - ''+ + input = '
    foobar
    bazqux
    boomoo
    ' + + '' + + '' + + '' + '
    foobar
    bazqux
    boomoo
    '; - output = ''+ - '
    foobar'+ - '
    bazqux'+ - '
    boomoo'+ + output = '' + + '
    foobar' + + '
    bazqux' + + '
    boomoo' + '
    '; equal(minify(input, { removeOptionalTags: true }), output); @@ -657,20 +660,20 @@ // example from htmldog.com input = ''; output = ''; @@ -747,15 +750,15 @@ test('source', function() { - input = '