PRQL Quick Reference
37 ready-to-use PRQL code queries, organized in 9 categories — copy them straight into the CppDepend query editor.
How to use this reference
Each query below is a complete, runnable PRQL query. Click Copy to copy a query to your clipboard, paste it into the CppDepend query editor, and run it against your codebase. Use the search box to filter queries by name.
New to the language? Start with the PRQL overview and the Validating PRQL Rules guide.
Basic Queries
from m in JustMyCode.Methods where m.IsPublic
select mfrom t in JustMyCode.Types where t.IsAbstract
select tfrom t in JustMyCode.Types where t.IsGeneric
select tfrom t in Application.Types where t.IsStructure
select tCode Implementation Queries
from m in Methods where m.CyclomaticComplexity>15
select new{m,m.CyclomaticComplexity}from t in Types where t.NbLinesOfCode>500
select new {t,t.NbLinesOfCode}from m in JustMyCode.Methods where m.MaintainabilityIndex<40
select new {m,m.MaintainabilityIndex}warnif count > 0
from m in Application.Methods
where m.NbParameters > 5
select new { m, m.NbParameters }Architecture & C++ Safety Rules
warnif count > 0
from n in Application.Namespaces
where n.DepthOfIsUsing(n) > 0
select new { Namespace = n, CyclicDependencies = n.NamespacesUsed.Where(n2 => n2.DepthOfIsUsing(n) > 0) }warnif count > 0
from t in Application.Types
where t.IsClass && t.Methods.Any(m => m.IsVirtual) && !t.Methods.Any(m => m.IsDestructor && m.IsVirtual)
select new { MissingVirtualDestructorIn = t }warnif count > 0
from f in Application.Fields
where f.IsPointer && !f.IsConst && f.IsPublic
select new { UnsafePublicPointerField = f }warnif count > 0
let uiMethods = Application.Namespaces.WithNameLike("UI").ChildMethods()
let storageMethods = Application.Namespaces.WithNameLike("Storage").ChildMethods()
from m in uiMethods
where m.IsUsing(storageMethods)
select new { IllegalCallFrom = m, Target = m.MethodsCalled.Intersect(storageMethods) }Issues & Technical Debt
from issue in Issues where issue.Severity==Severity.High
select issuefrom issue in Issues where issue.Severity==Severity.Medium
select new{issue,issue.Debt}from issue in Issues where issue.CodeElement!=null &&
issue.CodeElement.AsMethod!=null && issue.CodeElement.AsMethod.IsPublic && issue.CodeElement.AsMethod.IsGeneric
select new{issue,issue.Debt}from issue in Issues
orderby issue.Debt descending
select new { issue.CodeElement, issue.Debt, issue.Severity }from m in Application.Methods
where m.NbMethodsCalled > 10
let debt = m.Issues.Sum(i => i.Debt)
orderby m.NbMethodsCalled descending
select new {
Method = m,
CouplingCount = m.NbMethodsCalled,
TotalDebt = debt,
IssueCount = m.Issues.Count()
}Issues Diff Queries
from issue in Issues where issue.WasAdded()
select new {issue,issue.Debt}from issue in IssuesInBaseline where issue.WasFixed()
select new {issue,issue.Debt}from rule in Rules where rule.IsInNewerIssuesSet() && !rule.IsInOlderIssuesSet()
select rulewarnif count > 0
from m in Application.Methods
where m.WasAdded() && m.CyclomaticComplexity > 10
select new { NewComplexMethod = m, m.CyclomaticComplexity }Code Design Queries
from m in Methods where m.NbMethodsCalled>10 orderby m.NbMethodsCalled descending
select new{m,m.NbMethodsCalled}from t in JustMyCode.Types where t.LCOM > 0.8 &&
t.NbFields > 10 && t.NbMethods >10 select tfrom t in Types where t.BaseClasses.Count()>4
select tfrom t in Application.Types
where t.TypesUsed.Count() > 20
select new { Type = t, CouplingCount = t.TypesUsed.Count() }Code Diff Queries
from m in Methods where m.WasAdded()
select mfrom m in codeBase.OlderVersion().Application.Methods where m.IsPublic && m.WasRemoved()
select mfrom t in Types where t.isGeneric && t.WasChanged()
select twarnif count > 0
from m in Application.Methods
where m.IsCodeModified() && (m.NbLinesOfCode - m.OlderVersion().NbLinesOfCode) > 30
select new { m, CurrentLOC = m.NbLinesOfCode, OldLOC = m.OlderVersion().NbLinesOfCode }Dependencies & API Tracking
from m in Methods where m.MethodsCallingMe.Where(m=>m.CyclomaticComplexity>15).Any()
select new{m,m.MethodsCallingMe}from m in Methods where m.MethodsCalled.Where(m=>m.CyclomaticComplexity>15).Any()
select new{m,m.MethodsCalled}from m in Methods where m.MethodsCalled.Where(m=>m.ParentProject.Name=="Windows SDK").Any()
select new{m,m.MethodsCalled.Where(m=>m.ParentProject.Name=="Windows SDK")}let rawAllocators = ThirdParty.Methods.WithSimpleName("malloc")
from m in Application.Methods
where m.DepthOfIsUsing(rawAllocators) >= 1
select new { CallerMethod = m, Depth = m.DepthOfIsUsing(rawAllocators) }Statistics & Metrics
from m in Methods where m.NbMethodsCallingMe>20 orderby m.NbMethodsCallingMe descending
select new{m,m.NbMethodsCallingMe}from t in Types where t.NbLinesOfCode>400 orderby t.NbLinesOfCode
select new{t,t.NbLinesOfCode}from t in Types where t.NbTypesUsingMe>10 orderby t.NbTypesUsingMe
select new{t,t.TypesUsingMe}from m in Application.Methods
where m.IsPrivate && m.NbMethodsCallingMe == 0 && !m.IsMain
select new { UnusedMethod = m, m.NbLinesOfCode }