CodeSampleX

Sample

minimatch 10.1.1: Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch

Verified sample for npm minimatch 10.1.1: Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch. The…

sha256:3ae907b811ef9a96a655b6cdb6cbaf64b9acc9b816653b98a3ea8d76e57b190c

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment node linux x64 node node npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-18
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-18

Case

HOW
Goal
Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch
Packages
Symbols
  • minimatch
Environment
node
Created
2026-08-18T00:17:47Z

Contract

  1. assert minimatch treats leading hash characters as comments that match nothing by default, requiring nocomment or backslash escaping to match literal hashes
  2. assert negation patterns with leading exclamation marks invert matches by default, while flipNegate preserves positive matches and nonegate matches literal exclamation marks
  3. assert matchBase matches slash-less patterns against path basenames but is ignored when the pattern contains a slash
  4. assert dotfiles are excluded from wildcards and globstars by default unless explicitly matched or dot mode is enabled
  5. assert globstar matches zero or more directory levels when isolated between slashes but acts as a single wildcard when concatenated with other characters

Files

  • NOTES.md
  • csx.json
  • package-lock.json
  • package.json
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

NOTES.md
# Minimatch Pattern Semantics and Matching Options

## Search Result and Prior Samples
A query for `minimatch@10.1.1` returned sample `sha256:585ab2a8ea43909cb7e47145ba967133e7da688e33baa7e055319539c3675105`, which verified brace expansion, partial matching, magic detection, filtering, and escape utilities. This sample investigates a distinct set of pattern parsing behaviors and options in `minimatch`: leading hash comments, leading exclamation negation handling, `matchBase` behavior, dotfile filtering, and globstar segment isolation.

## Pinned Release
- `minimatch`: `10.1.1`

## Observed Behavior and Traps

1. **Leading Hash (`#`) Comment Interpretation**:
   - By default, patterns starting with `#` are treated as comment lines and match nothing.
   - For example, `minimatch('#header', '#header')` returns `false`.
   - To match a filename starting with `#`, either the `nocomment: true` option must be passed or the hash must be escaped as `\#header`.
   - A naive expectation that `#header` matches `#header` directly fails silently with a false negative (returning `false` instead of `true`).

2. **Negation (`!`), `flipNegate`, and `nonegate`**:
   - A leading `!` negates the match outcome by default (`minimatch('app.js', '!*.js')` is `false`, `minimatch('app.txt', '!*.js')` is `true`).
   - Enabling `flipNegate: true` returns `true` when the underlying pattern matches (`minimatch('app.js', '!*.js', { flipNegate: true })` returns `true`).
   - Enabling `nonegate: true` treats `!` as a literal character rather than a negation prefix (`minimatch('!app.js', '!*.js', { nonegate: true })` returns `true`).

3. **`matchBase` Slash-less Restriction**:
   - `matchBase: true` matches a pattern without slashes against the basename of a nested path (`minimatch('src/components/button.js', '*.js', { matchBase: true })` returns `true`).
   - When `matchBase` is `false`, `*.js` only matches root-level files.
   - If the pattern contains any slash (e.g. `components/*.js`), `matchBase` has no effect and matching evaluates against the full path from root.

4. **Dotfile Exclusion**:
   - By default (`dot: false`), wildcard `*` and globstar `**` do not match leading dots in filenames or directory segments (`minimatch('.env', '*')` and `minimatch('src/.config/app.json', 'src/**/app.json')` return `false`).
   - Matching dotfiles requires either explicit dot patterns (`.*`) or passing `dot: true`.

5. **Globstar Zero-Segment Matching and Isolation**:
   - An isolated globstar `**` between slashes matches zero or more directory segments (`minimatch('src/index.js', 'src/**/index.js')` returns `true`).
   - When `**` is concatenated with characters in a segment (e.g., `src/**index.js`), it behaves as a single wildcard `*` rather than crossing directory boundaries.
csx.json
{"case":{"believed":"patterns starting with a hash character match literal hash-prefixed filenames by default","caseId":"case:sha256:37691ac51126f1ba0907f6fd5f07c83a874d9b195f79e991c8888418ee6d8bb5","contract":["assert minimatch treats leading hash characters as comments that match nothing by default, requiring nocomment or backslash escaping to match literal hashes","assert negation patterns with leading exclamation marks invert matches by default, while flipNegate preserves positive matches and nonegate matches literal exclamation marks","assert matchBase matches slash-less patterns against path basenames but is ignored when the pattern contains a slash","assert dotfiles are excluded from wildcards and globstars by default unless explicitly matched or dot mode is enabled","assert globstar matches zero or more directory levels when isolated between slashes but acts as a single wildcard when concatenated with other characters"],"goal":"Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch","kind":"HOW","packages":["pkg:npm/minimatch@10.1.1"],"schemaVersion":1,"symbols":["minimatch"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/minimatch@10.1.1"],"schemaVersion":1,"symbols":["minimatch"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "minimatch-contract",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "minimatch-contract",
      "version": "1.0.0",
      "dependencies": {
        "minimatch": "10.1.1"
      }
    },
    "node_modules/@isaacs/balanced-match": {
      "version": "4.0.1",
      "resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
      "integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
      "license": "MIT",
      "engines": {
        "node": "20 || >=22"
      }
    },
    "node_modules/@isaacs/brace-expansion": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz",
      "integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==",
      "license": "MIT",
      "dependencies": {
        "@isaacs/balanced-match": "^4.0.1"
      },
      "engines": {
        "node": "20 || >=22"
      }
    },
    "node_modules/minimatch": {
      "version": "10.1.1",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz",
      "integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==",
      "license": "BlueOak-1.0.0",
      "dependencies": {
        "@isaacs/brace-expansion": "^5.0.0"
      },
      "engines": {
        "node": "20 || >=22"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    }
  }
}
package.json
{
  "name": "minimatch-contract",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "minimatch": "10.1.1"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { minimatch } from 'minimatch';

// 1. Comment handling: leading '#' is treated as a comment and matches nothing unless disabled or escaped
assert.strictEqual(minimatch('#header', '#header'), false);
assert.strictEqual(minimatch('#header', '#header', { nocomment: true }), true);
assert.strictEqual(minimatch('#header', '\\#header'), true);

// 2. Negation: leading '!' inverts match; flipNegate restores positive evaluation; nonegate treats '!' literally
assert.strictEqual(minimatch('app.js', '!*.js'), false);
assert.strictEqual(minimatch('app.txt', '!*.js'), true);
assert.strictEqual(minimatch('app.js', '!*.js', { flipNegate: true }), true);
assert.strictEqual(minimatch('!app.js', '!*.js', { nonegate: true }), true);

// 3. matchBase behavior: matches basenames only if pattern contains no slashes
assert.strictEqual(minimatch('src/components/button.js', '*.js'), false);
assert.strictEqual(minimatch('src/components/button.js', '*.js', { matchBase: true }), true);
assert.strictEqual(minimatch('src/components/button.js', 'components/*.js', { matchBase: true }), false);

// 4. Dotfile behavior: leading dot paths excluded by default unless explicitly matched or dot: true is passed
assert.strictEqual(minimatch('.env', '*'), false);
assert.strictEqual(minimatch('.env', '.*'), true);
assert.strictEqual(minimatch('src/.config/app.json', 'src/**/app.json'), false);
assert.strictEqual(minimatch('src/.config/app.json', 'src/**/app.json', { dot: true }), true);

// 5. Globstar behavior: '**' spans zero or more path segments only when isolated between slashes
assert.strictEqual(minimatch('src/index.js', 'src/**/index.js'), true);
assert.strictEqual(minimatch('src/nested/dir/index.js', 'src/**/index.js'), true);
assert.strictEqual(minimatch('src/a/b/index.js', 'src/**index.js'), false);

Origin Seeder

csx-seed