File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -42,14 +42,16 @@ async function unusedImportsActiveFile(editor) {
4242 const solhintRuleString = "solhint-disable no-unused-import"
4343 if ( text . includes ( solhintRuleString ) ) return ;
4444
45- const importRegex = / i m p o r t \s + ( (?: \{ .+ ?\} \s + f r o m \s + ) ? (?: \" .* ?\" | ' .* ?' ) ) ; / g;
46- const imports = text . match ( importRegex ) || [ ] ;
45+ const importRegex = / (?< ! \/ \/ \/ ? ) . * i m p o r t \s + ( (?: \{ .+ ?\} \s + f r o m \s + ) ? (?: \" .* ?\" | ' .* ?' ) ) ; / g;
46+ const importStatements = text . match ( importRegex ) || [ ] ;
4747 const unusedImportDecorations = [ ] ;
48+ for ( const importStatement of importStatements ) {
49+ // skip commented out import statements
50+ if ( importStatement . startsWith ( "//" ) || importStatement . startsWith ( "/*" ) ) return ;
4851
49- for ( const importStatement of imports ) {
5052 const imports = extractImports ( importStatement ) ;
5153 for ( const item of imports ) {
52- const regex = new RegExp ( item , 'g' ) ;
54+ const regex = new RegExp ( `\\b ${ item } \\b` , 'g' ) ;
5355 const itemOccurrencesInImportStatement = ( importStatement . replace ( / \. s o l \b / g, '' ) . match ( regex ) || [ ] ) . length ;
5456 const totalOccurrencesOfItem = ( text . match ( new RegExp ( `\\b${ item } \\b` , 'gi' ) ) || [ ] ) . length ;
5557 if ( totalOccurrencesOfItem == itemOccurrencesInImportStatement ) {
You can’t perform that action at this time.
0 commit comments