A periodical about version control, git, and the future of agentic version control.

Danger JS Configuration for Enforcing Team PR Standards

A Dangerfile turns PR conventions into CI checks so reviewers can focus on logic.

· 8 min read
Cover illustration for “Danger JS Configuration for Enforcing Team PR Standards”
Code Review Automation · November 12, 2026 · 8 min read · 1,764 words

Danger JS configuration turns team PR standards into executable rules, so reviewers do not have to enforce the same conventions by hand. A well-designed Dangerfile checks diff size, changelog updates, ticket references, and ownership automatically in CI. It works best when the team chooses the right severity and exemptions, so human reviewers can focus on logic, architecture, and intent.

What Danger JS is and what problem it solves

PR review culture often depends on someone remembering to ask whether the changelog was updated or the change links to a ticket. That memory weakens under time pressure. Danger JS moves those recurring questions into a Dangerfile, written in JavaScript or TypeScript, which evaluates rules against each PR and posts failures, warnings, or informational comments.

Danger can detect changes to a required file, but that does not establish whether the change is sound. With those routine checks out of the way, reviewers have more time for questions that call for an understanding of the code.

Where Danger fits in a CI pipeline and how it connects to the PR lifecycle

Danger runs inside CI, after tests and linters, so it needs no separate manual review step. It uses access to the GitHub or GitLab API to read PR metadata and post comments. The setup begins with installing the danger npm package and creating Dangerfile.js or Dangerfile.ts at the repository root. A bot token gives Danger permission to publish its feedback. CI invokes Danger with danger ci.

That line invokes the rules, while the token supplies the access needed to comment on the PR. The surrounding workflow remains responsible for running the tests and linters whose results precede Danger. For earlier iteration, danger local provides per-commit feedback without opening a PR. This gives rule authors a pre-PR path for refining conditions before relying on CI feedback.

The Dangerfile’s building blocks — fail, warn, message, and the danger object

The Dangerfile separates the condition being checked from the response it produces. fail marks the CI build as failed and provides the blocking result, while warn posts non-blocking feedback and message posts information. Severity expresses the team’s actual policy. When a convention allows exceptions, an easy-to-write condition is no reason to make it a hard failure.

By contrast, danger.git.modified_files, danger.git.created_files, and danger.git.deleted_files contain changed file paths. They are not the diff itself. Rules that need file contents from the diff use danger.git.diffForFile().

A minimal assignee rule begins with import { danger, fail, warn } from "danger" and follows it with if (!danger.github.pr.assignee) { const report = danger.github.pr.title.includes("WIP") ? warn : fail; report("This pull request needs an assignee, and optionally include any reviewers."); }. The rule runs when the assignee is missing, and the title sets the severity. This lets the team use the same requirement while work is in progress and when it is ready for review. Teams using TypeScript can place their rules in Dangerfile.ts when the project already has the typescript package installed.

Enforcing PR size limits to keep diffs reviewable

Large diffs are hard to review thoroughly. A size rule starts with danger.github.pr.additions + danger.github.pr.deletions, compares the result with a team-defined threshold, and reports when the threshold is exceeded. The message should explain that the diff needs to remain reviewable. Automating this feedback also removes the social awkwardness of asking an author to split their work.

A warning usually leaves more room for dependency upgrades and generated changes, which can make PRs large for good reasons. A failure is appropriate only where the team agrees that exceeding its limit is unacceptable. The threshold alone is not enough. Whether reviewers can trust the signal depends on what the rule counts.

For example, danger.git.modified_files.filter(file => file !== "package-lock.json") excludes that lockfile from the modified paths selected for inspection. The rule also needs to count created and deleted files when they fall within its scope.

Requiring a CHANGELOG entry on every PR that touches production code

A changelog rule checks whether CHANGELOG.md appears in danger.git.modified_files, but that check needs a scope condition. Documentation-only changes, CI configuration updates, and test-only changes should not trigger a production changelog requirement. The file classification comes first. Otherwise, the rule asks authors to create release documentation for work the team never intended to include.

The core conditional can be expressed as if (touchesProductionCode && !danger.git.modified_files.includes("CHANGELOG.md") && !skipChangelog) { fail("Production code changes require a CHANGELOG entry."); }. Here, touchesProductionCode is the team’s own check for production paths, which the team must supply because Danger has no such built-in property. That predicate should reflect the repository’s paths and account for relevant created or deleted files as well as modifications.

A label-based exception keeps genuinely trivial PRs from forcing the team to disable the rule. The expression danger.github.pr.labels.some(label => label.name === "skip-changelog") supplies the escape-hatch condition. This exemption remains explicit in PR metadata. A warning can replace the failure where changelog completion is a convention.

A ticket reference connects a code change to its requirements and gives later readers a route back to its purpose. Danger can check danger.github.pr.body with a regular expression that matches the team’s issue format. For a Jira-style identifier, /PROJ-\d+/.test(danger.github.pr.body || "") is the essential check. For a GitHub issue URL or Linear URL, the pattern needs to match that kind of URL. An arbitrary URL is too permissive because a Figma link does not establish the required issue connection.

The policy decision is more important than the regex. A team that requires traceability before merge can fail a ready-for-review PR with no matching reference. During work in progress, the same omission should produce a warning because the description may still be incomplete. Using the PR’s draft state or its WIP title marker preserves that distinction without maintaining separate versions of the ticket rule.

Requiring an assignee and catching work-in-progress PRs before they merge

An unassigned PR lacks a clear owner for follow-up. Danger’s assignee check flags a missing owner each time, so the team need not wait for a reviewer to notice. The Node App tutorial checks danger.github.pr.assignee, warns when the title includes "WIP", and fails otherwise. The condition is deliberately small.

The reusable part is const isWIP = danger.github.pr.title.includes("WIP"), defined once for other rules to reference. Teams using GitHub draft PRs can supplement or replace that title check with danger.github.pr.draft. Both checks show whether the work is still in progress or ready for review. However, relaxing an assignee or ticket rule for WIP does not itself reject WIP PRs, so that conditional should not be mistaken for a separate prohibition on merging unfinished work.

Warning when sensitive or high-risk files change

Some changes need a closer look even when the author has met every administrative requirement. Environment configuration, secrets management files, database migrations, CI definitions, and dependency manifests can all justify targeted review feedback. These rules filter the changed paths and identify the file that warrants scrutiny.

For example, a rule watching .env.example should explain that the environment configuration changed and needs review. A warning is appropriate because the change is not inherently wrong. Failing the build just because that file changed would treat a risk as a breach of policy. Informational message output is another option where the team wants visibility without a warning.

Dependency changes use the same pattern. A lockfile warning can direct reviewers to inspect the dependency diff rather than rely on the manifest’s package names alone. Danger’s separate Danger + Dependencies tutorial shows how to handle this case. The useful output names the changed file and the reason for attention.

Posting CI process output — linter results, test failures — directly into the PR

Danger can also bring diagnostic output into the review conversation. When a linter or test runner writes a log file, the Dangerfile can read it and publish the relevant contents or a summary. Reviewers can then see why a check failed without having to leave the PR. The underlying tool still performs the check.

The Node App tutorial bridges command output and Danger with tee, which lets a CI command display its output while saving it to a file. The Dangerfile then reads that file with fs.readFileSync, looks for failure strings, and posts formatted output with markdown(). Each part has a distinct role.

JSON reporters allow a more precise version of this pattern because the rule can select failed tests or error lines, keeping the PR comment focused on diagnosis. Tool-specific plugins such as danger-plugin-jest and danger-plugin-tslint wrap reporting logic of this kind for reuse.

Extending rules with plugins and sharing a Dangerfile across projects

Once rules stabilize, copying a Dangerfile across repositories creates multiple places to maintain the same policy. A Danger plugin provides a shared implementation instead. It is a plain npm module that repositories install and call from their Dangerfiles. Updates then propagate through dependency bumps.

An internal plugin can hold the ticket regex, sensitive-file matching logic, and PR-size calculation while allowing individual teams to configure their thresholds. This separates shared mechanics from repository-specific choices. The same distinction applies to exemptions, which can remain explicit without forcing each repository to rewrite the underlying rule. Danger’s Extending Danger documentation describes publishing plugins and importing them like other modules.

Sharing does not require every enforcement system to be written in JavaScript. The danger process command supports runners written in other languages, accommodating convention logic maintained elsewhere. At a broader organizational scope, Peril runs Dangerfile rules across a GitHub organization on webhook events.

How Danger JS fits into a CI pipeline that also runs automated end-to-end checks

A PR can pass every Danger rule and still break a critical flow in the application. An assignee establishes ownership, a ticket supplies context, and a changelog records the change, but none demonstrates runtime behavior. The validation layers have different jobs. Danger checks change-management conventions, unit and integration tests check code correctness, and end-to-end checks against a preview environment check user journeys.

That separation becomes especially useful when coding agents author PRs. A plausible implementation and a polished description can still omit a changelog entry or ticket reference. Danger applies the same conditions regardless of authorship. It does not infer compliance from how convincing the PR appears, and its success does not establish that the application works.

Composal complements that convention layer by sending AI browser agents through the running preview of every PR to check important user journeys automatically before human review. The pairing preserves a clear boundary between metadata enforcement and behavioral verification. A complete validation pipeline needs both kinds of evidence, and human reviewers still have to judge the logic, architecture, and intent that automated convention checks cannot judge.

Sources

  1. Danger JS
  2. Danger in a Node App

More in Code Review Automation