@@ -191,6 +191,57 @@ fn test() {
191191 use crate :: tester:: Tester ;
192192
193193 let pass = vec ! [
194+ // https://github.com/eslint/eslint/blob/946ae00457265eb298eb169d6d48ca7ec71b9eef/tests/lib/rules/no-unused-expressions.js#L21
195+ ( "function f(){}" , None ) ,
196+ ( "a = b" , None ) ,
197+ ( "new a" , None ) ,
198+ ( "{}" , None ) ,
199+ ( "f(); g()" , None ) ,
200+ ( "i++" , None ) ,
201+ ( "a()" , None ) ,
202+ ( "a && a()" , Some ( serde_json:: json!( [ { "allowShortCircuit" : true } ] ) ) ) ,
203+ ( "a() || (b = c)" , Some ( serde_json:: json!( [ { "allowShortCircuit" : true } ] ) ) ) ,
204+ ( "a ? b() : c()" , Some ( serde_json:: json!( [ { "allowTernary" : true } ] ) ) ) ,
205+ (
206+ "a ? b() || (c = d) : e()" ,
207+ Some ( serde_json:: json!( [ { "allowShortCircuit" : true , "allowTernary" : true } ] ) ) ,
208+ ) ,
209+ ( "delete foo.bar" , None ) ,
210+ ( "void new C" , None ) ,
211+ ( r#""use strict";"# , None ) ,
212+ ( r#""directive one"; "directive two"; f();"# , None ) ,
213+ ( r#"function foo() {"use strict"; return true; }"# , None ) ,
214+ ( r#"var foo = () => {"use strict"; return true; }"# , None ) , // { "ecmaVersion": 6 },
215+ ( r#"function foo() {"directive one"; "directive two"; f(); }"# , None ) ,
216+ ( r#"function foo() { var foo = "use strict"; return true; }"# , None ) ,
217+ ( "function* foo(){ yield 0; }" , None ) , // { "ecmaVersion": 6 },
218+ ( "async function foo() { await 5; }" , None ) , // { "ecmaVersion": 8 },
219+ ( "async function foo() { await foo.bar; }" , None ) , // { "ecmaVersion": 8 },
220+ (
221+ "async function foo() { bar && await baz; }" ,
222+ Some ( serde_json:: json!( [ { "allowShortCircuit" : true } ] ) ) ,
223+ ) , // { "ecmaVersion": 8 },
224+ (
225+ "async function foo() { foo ? await bar : await baz; }" ,
226+ Some ( serde_json:: json!( [ { "allowTernary" : true } ] ) ) ,
227+ ) , // { "ecmaVersion": 8 },
228+ (
229+ "tag`tagged template literal`" ,
230+ Some ( serde_json:: json!( [ { "allowTaggedTemplates" : true } ] ) ) ,
231+ ) , // { "ecmaVersion": 6 },
232+ (
233+ "shouldNotBeAffectedByAllowTemplateTagsOption()" ,
234+ Some ( serde_json:: json!( [ { "allowTaggedTemplates" : true } ] ) ) ,
235+ ) , // { "ecmaVersion": 6 },
236+ ( r#"import("foo")"# , None ) , // { "ecmaVersion": 11 },
237+ ( r#"func?.("foo")"# , None ) , // { "ecmaVersion": 11 },
238+ ( r#"obj?.foo("bar")"# , None ) , // { "ecmaVersion": 11 },
239+ ( "<div />" , None ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
240+ ( "<></>" , None ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
241+ ( "var partial = <div />" , None ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
242+ ( "var partial = <div />" , Some ( serde_json:: json!( [ { "enforceForJSX" : true } ] ) ) ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
243+ ( "var partial = <></>" , Some ( serde_json:: json!( [ { "enforceForJSX" : true } ] ) ) ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } }
244+ // https://github.com/typescript-eslint/typescript-eslint/blob/32a7a7061abba5bbf1403230526514768d3e2760/packages/eslint-plugin/tests/rules/no-unused-expressions.test.ts#L29
194245 (
195246 "
196247 test.age?.toLocaleString();
@@ -285,6 +336,58 @@ fn test() {
285336 ] ;
286337
287338 let fail = vec ! [
339+ // https://github.com/eslint/eslint/blob/946ae00457265eb298eb169d6d48ca7ec71b9eef/tests/lib/rules/no-unused-expressions.js#L111
340+ ( "0" , None ) ,
341+ ( "a" , None ) ,
342+ ( "f(), 0" , None ) ,
343+ ( "{0}" , None ) ,
344+ ( "[]" , None ) ,
345+ ( "a && b();" , None ) ,
346+ ( "a() || false" , None ) ,
347+ ( "a || (b = c)" , None ) ,
348+ ( "a ? b() || (c = d) : e" , None ) ,
349+ ( "`untagged template literal`" , None ) , // { "ecmaVersion": 6 },
350+ ( "tag`tagged template literal`" , None ) , // { "ecmaVersion": 6 },
351+ ( "a && b()" , Some ( serde_json:: json!( [ { "allowTernary" : true } ] ) ) ) ,
352+ ( "a ? b() : c()" , Some ( serde_json:: json!( [ { "allowShortCircuit" : true } ] ) ) ) ,
353+ ( "a || b" , Some ( serde_json:: json!( [ { "allowShortCircuit" : true } ] ) ) ) ,
354+ ( "a() && b" , Some ( serde_json:: json!( [ { "allowShortCircuit" : true } ] ) ) ) ,
355+ ( "a ? b : 0" , Some ( serde_json:: json!( [ { "allowTernary" : true } ] ) ) ) ,
356+ ( "a ? b : c()" , Some ( serde_json:: json!( [ { "allowTernary" : true } ] ) ) ) ,
357+ ( "foo.bar;" , None ) ,
358+ ( "!a" , None ) ,
359+ ( "+a" , None ) ,
360+ ( r#""directive one"; f(); "directive two";"# , None ) ,
361+ ( r#"function foo() {"directive one"; f(); "directive two"; }"# , None ) ,
362+ ( r#"if (0) { "not a directive"; f(); }"# , None ) ,
363+ ( r#"function foo() { var foo = true; "use strict"; }"# , None ) ,
364+ ( r#"var foo = () => { var foo = true; "use strict"; }"# , None ) , // { "ecmaVersion": 6 },
365+ (
366+ "`untagged template literal`" ,
367+ Some ( serde_json:: json!( [ { "allowTaggedTemplates" : true } ] ) ) ,
368+ ) , // { "ecmaVersion": 6 },
369+ (
370+ "`untagged template literal`" ,
371+ Some ( serde_json:: json!( [ { "allowTaggedTemplates" : false } ] ) ) ,
372+ ) , // { "ecmaVersion": 6 },
373+ (
374+ "tag`tagged template literal`" ,
375+ Some ( serde_json:: json!( [ { "allowTaggedTemplates" : false } ] ) ) ,
376+ ) , // { "ecmaVersion": 6 },
377+ ( "obj?.foo" , None ) , // { "ecmaVersion": 2020 },
378+ ( "obj?.foo.bar" , None ) , // { "ecmaVersion": 2020 },
379+ ( "obj?.foo().bar" , None ) , // { "ecmaVersion": 2020 },
380+ ( "<div />" , Some ( serde_json:: json!( [ { "enforceForJSX" : true } ] ) ) ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
381+ ( "<></>" , Some ( serde_json:: json!( [ { "enforceForJSX" : true } ] ) ) ) , // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
382+ ( "class C { static { 'use strict'; } }" , None ) , // { "ecmaVersion": 2022 },
383+ (
384+ "class C { static {
385+ 'foo'
386+ 'bar'
387+ } }" ,
388+ None ,
389+ ) , // { "ecmaVersion": 2022 }
390+ // https://github.com/typescript-eslint/typescript-eslint/blob/32a7a7061abba5bbf1403230526514768d3e2760/packages/eslint-plugin/tests/rules/no-unused-expressions.test.ts#L91
288391 (
289392 "
290393 if (0) 0;
0 commit comments