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.00
# Prettier Standard
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: prettier-standard
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install --save-dev prettier-standard` or `npm install -g prettier-standard`
10
- **Node.js requirement**: >=8
11
12
## Core Imports
13
14
```javascript
15
const { format, check, run } = require('prettier-standard');
16
```
17
18
For ES modules:
19
20
```javascript
21
import { format, check, run } from 'prettier-standard';
22
```
23
24
## Basic Usage
25
26
```javascript
27
const { format, check, run } = require('prettier-standard');
28
29
// Format source code
30
const formatted = format('function foo(){return "hello";}');
31
// Result: 'function foo () {\n return \'hello\'\n}\n'
32
33
// Check if code is properly formatted
34
const isValid = check('function foo () {\n return \'hello\'\n}\n');
35
// Result: true
36
37
// Process files in a directory
38
await run(process.cwd(), {
39
patterns: ['src/**/*.js'],
40
lint: true,
41
check: false
42
});
43
```
44
45
## Architecture
46
47
Prettier Standard is built around several key components:
48
49
- **Core API Functions**: Direct formatting and checking functions (`format`, `check`)
50
- **File Processing Engine**: Batch file processing with glob pattern support (`run`)
51
- **CLI Interface**: Command-line tool with comprehensive options
52
- **Git Integration**: SCM-aware processing for changed files and staged files
53
- **ESLint Integration**: Configurable linting with Standard rules preset
54
- **Configuration System**: Support for .prettierrc and .eslintrc files
55
56
## Capabilities
57
58
### Code Formatting
59
60
Core formatting functionality that transforms JavaScript code using Prettier with Standard-compliant defaults including single quotes, no semicolons, and proper spacing.
61
62
```javascript { .api }
63
function format(source, options);
64
function check(source, options);
65
function formatWithCursor(source, options);
66
function formatWithRanges(source, ranges, options);
67
function checkWithRanges(source, ranges, options);
68
function getFileInfo(filePath, options);
69
resolveConfig.sync(filePath, options);
70
function clearConfigCache();
71
function getSupportInfo();
72
```
73
74
[Code Formatting](./formatting.md)
75
76
### File Processing
77
78
Batch file processing system that can format and lint multiple files with glob patterns, Git integration, and configurable processing modes.
79
80
```javascript { .api }
81
async function run(cwd, config);
82
83
interface RunConfig {
84
patterns?: string[];
85
check?: boolean;
86
lint?: boolean;
87
changed?: boolean;
88
since?: string;
89
staged?: boolean;
90
lines?: boolean;
91
options?: object;
92
onStart?: (params: { engine?: object }) => void;
93
onProcessed?: (result: ProcessResult) => void;
94
}
95
96
interface ProcessResult {
97
file: string;
98
runtime: number;
99
formatted: boolean;
100
report?: object;
101
check?: boolean;
102
}
103
```
104
105
[File Processing](./file-processing.md)
106
107
### CLI Interface
108
109
Command-line interface providing comprehensive options for formatting, linting, and processing files with various modes including staged files, changed files, and range-based processing.
110
111
```bash { .api }
112
# Basic usage
113
prettier-standard [<glob>]
114
115
# Common options
116
prettier-standard --lint --staged
117
prettier-standard --check '**/*.js'
118
prettier-standard --since master
119
```
120
121
[CLI Interface](./cli.md)
122
123
## Types
124
125
```javascript { .api }
126
// Prettier options with Standard defaults
127
interface PrettierOptions {
128
spaceBeforeFunctionParen?: boolean; // default: true
129
generatorStarSpacing?: boolean; // default: true
130
yieldStarSpacing?: boolean; // default: true
131
singleQuote?: boolean; // default: true
132
semi?: boolean; // default: false
133
jsxSingleQuote?: boolean; // default: true
134
parser?: string; // default: 'babel'
135
filepath?: string;
136
[key: string]: any;
137
}
138
139
// Configuration for the run function
140
interface RunConfig {
141
patterns?: string[]; // File patterns to process
142
check?: boolean; // Check formatting without modifying
143
lint?: boolean; // Perform linting after formatting
144
changed?: boolean; // Process only changed files
145
since?: string; // Process changes since revision
146
staged?: boolean; // Process only staged files
147
lines?: boolean; // Process only changed lines (experimental)
148
options?: PrettierOptions; // Prettier configuration options
149
onStart?: (params: { engine?: object }) => void;
150
onProcessed?: (result: ProcessResult) => void;
151
}
152
153
// Result object passed to onProcessed callback
154
interface ProcessResult {
155
file: string; // File path processed
156
runtime: number; // Processing time in milliseconds
157
formatted: boolean; // Whether file was already formatted
158
report?: object; // ESLint report if linting enabled
159
check?: boolean; // Whether in check mode
160
}
161
162
// Range object for partial formatting
163
interface Range {
164
rangeStart: number; // Start character position
165
rangeEnd: number; // End character position
166
}
167
```