This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow fast null checks in no-unused-expression rule (#1638)
- Loading branch information
1 parent
4418cef
commit e649082
Showing
7 changed files
with
372 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/rules/no-unused-expression/allow-fast-null-checks/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"rules": { | ||
"no-unused-expression": [true, "allow-fast-null-checks"] | ||
}, | ||
"jsRules": { | ||
"no-unused-expression": [true, "allow-fast-null-checks"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.