From db8a2de54da6d82cecd6557602c6b57153f43884 Mon Sep 17 00:00:00 2001 From: AbdealiJK Date: Wed, 31 Aug 2016 20:48:04 +0530 Subject: [PATCH] JSHintBear: Deprecate - "globalstrict" -> "strict" The `strict` parameter has been created rather than the `globalstrict` which was used earlier. Deprecate this in the bear also. Fixes https://github.com/coala-analyzer/coala-bears/issues/270 --- bears/js/JSHintBear.py | 18 +++++++++++++----- tests/js/JSHintBearTest.py | 17 +++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/bears/js/JSHintBear.py b/bears/js/JSHintBear.py index 2816c52b28..1c0e75209c 100644 --- a/bears/js/JSHintBear.py +++ b/bears/js/JSHintBear.py @@ -43,6 +43,9 @@ class JSHintBear: @staticmethod @deprecate_settings(es_version='use_es6_syntax', + javascript_strictness=( + "allow_global_strict", + lambda x: "global" if x else True), cyclomatic_complexity='maxcomplexity', allow_unused_variables=('prohibit_unused', negate), max_parameters='maxparams', @@ -90,7 +93,6 @@ def generate_config(filename, file, allow_debugger: bool=False, allow_assignment_comparisions: bool=False, allow_eval: bool=False, - allow_global_strict: bool=False, allow_increment: bool=False, allow_proto: bool=False, allow_scripturls: bool=False, @@ -98,6 +100,7 @@ def generate_config(filename, file, allow_this_statements: bool=False, allow_with_statements: bool=False, use_mozilla_extension: bool=False, + javascript_strictness: bool_or_str=True, allow_noyield: bool=False, allow_eqnull: bool=False, allow_last_semicolon: bool=False, @@ -184,9 +187,6 @@ def generate_config(filename, file, :param allow_eval: This options suppresses warnings about the use of ``eval`` function. - :param allow_global_strict: - This option suppresses warnings about the use of global strict - mode. :param allow_increment: This option suppresses warnings about the use of unary increment and decrement operators. @@ -209,6 +209,14 @@ def generate_config(filename, file, :param use_mozilla_extension: This options tells JSHint that your code uses Mozilla JavaScript extensions. + :param javascript_strictness: + Determines what sort of strictness to use in the JavaScript code. + The possible options are: + + - "global" - there must be a ``"use strict";`` at global level + - "implied" - lint the code as if there is a ``"use strict";`` + - "False" - disable warnings about strict mode + - "True" - there must be a ``"use strict";`` at function level :param allow_noyield: This option suppresses warnings about generator functions with no ``yield`` statement in them. @@ -333,7 +341,7 @@ def generate_config(filename, file, "debug": allow_debugger, "boss": allow_assignment_comparisions, "evil": allow_eval, - "globalstrict": allow_global_strict, + "strict": javascript_strictness, "plusplus": allow_increment, "proto": allow_proto, "scripturl": allow_scripturls, diff --git a/tests/js/JSHintBearTest.py b/tests/js/JSHintBearTest.py index 7d2e53c261..85a3b4df7a 100644 --- a/tests/js/JSHintBearTest.py +++ b/tests/js/JSHintBearTest.py @@ -21,7 +21,10 @@ }()); """ -test_es6 = """ +# Test strictness and ES6 +test_file4 = """ +"use strict"; + var foo = { bar: 1, baz: 2 @@ -30,6 +33,7 @@ console.log(bar, baz); """ + jshintconfig = os.path.join(os.path.dirname(__file__), "test_files", "jshintconfig.json") @@ -42,7 +46,8 @@ "shadow": "False", "allow_last_semicolon": "True", "es_version": 3, - "allow_latedef": "no_func"} + "allow_latedef": "no_func", + "javascript_strictness": "False"} JSHintBearTest = verify_local_bear(JSHintBear, @@ -67,11 +72,11 @@ JSHintBearDeprecationTest = verify_local_bear( JSHintBear, valid_files=(), - invalid_files=(test_es6,), - settings={"use_es6_syntax": 'False'}) + invalid_files=(test_file4,), + settings={"use_es6_syntax": 'False', "allow_global_strict": 'False'}) JSHintBearDeprecation2Test = verify_local_bear( JSHintBear, - valid_files=(test_es6,), + valid_files=(test_file4,), invalid_files=(), - settings={"use_es6_syntax": 'True'}) + settings={"use_es6_syntax": 'True', "allow_global_strict": 'True'})