Skip to main content

require-codeql-branch-filters

Rule catalog ID: R113

Targeted pattern scopeโ€‹

CodeQL workflows that define push or pull_request triggers as mappings.

What this rule reportsโ€‹

This rule reports CodeQL push or pull_request triggers that do not define a non-empty branches or branches-ignore filter.

Why this rule existsโ€‹

Code scanning on every branch may be intentional, but for most repositories CodeQL is scoped to the main development branches. Requiring an explicit branch filter makes that intent visible and keeps trigger breadth reviewable.

โŒ Incorrectโ€‹

on:
push: {}
pull_request: {}

โœ… Correctโ€‹

on:
push:
branches: [main]
pull_request:
branches: [main]

Additional examplesโ€‹

This rule only checks CodeQL workflows and only when the trigger is expressed as a mapping where branch filters are supported.

ESLint flat config exampleโ€‹

import githubActions from "eslint-plugin-github-actions-2";

export default [githubActions.configs.codeScanning];

When not to use itโ€‹

Disable this rule if your repository intentionally wants CodeQL to react to every branch and that policy is already understood by maintainers.

Further readingโ€‹