=============== LIBRARY RULES =============== From library maintainers: - StopSlop detects structural code patterns; it does not determine whether code was written by a human or AI. - Run StopSlop without installing it with `npx stopslop .`. It requires Node.js ^20.19.0 or >=22.12.0 and analyzes JavaScript, JSX, TypeScript and TSX. - Exit code 0 means no unaccepted findings, 1 means findings were detected, and 2 means analysis or configuration failed. - Adopt an existing repository with `--baseline .stopslop-baseline.json --update-baseline`, commit that file, then use the same `--baseline` option in CI to reject only new findings. - A baseline changes the gate and reported findings but never lowers the full-repository slop score. - Use `--base ` to compare against a Git revision without maintaining a baseline file. CI must fetch enough Git history to resolve that ref. - Report formats are text, json, sarif and shields. Use JSON for coding agents, SARIF for code scanning and shields for the binary `AI slop | clear` badge. - StopSlop works without configuration. Put optional overrides in `stopslop.json` and use `$schema: https://unpkg.com/stopslop/schema.json` for editor validation. - Use `--fast` only when intentionally skipping duplicate-code and dead-code analysis; it runs the AST checks for cognitive complexity and god units. - The Node API is ESM and typed: call `resolveConfig()` before `analyze()`, or call `loadConfig()` to read stopslop.json. The slop score always describes the complete analyzed repository. - Clone detection is powered by Clone Alert and dead-code analysis by Knip. Configure Knip only under the `knip` property in stopslop.json. ### Full stopslop.json configuration example Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md A complete example showing all available configuration fields and their default values. ```json { "$schema": "https://unpkg.com/stopslop/schema.json", "cognitiveComplexity": 15, "godModule": { "minMembers": 15, "minClusters": 3, "minComplexity": 150, "sizeMembers": 37, "sizeComplexity": 350 }, "godClass": { "minMembers": 12, "minClusters": 3, "minComplexity": 90, "sizeMembers": 30, "sizeComplexity": 200 }, "multipleExportedClasses": { "maxPerFile": 1 }, "duplicates": { "minTokens": 50, "minLines": 5, "ignoreIdentifiers": false, "ignoreLiterals": false }, "deadCode": { "exports": true, "dependencies": true, "files": true, "orphans": true, "production": false }, "knip": { "workspaces": { ".": { "entry": ["src/index.ts"] }, "packages/*": { "entry": ["src/index.ts"], "project": ["src/**/*.ts"] } } }, "score": { "weights": { "god": 0.35, "duplication": 0.25, "complexity": 0.2, "deadCode": 0.2 }, "budgets": { "god": 0.1, "duplication": 0.3, "complexity": 4, "deadCode": 4 }, "floors": { "god": 0, "duplication": 0.05, "complexity": 0, "deadCode": 0 } }, "hubFanInRatio": 0.5, "ignore": [] } ``` -------------------------------- ### Example output report Source: https://github.com/baryshevrs/stopslop/blob/main/README.md The default output format showing repository score, file metrics, and status. ```text stopslop 27 files 4.3 KLOC 980ms slop level: low (22.3/100) · worse than 49% of reference repos god units 0.00/KLOC · complex fns 4.42/KLOC · duplication 0.8% baseline: 23 accepted · 0 new ✓ no new slop since baseline ``` -------------------------------- ### Configure Knip settings Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Example of defining Knip configuration, including ignored dependencies and workspace-specific entry points. ```json { "knip": { "ignoreDependencies": ["optional-adapter"], "workspaces": { ".": { "entry": ["src/index.ts"] }, "packages/*": { "entry": ["src/index.ts"], "project": ["src/**/*.ts"] }, "packages/cli": { "entry": ["src/cli.ts"] } } } } ``` -------------------------------- ### Install and run stopslop Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Add stopslop as a development dependency and execute it using package manager commands. ```bash npm install --save-dev stopslop npx stopslop . # pnpm pnpm add -D stopslop pnpm exec stopslop . # Yarn yarn add --dev stopslop yarn stopslop . ``` -------------------------------- ### Configure score metrics Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Example of setting custom weights, budgets, and floors for the slop level scoring formula. ```json { "score": { "weights": { "god": 0.35, "duplication": 0.25, "complexity": 0.2, "deadCode": 0.2 }, "budgets": { "god": 0.1, "duplication": 0.3, "complexity": 4, "deadCode": 4 }, "floors": { "god": 0, "duplication": 0.05, "complexity": 0, "deadCode": 0 } } } ``` -------------------------------- ### Configure deadCode settings Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Example of disabling file reporting and enabling production mode for dead code analysis. ```json { "deadCode": { "files": false, "production": true } } ``` -------------------------------- ### Record and use a baseline Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Create a baseline file to ignore existing legacy findings and use it as a gate for CI. ```bash # Record accepted legacy. npx stopslop . \ --baseline .stopslop-baseline.json \ --update-baseline git add .stopslop-baseline.json # Use the same file as the CI gate. npx stopslop . --baseline .stopslop-baseline.json ``` -------------------------------- ### CLI Usage Reference Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Displays the available command-line arguments and options for the stopslop utility. ```text stopslop [path] analyze a directory or file (default: .) --format text (default) · json · sarif · shields --json alias for --format json --details, -d show split groups, hubs, and all clone locations --fast skip clone and dead-code analysis --config use a specific stopslop.json --base gate on findings absent from a Git revision --baseline gate on findings absent from a baseline file --update-baseline replace the baseline with current findings --help, -h show help ``` -------------------------------- ### Create and commit a baseline Source: https://github.com/baryshevrs/stopslop/blob/main/docs/ci-and-automation.md Generate a baseline file to suppress existing findings and commit it to version control. ```bash npx stopslop . \ --baseline .stopslop-baseline.json \ --update-baseline git add .stopslop-baseline.json ``` -------------------------------- ### Development Workflow Commands Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Use these commands to manage dependencies, run tests, perform type checks, and build the project. ```bash pnpm install pnpm test pnpm typecheck pnpm check:clones pnpm build pnpm test:package pnpm release:check ``` -------------------------------- ### Load configuration from file or object Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Demonstrates loading configuration from a stopslop.json file or defining it programmatically using StopSlopConfig. ```ts import { analyze, loadConfig } from 'stopslop'; const root = process.cwd(); const result = await analyze(root, loadConfig(root)); ``` ```ts import { analyze, resolveConfig, type StopSlopConfig } from 'stopslop'; const input: StopSlopConfig = { cognitiveComplexity: 20, duplicates: { minTokens: 100, minLines: 10 }, deadCode: { files: false }, }; const result = await analyze(process.cwd(), resolveConfig(input)); ``` -------------------------------- ### Analyze with default configuration Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Resolves default configuration and executes analysis on the current working directory. ```ts import { analyze, resolveConfig } from 'stopslop'; const result = await analyze(process.cwd(), resolveConfig(undefined)); for (const finding of result.findings) { console.log(finding.kind, finding.file, finding.line, finding.message); } console.log({ score: result.slop.score, level: result.slop.level, errors: result.errors, notes: result.notes, }); ``` -------------------------------- ### Configure god class and module thresholds Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Adjust dispersion and size thresholds for flagging god classes or modules. ```json { "godClass": { "sizeMembers": 45, "sizeComplexity": 300 }, "godModule": false } ``` -------------------------------- ### Run StopSlop via npx Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Execute the static analyzer locally against the current directory. ```bash npx stopslop . ``` -------------------------------- ### analyze(root, config, analyzers?) Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Performs analysis on the specified root directory using the provided configuration and optional custom analyzers. ```APIDOC ## analyze(root, config, analyzers?) ### Description Analyzes the codebase at the given root path. Returns findings and slop metrics based on the provided configuration. ### Parameters - **root** (string) - Required - The file system path to the repository root. - **config** (StopSlopConfig) - Required - The resolved configuration object. - **analyzers** (Analyzer[]) - Optional - A list of analyzers to run, including custom ones. ``` -------------------------------- ### Configure multiple exported classes threshold Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Set the maximum number of classes allowed per file before flagging. ```json { "multipleExportedClasses": { "maxPerFile": 2 } } ``` -------------------------------- ### Generate a Shields badge Source: https://github.com/baryshevrs/stopslop/blob/main/docs/ci-and-automation.md Create a JSON file for a Shields badge based on the current baseline. ```bash npx stopslop . \ --baseline .stopslop-baseline.json \ --format shields > stopslop-badge.json ``` -------------------------------- ### Analyze projects using the Node.js API Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Programmatically run analysis on a project directory using the exported analyze and loadConfig functions. ```ts import { analyze, loadConfig } from 'stopslop'; const root = process.cwd(); const result = await analyze(root, loadConfig(root)); console.log(result.slop.score, result.findings); ``` -------------------------------- ### Configure StopSlop with stopslop.json Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Define custom thresholds for cognitive complexity and duplicate detection, or specify files to ignore. ```json { "$schema": "https://unpkg.com/stopslop/schema.json", "cognitiveComplexity": 20, "duplicates": { "minTokens": 100, "minLines": 10, "ignoreIdentifiers": true }, "ignore": ["**/*.generated.ts"] } ``` -------------------------------- ### loadConfig(root) Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Reads and parses the stopslop.json configuration file from the specified root directory. ```APIDOC ## loadConfig(root) ### Description Loads configuration from a 'stopslop.json' file located at the analysis root. ### Parameters - **root** (string) - Required - The directory path containing the configuration file. ``` -------------------------------- ### analyzeGitBase(root, ref, config) Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Performs analysis comparing the current state against a specific Git revision. ```APIDOC ## analyzeGitBase(root, ref, config) ### Description Returns findings that are absent from the specified Git revision while maintaining the current repository's full score. ### Parameters - **root** (string) - Required - The repository root path. - **ref** (string) - Required - The Git revision (e.g., 'origin/main') to compare against. - **config** (StopSlopConfig) - Required - The resolved configuration object. ``` -------------------------------- ### Configure duplicate detection Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Adjust token and line thresholds for copy-paste detection, with options to ignore identifiers or literals. ```json { "duplicates": { "minTokens": 100, "minLines": 10, "ignoreIdentifiers": true } } ``` -------------------------------- ### Emit SARIF report for GitHub Code Scanning Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Generate a SARIF file for integration with GitHub Code Scanning while maintaining gate failure logic. ```bash npx stopslop . --base origin/main --format sarif > stopslop.sarif ``` -------------------------------- ### Publish SARIF and enforce gate Source: https://github.com/baryshevrs/stopslop/blob/main/docs/ci-and-automation.md Configure permissions and workflow steps to upload SARIF reports while ensuring the gate failure is still enforced. ```yaml permissions: contents: read security-events: write ``` ```yaml - name: Scan with StopSlop id: stopslop continue-on-error: true run: npx stopslop . --base origin/main --format sarif > stopslop.sarif - name: Upload StopSlop SARIF if: always() && hashFiles('stopslop.sarif') != '' uses: github/codeql-action/upload-sarif@v4 with: sarif_file: stopslop.sarif - name: Enforce StopSlop gate if: steps.stopslop.outcome == 'failure' run: exit 1 ``` -------------------------------- ### Export structured findings for agents Source: https://github.com/baryshevrs/stopslop/blob/main/docs/ci-and-automation.md Generate a JSON report containing structured findings for use by coding agents. ```bash npx stopslop . --format json > slop-report.json ``` -------------------------------- ### resolveConfig(input) Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Validates and resolves a user-provided configuration object into the internal format required by the analyzer. ```APIDOC ## resolveConfig(input) ### Description Processes a user-facing configuration object. Throws an error if unknown fields or invalid values are provided. ### Parameters - **input** (StopSlopConfig | undefined) - Required - The configuration object defining complexity, duplicate, and dead code thresholds. ``` -------------------------------- ### Generate JSON Report Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Redirects the analysis output to a JSON file for consumption by automated agents. ```bash npx stopslop . --json > slop-report.json ``` -------------------------------- ### Configure cognitive complexity threshold Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Set the maximum allowed cognitive complexity for functions. ```json { "cognitiveComplexity": 20 } ``` -------------------------------- ### Reject new findings in CI Source: https://github.com/baryshevrs/stopslop/blob/main/docs/ci-and-automation.md Use the committed baseline in a CI workflow to reject new AI slop. ```yaml - name: Reject new AI slop run: npx stopslop . --baseline .stopslop-baseline.json ``` -------------------------------- ### Gate pull requests against base branch Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Compare the current working tree against a target branch to identify new findings without a baseline file. ```bash npx stopslop . --base origin/main ``` -------------------------------- ### Compare pull request with Git base Source: https://github.com/baryshevrs/stopslop/blob/main/docs/ci-and-automation.md Configure GitHub Actions to compare the current branch against a base revision. ```yaml - uses: actions/checkout@v7 with: fetch-depth: 0 - name: Reject AI slop added by this change run: npx stopslop . --base origin/main ``` -------------------------------- ### Configure ignore patterns Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Defines additional glob patterns to exclude from analysis beyond the built-in defaults. ```json { "ignore": ["**/*.generated.ts", "src/legacy/**"] } ``` -------------------------------- ### Add status badge to Markdown Source: https://github.com/baryshevrs/stopslop/blob/main/README.md Embed the generated badge in your README using the Shields.io endpoint URL format. ```md [![AI slop](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/OWNER/REPO/main/stopslop-badge.json)](https://github.com/BaryshevRS/stopslop) ``` -------------------------------- ### Extend analyzer list with custom rules Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Appends a custom analyzer to the default set by passing it as a third argument to the analyze function. ```ts import { analyze, defaultAnalyzers, resolveConfig, type Analyzer, } from 'stopslop'; const custom: Analyzer = { name: 'project-policy', analyzeFile(file) { return file.source.includes('DO NOT SHIP') ? [{ kind: 'unused-file', file: file.relPath, symbol: 'DO NOT SHIP', line: 1, severity: 'warn', message: 'Unresolved project marker', }] : []; }, }; const result = await analyze( process.cwd(), resolveConfig(undefined), [...defaultAnalyzers(), custom], ); ``` -------------------------------- ### Compare analysis with a Git revision Source: https://github.com/baryshevrs/stopslop/blob/main/docs/node-api.md Returns findings absent from a specific Git revision while maintaining the current repository's metrics. ```ts import { analyzeGitBase, loadConfig } from 'stopslop'; const root = process.cwd(); const result = await analyzeGitBase(root, 'origin/main', loadConfig(root)); if (result.errors.length > 0) process.exitCode = 2; else if (result.findings.length > 0) process.exitCode = 1; ``` -------------------------------- ### Disable checks Source: https://github.com/baryshevrs/stopslop/blob/main/docs/configuration.md Set a check to false to disable it entirely. ```json { "godModule": false, "multipleExportedClasses": false } ``` -------------------------------- ### Calculate slop level score Source: https://github.com/baryshevrs/stopslop/blob/main/docs/score.md The mathematical formula for calculating the aggregate slop score and the saturation function for individual signals. ```text score = 100 · Σ wᵢ · sat(xᵢ) / Σ wᵢ sat(x) = clamp((x − floorᵢ) / (budgetᵢ − floorᵢ), 0, 1) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.