Skip to content

Grader: file-matches

Property Value
Determinism static
Cost low
Reference reference-free
Temporal scope trajectory-level
Score kind code
graders:
- type: file-matches
config:
path: "**/Program.cs"
pattern: "static\\s+\\w+\\s+Add\\("
Field Type Required Description
path string Yes Glob pattern to select files in the workspace
pattern string Yes JavaScript regex pattern to match against file content
negate boolean No When 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

Glob patterns match regular files, including dotfiles and files inside dot-directories. Directories, symlinks, and other special entries are not matched.

Passes when the pattern matches at least one readable file. In negated mode, it passes only when every matching file is readable and none matches the pattern, or when no files match. Fails otherwise. If unreadable matching files prevent a conclusive result, both normal and negated modes fail.

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 (for example, because access is denied or it was removed after matching), it is skipped and noted in the evidence string. Binary files are NOT skipped — readFile("utf-8") returns mojibake for binary content, which simply won’t match most patterns.

If no readable file matches the pattern but at least one candidate was unreadable, the result is indeterminate. Both normal and negated modes fail because presence or absence cannot be proven from the readable files alone.

✔ 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)
✘ Indeterminate: Pattern /Add/ did not match any readable file matching '**/*.cs'; 1 unreadable file: obj/Debug/app.dll. Cannot prove presence.