Merge pull request #311 from dhasenan/renamed_local_import

Don't warn about renamed imports.
This commit is contained in:
Brian Schott 2016-03-14 13:31:13 -07:00
commit d04d352650
1 changed files with 28 additions and 4 deletions

View File

@ -52,10 +52,16 @@ class LocalImportCheck : BaseAnalyzer
if ((!isStatic && interesting) && (id.importBindings is null if ((!isStatic && interesting) && (id.importBindings is null
|| id.importBindings.importBinds.length == 0)) || id.importBindings.importBinds.length == 0))
{ {
addErrorMessage(id.singleImports[0].identifierChain.identifiers[0].line, foreach (singleImport; id.singleImports)
id.singleImports[0].identifierChain.identifiers[0].column, "dscanner.suspicious.local_imports", {
"Local imports should specify" if (singleImport.rename.text.length == 0)
~ " the symbols being imported to avoid hiding local symbols."); {
addErrorMessage(singleImport.identifierChain.identifiers[0].line,
singleImport.identifierChain.identifiers[0].column,
"dscanner.suspicious.local_imports", "Local imports should specify"
~ " the symbols being imported to avoid hiding local symbols.");
}
}
} }
} }
@ -75,3 +81,21 @@ private:
bool interesting; bool interesting;
bool isStatic; bool isStatic;
} }
unittest
{
import analysis.config : StaticAnalysisConfig;
StaticAnalysisConfig sac;
sac.local_import_check = true;
assertAnalyzerWarnings(q{
void testLocalImport()
{
import std.stdio; // [warn]: Local imports should specify the symbols being imported to avoid hiding local symbols.
import std.fish : scales, head;
import DAGRON = std.experimental.dragon;
}
}c, sac);
stderr.writeln("Unittest for LocalImportCheck passed.");
}