Skip to content

QL: simplify the NonDocBlock query #11475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/ql-for-ql-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@ jobs:
run: |
"${CODEQL}" test run --check-databases --check-unused-labels --check-repeated-labels --check-redefined-labels --check-use-before-definition --search-path "${{ github.workspace }}/ql/extractor-pack" --consistency-queries ql/ql/consistency-queries ql/ql/test
env:
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
- name: Check QL formatting
run: |
find ql/ql/src "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 "${CODEQL}" query format --check-only
env:
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
33 changes: 12 additions & 21 deletions ql/ql/src/queries/style/NonDocBlock.ql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ predicate canHaveQLDoc(AstNode node) {
node instanceof ClasslessPredicate
or
node instanceof ClassPredicate
or
node instanceof TopLevel
}

pragma[noinline]
Expand All @@ -28,19 +30,23 @@ int getLineAboveNodeThatCouldHaveDoc(File file) {
}

pragma[noinline]
BlockComment getACommentThatCouldBeQLDoc(File file) {
BlockComment getACommentThatCouldBeQLDoc(File file, int line, string descrip) {
exists(Location loc | loc = result.getLocation() |
file = loc.getFile() and
loc.getFile().getExtension() = "qll" and
not result.getContents().matches("/**%") and
not [loc.getStartLine(), loc.getEndLine()] = getLinesWithNonComment(file) and
(
// above something that can be commented.
loc.getEndLine() = getLineAboveNodeThatCouldHaveDoc(file)
loc.getEndLine() = getLineAboveNodeThatCouldHaveDoc(file) and
descrip = "the below code" and
line = loc.getEndLine() + 1
or
// toplevel in file.
loc.getStartLine() = 1 and
loc.getStartColumn() = 1
loc.getStartColumn() = 1 and
descrip = "the file" and
line = 1
)
)
}
Expand All @@ -57,28 +63,13 @@ int getLinesWithNonComment(File f) {
)
}

pragma[noinline]
BlockComment getCommentAtEnd(File file, int endLine) {
result = getACommentThatCouldBeQLDoc(file) and
result.getLocation().getEndLine() = endLine
}

pragma[noinline]
BlockComment getCommentAtStart(File file, int startLine) {
result = getACommentThatCouldBeQLDoc(file) and
result.getLocation().getStartLine() = startLine
}

from AstNode node, BlockComment comment, string nodeDescrip
where
(
canHaveQLDoc(node) and
comment = getCommentAtEnd(node.getLocation().getFile(), node.getLocation().getStartLine() - 1) and
nodeDescrip = "the below code"
or
node instanceof TopLevel and
comment = getCommentAtStart(node.getLocation().getFile(), 1) and
nodeDescrip = "the file"
comment =
getACommentThatCouldBeQLDoc(node.getLocation().getFile(), node.getLocation().getStartLine(),
nodeDescrip)
) and
not exists(node.getQLDoc()) and
not node.(ClassPredicate).isOverride() and // ignore override predicates
Expand Down