CodeSampleX

Ejemplo

eslint-scope 8.4.0: analyze

Muestra verificada para npm eslint-scope 8.4.0: analyze. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:ba9e475e49cba3e50ce9c1966890efbb9ba25ec4f1cc660d9ea354064e4eb28b

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-16

Caso

HOW
Objetivo
verify eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0
Paquetes
Símbolos
  • eslint-scope.analyze
Creado
2026-09-16T22:37:47Z

Contrato

  1. assert eslint-scope.analyze returns a ScopeManager instance for an ESTree AST
  2. assert eslint-scope.analyze creates global and module scopes and records module-level declarations
  3. assert eslint-scope.analyze creates function and block scopes and isolates parameters and local variables
  4. assert eslint-scope.analyze acquires associated scope and declared variables for AST nodes
  5. assert eslint-scope.analyze supports nodejsScope option adding an enclosing function scope

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/eslint-scope@8.4.0
Demonstrate these symbols/APIs:
  - eslint-scope.analyze

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:9eb8b46f680e7c539f17362287fb3abbeb42455936efd1b77688451675d5d559","contract":["assert eslint-scope.analyze returns a ScopeManager instance for an ESTree AST","assert eslint-scope.analyze creates global and module scopes and records module-level declarations","assert eslint-scope.analyze creates function and block scopes and isolates parameters and local variables","assert eslint-scope.analyze acquires associated scope and declared variables for AST nodes","assert eslint-scope.analyze supports nodejsScope option adding an enclosing function scope"],"goal":"verify eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0","kind":"HOW","packages":["pkg:npm/eslint-scope@8.4.0"],"schemaVersion":1,"symbols":["eslint-scope.analyze"]},"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/eslint-scope@8.4.0"],"schemaVersion":1,"subject":"pkg:npm/eslint-scope@8.4.0","symbols":["eslint-scope.analyze"],"verifierAdapter":"node-typescript@1"}
index.mjs
import * as eslintScope from 'eslint-scope';

export const { analyze, ScopeManager, Scope, Variable, Reference } = eslintScope;

/**
 * Analyzes an ESTree AST and returns the ScopeManager instance.
 *
 * @param {object} ast ESTree abstract syntax tree
 * @param {object} [options] Analysis configuration options
 * @returns {eslintScope.ScopeManager} Analyzed scope manager
 */
export function analyzeAst(ast, options = {}) {
  return analyze(ast, options);
}

export default analyze;
package-lock.json
{
  "name": "sample-eslint-scope-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-eslint-scope-verify",
      "version": "1.0.0",
      "dependencies": {
        "eslint-scope": "8.4.0"
      }
    },
    "node_modules/eslint-scope": {
      "version": "8.4.0",
      "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz",
      "integrity": "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "esrecurse": "^4.3.0",
        "estraverse": "^5.2.0"
      },
      "engines": {
        "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/eslint"
      }
    },
    "node_modules/esrecurse": {
      "version": "4.3.0",
      "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",
      "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "estraverse": "^5.2.0"
      },
      "engines": {
        "node": ">=4.0"
      }
    },
    "node_modules/estraverse": {
      "version": "5.3.0",
      "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",
      "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=4.0"
      }
    }
  }
}
package.json
{
  "name": "sample-eslint-scope-verify",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "eslint-scope": "8.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify eslint-scope.analyze in pkg:npm/eslint-scope@8.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/eslint-scope@8.4.0"
  ],
  "symbols": [
    "eslint-scope.analyze"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  analyze,
  ScopeManager,
  Scope,
  Variable,
  analyzeAst,
} from '../index.mjs';

function createSampleAst() {
  return {
    type: 'Program',
    range: [0, 100],
    sourceType: 'module',
    body: [
      {
        type: 'VariableDeclaration',
        range: [0, 20],
        kind: 'let',
        declarations: [
          {
            type: 'VariableDeclarator',
            range: [4, 20],
            id: { type: 'Identifier', name: 'count', range: [4, 9] },
            init: { type: 'Literal', value: 0, raw: '0', range: [12, 13] },
          },
        ],
      },
      {
        type: 'FunctionDeclaration',
        range: [22, 90],
        id: { type: 'Identifier', name: 'increment', range: [31, 40] },
        params: [{ type: 'Identifier', name: 'step', range: [41, 45] }],
        body: {
          type: 'BlockStatement',
          range: [47, 90],
          body: [
            {
              type: 'BlockStatement',
              range: [50, 75],
              body: [
                {
                  type: 'VariableDeclaration',
                  range: [52, 65],
                  kind: 'const',
                  declarations: [
                    {
                      type: 'VariableDeclarator',
                      range: [58, 65],
                      id: { type: 'Identifier', name: 'temp', range: [58, 62] },
                      init: { type: 'Identifier', name: 'step', range: [65, 69] },
                    },
                  ],
                },
              ],
            },
            {
              type: 'ReturnStatement',
              range: [77, 88],
              argument: {
                type: 'BinaryExpression',
                range: [84, 88],
                operator: '+',
                left: { type: 'Identifier', name: 'count', range: [84, 85] },
                right: { type: 'Identifier', name: 'step', range: [87, 88] },
              },
            },
          ],
        },
      },
    ],
  };
}

// 1. assert eslint-scope.analyze returns a ScopeManager instance for an ESTree AST
{
  assert.strictEqual(typeof analyze, 'function', 'analyze must be a function');
  const ast = createSampleAst();
  const manager = analyze(ast, { ecmaVersion: 2022, sourceType: 'module' });
  assert.ok(manager instanceof ScopeManager, 'result must be an instance of ScopeManager');
  assert.ok(manager.globalScope instanceof Scope, 'globalScope must be an instance of Scope');
  assert.strictEqual(manager.globalScope.type, 'global');
  assert.ok(Array.isArray(manager.scopes), 'scopes must be an array');
  assert.strictEqual(manager.scopes.length, 4, 'scopes count must match expected');
}

// 2. assert eslint-scope.analyze creates global and module scopes and records module-level declarations
{
  const ast = createSampleAst();
  const manager = analyzeAst(ast, { ecmaVersion: 2022, sourceType: 'module' });
  const moduleScope = manager.scopes.find((s) => s.type === 'module');
  assert.ok(moduleScope, 'module scope must exist');
  assert.strictEqual(moduleScope.upper, manager.globalScope);
  assert.ok(moduleScope.set.has('count'), 'module scope should define count');
  assert.ok(moduleScope.set.has('increment'), 'module scope should define increment');

  const countVar = moduleScope.set.get('count');
  assert.ok(countVar instanceof Variable, 'count must be a Variable instance');
  assert.strictEqual(countVar.name, 'count');
  assert.strictEqual(countVar.defs.length, 1);
  assert.strictEqual(countVar.defs[0].type, 'Variable');
}

// 3. assert eslint-scope.analyze creates function and block scopes and isolates parameters and local variables
{
  const ast = createSampleAst();
  const manager = analyze(ast, { ecmaVersion: 2022, sourceType: 'module' });
  const fnScope = manager.scopes.find((s) => s.type === 'function');
  assert.ok(fnScope, 'function scope must exist');
  assert.ok(fnScope.set.has('arguments'), 'function scope should contain arguments');
  assert.ok(fnScope.set.has('step'), 'function scope should contain parameter step');
  assert.strictEqual(fnScope.block.id.name, 'increment');

  const blockScope = manager.scopes.find((s) => s.type === 'block');
  assert.ok(blockScope, 'block scope must exist');
  assert.ok(blockScope.set.has('temp'), 'block scope should contain local variable temp');
  assert.strictEqual(blockScope.upper, fnScope, 'block scope upper must be function scope');
}

// 4. assert eslint-scope.analyze acquires associated scope and declared variables for AST nodes
{
  const ast = createSampleAst();
  const manager = analyze(ast, { ecmaVersion: 2022, sourceType: 'module' });
  const fnDecl = ast.body[1];
  const acquired = manager.acquire(fnDecl);
  assert.ok(acquired, 'acquire should find scope for function declaration');
  assert.strictEqual(acquired.type, 'function');

  const varDecl = ast.body[0];
  const declared = manager.getDeclaredVariables(varDecl);
  assert.strictEqual(declared.length, 1);
  assert.strictEqual(declared[0].name, 'count');
}

// 5. assert eslint-scope.analyze supports nodejsScope option adding an enclosing function scope
{
  const scriptAst = {
    type: 'Program',
    range: [0, 25],
    sourceType: 'script',
    body: [
      {
        type: 'VariableDeclaration',
        range: [0, 20],
        kind: 'var',
        declarations: [
          {
            type: 'VariableDeclarator',
            range: [4, 20],
            id: { type: 'Identifier', name: 'appConfig', range: [4, 13] },
            init: { type: 'Literal', value: 1, raw: '1', range: [16, 17] },
          },
        ],
      },
    ],
  };

  const nodeManager = analyze(scriptAst, {
    ecmaVersion: 2020,
    sourceType: 'script',
    nodejsScope: true,
  });
  assert.strictEqual(nodeManager.scopes.length, 2);
  assert.strictEqual(nodeManager.scopes[0].type, 'global');
  assert.strictEqual(nodeManager.scopes[1].type, 'function');
  assert.ok(nodeManager.isGlobalReturn());
}

console.log('All eslint-scope.analyze contract assertions passed.');

Seeder de origen

anónimo