![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
eslint-config-prettier
Advanced tools
Package description
The eslint-config-prettier npm package is used to disable all formatting-related ESLint rules that might conflict with Prettier. This allows developers to use both ESLint and Prettier without having to deal with conflicting formatting rules. It ensures that ESLint focuses on code-quality rules, and Prettier takes care of code formatting.
Disabling conflicting rules
By extending eslint-config-prettier in your ESLint configuration file, you can turn off all rules that are unnecessary or might conflict with Prettier.
{ "extends": ["prettier"] }
Integration with other ESLint configs
eslint-config-prettier can be easily integrated with other ESLint configurations like Airbnb by placing it last in the extends array, which ensures that it will override any other formatting rules that might conflict with Prettier.
{ "extends": ["airbnb", "prettier"] }
Support for plugins
eslint-config-prettier provides support for disabling conflicting rules from various ESLint plugins, such as React or TypeScript, ensuring compatibility across different codebases.
{ "extends": ["prettier/react", "prettier/@typescript-eslint"] }
eslint-config-standard is an ESLint Shareable Config for JavaScript Standard Style. It enforces a consistent style across your codebase. Unlike eslint-config-prettier, it does not turn off formatting rules and is not specifically designed to be used with Prettier.
eslint-config-airbnb is one of the most popular ESLint configurations which enforces Airbnb's JavaScript style guide. It includes a set of rules for code quality and formatting. While it can be used with Prettier, it does not disable formatting rules by default like eslint-config-prettier does.
eslint-config-google is based on Google's JavaScript style guide. It provides a set of ESLint rules that align with Google's code style recommendations. Similar to eslint-config-airbnb, it is not tailored for use with Prettier and does not disable conflicting formatting rules.
Changelog
Version 2.6.0 (2017-09-23)
Readme
Turns off all rules that are unnecessary or might conflict with Prettier.
This lets you use you favorite shareable config without letting its stylistic choices get in the way when using Prettier.
Tip: First, you might be interested in installing eslint-plugin-prettier. Follow the instructions over there. This is optional, though.
Install eslint-config-prettier:
$ npm install --save-dev eslint-config-prettier
Then, add eslint-config-prettier to the "extends" array in your .eslintrc.*
file. Make sure to put it last, so it gets the chance to override other
configs.
{
"extends": [
"prettier"
]
}
A few ESLint plugins are supported as well:
Add extra exclusions for the plugins you use like so:
{
"extends": [
"prettier",
"prettier/flowtype",
"prettier/react",
"prettier/standard"
]
}
eslint-config-prettier also ships with a little CLI tool to help you check if your configuration contains any rules that are unnecessary or conflict with Prettier.
First, add a script for it to package.json:
{
"scripts": {
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check"
}
}
Then run npm run eslint-check
.
(Swap out .eslintrc.js with the path to your config if needed.)
Exit codes:
{
"extends": [
"standard",
"plugin:flowtype/recommended",
"plugin:react/recommended",
"prettier",
"prettier/flowtype",
"prettier/react",
"prettier/standard"
],
"plugins": [
"flowtype",
"react",
"prettier",
"standard"
],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"node": true
},
"rules": {
"prettier/prettier": "error"
}
}
There a few rules that eslint-config-prettier disables that actually can be enabled in some cases.
For maximum ease of use, the special rules are disabled by default. If you want them, you need to explicitly specify them in your ESLint config.
This rule requires certain options.
If a block (for example after if
, else
, for
or while
) contains only one
statement, JavaScript allows omitting the curly braces around that statement.
This rule enforces if or when those optional curly braces should be omitted.
If you use the "multi-line"
or "multi-or-nest"
option, the rule can conflict
with Prettier.
For example, the "multi-line"
option allows this line:
if (cart.items && cart.items[0] && cart.items[0].quantity === 0) updateCart(cart);
However, Prettier might consider the line too long and turn it into the
following, which the "multi-line"
option does not allow:
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
updateCart(cart);
The eslint-config-airbnb config includes curly
with the "multi-line"
option turned on by default. Since that config is very popular, it makes sense
for eslint-config-prettier to turn this rule off.
If you like this rule, it can be used just fine with Prettier as long as you
don’t use the "multi-line"
or "multi-or-nest"
option.
Example configuration:
{
"rules": {
"curly": ["error", "all"]
}
}
This rule requires special attention when writing code.
Usually, Prettier takes care of following a maximum line length automatically. However, there are cases where Prettier can’t do anything, such as for long strings, regular expressions and comments. Those need to be split up by a human.
If you’d like to enforce an even stricter maximum line length policy than
Prettier can provide automatically, you can enable this rule. Just remember to
keep max-len
’s options and Prettier’s printWidth
option in sync.
Keep in mind that you might have to refactor code slightly if Prettier formats
lines in a way that the max-len
rule does not approve of.
Example configuration:
{
"rules": {
"max-len": ["error", {"code": 80, "ignoreUrls": true}]
}
}
This rule requires certain options.
For example, the rule could warn about this line:
var x = a => 1 ? 2 : 3;
By default, ESLint suggests switching to an explicit return:
var x = a => { return 1 ? 2 : 3; };
That causes no problems with Prettier.
With {allowParens: true}
, adding parentheses is also considered a valid way to
avoid the arrow confusion:
var x = a => (1 ? 2 : 3);
While Prettier keeps thoses parentheses, it removes them if the line is long enough to introduce a line break:
EnterpriseCalculator.prototype.calculateImportantNumbers = inputNumber =>
1 ? 2 : 3;
eslint-config-airbnb config includes no-confusing-arrow
with the
allowParens
option turned on by default. Since that config is very popular, it
makes sense for eslint-config-prettier to turn this rule off.
If you like this rule, it can be used just fine with Prettier as long as the
allowParens
option is off.
Example configuration:
{
"rules": {
"no-confusing-arrow": "error"
}
}
This rule requires special attention when writing code.
This rule forbids mixing certain operators, such as &&
and ||
.
For example, the rule could warn about this line:
var foo = a + b * c;
The rule suggests adding parentheses, like this:
var foo = a + (b * c);
However, Prettier removes many “unnecessary” parentheses, turning it back to:
var foo = a + b * c;
If you want to use this rule with Prettier, you need to split the expression into another variable:
var bar = b * c;
var foo = a + bar;
Keep in mind that Prettier prints some “unnecessary” parentheses, though:
var foo = (a && b) || c;
Example configuration:
{
"rules": {
"no-mixed-operators": "error"
}
}
This rule disallows the use of tab characters at all. It can be used just fine with Prettier as long as you don’t configure Prettier to indent using tabs.
Example configuration:
{
"rules": {
"no-tabs": "error"
}
}
This rule requires certain options.
If you’d like to enforce the use of backticks rather than single or double
quotes for strings, you can enable this rule. Otherwise, there’s no need to.
Just remember to enable the "backtick"
option!
Example configuration:
{
"rules": {
"quotes": ["error", "backtick"]
}
}
eslint-config-prettier has been tested with:
Have new rules been added since those versions? Have we missed any rules? Is there a plugin you would like to see exclusions for? Open an issue or a pull request!
If you’d like to add support for eslint-plugin-foobar, this is how you’d go about it:
First, create foobar.js
:
"use strict";
module.exports = {
rules: {
"foobar/some-rule": "off"
}
};
Then, create test-lint/foobar.js
:
/* eslint-disable quotes */
"use strict";
// Prettier does not want spaces before the parentheses, but
// eslint-config-foobar wants one.
console.log ();
test-lint/foobar.js
must fail when used with eslint-plugin-foobar and
eslint-plugin-prettier at the same time – until "prettier/foobar"
is added to
the "extends" property of an ESLint config.
Finally, you need to mention the plugin in several places:
"foobar.js"
to the "files" field in package.json
.package.json
..eslintrc.base.js
.README.md
.When you’re done, run npm test
to verify that you got it all right. It runs
several other npm scripts:
"test:lint"
makes sure that the files in test-lint/
pass ESLint when
the exclusions from eslint-config-prettier are used. It also lints the code of
eslint-config-prettier itself."test:lint-verify-fail"
is run by a test in test/lint-verify-fail.js
."test:lint-rules"
is run by a test in test/rules.js
."test:ava"
runs unit tests that check a number of things:
"test:cli-sanity"
is a sanity check for the CLI.MIT.
FAQs
Turns off all rules that are unnecessary or might conflict with Prettier.
The npm package eslint-config-prettier receives a total of 17,122,473 weekly downloads. As such, eslint-config-prettier popularity was classified as popular.
We found that eslint-config-prettier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.