Skip to content

json_path_matches

Same shape as the *_equals variants, but the asserted value is a regex matched against string values. Non-string matches produce a clear “value is not a string” violation.

OptionTypeRequiredDefaultDescription
if_presentbooleanfalseWhen true, a query returning zero matches is silently OK - only real matches that fail the op produce violations.
matchesstringyesRust-regex pattern to match against the value at path.
pathstringyesJSONPath expression rooted at $.

Plus the common paths, level, id, and when fields. This table is generated from the JSON Schema; option types and defaults are authoritative.

A package version that is not valid semver

Section titled “A package version that is not valid semver”

The rule fires on this repository:

packages/
packages/bad/
packages/bad/package.json
packages/ok/
packages/ok/package.json
packages/bad/package.json
{"name": "@demo/bad", "version": "not-a-semver"}
packages/ok/package.json
{"name": "@demo/ok", "version": "1.2.3"}

With this .alint.yml:

version: 1
rules:
- id: require-semver-version
kind: json_path_matches
paths: "packages/*/package.json"
path: "$.version"
matches: '^\d+\.\d+\.\d+$'
level: error

alint check reports:

Terminal window
--- packages/bad/package.json --------------------------------------------------
x error require-semver-version
value at path "not-a-semver" does not match regex ^\d+\.\d+\.\d+$
Summary (1 violation):
x 1 error
0 passing * 1 failing

This repository is compliant:

packages/
packages/a/
packages/a/package.json
packages/b/
packages/b/package.json
packages/a/package.json
{"name": "@demo/a", "version": "1.2.3"}
packages/b/package.json
{"name": "@demo/b", "version": "0.10.0"}

With this .alint.yml:

version: 1
rules:
- id: semver-versions
kind: json_path_matches
paths: "packages/*/package.json"
path: "$.version"
matches: '^\d+\.\d+\.\d+$'
level: warning

alint check reports:

Terminal window
v All 1 rule(s) passed.