From 3add2634b9a263ea32702976ad663f9dcfdaa8c6 Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Wed, 19 Oct 2016 12:02:08 -0400 Subject: [PATCH] [[DOCS]] Improve warning message for W040 (#3052) Expand the message to describe the rationale for the warning. --- src/messages.js | 3 ++- tests/regression/thirdparty.js | 12 ++++++------ tests/unit/options.js | 16 ++++++++-------- tests/unit/parser.js | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/messages.js b/src/messages.js index b8e716d651..0c910afa1f 100644 --- a/src/messages.js +++ b/src/messages.js @@ -119,7 +119,8 @@ var warnings = { W037: "'{a}' is a statement label.", W038: "'{a}' used out of scope.", W039: "'{a}' is not allowed.", - W040: "Possible strict violation.", + W040: "If a strict mode function is executed using function invocation, " + + "its 'this' value will be undefined.", W041: "Use '{a}' to compare with '{b}'.", W042: "Avoid EOL escaping.", W043: "Bad escaping of EOL. Use option multistr if needed.", diff --git a/tests/regression/thirdparty.js b/tests/regression/thirdparty.js index 75fe8941ba..a76995f0cc 100644 --- a/tests/regression/thirdparty.js +++ b/tests/regression/thirdparty.js @@ -152,7 +152,7 @@ exports.lodash_0_6_1 = function (test) { }; TestRun(test) - .addError(168, "Possible strict violation.") + .addError(168, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .addError(170, "Missing '()' invoking a constructor.") .addError(632, "Missing semicolon.") .addError(920, "Reassignment of 'isArguments', which is is a function. Use 'var' or 'let' to declare bindings that may change.") @@ -164,15 +164,15 @@ exports.lodash_0_6_1 = function (test) { .addError(1159, "'isArr' used out of scope.") .addError(1490, "Use '===' to compare with '0'.") .addError(1670, "Missing semicolon.") - .addError(3374, "Possible strict violation.") + .addError(3374, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .addError(3377, "Missing '()' invoking a constructor.") .addError(3384, "Missing semicolon.") .addError(3677, "Missing '()' invoking a constructor.") .addError(3683, "Missing '()' invoking a constructor.") - .addError(3825, "Possible strict violation.") - .addError(4225, "Possible strict violation.") - .addError(4226, "Possible strict violation.") - .addError(4242, "Possible strict violation.") + .addError(3825, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") + .addError(4225, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") + .addError(4226, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") + .addError(4242, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(src, options, globals); test.done(); diff --git a/tests/unit/options.js b/tests/unit/options.js index 8a0b2e745d..1b88db4f95 100644 --- a/tests/unit/options.js +++ b/tests/unit/options.js @@ -1705,7 +1705,7 @@ exports.strict = function (test) { // Test for strict mode violations run = TestRun(test) - .addError(4, 'Possible strict violation.') + .addError(4, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .addError(7, 'Strict violation.') .addError(8, 'Strict violation.'); run.test(src, { es3: true, strict: true }); @@ -1992,9 +1992,9 @@ exports.validthis = function (test) { var src = fs.readFileSync(__dirname + '/fixtures/strict_this.js', 'utf8'); TestRun(test) - .addError(8, "Possible strict violation.") - .addError(9, "Possible strict violation.") - .addError(11, "Possible strict violation.") + .addError(8, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") + .addError(9, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") + .addError(11, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(src, {es3: true}); src = fs.readFileSync(__dirname + '/fixtures/strict_this2.js', 'utf8'); @@ -3596,12 +3596,12 @@ exports.module.behavior = function(test) { TestRun(test) .addError(0, "The 'module' option is only available when linting ECMAScript 6 code.") .addError(1, "Expected an identifier and instead saw 'package' (a reserved word).") - .addError(2, "Possible strict violation.") + .addError(2, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(code, { module: true }); TestRun(test) .addError(1, "Expected an identifier and instead saw 'package' (a reserved word).") - .addError(2, "Possible strict violation.") + .addError(2, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(code, { module: true, esnext: true }); code = [ @@ -3613,14 +3613,14 @@ exports.module.behavior = function(test) { TestRun(test) .addError(1, "The 'module' option is only available when linting ECMAScript 6 code.") .addError(2, "Expected an identifier and instead saw 'package' (a reserved word).") - .addError(3, "Possible strict violation.") + .addError(3, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(code); code[0] = "/* jshint module: true, esnext: true */"; TestRun(test) .addError(2, "Expected an identifier and instead saw 'package' (a reserved word).") - .addError(3, "Possible strict violation.") + .addError(3, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(code); test.done(); diff --git a/tests/unit/parser.js b/tests/unit/parser.js index 67c0aa8f66..01b4e9acae 100644 --- a/tests/unit/parser.js +++ b/tests/unit/parser.js @@ -6126,7 +6126,7 @@ exports["class method this"] = function (test) { ]; TestRun(test) - .addError(10, "Possible strict violation.") + .addError(10, "If a strict mode function is executed using function invocation, its 'this' value will be undefined.") .test(code, {esnext: true}); test.done();