rewrite xpath rule and add some test cases

This commit is contained in:
Oleksandr Shvets 2024-03-10 18:08:07 +02:00
parent 0ec6a4f770
commit 3c0aea6c52
2 changed files with 27 additions and 16 deletions

View File

@ -222,21 +222,17 @@ be misleading. Considering removing this unnecessary Block.
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//(Block|Scope)
[not(
parent::FunctionNode or
parent::IfStatement or
parent::ForLoop or
parent::ForInLoop or
parent::WhileLoop or
parent::DoLoop or
parent::TryStatement or
parent::CatchClause
)]
]]>
</value>
<value><![CDATA[
//Scope[
count(ancestor::*) = 1
and not(preceding::EmptyStatement)
]
| //SwitchCase[./Scope]
| //(Scope|Block)[
./(Scope|Block)
and count(./*) = 1
]
]]></value>
</property>
</properties>
<example>

View File

@ -174,13 +174,18 @@ do {
<test-code>
<description>Bad, switch</description>
<expected-problems>1</expected-problems>
<expected-problems>2</expected-problems>
<code><![CDATA[
switch(1) {
case 1:
{
}
break;
case 2:
{
1 + 2;
}
return;
}
]]></code>
</test-code>
@ -241,4 +246,14 @@ let a, b, a1, b1, c, d, rest, pop, push;
function fn( ({arg}) ){ return arg}
]]></code>
</test-code>
<test-code>
<description>not using semicolons case</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import { foo } from './someScript.js' // missing semicolon
const { isLoggedIn } = useAuth(); // <--- violation here: unnecessary block
import { foo2 } from './someScript2.js';
const { isLoggedIn2 } = useAuth2() //
]]></code>
</test-code>
</test-data>