Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
eslint-config-prettier
Advanced tools
Turns all rules that are unnecessary or might conflict with prettier off.
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.
Turns all rules that are unnecessary or might conflict with prettier off.
This let’s you use you favorite shareable config without letting its stylistic choices get in the way when using prettier.
Intended to be used together with eslint-plugin-prettier.
First, install eslint-plugin-prettier. Follow the instructions over there.
Then, install eslint-config-prettier:
$ npm install --save-dev eslint-config-prettier
Finally, 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"
]
}
If you use React and eslint-plugin-react, there are exclusions for those rules as well:
{
"extends": [
"prettier",
"prettier/react"
]
}
Do you know of some other eslint plugin that contains rules that eslint-plugin-prettier could turn off? Send a pull request!
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.)
module.exports = {
"extends": [
"google",
"plugin:react/all",
"prettier",
"prettier/react"
],
"plugins": [
"react",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2016,
"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.
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.
Example configuration:
{
"rules": {
"max-len": ["error", {"code": 80, "ignoreUrls": true}]
}
}
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 prints the minimum amount of parentheses technically needed, 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 = a && b;
var foo = bar || c;
Example configuration:
{
"rules": {
"no-mixed-operators": "error"
}
}
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"]
}
}
MIT.
Version 1.0.2 (2017-01-30)
FAQs
Turns off all rules that are unnecessary or might conflict with Prettier.
The npm package eslint-config-prettier receives a total of 17,973,600 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.