CodeSampleX

Sample

@typescript-eslint/scope-manager 8.65.0: ForScope

Verified sample for npm @typescript-eslint/scope-manager 8.65.0: ForScope. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:327613b4abf29ee8237a2dfad8e61bc2e1725cdd13c6cece937512f639032cb0

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
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-05

Case

HOW
Goal
verify @typescript-eslint/scope-manager.ForScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Packages
Symbols
  • @typescript-eslint/scope-manager.ForScope
Created
2026-09-05T17:17:55Z

Contract

  1. ForScope is exported by @typescript-eslint/scope-manager and instantiates with for ScopeType, upper scope, and block AST node
  2. ScopeManager.nestForScope creates and registers a ForScope within the active scope hierarchy
  3. analyze produces a ForScope for standard for-loops with block-scoped iteration variables and resolves identifier references
  4. ForScope captures iteration variables declared in for-in and for-of loops including destructuring patterns
  5. ForScope nests child block scopes for loop bodies and links parent-child scope references correctly

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify @typescript-eslint/scope-manager.ForScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40typescript-eslint/scope-manager@8.65.0
Demonstrate these symbols/APIs:
  - @typescript-eslint/scope-manager.ForScope

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:34c9b788605de93d4e55f8fc942baae37b634c9a9dbca2d4e59cd0c765ac7ecd","contract":["ForScope is exported by @typescript-eslint/scope-manager and instantiates with for ScopeType, upper scope, and block AST node","ScopeManager.nestForScope creates and registers a ForScope within the active scope hierarchy","analyze produces a ForScope for standard for-loops with block-scoped iteration variables and resolves identifier references","ForScope captures iteration variables declared in for-in and for-of loops including destructuring patterns","ForScope nests child block scopes for loop bodies and links parent-child scope references correctly"],"goal":"verify @typescript-eslint/scope-manager.ForScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.65.0"],"schemaVersion":1,"symbols":["@typescript-eslint/scope-manager.ForScope"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.65.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/scope-manager@8.65.0","symbols":["@typescript-eslint/scope-manager.ForScope"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-scope-manager-for-scope",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-scope-manager-for-scope",
      "version": "1.0.0",
      "dependencies": {
        "@typescript-eslint/scope-manager": "8.65.0"
      }
    },
    "node_modules/@typescript-eslint/scope-manager": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.65.0.tgz",
      "integrity": "sha512-Esbl8OSYiVxBokYgWPf7VVWg/BE798wXhimnn9ML9Pt5qoDf8bfQlgjlKXR/k98+AcNzlLKYrpCcrcuZ9DZLgg==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.0",
        "@typescript-eslint/visitor-keys": "8.65.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/@typescript-eslint/types": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.65.0.tgz",
      "integrity": "sha512-JSSwWNy+H0E/01jJEM+hrX6N0OFDzFzeIhHFSAS01tlVaevpG8cFyYRPhS5yjGOvBUx3sqQHVMjCL1CAZZMxBg==",
      "license": "MIT",
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/@typescript-eslint/visitor-keys": {
      "version": "8.65.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.65.0.tgz",
      "integrity": "sha512-8C71BQkGjiMmXtop7pHVJu1l2NNShFdkCyD6a2ezzs5vU/L3LRtb69EtcteFwz0mYMPzIgOw0n6OV4VBUWZd7A==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.65.0",
        "eslint-visitor-keys": "^5.0.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/typescript-eslint"
      }
    },
    "node_modules/eslint-visitor-keys": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz",
      "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^20.19.0 || ^22.13.0 || >=24"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/eslint"
      }
    }
  }
}
package.json
{
  "name": "verify-scope-manager-for-scope",
  "version": "1.0.0",
  "private": true,
  "description": "verify @typescript-eslint/scope-manager.ForScope in pkg:npm/@typescript-eslint/scope-manager@8.65.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@typescript-eslint/scope-manager": "8.65.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/scope-manager.ForScope in pkg:npm/%40typescript-eslint/scope-manager@8.65.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/scope-manager@8.65.0"
  ],
  "symbols": [
    "@typescript-eslint/scope-manager.ForScope"
  ]
}
src/index.js
const { ScopeManager, ForScope, analyze } = require('@typescript-eslint/scope-manager');

/**
 * Creates an instance of ForScope directly given a ScopeManager, upper scope, and loop AST node.
 *
 * @param {ScopeManager} scopeManager - The managing ScopeManager instance
 * @param {import('@typescript-eslint/scope-manager').Scope} upperScope - The parent scope
 * @param {object} loopNode - The ESTree/TSESTree ForStatement, ForInStatement, or ForOfStatement AST node
 * @returns {ForScope} The newly instantiated ForScope
 */
function createForScope(scopeManager, upperScope, loopNode) {
  return new ForScope(scopeManager, upperScope, loopNode);
}

/**
 * Nests a ForScope within an existing ScopeManager hierarchy for a loop AST node.
 *
 * @param {ScopeManager} scopeManager - The ScopeManager instance
 * @param {object} loopNode - The ESTree/TSESTree loop AST node
 * @returns {ForScope} The nested ForScope
 */
function nestForScopeInManager(scopeManager, loopNode) {
  return scopeManager.nestForScope(loopNode);
}

/**
 * Analyzes an ESTree/TSESTree Program AST and returns all ForScope instances found.
 *
 * @param {object} ast - The ESTree Program AST node
 * @param {object} [options={}] - Optional analyzer options
 * @returns {ForScope[]} Array of ForScope instances found in the analyzed AST
 */
function findForScopes(ast, options = {}) {
  const scopeManager = analyze(ast, options);
  return scopeManager.scopes.filter((scope) => scope instanceof ForScope);
}

/**
 * Extracts variable names defined within a ForScope (e.g. iteration bindings).
 *
 * @param {ForScope} forScope - The ForScope instance
 * @returns {string[]} Array of declared variable names
 */
function getForVariableNames(forScope) {
  return forScope.variables.map((variable) => variable.name);
}

module.exports = {
  ForScope,
  ScopeManager,
  analyze,
  createForScope,
  nestForScopeInManager,
  findForScopes,
  getForVariableNames,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  ForScope,
  ScopeManager,
  createForScope,
  nestForScopeInManager,
  findForScopes,
  getForVariableNames,
} = require('../src/index.js');
const scopeManagerModule = require('@typescript-eslint/scope-manager');

// 1. ForScope is exported by @typescript-eslint/scope-manager and instantiates with for ScopeType, upper scope, and block AST node
assert.strictEqual(typeof ForScope, 'function', 'ForScope constructor should be exported as a function');
assert.strictEqual(ForScope, scopeManagerModule.ForScope, 'ForScope export must match package ForScope export');

const sm1 = new ScopeManager({});
const globalNode1 = { type: 'Program', body: [] };
const globalScope1 = sm1.nestGlobalScope(globalNode1);
const forNode1 = {
  type: 'ForStatement',
  init: null,
  test: null,
  update: null,
  body: { type: 'BlockStatement', body: [] },
};
const directScope = createForScope(sm1, globalScope1, forNode1);

assert.strictEqual(directScope instanceof ForScope, true, 'Instance should be an instanceof ForScope');
assert.strictEqual(directScope.type, 'for', 'Scope type must be "for"');
assert.strictEqual(directScope.upper, globalScope1, 'ForScope upper must point to the parent scope');
assert.strictEqual(directScope.block, forNode1, 'ForScope block must point to the loop AST node');

// 2. ScopeManager.nestForScope creates and registers a ForScope within the active scope hierarchy
const sm2 = new ScopeManager({});
const globalNode2 = { type: 'Program', body: [] };
sm2.nestGlobalScope(globalNode2);
const forNode2 = {
  type: 'ForStatement',
  init: null,
  test: null,
  update: null,
  body: { type: 'BlockStatement', body: [] },
};

const nestedScope = nestForScopeInManager(sm2, forNode2);
assert.strictEqual(nestedScope instanceof ForScope, true, 'nestedScope should be an instance of ForScope');
assert.strictEqual(nestedScope.type, 'for', 'nestedScope type must be "for"');
assert.strictEqual(sm2.scopes.includes(nestedScope), true, 'ScopeManager scopes array must contain the ForScope');
assert.strictEqual(sm2.acquire(forNode2), nestedScope, 'ScopeManager acquire must resolve the loop node to the ForScope');
assert.strictEqual(sm2.currentScope, nestedScope, 'ScopeManager currentScope should be updated to the ForScope');

// 3. analyze produces a ForScope for standard for-loops with block-scoped iteration variables and resolves identifier references
const astStandard = {
  type: 'Program',
  sourceType: 'script',
  body: [
    {
      type: 'ForStatement',
      init: {
        type: 'VariableDeclaration',
        kind: 'let',
        declarations: [
          {
            type: 'VariableDeclarator',
            id: { type: 'Identifier', name: 'i' },
            init: { type: 'Literal', value: 0 },
          },
        ],
      },
      test: {
        type: 'BinaryExpression',
        operator: '<',
        left: { type: 'Identifier', name: 'i' },
        right: { type: 'Literal', value: 10 },
      },
      update: {
        type: 'UpdateExpression',
        operator: '++',
        argument: { type: 'Identifier', name: 'i' },
        prefix: false,
      },
      body: {
        type: 'BlockStatement',
        body: [
          {
            type: 'ExpressionStatement',
            expression: { type: 'Identifier', name: 'i' },
          },
        ],
      },
    },
  ],
};

const forScopesStandard = findForScopes(astStandard);
assert.strictEqual(forScopesStandard.length, 1, 'Exactly one ForScope should be found in AST');
const [forScope3] = forScopesStandard;

assert.strictEqual(forScope3.type, 'for', 'Scope type must be "for"');
assert.strictEqual(forScope3.set.has('i'), true, 'ForScope set must contain the iteration variable');
const names = getForVariableNames(forScope3);
assert.deepStrictEqual(names, ['i'], 'Variables declared in ForScope must match iteration variable');

const iVariable = forScope3.set.get('i');
assert.strictEqual(iVariable.name, 'i');
assert.strictEqual(iVariable.defs[0].type, 'Variable', 'Variable definition type should be Variable');
assert.ok(iVariable.references.length >= 2, 'Variable should resolve identifier references across test, update, or body');

// 4. ForScope captures iteration variables declared in for-in and for-of loops including destructuring patterns
const astInAndOf = {
  type: 'Program',
  sourceType: 'script',
  body: [
    {
      type: 'ForInStatement',
      left: {
        type: 'VariableDeclaration',
        kind: 'const',
        declarations: [
          {
            type: 'VariableDeclarator',
            id: { type: 'Identifier', name: 'key' },
            init: null,
          },
        ],
      },
      right: { type: 'Identifier', name: 'obj' },
      body: { type: 'BlockStatement', body: [] },
    },
    {
      type: 'ForOfStatement',
      left: {
        type: 'VariableDeclaration',
        kind: 'const',
        declarations: [
          {
            type: 'VariableDeclarator',
            id: {
              type: 'ArrayPattern',
              elements: [
                { type: 'Identifier', name: 'k' },
                { type: 'Identifier', name: 'v' },
              ],
            },
            init: null,
          },
        ],
      },
      right: { type: 'Identifier', name: 'entries' },
      body: { type: 'BlockStatement', body: [] },
    },
  ],
};

const inAndOfScopes = findForScopes(astInAndOf);
assert.strictEqual(inAndOfScopes.length, 2, 'Both for-in and for-of loops must produce ForScope instances');

const [forInScope, forOfScope] = inAndOfScopes;
assert.strictEqual(forInScope.block.type, 'ForInStatement');
assert.deepStrictEqual(getForVariableNames(forInScope), ['key'], 'ForInScope must capture "key" variable');
assert.strictEqual(forInScope.set.has('key'), true);

assert.strictEqual(forOfScope.block.type, 'ForOfStatement');
const destructuredNames = getForVariableNames(forOfScope);
assert.strictEqual(destructuredNames.length, 2, 'ForOfScope must capture destructured variables');
assert.strictEqual(destructuredNames.includes('k'), true);
assert.strictEqual(destructuredNames.includes('v'), true);
assert.strictEqual(forOfScope.set.has('k'), true);
assert.strictEqual(forOfScope.set.has('v'), true);

// 5. ForScope nests child block scopes for loop bodies and links parent-child scope references correctly
const astBody = {
  type: 'Program',
  sourceType: 'script',
  body: [
    {
      type: 'ForStatement',
      init: {
        type: 'VariableDeclaration',
        kind: 'let',
        declarations: [
          {
            type: 'VariableDeclarator',
            id: { type: 'Identifier', name: 'count' },
            init: { type: 'Literal', value: 0 },
          },
        ],
      },
      test: null,
      update: null,
      body: {
        type: 'BlockStatement',
        body: [
          {
            type: 'VariableDeclaration',
            kind: 'let',
            declarations: [
              {
                type: 'VariableDeclarator',
                id: { type: 'Identifier', name: 'innerVar' },
                init: { type: 'Identifier', name: 'count' },
              },
            ],
          },
        ],
      },
    },
  ],
};

const [forScope5] = findForScopes(astBody);
assert.ok(forScope5, 'ForScope should be created');
assert.strictEqual(forScope5.childScopes.length, 1, 'ForScope must contain the inner body BlockScope as child');
const childBlockScope = forScope5.childScopes[0];
assert.strictEqual(childBlockScope.type, 'block', 'Child scope should have type "block"');
assert.strictEqual(childBlockScope.upper, forScope5, 'Child block scope upper pointer must link to ForScope');
assert.strictEqual(childBlockScope.set.has('innerVar'), true, 'Inner block scope should contain innerVar');
assert.strictEqual(forScope5.set.has('count'), true, 'ForScope should contain count');

console.log('All ForScope contract assertions passed successfully.');

Origin Seeder

anonymous