CodeSampleX

示例

@eslint/plugin-kit 0.7.3

已验证示例 — npm @eslint/plugin-kit 0.7.3. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert TextSourceCodeBase resolves unist position-style nodes…

sha256:3aaa3698b995b0f7ff32d1fd2b7bf5b72ffd32c596d19c21c8bde1f4b037c76d

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-09-05

案例

HOW
目标
verify pkg:npm/%40eslint/plugin-kit@0.7.3
包
环境
node 22.23.2
创建时间
2026-09-05T16:18:06Z

契约

  1. assert TextSourceCodeBase resolves unist position-style nodes for getLoc and getRange
  2. assert TextSourceCodeBase constructor accepts custom lineEndingPattern for CRLF line breaking and index mapping
  3. assert TextSourceCodeBase traverse yields enter and exit VisitNodeStep instances and CallMethodStep instances
  4. assert TextSourceCodeBase getText retrieves node text with beforeCount and afterCount bounds
  5. assert ConfigCommentParser parseDirective returns undefined for comments not matching directive format
  6. assert Directive represents enable, disable, disable-line, and disable-next-line directive types

文件

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

下载源代码构件 (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 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

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:8e1345fcd4ba81747c06ca7ad69ef050efda497b634401928dc94246a188c6f1","constraints":{"executionContext":"node"},"contract":["assert TextSourceCodeBase resolves unist position-style nodes for getLoc and getRange","assert TextSourceCodeBase constructor accepts custom lineEndingPattern for CRLF line breaking and index mapping","assert TextSourceCodeBase traverse yields enter and exit VisitNodeStep instances and CallMethodStep instances","assert TextSourceCodeBase getText retrieves node text with beforeCount and afterCount bounds","assert ConfigCommentParser parseDirective returns undefined for comments not matching directive format","assert Directive represents enable, disable, disable-line, and disable-next-line directive types"],"goal":"verify pkg:npm/%40eslint/plugin-kit@0.7.3","kind":"HOW","packages":["pkg:npm/%40eslint/plugin-kit@0.7.3"],"schemaVersion":1},"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","verifierAdapter":"node-typescript@1"}
index.js
const {
  TextSourceCodeBase,
  VisitNodeStep,
  CallMethodStep,
  ConfigCommentParser,
  Directive,
} = require('@eslint/plugin-kit');

/**
 * Custom SourceCode class supporting AST traversal and Unist-style position nodes.
 */
class PluginSourceCode extends TextSourceCodeBase {
  #parents = new Map();

  getParent(node) {
    return this.#parents.get(node);
  }

  setParent(node, parent) {
    this.#parents.set(node, parent);
  }

  /**
   * Traverses AST yielding VisitNodeStep (enter and exit) and CallMethodStep.
   * @returns {Iterable<object>}
   */
  *traverse() {
    const self = this;
    function* walk(node, parent) {
      if (!node) return;
      self.#parents.set(node, parent);

      yield new VisitNodeStep({
        target: node,
        phase: 1,
        args: [node, parent],
      });

      yield new CallMethodStep({
        target: 'onNodeEnter',
        args: [node.type || 'Unknown'],
      });

      if (Array.isArray(node.children)) {
        for (const child of node.children) {
          yield* walk(child, node);
        }
      }

      yield new VisitNodeStep({
        target: node,
        phase: 2,
        args: [node, parent],
      });
    }

    yield* walk(this.ast, null);
  }

  /**
   * Extracts disable/enable directives from comment nodes.
   * @param {Array<{ value: string }>} commentNodes
   * @returns {Array<Directive>}
   */
  extractDirectives(commentNodes) {
    const parser = new ConfigCommentParser();
    const directives = [];

    for (const comment of commentNodes) {
      const parsed = parser.parseDirective(comment.value);
      if (!parsed) {
        continue;
      }

      if (parsed.label.startsWith('eslint-')) {
        const directiveType = parsed.label.slice('eslint-'.length);
        if (['disable', 'enable', 'disable-line', 'disable-next-line'].includes(directiveType)) {
          directives.push(
            new Directive({
              type: directiveType,
              node: comment,
              value: parsed.value,
              justification: parsed.justification,
            })
          );
        }
      }
    }

    return directives;
  }
}

module.exports = {
  PluginSourceCode,
  TextSourceCodeBase,
  VisitNodeStep,
  CallMethodStep,
  ConfigCommentParser,
  Directive,
};
package-lock.json
{
  "name": "sample-eslint-plugin-kit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-eslint-plugin-kit",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@eslint/plugin-kit": "0.7.3"
      }
    },
    "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",
  "version": "1.0.0",
  "description": "Clean-room sample verifying @eslint/plugin-kit custom source code and traversal",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "@eslint/plugin-kit": "0.7.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40eslint/plugin-kit@0.7.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40eslint/plugin-kit@0.7.3"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import {
  PluginSourceCode,
  TextSourceCodeBase,
  ConfigCommentParser,
} from '../index.js';

// 1. assert TextSourceCodeBase resolves unist position-style nodes for getLoc and getRange
const headingNode = {
  type: 'heading',
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 1, column: 14, offset: 13 },
  },
};
const sourceText = '# Hello World\nSecond line\n';
const rootNode = {
  type: 'root',
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 2, column: 12, offset: 25 },
  },
  children: [headingNode],
};

const pluginCode = new PluginSourceCode({ ast: rootNode, text: sourceText });
const loc = pluginCode.getLoc(headingNode);
assert.deepStrictEqual(loc, headingNode.position);
const range = pluginCode.getRange(headingNode);
assert.deepStrictEqual(range, [0, 13]);

// 2. assert TextSourceCodeBase constructor accepts custom lineEndingPattern for CRLF line breaking and index mapping
const crlfText = 'first line\r\nsecond line\r\nthird line';
const crlfAst = {
  type: 'root',
  loc: {
    start: { line: 1, column: 0 },
    end: { line: 3, column: 10 },
  },
};
const crlfCode = new TextSourceCodeBase({
  text: crlfText,
  ast: crlfAst,
  lineEndingPattern: /\r\n/u,
});
assert.deepStrictEqual(crlfCode.lines, ['first line', 'second line', 'third line']);

const locSecond = crlfCode.getLocFromIndex(12);
assert.strictEqual(locSecond.line, 2);
assert.strictEqual(locSecond.column, 0);

const idxSecond = crlfCode.getIndexFromLoc({ line: 2, column: 0 });
assert.strictEqual(idxSecond, 12);

// 3. assert TextSourceCodeBase traverse yields enter and exit VisitNodeStep instances and CallMethodStep instances
const steps = Array.from(pluginCode.traverse());
assert.ok(steps.length >= 4);

const enterSteps = steps.filter(s => s.type === 'visit' && s.phase === 1);
assert.strictEqual(enterSteps.length, 2);
assert.strictEqual(enterSteps[0].target, rootNode);
assert.strictEqual(enterSteps[0].kind, 1);
assert.strictEqual(enterSteps[1].target, headingNode);

const callSteps = steps.filter(s => s.type === 'call' && s.target === 'onNodeEnter');
assert.strictEqual(callSteps.length, 2);
assert.strictEqual(callSteps[0].kind, 2);
assert.deepStrictEqual(callSteps.map(s => s.args), [['root'], ['heading']]);

const exitSteps = steps.filter(s => s.type === 'visit' && s.phase === 2);
assert.strictEqual(exitSteps.length, 2);
assert.strictEqual(exitSteps[0].target, headingNode);
assert.strictEqual(exitSteps[1].target, rootNode);

// 4. assert TextSourceCodeBase getText retrieves node text with beforeCount and afterCount bounds
const innerNode = {
  type: 'text',
  position: {
    start: { line: 1, column: 3, offset: 2 },
    end: { line: 1, column: 14, offset: 13 },
  },
};
assert.strictEqual(pluginCode.getText(innerNode), 'Hello World');
assert.strictEqual(pluginCode.getText(innerNode, 2), '# Hello World');
assert.strictEqual(pluginCode.getText(innerNode, 2, 1), '# Hello World\n');

// 5. assert ConfigCommentParser parseDirective returns undefined for comments not matching directive format
const parser = new ConfigCommentParser();
assert.strictEqual(parser.parseDirective('TODO: refactor this function'), undefined);
assert.strictEqual(parser.parseDirective('1234 invalid directive'), undefined);
assert.strictEqual(parser.parseDirective(''), undefined);

// 6. assert Directive represents enable, disable, disable-line, and disable-next-line directive types
const commentList = [
  { value: 'eslint-disable-next-line no-console -- temporary log' },
  { value: 'eslint-disable no-alert' },
  { value: 'eslint-enable no-alert -- re-enable' },
  { value: 'eslint-disable-line no-debugger' },
  { value: 'regular comment without directive' },
];
const directives = pluginCode.extractDirectives(commentList);
assert.strictEqual(directives.length, 4);

assert.strictEqual(directives[0].type, 'disable-next-line');
assert.strictEqual(directives[0].value, 'no-console');
assert.strictEqual(directives[0].justification, 'temporary log');

assert.strictEqual(directives[1].type, 'disable');
assert.strictEqual(directives[1].value, 'no-alert');
assert.strictEqual(directives[1].justification, '');

assert.strictEqual(directives[2].type, 'enable');
assert.strictEqual(directives[2].value, 'no-alert');
assert.strictEqual(directives[2].justification, 're-enable');

assert.strictEqual(directives[3].type, 'disable-line');
assert.strictEqual(directives[3].value, 'no-debugger');

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

原始种子者

匿名