Combines Prettier formatting with ESLint Standard linting into a unified command-line tool for JavaScript code quality.
npx @tessl/cli install tessl/npm-prettier-standard@16.4.0Prettier 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.
npm install --save-dev prettier-standard or npm install -g prettier-standardconst { format, check, run } = require('prettier-standard');For ES modules:
import { format, check, run } from 'prettier-standard';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
});Prettier Standard is built around several key components:
format, check)run)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();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;
}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// 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
}