xml_path_absent
Assert a JSONPath query over the document matches nothing; one file-level violation if present.
Semantics:
- The query must select zero nodes. Any match fires exactly one violation for the file — never per-match, so a
$[?…]filter that fans out over every top-level key still yields a single violation. - The existence sibling of the value-checking kinds; mirrors
file_absentfor a path.equals/matches/if_presentdon’t apply. - Useful for forbidding a key: a
postinstallscript inpackage.json, a[patch]table inCargo.toml, orwrite-allpermissions in a workflow.
Options
Section titled “Options”| Option | Type | Required | Default | Description |
|---|---|---|---|---|
path | string | yes | JSONPath expression rooted at $. The rule fires one violation per file if the query matches any node (the path must be absent). |
Plus the common paths, level, id, and when fields. This table is generated from the JSON Schema; option types and defaults are authoritative.
Example
Section titled “Example”A .csproj that opts into unsafe code
Section titled “A .csproj that opts into unsafe code”The rule fires on this repository:
App.csproj<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> </PropertyGroup></Project>With this .alint.yml:
version: 1rules: - id: no-unsafe-blocks kind: xml_path_absent paths: "*.csproj" path: "$.Project.PropertyGroup.AllowUnsafeBlocks" level: error message: >- Project enables AllowUnsafeBlocks; unsafe code bypasses the memory guarantees the rest of the codebase relies on.alint check reports:
--- App.csproj ----------------------------------------------------------------- x error no-unsafe-blocks Project enables AllowUnsafeBlocks; unsafe code bypasses the memory guarantees the rest of the codebase relies on.
Summary (1 violation): x 1 error 0 passing * 1 failingA .csproj that stays safe
Section titled “A .csproj that stays safe”This repository is compliant:
App.csproj<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> </PropertyGroup></Project>With this .alint.yml:
version: 1rules: - id: no-unsafe-blocks kind: xml_path_absent paths: "*.csproj" path: "$.Project.PropertyGroup.AllowUnsafeBlocks" level: erroralint check reports:
v All 1 rule(s) passed.