From: Mike Sherov Date: Tue, 16 Oct 2012 14:17:14 +0000 (-0400) Subject: enforce double quotes via JSHint. Closes gh-975 X-Git-Tag: 1.9.0b1~198 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ed9e34482a303e7e64c397f89533dbe64f51cfbf;p=jquery.git enforce double quotes via JSHint. Closes gh-975 --- diff --git a/.jshintrc b/.jshintrc index fd498d83b..1c2f7c2b0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -5,6 +5,7 @@ "expr": true, "latedef": true, "noarg": true, + "quotmark": "double", "smarttabs": true, "trailing": true, "undef": true diff --git a/grunt.js b/grunt.js index 4d94fd242..029106007 100644 --- a/grunt.js +++ b/grunt.js @@ -153,7 +153,7 @@ module.exports = function( grunt ) { }, { authUsername: config.authUsername, authToken: config.authToken, - jobName: 'jQuery commit #' + commit.substr( 0, 10 ) + '', + jobName: "jQuery commit #" + commit.substr( 0, 10 ) + "", runMax: config.runMax, "runNames[]": tests, "runUrls[]": testUrls, diff --git a/package.json b/package.json index d4585846d..ce4d9ee9e 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "grunt-compare-size": ">=0.1.0", "grunt-git-authors": ">=1.0.0", "grunt-update-submodules": ">=0.1.0", - "grunt": "~0.3.9", + "grunt": "~0.3.17", "testswarm": "0.2.2" }, "keywords": [] diff --git a/src/.jshintrc b/src/.jshintrc index 755c86a07..d75461017 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -10,7 +10,8 @@ "undef": true, "smarttabs": true, "sub": true, - "maxerr": 100 + "maxerr": 100, + "quotmark": "double" }, "globals": { "define": true, diff --git a/test/.jshintrc b/test/.jshintrc index a0dfa0ccb..9068558c4 100644 --- a/test/.jshintrc +++ b/test/.jshintrc @@ -10,7 +10,8 @@ "undef": true, "smarttabs": true, "maxerr": 100, - "sub": true + "sub": true, + "quotmark": "double" }, "globals": { "define": true, diff --git a/test/unit/ajax.js b/test/unit/ajax.js index c11b8b52f..d11cb13f7 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2674,7 +2674,7 @@ if ( jQuery.ajax && ( !isLocal || hasPHP ) ) { ok( false, "error callback called" ); } }).fail(function( _, reason ) { - strictEqual( reason, 'canceled', "Request aborted by the prefilter must fail with 'canceled' status text" ); + strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" ); }); }); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 9c3b55c21..13d680033 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -516,11 +516,11 @@ test("removeAttr(String)", function() { try { $first = jQuery("#first").attr("contenteditable", "true").removeAttr("contenteditable"); - equal( $first.attr('contenteditable'), undefined, "Remove the contenteditable attribute" ); + equal( $first.attr("contenteditable"), undefined, "Remove the contenteditable attribute" ); } catch(e) { ok( false, "Removing contenteditable threw an error (#10429)" ); } - + $first = jQuery("
"); equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" ); $first.removeAttr("Case"); diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index f0b3fdd51..6abcaf0d1 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -32,14 +32,14 @@ var output, }; } }; - + function showFlags( flags ) { if ( typeof flags === "string" ) { - return '"' + flags + '"'; + return "'" + flags + "'"; } var output = [], key; for ( key in flags ) { - output.push( '"' + key + '": ' + flags[ key ] ); + output.push( "'" + key + "': " + flags[ key ] ); } return "{ " + output.join( ", " ) + " }"; } diff --git a/test/unit/core.js b/test/unit/core.js index 3ca3c31fd..c0a719fe3 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -567,7 +567,7 @@ test("XSS via location.hash", function() { }; try { // This throws an error because it's processed like an id - jQuery( '#' ).appendTo("#qunit-fixture"); + jQuery( "#" ).appendTo("#qunit-fixture"); } catch (err) { jQuery["_check9521"](true); } diff --git a/test/unit/data.js b/test/unit/data.js index 765aefcd2..01d042e4e 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -570,7 +570,10 @@ test("jQuery.data supports interoperable hyphenated/camelCase get/set of propert "an-object": {}, "bool-true": true, "bool-false": false, - "some-json": '{ "foo": "bar" }', + // JSHint enforces double quotes, + // but JSON strings need double quotes to parse + // so we need escaped double quotes here + "some-json": "{ \"foo\": \"bar\" }", "num-1-middle": true, "num-end-2": true, "2-num-start": true @@ -597,7 +600,10 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert "an-object": {}, "bool-true": true, "bool-false": false, - "some-json": '{ "foo": "bar" }' + // JSHint enforces double quotes, + // but JSON strings need double quotes to parse + // so we need escaped double quotes here + "some-json": "{ \"foo\": \"bar\" }" }; expect( 27 ); @@ -650,7 +656,7 @@ test( "Only check element attributes once when calling .data() - #8909", functio test( "JSON data- attributes can have newlines", function() { expect(1); - + var x = jQuery("
"); equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" ); x.remove(); diff --git a/test/unit/effects.js b/test/unit/effects.js index 366416cc2..a2dbb06b2 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -429,7 +429,7 @@ asyncTest( "animate option { queue: 'name' }", function() { order = []; foo.animate( { width: origWidth + 100 }, { - queue: 'name', + queue: "name", duration: 1, complete: function() { @@ -1369,10 +1369,10 @@ test("animate will scale margin properties individually", function() { // clean up for next test foo.css({ - "marginLeft": '', - "marginRight": '', - "marginTop": '', - "marginBottom": '' + "marginLeft": "", + "marginRight": "", + "marginTop": "", + "marginBottom": "" }); start(); }); @@ -1486,9 +1486,9 @@ test( "animate should set display for disconnected nodes", function() { // parentNode = null jQuery("
"), - jQuery('
'), + jQuery("
"), - jQuery('
') + jQuery("
") ]; strictEqual( elems[ 0 ].show()[ 0 ].style.display, "block", "set display with show() for element with parentNode = document fragment" ); @@ -1532,7 +1532,7 @@ asyncTest("Animation callback should not show animated element as animated (#715 foo.animate({ opacity: 0 }, 100, function() { - ok( !foo.is(':animated'), "The element is not animated" ); + ok( !foo.is(":animated"), "The element is not animated" ); start(); }); }); @@ -1563,7 +1563,7 @@ asyncTest( "hide, fadeOut and slideUp called on element width height and width = elems = jQuery(); for ( ; i < 5; i++ ) { - elems = elems.add('
'); + elems = elems.add("
"); } foo.append( elems ); diff --git a/test/unit/event.js b/test/unit/event.js index 667920475..e626ede1d 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -861,7 +861,7 @@ test("withinElement implemented with jQuery.contains()", function() { expect(1); - jQuery("#qunit-fixture").append('
'); + jQuery("#qunit-fixture").append("
"); jQuery("#jc-outer").bind("mouseenter mouseleave", function( event ) { @@ -934,8 +934,8 @@ test("trigger() shortcuts", function() { elem.remove(); // test that special handlers do not blow up with VML elements (#7071) - jQuery('').appendTo('head'); - jQuery(' ').appendTo('#form'); + jQuery("").appendTo("head"); + jQuery(" ").appendTo("#form"); jQuery("#oval").click().keydown(); }); @@ -1003,21 +1003,21 @@ test("trigger(type, [data], [fn])", function() { }; - $elem.live('mouseenter', function(){ - ok( true, 'Trigger mouseenter bound by live' ); + $elem.live("mouseenter", function(){ + ok( true, "Trigger mouseenter bound by live" ); }); - $elem.live('mouseleave', function(){ - ok( true, 'Trigger mouseleave bound by live' ); + $elem.live("mouseleave", function(){ + ok( true, "Trigger mouseleave bound by live" ); }); - $elem.trigger('mouseenter'); + $elem.trigger("mouseenter"); - $elem.trigger('mouseleave'); + $elem.trigger("mouseleave"); - $elem.die('mouseenter'); + $elem.die("mouseenter"); - $elem.die('mouseleave'); + $elem.die("mouseleave"); // Triggers handlrs and native // Trigger 5 @@ -1264,7 +1264,7 @@ test(".trigger() doesn't bubble load event (#10717)", function() { }); // It's not an image, but as long as it fires load... - jQuery( '' ) + jQuery("") .appendTo( "body" ) .on( "load", function() { ok( true, "load fired on img" ); @@ -1279,10 +1279,10 @@ test("Delegated events in SVG (#10791)", function() { expect(2); var svg = jQuery( - ''+ - ''+ - ''+ - '' + "" + + "" + + "" + + "" ).appendTo( "body" ); jQuery( "body" ) @@ -1305,9 +1305,9 @@ test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", functi // Alias names like "id" cause havoc var form = jQuery( - '
'+ - ''+ - '
' + "
" + + "" + + "
" ) .on( "submit", function( event ) { event.preventDefault(); @@ -1323,7 +1323,7 @@ test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", functi .end() .off("submit"); - form.append(''); + form.append(""); jQuery("body") .on( "submit", "#myform", function() { ok( true, "delegated id selector with aliased disabled" ); @@ -1334,7 +1334,7 @@ test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", functi .off("submit"); form - .append( '' ) + .append( "" ) .on( "click", "#nestyDisabledBtn", function() { ok( true, "click on enabled/disabled button with nesty elements" ); }) @@ -1360,10 +1360,10 @@ test("Submit event can be stopped (#11049)", function() { // Since we manually bubble in IE, make sure inner handlers get a chance to cancel var form = jQuery( - '
'+ - ''+ - ''+ - '
' + "
" + + "" + + "" + + "
" ) .appendTo("body"); @@ -2255,14 +2255,14 @@ test(".delegate()/.undelegate()", function() { test("jQuery.off using dispatched jQuery.Event", function() { expect(1); - var markup = jQuery( '

target

' ), + var markup = jQuery("

target

"), count = 0; markup .on( "click.name", "a", function( event ) { equal( ++count, 1, "event called once before removal" ); jQuery().off( event ); }) - .find( "a" ).click().click().end() + .find("a").click().click().end() .remove(); }); @@ -2708,7 +2708,7 @@ test("special bind/delegate name mapping", function() { }; // Ensure a special event isn't removed by its mapped type - jQuery( '

Gut Feeling

' ) + jQuery( "

Gut Feeling

" ) .on( "click", jQuery.noop ) .on( "gutfeeling", jQuery.noop ) .off( "click" ) @@ -2716,14 +2716,14 @@ test("special bind/delegate name mapping", function() { .remove(); // Ensure special events are removed when only a namespace is provided - jQuery( '

Gut Feeling

' ) + jQuery( "

Gut Feeling

" ) .on( "gutfeeling.Devo", jQuery.noop ) .off( ".Devo" ) .trigger( "gutfeeling" ) .remove(); // Ensure .one() events are removed after their maiden voyage - jQuery( '

Gut Feeling

' ) + jQuery( "

Gut Feeling

" ) .one( "gutfeeling", jQuery.noop ) .trigger( "gutfeeling" ) // This one should .trigger( "gutfeeling" ) // This one should not @@ -2805,7 +2805,7 @@ test("fixHooks extensions", function() { $fixture.bind( "click", function( event ) { ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" ); }); - fireNative( $fixture[0], 'click' ); + fireNative( $fixture[0], "click" ); $fixture.unbind( "click" ); jQuery.event.fixHooks.click = { @@ -2819,7 +2819,7 @@ test("fixHooks extensions", function() { $fixture.bind( "click", function( event ) { equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" ); }); - fireNative( $fixture[0], 'click' ); + fireNative( $fixture[0], "click" ); delete jQuery.event.fixHooks.click; $fixture.unbind( "click" ).remove(); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 738fdf376..669d52688 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -190,7 +190,7 @@ test("wrap(String) consecutive elements (#10177)", function() { targets.each(function() { var $this = jQuery(this); - ok( $this.parent().is('.wrapper'), "Check each elements parent is correct (.wrapper)" ); + ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" ); equal( $this.siblings().length, 0, "Each element should be wrapped individually" ); }); }); @@ -447,7 +447,7 @@ var testAppend = function(valueObj) { ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" ); QUnit.reset(); - var $input = jQuery("").attr({ "type": "checkbox", "checked": true }).appendTo('#testForm'); + var $input = jQuery("").attr({ "type": "checkbox", "checked": true }).appendTo("#testForm"); equal( $input[0].checked, true, "A checked checkbox that is appended stays checked" ); QUnit.reset(); @@ -746,8 +746,8 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() { if ( jQuery.getScript ) { stop(); - jQuery.getScript('data/test.js', function() { - jQuery('script[src*="data\\/test\\.js"]').remove(); + jQuery.getScript("data/test.js", function() { + jQuery("script[src*='data\\/test\\.js']").remove(); start(); }); } @@ -919,7 +919,7 @@ test("before and after w/ empty object (#10812)", function() { test("before and after on disconnected node (#10517)", function() { expect(2); - + equal( jQuery("").before("
").length, 2, "before() returned all elements" ); equal( jQuery("").after("
").length, 2, "after() returned all elements" ); }); @@ -1242,7 +1242,7 @@ test("clone()", function() { divEvt.remove(); // Test both html() and clone() for ").html(''); + div = jQuery("
").html(""); clone = div.clone(true); equal( clone.length, 1, "One element cloned" ); @@ -1713,25 +1713,25 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() { test( "jQuery.html - execute scripts escaped with html comment or CDATA (#9221)", function() { expect( 3 ); jQuery( [ - '' + "" ].join ( "\n" ) ).appendTo( "#qunit-fixture" ); jQuery( [ - '' + "" ].join ( "\n" ) ).appendTo( "#qunit-fixture" ); jQuery( [ - '' + "" ].join ( "\n" ) ).appendTo( "#qunit-fixture" ); }); @@ -1739,7 +1739,7 @@ test("jQuery.buildFragment - plain objects are not a document #8950", function() expect(1); try { - jQuery('', {}); + jQuery("", {}); ok( true, "Does not allow attribute object to be treated like a doc object"); } catch (e) {} @@ -1930,7 +1930,7 @@ test("checked state is cloned with clone()", function(){ var elem = jQuery.parseHTML("")[0]; elem.checked = false; equal( jQuery(elem).clone().attr("id","clone")[0].checked, false, "Checked false state correctly cloned" ); - + elem = jQuery.parseHTML("")[0]; elem.checked = true; equal( jQuery(elem).clone().attr("id","clone")[0].checked, true, "Checked true state correctly cloned" ); diff --git a/test/unit/offset.js b/test/unit/offset.js index ab44416d0..7a1d719f0 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -476,15 +476,15 @@ test("offsetParent", function(){ test("fractions (see #7730 and #7885)", function() { expect(2); - jQuery('body').append('
'); + jQuery("body").append("
"); var expected = { "top": 1000, "left": 1000 }; - var div = jQuery('#fractions'); + var div = jQuery("#fractions"); div.css({ - "position": 'absolute', - "left": '1000.7432222px', - "top": '1000.532325px', + "position": "absolute", + "left": "1000.7432222px", + "top": "1000.532325px", "width": 100, "height": 100 }); diff --git a/test/unit/selector.js b/test/unit/selector.js index 60d3e297d..899d06ee1 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -48,30 +48,30 @@ if ( jQuery.css ) { t( "Is Not Hidden", "#qunit-fixture:hidden", [] ); t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] ); - var $div = jQuery('
').appendTo("body"); + var $div = jQuery("
").appendTo("body"); $div.css({ fontSize: 0, lineHeight: 0 });// IE also needs to set font-size and line-height to 0 $div.css( "width", 1 ).css( "height", 0 ); - t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] ); - t( "Is Not Visible", '#nothiddendivchild:hidden', [] ); + t( "Is Visible", "#nothiddendivchild:visible", ["nothiddendivchild"] ); + t( "Is Not Visible", "#nothiddendivchild:hidden", [] ); $div.css( "width", 0 ).css( "height", 1 ); - t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] ); - t( "Is Not Visible", '#nothiddendivchild:hidden', [] ); + t( "Is Visible", "#nothiddendivchild:visible", ["nothiddendivchild"] ); + t( "Is Not Visible", "#nothiddendivchild:hidden", [] ); $div.css( "width", 1 ).css( "height", 1 ); - t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] ); - t( "Is Not Visible", '#nothiddendivchild:hidden', [] ); + t( "Is Visible", "#nothiddendivchild:visible", ["nothiddendivchild"] ); + t( "Is Not Visible", "#nothiddendivchild:hidden", [] ); $div.remove(); }); } test("disconnected nodes", function() { expect( 4 ); - var $opt = jQuery('').attr("value", "whipit").appendTo("#qunit-fixture").detach(); + var $opt = jQuery("").attr("value", "whipit").appendTo("#qunit-fixture").detach(); equal( $opt.val(), "whipit", "option value" ); equal( $opt.is(":selected"), false, "unselected option" ); $opt.attr("selected", true); equal( $opt.is(":selected"), true, "selected option" ); - var $div = jQuery( '
' ); + var $div = jQuery("
"); equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnect nodes." ); }); @@ -105,7 +105,7 @@ testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQue i = 0; for ( ; i < f.length; i++ ) { - s += (s && ",") + '"' + f[i].id + '"'; + s += (s && ",") + "'" + f[i].id + "'"; } deepEqual(f, q.apply( q, c ), a + " (" + b + ")"); @@ -167,7 +167,7 @@ testIframe("selector/sizzle_cache", "Sizzle cache collides with multiple Sizzles var $cached = window["$cached"]; expect(3); - deepEqual( $cached('.test a').get(), [ document.getElementById('collision') ], "Select collision anchor with first sizzle" ); - equal( jQuery('.evil a').length, 0, "Select nothing with second sizzle" ); - equal( jQuery('.evil a').length, 0, "Select nothing again with second sizzle" ); + deepEqual( $cached(".test a").get(), [ document.getElementById("collision") ], "Select collision anchor with first sizzle" ); + equal( jQuery(".evil a").length, 0, "Select nothing with second sizzle" ); + equal( jQuery(".evil a").length, 0, "Select nothing again with second sizzle" ); }); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index e1d982c80..dd957c28b 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -107,7 +107,7 @@ test("is() with positional selectors", function() { expect(23); var html = jQuery( - '

firsttest

' + "

firsttest

" ).appendTo( "body" ), isit = function(sel, match, expect) { equal( jQuery( sel ).is( match ), expect, "jQuery( " + sel + " ).is( " + match + " )" ); @@ -234,16 +234,16 @@ test("filter(jQuery)", function() { test("filter() with positional selectors", function() { expect(19); - var html = jQuery('' + - '

' + - '' + - 'first' + - '' + - '' + - 'test' + - '' + - '' + - '

').appendTo( "body" ), + var html = jQuery( "" + + "

" + + "" + + "first" + + "" + + "" + + "test" + + "" + + "" + + "

" ).appendTo( "body" ), filterit = function(sel, filter, length) { equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); };