CodeSampleX

Beispiel

postcss 8.5.26: rule

Verifiziertes Beispiel für npm postcss 8.5.26: rule. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: postcss.rule creates a new Rule…

sha256:7b217bfe21aed2c4ed2ddd144725239a8b8bcc45fa6649a5e2c931c6e0b963e1

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Fall

HOW
Ziel
verify postcss.rule in pkg:npm/postcss@8.5.26
Pakete
Symbole
  • postcss.rule
Erstellt
2026-08-27T02:13:56Z

Contract

  1. postcss.rule creates a new Rule AST node with type rule
  2. rule instance contains selector and parses multiple comma-separated selectors into selectors array
  3. rule.append adds declaration nodes to the rule AST
  4. rule.walkDecls iterates over child declarations inside the rule
  5. rule.clone creates a copy of the rule with overridden properties
  6. rule.toString serializes the rule AST into valid CSS string format

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 postcss.rule in pkg:npm/postcss@8.5.26
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss@8.5.26
Demonstrate these symbols/APIs:
  - postcss.rule

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:5d5ddb8709c791e60c83ae4c989bc1ab38b37b29e3f8cf0168be9d0ca0086c5f","contract":["postcss.rule creates a new Rule AST node with type rule","rule instance contains selector and parses multiple comma-separated selectors into selectors array","rule.append adds declaration nodes to the rule AST","rule.walkDecls iterates over child declarations inside the rule","rule.clone creates a copy of the rule with overridden properties","rule.toString serializes the rule AST into valid CSS string format"],"goal":"verify postcss.rule in pkg:npm/postcss@8.5.26","kind":"HOW","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"symbols":["postcss.rule"]},"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/postcss@8.5.26"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.26","symbols":["postcss.rule"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-postcss-rule",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-rule",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "postcss": "8.5.26"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.18",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
      "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==",
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    },
    "node_modules/picocolors": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
      "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
      "license": "ISC"
    },
    "node_modules/postcss": {
      "version": "8.5.26",
      "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
      "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==",
      "funding": [
        {
          "type": "opencollective",
          "url": "https://opencollective.com/postcss/"
        },
        {
          "type": "tidelift",
          "url": "https://tidelift.com/funding/github/npm/postcss"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "nanoid": "^3.3.17",
        "picocolors": "^1.1.1",
        "source-map-js": "^1.2.1"
      },
      "engines": {
        "node": "^10 || ^12 || >=14"
      }
    },
    "node_modules/source-map-js": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
      "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-postcss-rule",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "postcss": "8.5.26"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify postcss.rule in pkg:npm/postcss@8.5.26",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss@8.5.26"
  ],
  "symbols": [
    "postcss.rule"
  ]
}
src/index.mjs
import postcss from 'postcss';

/**
 * Creates a new CSS rule node using postcss.rule.
 * @param {string} selector
 * @param {Array<{prop: string, value: string}>} [declarations=[]]
 * @returns {import('postcss').Rule}
 */
export function createRule(selector, declarations = []) {
  const rule = postcss.rule({ selector });
  for (const decl of declarations) {
    rule.append(decl);
  }
  return rule;
}

/**
 * Gets the selector list for a rule.
 * @param {import('postcss').Rule} rule
 * @returns {string[]}
 */
export function getRuleSelectors(rule) {
  return rule.selectors;
}

/**
 * Updates the selectors of a rule.
 * @param {import('postcss').Rule} rule
 * @param {string[]} selectors
 * @returns {string}
 */
export function setRuleSelectors(rule, selectors) {
  rule.selectors = selectors;
  return rule.selector;
}

/**
 * Traverses declarations inside a rule and collects them into an array.
 * @param {import('postcss').Rule} rule
 * @returns {Array<{prop: string, value: string}>}
 */
export function collectDeclarations(rule) {
  const decls = [];
  rule.walkDecls((decl) => {
    decls.push({ prop: decl.prop, value: decl.value });
  });
  return decls;
}

/**
 * Clones a rule with an updated selector.
 * @param {import('postcss').Rule} rule
 * @param {string} newSelector
 * @returns {import('postcss').Rule}
 */
export function cloneRuleWithSelector(rule, newSelector) {
  return rule.clone({ selector: newSelector });
}

/**
 * Formats a rule to a CSS string.
 * @param {import('postcss').Rule} rule
 * @returns {string}
 */
export function formatRule(rule) {
  return rule.toString();
}

export { postcss };
test/contract.mjs
import assert from 'node:assert/strict';
import postcss from 'postcss';
import {
  createRule,
  getRuleSelectors,
  setRuleSelectors,
  collectDeclarations,
  cloneRuleWithSelector,
  formatRule,
} from '../src/index.mjs';

// 1. postcss.rule creates a new Rule AST node with type 'rule'
const rule = postcss.rule({ selector: 'h1, h2' });
assert.equal(rule.type, 'rule');
assert.equal(typeof postcss.rule, 'function');
assert.ok(rule instanceof postcss.Rule);

// 2. rule instance contains selector and parses multiple comma-separated selectors into selectors array
assert.equal(rule.selector, 'h1, h2');
assert.deepEqual(rule.selectors, ['h1', 'h2']);
assert.deepEqual(getRuleSelectors(rule), ['h1', 'h2']);

setRuleSelectors(rule, ['h1', 'h2', 'h3']);
assert.equal(rule.selector, 'h1, h2, h3');
assert.deepEqual(rule.selectors, ['h1', 'h2', 'h3']);

// 3. rule.append adds declaration nodes to the rule AST
const builtRule = createRule('.card', [
  { prop: 'margin', value: '16px' },
  { prop: 'padding', value: '24px' },
]);
assert.equal(builtRule.nodes.length, 2);
assert.equal(builtRule.nodes[0].prop, 'margin');
assert.equal(builtRule.nodes[0].value, '16px');
assert.equal(builtRule.nodes[1].prop, 'padding');
assert.equal(builtRule.nodes[1].value, '24px');

// 4. rule.walkDecls iterates over child declarations inside the rule
const decls = collectDeclarations(builtRule);
assert.equal(decls.length, 2);
assert.deepEqual(decls, [
  { prop: 'margin', value: '16px' },
  { prop: 'padding', value: '24px' },
]);

let visited = 0;
builtRule.walkDecls((decl) => {
  visited++;
  assert.ok(['margin', 'padding'].includes(decl.prop));
});
assert.equal(visited, 2);

// 5. rule.clone creates a copy of the rule with overridden properties
const clonedRule = cloneRuleWithSelector(builtRule, '.card--featured');
assert.equal(clonedRule.selector, '.card--featured');
assert.equal(clonedRule.nodes.length, 2);
assert.equal(builtRule.selector, '.card');
assert.notEqual(clonedRule, builtRule);

// 6. rule.toString serializes the rule AST into valid CSS string format
const cssOutput = formatRule(builtRule);
assert.ok(cssOutput.includes('.card {'));
assert.ok(cssOutput.includes('margin: 16px'));
assert.ok(cssOutput.includes('padding: 24px'));
assert.ok(cssOutput.endsWith('}'));

console.log('All postcss.rule contract tests passed successfully.');

Ursprungs-Seeder

anonym