Top Related Projects
Find and fix problems in your JavaScript code.
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code
🌟 JavaScript Style Guide, with linter & automatic code fixer
A mighty CSS linter that helps you avoid errors and enforce conventions.
Unified developer tools for JavaScript, TypeScript, and the web
:vertical_traffic_light: An extensible linter for the TypeScript language
Quick Overview
Prettier is an opinionated code formatter that supports multiple programming languages. It automatically formats code to ensure consistent style, removing the need for manual formatting and reducing debates about code style in development teams.
Pros
- Supports a wide range of programming languages and file formats
- Integrates easily with most popular editors and IDEs
- Reduces time spent on manual code formatting
- Helps maintain consistent code style across projects and teams
Cons
- Opinionated nature may not suit all coding preferences
- Limited customization options compared to some other formatters
- Can sometimes produce unexpected formatting results
- May conflict with existing linting rules in some projects
Code Examples
- Basic JavaScript formatting:
// Before formatting
function hello(name) {
console.log("Hello, "+name+"!")
}
// After formatting with Prettier
function hello(name) {
console.log(`Hello, ${name}!`);
}
- Formatting JSX in React:
// Before formatting
function App() {
return (
<div className="App">
<header className="App-header">
<h1>Welcome to React</h1>
<p>Edit <code>src/App.js</code> and save to reload.</p>
</header>
</div>
)
}
// After formatting with Prettier
function App() {
return (
<div className="App">
<header className="App-header">
<h1>Welcome to React</h1>
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
</header>
</div>
);
}
- Formatting CSS:
/* Before formatting */
.example {color: red;
font-size:14px;
margin: 10px 5px;
}
/* After formatting with Prettier */
.example {
color: red;
font-size: 14px;
margin: 10px 5px;
}
Getting Started
To use Prettier in your project:
- Install Prettier:
npm install --save-dev prettier
- Create a configuration file (optional):
echo {}> .prettierrc.json
- Add a script to your
package.json
:
{
"scripts": {
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,scss,md}\""
}
}
- Run Prettier:
npm run format
Competitor Comparisons
Find and fix problems in your JavaScript code.
Pros of ESLint
- More flexible and customizable, allowing for fine-tuned rule configuration
- Capable of detecting logical errors and potential bugs, not just style issues
- Supports plugins for extended functionality and language-specific rules
Cons of ESLint
- Requires more setup and configuration to get started
- Can be slower to run, especially on large codebases
- May lead to inconsistent code style across different projects due to varied configurations
Code Comparison
ESLint configuration example:
{
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "double"],
"indent": ["error", 2]
}
}
Prettier configuration example:
{
"semi": true,
"singleQuote": false,
"tabWidth": 2
}
Summary
ESLint offers more comprehensive linting capabilities, including error detection and custom rule creation. It's highly configurable but requires more setup. Prettier focuses solely on code formatting with minimal configuration, ensuring consistent style across projects. ESLint is better for enforcing coding standards and catching potential issues, while Prettier excels at maintaining uniform code appearance with less effort.
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code
Pros of JSHint
- More flexible and customizable linting rules
- Focuses on detecting potential errors and problematic patterns
- Integrates well with various build tools and IDEs
Cons of JSHint
- Doesn't automatically fix code issues
- Limited formatting capabilities
- Less active development and community support
Code Comparison
JSHint example:
function example(x, y) {
if (x == null)
return y;
return x;
}
Prettier example:
function example(x, y) {
if (x == null) return y;
return x;
}
Key Differences
- Prettier is primarily a code formatter, while JSHint is a linter
- Prettier enforces a consistent code style, JSHint focuses on code quality
- Prettier automatically fixes formatting issues, JSHint only reports problems
- Prettier has broader language support, including CSS and markdown
- JSHint provides more granular control over specific linting rules
Use Cases
- Use JSHint for detecting potential errors and enforcing coding standards
- Use Prettier for maintaining consistent code formatting across projects
- Consider using both tools in combination for comprehensive code quality management
Community and Ecosystem
- Prettier has a larger and more active community
- JSHint has been around longer but has seen less recent development
- Both tools have extensive plugin ecosystems and integrations
🌟 JavaScript Style Guide, with linter & automatic code fixer
Pros of Standard
- Simpler setup with zero configuration required
- Includes both linting and formatting in a single package
- Opinionated style guide that promotes consistency across projects
Cons of Standard
- Less flexibility in customizing rules and formatting options
- Smaller ecosystem and fewer integrations compared to Prettier
- May not support all the latest JavaScript features as quickly as Prettier
Code Comparison
Standard:
function example (foo) {
if (foo) {
return bar
}
}
Prettier:
function example(foo) {
if (foo) {
return bar;
}
}
Standard focuses on a specific set of rules and formatting choices, while Prettier offers more flexibility in configuration. Standard combines linting and formatting, whereas Prettier is primarily a code formatter that can be used alongside various linters.
Standard has a simpler setup process, but Prettier offers more extensive customization options. Prettier has a larger ecosystem and better integration with various tools and editors.
Both tools aim to improve code consistency and readability, but they approach the task differently. The choice between them often depends on project requirements, team preferences, and the desired level of customization.
A mighty CSS linter that helps you avoid errors and enforce conventions.
Pros of stylelint
- Highly customizable with extensive rule set for CSS and preprocessors
- Supports plugins for additional functionality and custom rules
- Provides more detailed and specific error messages for CSS issues
Cons of stylelint
- Steeper learning curve due to its extensive configuration options
- Slower performance compared to Prettier, especially on large codebases
- Requires more setup and maintenance to keep rules up-to-date
Code Comparison
stylelint configuration example:
{
"rules": {
"color-hex-case": "lower",
"indentation": 2,
"selector-max-id": 0
}
}
Prettier configuration example:
{
"semi": false,
"singleQuote": true,
"tabWidth": 2
}
Key Differences
- Focus: stylelint is specifically designed for CSS and preprocessors, while Prettier is a general-purpose code formatter.
- Flexibility: stylelint offers more granular control over styling rules, whereas Prettier aims for simplicity with fewer options.
- Scope: stylelint can enforce coding standards and catch potential errors, while Prettier primarily focuses on consistent formatting.
- Integration: stylelint is often used alongside other linters, while Prettier can be used as a standalone tool for multiple languages.
Both tools have their strengths and can be used together in a development workflow to achieve comprehensive code quality and consistency.
Unified developer tools for JavaScript, TypeScript, and the web
Pros of Rome
- All-in-one toolchain: Rome combines linting, formatting, bundling, and more
- Faster performance due to being built in Rust
- Designed for extensibility and customization
Cons of Rome
- Less mature and stable compared to Prettier
- Smaller community and ecosystem
- Limited language support (primarily focused on JavaScript/TypeScript)
Code Comparison
Rome:
function example() {
const x = 1;
const y = 2;
return x + y;
}
Prettier:
function example() {
const x = 1;
const y = 2;
return x + y;
}
Key Differences
- Rome aims to be a comprehensive toolchain, while Prettier focuses solely on code formatting
- Rome has a steeper learning curve due to its broader feature set
- Prettier supports more languages and file types out of the box
- Rome offers more configuration options and flexibility in formatting rules
Community and Adoption
- Prettier has a larger user base and more widespread adoption
- Rome is gaining traction but still relatively new in comparison
- Prettier has more third-party integrations and plugins available
Performance
- Rome generally offers faster processing times, especially for larger codebases
- Prettier's performance is still good for most use cases but may lag behind on very large projects
:vertical_traffic_light: An extensible linter for the TypeScript language
Pros of TSLint
- More granular control over linting rules and configurations
- Specifically designed for TypeScript, offering deeper language-specific checks
- Supports custom rule creation for project-specific needs
Cons of TSLint
- Slower performance, especially on larger codebases
- Less active development and community support (deprecated in favor of ESLint)
- Steeper learning curve for configuring and customizing rules
Code Comparison
TSLint configuration:
{
"rules": {
"no-unused-variable": true,
"semicolon": [true, "always"],
"quotemark": [true, "single"]
}
}
Prettier configuration:
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}
Key Differences
- TSLint focuses on linting and enforcing coding standards, while Prettier is primarily a code formatter
- TSLint requires more configuration but offers more flexibility, whereas Prettier aims for simplicity and consistency
- TSLint can catch potential errors and enforce best practices, while Prettier ensures consistent code style
Conclusion
While TSLint provides more detailed TypeScript-specific linting, Prettier offers a simpler, opinionated approach to code formatting. Many projects now use ESLint with TypeScript support as a replacement for TSLint, often in combination with Prettier for optimal code quality and consistency.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Opinionated Code Formatter
JavaScript
· TypeScript
· Flow
· JSX
· JSON
CSS
· SCSS
· Less
HTML
· Vue
· Angular
GraphQL
· Markdown
· YAML
Your favorite language?
Intro
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
Input
foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());
Output
foo(
reallyLongArg(),
omgSoManyParameters(),
IShouldRefactorThis(),
isThereSeriouslyAnotherOne(),
);
Prettier can be run in your editor on-save, in a pre-commit hook, or in CI environments to ensure your codebase has a consistent style without devs ever having to post a nit-picky comment on a code review ever again!
Install · Options · CLI · API
Badge
Show the world you're using Prettier â
[](https://github.com/prettier/prettier)
Contributing
See CONTRIBUTING.md.
Top Related Projects
Find and fix problems in your JavaScript code.
JSHint is a tool that helps to detect errors and potential problems in your JavaScript code
🌟 JavaScript Style Guide, with linter & automatic code fixer
A mighty CSS linter that helps you avoid errors and enforce conventions.
Unified developer tools for JavaScript, TypeScript, and the web
:vertical_traffic_light: An extensible linter for the TypeScript language
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot