From 061d4332fba9a048d50c79f2c52fc9a5af653609 Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Wed, 16 Nov 2016 02:38:07 +0200 Subject: [PATCH] Update PR with JS support --- .../{ => allow-fast-null-checks}/test.js.lint | 18 +++ .../allow-fast-null-checks/tslint.json | 3 + .../no-unused-expression/default/test.js.lint | 133 ++++++++++++++++++ 3 files changed, 154 insertions(+) rename test/rules/no-unused-expression/{ => allow-fast-null-checks}/test.js.lint (81%) create mode 100644 test/rules/no-unused-expression/default/test.js.lint diff --git a/test/rules/no-unused-expression/test.js.lint b/test/rules/no-unused-expression/allow-fast-null-checks/test.js.lint similarity index 81% rename from test/rules/no-unused-expression/test.js.lint rename to test/rules/no-unused-expression/allow-fast-null-checks/test.js.lint index 80e8e7bd054..b2386eac84a 100644 --- a/test/rules/no-unused-expression/test.js.lint +++ b/test/rules/no-unused-expression/allow-fast-null-checks/test.js.lint @@ -109,4 +109,22 @@ a => fun2(a); "use strct"; ~~~~~~~~~~~~ [0] +afterEach((el) => { + el && el.remove(); +}); + +checkParams((a, b) => { + (a || required('a')) && (b || required('b')); +}); + +checkParams((a, b) => { + ((a && b) || required('a, b')); +}); + +function interactionHandler(e) { + // fails in all cases since logical NOT operator is redundant + e && !e.preventDefault(); + ~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +} + [0]: expected an assignment or function call diff --git a/test/rules/no-unused-expression/allow-fast-null-checks/tslint.json b/test/rules/no-unused-expression/allow-fast-null-checks/tslint.json index a0cf399bd23..c8a2a238f40 100644 --- a/test/rules/no-unused-expression/allow-fast-null-checks/tslint.json +++ b/test/rules/no-unused-expression/allow-fast-null-checks/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-unused-expression": [true, "allow-fast-null-checks"] + }, + "jsRules": { + "no-unused-expression": [true, "allow-fast-null-checks"] } } diff --git a/test/rules/no-unused-expression/default/test.js.lint b/test/rules/no-unused-expression/default/test.js.lint new file mode 100644 index 00000000000..936dd446696 --- /dev/null +++ b/test/rules/no-unused-expression/default/test.js.lint @@ -0,0 +1,133 @@ +"use strict"; +'use asm'; +"ngInject"; +''; + +function fun1() { + "use strict"; + 'someOtherDirective'; + return 0; +} + +(function() { "directive"; +'foo' +'directive2' +console.log('foo'); +'notdirective'; +~~~~~~~~~~~~~~~ [0] +})(); + +const a = () => { +'use strict'; "use cool"; "use lint"; var a = 1; "notdirective"; } + ~~~~~~~~~~~~~~~ [0] + +function fun2(a) { + return 0; +} + +function fun3(a, b) { + return 0; +} + +class Foo { + constructor() { + "ngInject"; + var a = 1; + 'notdirective'; + ~~~~~~~~~~~~~~~ [0] + } + + bar() { + 'use strict'; + } + + get baz() { + 'use asm'; + } + + set baz(newValue) { + "use asm"; + } +} + +// valid code: + +var i; +var j = 3; +i = 1 + 2; +j = fun1(); +fun1(); +fun2(2); +fun3(2, fun1()); +i++; +i += 2; +--i; +i <<= 2; +i = fun1() + fun1(); +j = (j === 0 ? 5 : 6); +(j === 0 ? fun1() : fun2(j)); +(a => 5)(4); +var obj = {}; +delete obj.key; +function* g() { + for (let i = 0; i < 100; i++) { + yield i; + } +} + +async function f(foo) { + await foo; + return 0; +} + +new Foo(); + +// invalid code: + +5; +~~ [0] +i; +~~ [0] +3 + 5; +~~~~~~ [0] +fun1() + fun1(); +~~~~~~~~~~~~~~~~ [0] +fun2(i) + fun3(4,7); +~~~~~~~~~~~~~~~~~~~~ [0] +fun1() + 4; +~~~~~~~~~~~ [0] +4 + fun2(j); +~~~~~~~~~~~~ [0] +(j === 0 ? fun1() : 5); +~~~~~~~~~~~~~~~~~~~~~~~ [0] +(j === 0 ? i : fun2(j)); +~~~~~~~~~~~~~~~~~~~~~~~~ [0] +a => fun2(a); +~~~~~~~~~~~~~ [0] +() => {return fun1();}; +~~~~~~~~~~~~~~~~~~~~~~~ [0] +"use strct"; +~~~~~~~~~~~~ [0] + +afterEach((el) => { + el && el.remove(); + ~~~~~~~~~~~~~~~~~~ [0] +}); + +checkParams((a, b) => { + (a || required('a')) && (b || required('b')); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +}); + +checkParams((a, b) => { + ((a && b) || required('a, b')); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +}); + +function interactionHandler(e) { + // fails in all cases since logical NOT operator is redundant + e && !e.preventDefault(); + ~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +} + +[0]: expected an assignment or function call