CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-snazzy

Format JavaScript Standard Style as Stylish (i.e. snazzy) output

94

1.18x
Overview
Eval results
Files

task.mdevals/scenario-4/

Code Quality Report Tool

Goal

Build a command-line tool that processes code quality reports from stdin and outputs formatted results. The tool must correctly report success or failure to the calling process through its exit code, enabling integration with CI/CD pipelines and automated workflows.

Requirements

Input Format

The tool must read JSON data from stdin. The input contains an array of file reports, where each report includes:

  • A file path
  • An array of issues found in that file
  • Each issue contains: line number, column number, severity level, and description

Example input structure:

[
  {
    "file": "src/app.js",
    "issues": [
      {"line": 10, "column": 5, "severity": "error", "message": "Undefined variable"},
      {"line": 15, "column": 2, "severity": "warning", "message": "Unused import"}
    ]
  },
  {
    "file": "src/utils.js",
    "issues": []
  }
]

Output Format

The tool should output a human-readable summary to stdout showing:

  • Each file with issues
  • The total count of issues found
  • A clear indication of whether the check passed or failed

Exit Code Behavior

The tool MUST set its exit code to communicate results to the calling process:

  • Exit with code 0 if no issues are found (all files passed)
  • Exit with code 1 if one or more issues are found
  • The exit code must be properly set even when the tool is used programmatically as a stream

Implementation Constraints

  1. The tool must work as a standalone CLI program that reads from stdin
  2. The tool should also be usable programmatically as a Node.js module
  3. When used programmatically, it should expose the exit code through a property that can be checked after processing completes
  4. The exit code should only be set after all input has been fully processed
  5. If the process would already exit with a non-zero code, do not override it

Dependencies { .dependencies }

snazzy { .dependency }

A Node.js package for formatting linter output. Use this as a reference for implementing proper exit code handling patterns.

Test Cases

Test 1: Clean Report (No Issues) { .test }

Input (via stdin):

[
  {"file": "src/clean.js", "issues": []},
  {"file": "src/perfect.js", "issues": []}
]

Expected stdout:

All files passed - no issues found

Expected exit code: 0

Test file: tests/cli.test.js

Test 2: Report with Issues { .test }

Input (via stdin):

[
  {
    "file": "src/buggy.js",
    "issues": [
      {"line": 5, "column": 10, "severity": "error", "message": "Syntax error"}
    ]
  }
]

Expected stdout (must include):

src/buggy.js
  5:10  error  Syntax error

1 issue found

Expected exit code: 1

Test file: tests/cli.test.js

Test 3: Programmatic Usage with Exit Code Check { .test }

Test code:

const QualityReporter = require('./reporter');
const { Readable } = require('stream');

const input = JSON.stringify([
  {
    file: "test.js",
    issues: [{ line: 1, column: 1, severity: "error", message: "Failed" }]
  }
]);

const reporter = new QualityReporter();
const inputStream = Readable.from([input]);

inputStream.pipe(reporter).pipe(process.stdout);

reporter.on('finish', () => {
  console.log(`Exit code: ${reporter.exitCode}`);
  // Should output: Exit code: 1
});

Expected: The reporter instance should expose an exitCode property set to 1 after processing completes.

Test file: tests/programmatic.test.js

Install with Tessl CLI

npx tessl i tessl/npm-snazzy

tile.json