CodeSampleX

Пример

@typescript-eslint/scope-manager 8.69.0: TSEnumMemberDefinition

Проверенный пример — npm @typescript-eslint/scope-manager 8.69.0: TSEnumMemberDefinition. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.

sha256:5dd18130c431965289f13a55285e7a8fdfc0c949deb3b6928f8e58d562774a28

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-10-12

Кейс

HOW
Цель
verify @typescript-eslint/scope-manager.TSEnumMemberDefinition in pkg:npm/%40typescript-eslint/scope-manager@8.69.0
Пакеты
Символы
  • @typescript-eslint/scope-manager.TSEnumMemberDefinition
Окружение
node 22.23.2
Создан
2026-10-12T02:21:20Z

Контракт

  1. TSEnumMemberDefinition can be directly instantiated with name and enum member AST nodes
  2. TSEnumMemberDefinition marks definition as both type definition and variable definition
  3. analyze creates TSEnumMemberDefinition for identifier-named enum members
  4. analyze creates TSEnumMemberDefinition for string-literal-named enum members
  5. TSEnumMemberDefinition assigns a unique numeric $id to each instance

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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.TSEnumMemberDefinition in pkg:npm/%40typescript-eslint/scope-manager@8.69.0
Kind: HOW

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

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:c719ca68c5338fcba6b01f418f6cc3ac3bb23c9cc0a7daea05fd08998bc522bd","contract":["TSEnumMemberDefinition can be directly instantiated with name and enum member AST nodes","TSEnumMemberDefinition marks definition as both type definition and variable definition","analyze creates TSEnumMemberDefinition for identifier-named enum members","analyze creates TSEnumMemberDefinition for string-literal-named enum members","TSEnumMemberDefinition assigns a unique numeric $id to each instance"],"goal":"verify @typescript-eslint/scope-manager.TSEnumMemberDefinition in pkg:npm/%40typescript-eslint/scope-manager@8.69.0","kind":"HOW","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.69.0"],"schemaVersion":1,"symbols":["@typescript-eslint/scope-manager.TSEnumMemberDefinition"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40typescript-eslint/scope-manager@8.69.0"],"schemaVersion":1,"subject":"pkg:npm/%40typescript-eslint/scope-manager@8.69.0","symbols":["@typescript-eslint/scope-manager.TSEnumMemberDefinition"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-scope-manager-tsenummemberdefinition",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-scope-manager-tsenummemberdefinition",
      "version": "1.0.0",
      "dependencies": {
        "@typescript-eslint/scope-manager": "8.69.0"
      }
    },
    "node_modules/@typescript-eslint/scope-manager": {
      "version": "8.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.69.0.tgz",
      "integrity": "sha512-ewfspqWvSxKSOaplqAUNbaSFO0eB6w1EtQ+esfYFRm3614Ty4uNtExkcbgd6nWsXphbqKyf9ZYdbZdv2xEoWEQ==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.69.0",
        "@typescript-eslint/visitor-keys": "8.69.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.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.69.0.tgz",
      "integrity": "sha512-K3VrubUPhlo9VDBS6QdI8YB5j7ClpqLRdefcz6PFrhnwicehBweqQ9Evhl4l+FYz0HdDmMqIiSX0aldGRYtDCA==",
      "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.69.0",
      "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.69.0.tgz",
      "integrity": "sha512-+rmdgPA+EXkNgKYvHvFfhrs35utXbwaC5PGpDquSXcoXQDKUA5UjV0LmTucG/4JXkM31BTu4TilHtrN8IVBe8w==",
      "license": "MIT",
      "dependencies": {
        "@typescript-eslint/types": "8.69.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": {
        "url": "https://opencollective.com/eslint"
      }
    }
  }
}
package.json
{
  "name": "verify-scope-manager-tsenummemberdefinition",
  "version": "1.0.0",
  "private": true,
  "description": "verify @typescript-eslint/scope-manager.TSEnumMemberDefinition in pkg:npm/@typescript-eslint/scope-manager@8.69.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@typescript-eslint/scope-manager": "8.69.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @typescript-eslint/scope-manager.TSEnumMemberDefinition in pkg:npm/%40typescript-eslint/scope-manager@8.69.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40typescript-eslint/scope-manager@8.69.0"
  ],
  "symbols": [
    "@typescript-eslint/scope-manager.TSEnumMemberDefinition"
  ]
}
src/index.js
const {
  analyze,
  TSEnumMemberDefinition,
  ScopeType,
  DefinitionType,
} = require('@typescript-eslint/scope-manager');

/**
 * Creates a new TSEnumMemberDefinition instance directly.
 *
 * @param {object} name - The Identifier or StringLiteral node representing the enum member name.
 * @param {object} node - The TSEnumMember AST node.
 * @returns {TSEnumMemberDefinition} The created TSEnumMemberDefinition instance.
 */
function createEnumMemberDefinition(name, node) {
  return new TSEnumMemberDefinition(name, node);
}

/**
 * Analyzes an AST and returns all TSEnumMemberDefinition instances found in the scopes.
 *
 * @param {object} ast - ESTree / TSESTree program AST.
 * @returns {TSEnumMemberDefinition[]} Array of TSEnumMemberDefinition instances.
 */
function extractEnumMemberDefinitions(ast) {
  const scopeManager = analyze(ast);
  const definitions = [];

  for (const scope of scopeManager.scopes) {
    if (scope.type === ScopeType.tsEnum) {
      for (const variable of scope.variables) {
        for (const def of variable.defs) {
          if (def instanceof TSEnumMemberDefinition) {
            definitions.push(def);
          }
        }
      }
    }
  }

  return definitions;
}

/**
 * Checks whether an object is an instance of TSEnumMemberDefinition.
 *
 * @param {unknown} def - Value to check.
 * @returns {boolean} True if the value is a TSEnumMemberDefinition.
 */
function isEnumMemberDefinition(def) {
  return def instanceof TSEnumMemberDefinition;
}

module.exports = {
  createEnumMemberDefinition,
  extractEnumMemberDefinitions,
  isEnumMemberDefinition,
  TSEnumMemberDefinition,
  DefinitionType,
  ScopeType,
  analyze,
};
test/contract.cjs
const assert = require('node:assert/strict');
const {
  createEnumMemberDefinition,
  extractEnumMemberDefinitions,
  isEnumMemberDefinition,
  TSEnumMemberDefinition,
  DefinitionType,
  ScopeType,
  analyze,
} = require('../src/index.js');

// 1. TSEnumMemberDefinition can be directly instantiated with name and enum member AST nodes
const identifierNameNode = {
  type: 'Identifier',
  name: 'Active',
  range: [10, 16],
};
const enumMemberNode = {
  type: 'TSEnumMember',
  id: identifierNameNode,
  initializer: null,
  range: [10, 16],
};

const directDefinition = createEnumMemberDefinition(identifierNameNode, enumMemberNode);

assert.ok(directDefinition, 'Direct definition instance should be created');
assert.ok(isEnumMemberDefinition(directDefinition), 'Instance should be recognized as TSEnumMemberDefinition');
assert.strictEqual(
  directDefinition.type,
  DefinitionType.TSEnumMember,
  'Definition type should match DefinitionType.TSEnumMember'
);
assert.strictEqual(directDefinition.name, identifierNameNode, 'Definition name should refer to the name node');
assert.strictEqual(directDefinition.node, enumMemberNode, 'Definition node should refer to the member node');
assert.strictEqual(directDefinition.parent, null, 'Definition parent should be null');

// 2. TSEnumMemberDefinition marks definition as both type definition and variable definition
assert.strictEqual(
  directDefinition.isTypeDefinition,
  true,
  'TSEnumMemberDefinition should have isTypeDefinition set to true'
);
assert.strictEqual(
  directDefinition.isVariableDefinition,
  true,
  'TSEnumMemberDefinition should have isVariableDefinition set to true'
);

// 3. analyze creates TSEnumMemberDefinition for identifier-named enum members
const identifierAst = {
  type: 'Program',
  body: [
    {
      type: 'TSEnumDeclaration',
      id: { type: 'Identifier', name: 'Direction', range: [0, 9] },
      body: {
        type: 'TSEnumBody',
        members: [
          {
            type: 'TSEnumMember',
            id: { type: 'Identifier', name: 'Up', range: [12, 14] },
            initializer: { type: 'Literal', value: 1, raw: '1', range: [17, 18] },
            range: [12, 18],
          },
          {
            type: 'TSEnumMember',
            id: { type: 'Identifier', name: 'Down', range: [20, 24] },
            initializer: { type: 'Literal', value: 2, raw: '2', range: [27, 28] },
            range: [20, 28],
          },
        ],
        range: [10, 30],
      },
      range: [0, 30],
    },
  ],
  sourceType: 'module',
  range: [0, 30],
};

const scopeManager = analyze(identifierAst);
const enumScope = scopeManager.scopes.find((s) => s.type === ScopeType.tsEnum);
assert.ok(enumScope, 'TSEnumScope should exist for the enum declaration');

const upVariable = enumScope.variables.find((v) => v.name === 'Up');
assert.ok(upVariable, 'Variable for enum member Up should exist in enum scope');
assert.strictEqual(upVariable.defs.length, 1, 'Enum member Up should have exactly one definition');

const upDef = upVariable.defs[0];
assert.ok(upDef instanceof TSEnumMemberDefinition, 'Up definition should be instance of TSEnumMemberDefinition');
assert.strictEqual(upDef.type, DefinitionType.TSEnumMember, 'Up definition type should be TSEnumMember');
assert.strictEqual(upDef.name.name, 'Up', 'Up definition name should be Up');
assert.strictEqual(upDef.isTypeDefinition, true, 'Up definition should be a type definition');
assert.strictEqual(upDef.isVariableDefinition, true, 'Up definition should be a variable definition');

const identifierDefinitions = extractEnumMemberDefinitions(identifierAst);
assert.strictEqual(identifierDefinitions.length, 2, 'Should extract 2 enum member definitions');
assert.ok(identifierDefinitions.every(isEnumMemberDefinition), 'All extracted definitions should be TSEnumMemberDefinition');

// 4. analyze creates TSEnumMemberDefinition for string-literal-named enum members
const stringLiteralAst = {
  type: 'Program',
  body: [
    {
      type: 'TSEnumDeclaration',
      id: { type: 'Identifier', name: 'HttpStatus', range: [0, 10] },
      body: {
        type: 'TSEnumBody',
        members: [
          {
            type: 'TSEnumMember',
            id: { type: 'Literal', value: 'NOT_FOUND', raw: "'NOT_FOUND'", range: [13, 24] },
            initializer: { type: 'Literal', value: 404, raw: '404', range: [27, 30] },
            range: [13, 30],
          },
        ],
        range: [11, 32],
      },
      range: [0, 32],
    },
  ],
  sourceType: 'module',
  range: [0, 32],
};

const literalScopeManager = analyze(stringLiteralAst);
const literalEnumScope = literalScopeManager.scopes.find((s) => s.type === ScopeType.tsEnum);
assert.ok(literalEnumScope, 'TSEnumScope should exist for HttpStatus enum');

const notFoundVariable = literalEnumScope.variables.find((v) => v.name === 'NOT_FOUND');
assert.ok(notFoundVariable, 'Variable for enum member NOT_FOUND should exist in enum scope');
assert.strictEqual(notFoundVariable.defs.length, 1, 'NOT_FOUND should have one definition');

const notFoundDef = notFoundVariable.defs[0];
assert.ok(
  notFoundDef instanceof TSEnumMemberDefinition,
  'NOT_FOUND definition should be instance of TSEnumMemberDefinition'
);
assert.strictEqual(notFoundDef.type, DefinitionType.TSEnumMember, 'Definition type should be TSEnumMember');
assert.strictEqual(notFoundDef.name.value, 'NOT_FOUND', 'Definition name should match string literal value');

// 5. TSEnumMemberDefinition assigns a unique numeric $id to each instance
const secondDefinition = createEnumMemberDefinition(identifierNameNode, enumMemberNode);
assert.strictEqual(typeof directDefinition.$id, 'number', '$id should be a number');
assert.strictEqual(typeof secondDefinition.$id, 'number', '$id should be a number');
assert.notStrictEqual(
  directDefinition.$id,
  secondDefinition.$id,
  'Each TSEnumMemberDefinition instance should have a unique $id'
);

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

Исходный сидер

аноним