Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54e2215

Browse files
author
Esben Sparre Andreasen
committed
JS: support require in isReactImportForJSX
1 parent 737a816 commit 54e2215

5 files changed

Lines changed: 11 additions & 0 deletions

File tree

javascript/ql/src/Declarations/UnusedVariable.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ predicate isReactImportForJSX(UnusedLocal v) {
7171
)
7272
|
7373
v.getADeclaration() = any(ImportDeclaration imp).getASpecifier().getLocal()
74+
or
75+
exists(VariableDeclarator vd | vd.getBindingPattern() = v.getADeclaration() |
76+
vd.getInit() instanceof Require
77+
)
7478
)
7579
}
7680

javascript/ql/test/query-tests/Declarations/UnusedVariable/UnusedVariable.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| importWithoutPragma.jsx:1:1:1:27 | import ... react'; | Unused import h. |
88
| multi-imports.js:1:1:1:29 | import ... om 'x'; | Unused imports a, b, d. |
99
| multi-imports.js:2:1:2:42 | import ... om 'x'; | Unused imports alphabetically, ordered. |
10+
| require-react-3.js:1:7:1:11 | React | Unused variable React. |
1011
| typeoftype.ts:9:7:9:7 | y | Unused variable y. |
1112
| unusedShadowed.ts:1:1:1:26 | import ... where'; | Unused import T. |
1213
| unusedShadowed.ts:2:1:2:31 | import ... where'; | Unused import object. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var React = require("probably-react"); // OK
2+
(<e/>);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var { React } = { React: require("probably-react") }; // OK
2+
(<e/>);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var { React } = require("probably-react"); // OK, but not yet supported
2+
(<e/>);

0 commit comments

Comments
 (0)