CodeSampleX

Exemple

@eslint/plugin-kit 0.7.3: TextSourceCodeBase.getAncestors

Échantillon vérifié pour npm @eslint/plugin-kit 0.7.3: TextSourceCodeBase.getAncestors. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a…

sha256:87c3cc4282ca90bd88b7d033d9c71e67d049698a189885be4204651a2ca6c083

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify TextSourceCodeBase.getAncestors in pkg:npm/%40eslint/plugin-kit@0.7.3
Paquets
Symboles
  • TextSourceCodeBase.getAncestors
Environnement
node 22.23.2
Créé
2026-09-05T16:41:18Z

Contrat

  1. assert TextSourceCodeBase getAncestors throws TypeError when node is missing
  2. assert TextSourceCodeBase getAncestors throws error when getParent is not implemented
  3. assert TextSourceCodeBase getAncestors returns empty array for root node without parent
  4. assert TextSourceCodeBase getAncestors returns ancestors ordered from root to immediate parent
  5. assert TreeSourceCode resolves ancestors across multiple nested AST levels

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 TextSourceCodeBase.getAncestors in pkg:npm/%40eslint/plugin-kit@0.7.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40eslint/plugin-kit@0.7.3
Demonstrate these symbols/APIs:
  - TextSourceCodeBase.getAncestors

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:4ed5df7fc92365df518c72f1e8217b2415996f3493cf6e32248731b2ec554eee","constraints":{"executionContext":"node"},"contract":["assert TextSourceCodeBase getAncestors throws TypeError when node is missing","assert TextSourceCodeBase getAncestors throws error when getParent is not implemented","assert TextSourceCodeBase getAncestors returns empty array for root node without parent","assert TextSourceCodeBase getAncestors returns ancestors ordered from root to immediate parent","assert TreeSourceCode resolves ancestors across multiple nested AST levels"],"goal":"verify TextSourceCodeBase.getAncestors in pkg:npm/%40eslint/plugin-kit@0.7.3","kind":"HOW","packages":["pkg:npm/%40eslint/plugin-kit@0.7.3"],"schemaVersion":1,"symbols":["TextSourceCodeBase.getAncestors"]},"contractCommand":["node","test/contract.mjs"],"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/%40eslint/plugin-kit@0.7.3"],"schemaVersion":1,"subject":"pkg:npm/%40eslint/plugin-kit@0.7.3","symbols":["TextSourceCodeBase.getAncestors"],"verifierAdapter":"node-typescript@1"}
index.js
const { TextSourceCodeBase } = require("@eslint/plugin-kit");

/**
 * TextSourceCodeBase subclass that resolves parent nodes via an internal mapping.
 */
class TreeSourceCode extends TextSourceCodeBase {
  /**
   * Internal mapping from child nodes to their parent nodes.
   * @type {Map<object, object>}
   */
  #parents = new Map();

  /**
   * @param {object} options
   * @param {string} options.text
   * @param {object} options.ast
   * @param {Array<[object, object]>} [options.parents]
   * @param {RegExp} [options.lineEndingPattern]
   */
  constructor({ text, ast, parents = [], lineEndingPattern }) {
    super({ text, ast, lineEndingPattern });
    for (const [child, parent] of parents) {
      this.#parents.set(child, parent);
    }
  }

  /**
   * Returns the parent of the given node.
   * @param {object} node
   * @returns {object|undefined}
   */
  getParent(node) {
    return this.#parents.get(node);
  }
}

module.exports = {
  TextSourceCodeBase,
  TreeSourceCode,
};
package-lock.json
{
  "name": "sample-eslint-plugin-kit-text-source-code-base",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-eslint-plugin-kit-text-source-code-base",
      "version": "1.0.0",
      "dependencies": {
        "@eslint/plugin-kit": "0.7.3"
      },
      "license": "MIT-0"
    },
    "node_modules/@eslint/core": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/@eslint/core/-/core-1.2.1.tgz",
      "integrity": "sha512-MwcE1P+AZ4C6DWlpin/OmOA54mmIZ/+xZuJiQd4SyB29oAJjN30UW9wkKNptW2ctp4cEsvhlLY/CsQ1uoHDloQ==",
      "license": "Apache-2.0",
      "dependencies": {
        "@types/json-schema": "^7.0.15"
      },
      "engines": {
        "node": "^20.19.0 || ^22.13.0 || >=24"
      }
    },
    "node_modules/@eslint/plugin-kit": {
      "version": "0.7.3",
      "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.7.3.tgz",
      "integrity": "sha512-IkO+/KEUvwbVpiURZg+P7zF74z5Jxe0UgJxVni+RtoHQ6IZieXaO02kmadomap/q+l6bc/jdPGGqTjhuZnuz1Q==",
      "license": "Apache-2.0",
      "dependencies": {
        "@eslint/core": "^1.2.1",
        "levn": "^0.4.1"
      },
      "engines": {
        "node": "^20.19.0 || ^22.13.0 || >=24"
      }
    },
    "node_modules/@types/json-schema": {
      "version": "7.0.15",
      "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
      "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
      "license": "MIT"
    },
    "node_modules/levn": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
      "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==",
      "license": "MIT",
      "dependencies": {
        "prelude-ls": "^1.2.1",
        "type-check": "~0.4.0"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/prelude-ls": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
      "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/type-check": {
      "version": "0.4.0",
      "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
      "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==",
      "license": "MIT",
      "dependencies": {
        "prelude-ls": "^1.2.1"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    }
  }
}
package.json
{
  "name": "sample-eslint-plugin-kit-text-source-code-base",
  "version": "1.0.0",
  "description": "Clean-room sample verifying TextSourceCodeBase.getAncestors from @eslint/plugin-kit",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "@eslint/plugin-kit": "0.7.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify TextSourceCodeBase.getAncestors in pkg:npm/%40eslint/plugin-kit@0.7.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40eslint/plugin-kit@0.7.3"
  ],
  "symbols": [
    "TextSourceCodeBase.getAncestors"
  ]
}
test/contract.mjs
import assert from "node:assert";
import { TextSourceCodeBase, TreeSourceCode } from "../index.js";

// Subclass without implementing getParent
class UnimplementedSourceCode extends TextSourceCodeBase {}

// 1. assert TextSourceCodeBase getAncestors throws TypeError when node is missing
{
  const ast = { type: "Program" };
  const sourceCode = new TreeSourceCode({ text: "let a = 1;", ast });
  assert.throws(
    () => sourceCode.getAncestors(),
    {
      name: "TypeError",
      message: "Missing required argument: node.",
    }
  );
  assert.throws(
    () => sourceCode.getAncestors(null),
    {
      name: "TypeError",
      message: "Missing required argument: node.",
    }
  );
}

// 2. assert TextSourceCodeBase getAncestors throws error when getParent is not implemented
{
  const ast = { type: "Program" };
  const sourceCode = new UnimplementedSourceCode({ text: "let a = 1;", ast });
  const node = { type: "Identifier", name: "a" };
  assert.throws(
    () => sourceCode.getAncestors(node),
    {
      name: "Error",
      message: "Not implemented.",
    }
  );
}

// 3. assert TextSourceCodeBase getAncestors returns empty array for root node without parent
{
  const ast = { type: "Program" };
  const sourceCode = new TreeSourceCode({ text: "let a = 1;", ast });
  const ancestors = sourceCode.getAncestors(ast);
  assert.ok(Array.isArray(ancestors));
  assert.strictEqual(ancestors.length, 0);
}

// 4. assert TextSourceCodeBase getAncestors returns ancestors ordered from root to immediate parent
{
  const root = { type: "Program" };
  const decl = { type: "VariableDeclaration" };
  const id = { type: "Identifier", name: "x" };

  const sourceCode = new TreeSourceCode({
    text: "let x = 10;",
    ast: root,
    parents: [
      [decl, root],
      [id, decl],
    ],
  });

  const ancestors = sourceCode.getAncestors(id);
  assert.deepStrictEqual(ancestors, [root, decl]);
}

// 5. assert TreeSourceCode resolves ancestors across multiple nested AST levels
{
  const root = { type: "Program" };
  const func = { type: "FunctionDeclaration" };
  const block = { type: "BlockStatement" };
  const exprStmt = { type: "ExpressionStatement" };
  const call = { type: "CallExpression" };

  const sourceCode = new TreeSourceCode({
    text: "function fn() { call(); }",
    ast: root,
    parents: [
      [func, root],
      [block, func],
      [exprStmt, block],
      [call, exprStmt],
    ],
  });

  const ancestors = sourceCode.getAncestors(call);
  assert.strictEqual(ancestors.length, 4);
  assert.strictEqual(ancestors[0], root);
  assert.strictEqual(ancestors[1], func);
  assert.strictEqual(ancestors[2], block);
  assert.strictEqual(ancestors[3], exprStmt);
}

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

Seeder d'origine

anonyme