QL: add query detecting use of db-types outside the lib folder

This commit is contained in:
Erik Krogh Kristensen
2022-01-20 14:00:04 +01:00
parent c09b6691e1
commit 9b69de8588

View File

@@ -0,0 +1,24 @@
/**
* @name Use of database type outside the language core
* @description Database types should only be used in the language core, abstractions should be used elsewhere.
* @kind problem
* @problem.severity warning
* @id ql/db-type-outside-core
* @tags maintainability
* @precision very-high
*/
import ql
from TypeExpr te
where
te.isDBType() and
not te.getLocation().getFile().getAbsolutePath().matches("%/lib/%") and
exists(File f | f.getAbsolutePath().matches("%/lib/%")) and
// it is needed in one case.
not te = any(Class c | c.getName() = "SuppressionScope").getASuperType() and
// QL-for-QL only has a src/ folder.
not te.getLocation().getFile().getAbsolutePath().matches("%/ql/ql/%") and
// tests are allowed to use DB types.
not te.getLocation().getFile().getAbsolutePath().matches("%/test/%")
select te, "Database type used outside the language lib/ folder."