CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-prettier-standard

Combines Prettier formatting with ESLint Standard linting into a unified command-line tool for JavaScript code quality.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

Prettier Standard

Prettier Standard is a unified command-line tool that combines Prettier formatting with ESLint Standard linting for JavaScript code. It eliminates the need to configure and run multiple tools by providing a single command that formats code with Prettier (via prettierx) and lints with ESLint using Standard rules.

Package Information

  • Package Name: prettier-standard
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev prettier-standard or npm install -g prettier-standard
  • Node.js requirement: >=8

Core Imports

const { format, check, run } = require('prettier-standard');

For ES modules:

import { format, check, run } from 'prettier-standard';

Basic Usage

const { format, check, run } = require('prettier-standard');

// Format source code
const formatted = format('function foo(){return "hello";}');
// Result: 'function foo () {\n  return \'hello\'\n}\n'

// Check if code is properly formatted
const isValid = check('function foo () {\n  return \'hello\'\n}\n');
// Result: true

// Process files in a directory
await run(process.cwd(), {
  patterns: ['src/**/*.js'],
  lint: true,
  check: false
});

Architecture

Prettier Standard is built around several key components:

  • Core API Functions: Direct formatting and checking functions (format, check)
  • File Processing Engine: Batch file processing with glob pattern support (run)
  • CLI Interface: Command-line tool with comprehensive options
  • Git Integration: SCM-aware processing for changed files and staged files
  • ESLint Integration: Configurable linting with Standard rules preset
  • Configuration System: Support for .prettierrc and .eslintrc files

Capabilities

Code Formatting

Core formatting functionality that transforms JavaScript code using Prettier with Standard-compliant defaults including single quotes, no semicolons, and proper spacing.

function format(source, options);
function check(source, options);
function formatWithCursor(source, options);
function formatWithRanges(source, ranges, options);
function checkWithRanges(source, ranges, options);
function getFileInfo(filePath, options);
resolveConfig.sync(filePath, options);
function clearConfigCache();
function getSupportInfo();

Code Formatting

File Processing

Batch file processing system that can format and lint multiple files with glob patterns, Git integration, and configurable processing modes.

async function run(cwd, config);

interface RunConfig {
  patterns?: string[];
  check?: boolean;
  lint?: boolean;
  changed?: boolean;
  since?: string;
  staged?: boolean;
  lines?: boolean;
  options?: object;
  onStart?: (params: { engine?: object }) => void;
  onProcessed?: (result: ProcessResult) => void;
}

interface ProcessResult {
  file: string;
  runtime: number;
  formatted: boolean;
  report?: object;
  check?: boolean;
}

File Processing

CLI Interface

Command-line interface providing comprehensive options for formatting, linting, and processing files with various modes including staged files, changed files, and range-based processing.

# Basic usage
prettier-standard [<glob>]

# Common options
prettier-standard --lint --staged
prettier-standard --check '**/*.js'
prettier-standard --since master

CLI Interface

Types

// Prettier options with Standard defaults
interface PrettierOptions {
  spaceBeforeFunctionParen?: boolean; // default: true
  generatorStarSpacing?: boolean;     // default: true
  yieldStarSpacing?: boolean;         // default: true
  singleQuote?: boolean;              // default: true
  semi?: boolean;                     // default: false
  jsxSingleQuote?: boolean;           // default: true
  parser?: string;                    // default: 'babel'
  filepath?: string;
  [key: string]: any;
}

// Configuration for the run function
interface RunConfig {
  patterns?: string[];        // File patterns to process
  check?: boolean;           // Check formatting without modifying
  lint?: boolean;            // Perform linting after formatting
  changed?: boolean;         // Process only changed files
  since?: string;            // Process changes since revision
  staged?: boolean;          // Process only staged files
  lines?: boolean;           // Process only changed lines (experimental)
  options?: PrettierOptions; // Prettier configuration options
  onStart?: (params: { engine?: object }) => void;
  onProcessed?: (result: ProcessResult) => void;
}

// Result object passed to onProcessed callback
interface ProcessResult {
  file: string;      // File path processed
  runtime: number;   // Processing time in milliseconds
  formatted: boolean; // Whether file was already formatted
  report?: object;   // ESLint report if linting enabled
  check?: boolean;   // Whether in check mode
}

// Range object for partial formatting
interface Range {
  rangeStart: number; // Start character position
  rangeEnd: number;   // End character position
}

Install with Tessl CLI

npx tessl i tessl/npm-prettier-standard
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/prettier-standard@16.4.x
Publish Source
CLI
Badge
tessl/npm-prettier-standard badge