Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Update PR with JS support
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionMH committed Jan 7, 2017
1 parent 7e8015a commit 061d433
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"rules": {
"no-unused-expression": [true, "allow-fast-null-checks"]
},
"jsRules": {
"no-unused-expression": [true, "allow-fast-null-checks"]
}
}
133 changes: 133 additions & 0 deletions test/rules/no-unused-expression/default/test.js.lint
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

0 comments on commit 061d433

Please sign in to comment.