Skip to content

Grader: file-matches

PropertyValue
Determinismstatic
Costlow
Portabilityt1-universal
Referencereference-free
Temporal scopetrajectory-level
Score kindcode
graders:
- type: file-matches
config:
path: "**/Program.cs"
pattern: "static\\s+\\w+\\s+Add\\("
FieldTypeRequiredDescription
pathstringYesGlob pattern to select files in the workspace
patternstringYesJavaScript regex pattern to match against file content
negatebooleanNoWhen true, passes when the pattern does NOT match any file

Use file-not-matches as a shorthand for negate: true:

graders:
- type: file-not-matches
config:
path: "**/Program.cs"
pattern: "null!"

This is equivalent to type: file-matches with negate: true.

  1. Finds files matching path in the workspace using glob
  2. Validates the regex pattern (fails immediately if invalid)
  3. Reads each matching file as UTF-8
  4. Tests file content against the regex

Passes when the pattern matches at least one file’s content (or NO files match if negated). Fails otherwise.

Use the (?flags) prefix syntax for inline regex flags:

  • (?i)pattern — case-insensitive
  • (?m)pattern — multiline (^/$ match line start/end)
  • (?s)pattern — dotAll (. matches newlines)
graders:
- type: file-matches
config:
path: "**/*.cs"
pattern: "(?i)public static void main"

If a matching file can’t be read (EACCES, EISDIR, etc.), it is skipped and noted in the evidence string. This handles agent workspaces that may contain build artifacts or directories matching a broad glob. Binary files are NOT skipped — readFile("utf-8") returns mojibake for binary content, which simply won’t match most patterns.

✔ Pattern /static\s+Add/ matched in Program.cs
✘ Pattern /static\s+Add/ not found in any file matching '**/Program.cs'
✘ No files matching '**/Program.cs' found
✘ Invalid regex pattern: [bad. Error: Unterminated character class
✔ Pattern /Add/ matched in b.cs (skipped 1 unreadable file: obj/Debug/app.dll)