Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
eslint-plugin-prettier
Advanced tools
The eslint-plugin-prettier npm package integrates Prettier, an opinionated code formatter, with ESLint, a tool for identifying and reporting on patterns in JavaScript. It allows you to use Prettier as an ESLint rule and reports differences as individual ESLint issues.
Code Formatting
Automatically format code to match the style specified in your Prettier configuration when you run ESLint with the --fix option.
"scripts": { "lint": "eslint --fix 'src/**/*.js'" }
Integration with ESLint Rules
Use Prettier to enforce a consistent code style while still using ESLint to catch possible errors.
{ "extends": ["plugin:prettier/recommended"] }
Customizable Formatting Rules
Override default Prettier options to tailor the formatting to your project's needs.
{ "rules": { "prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }] } }
Turns off all ESLint rules that are unnecessary or might conflict with Prettier. It's used to avoid conflicts between ESLint and Prettier formatting rules.
Formats your JavaScript using Prettier followed by ESLint --fix. It's similar to eslint-plugin-prettier but applies Prettier formatting first and then runs ESLint's auto-fixing feature.
Runs Prettier as a Stylelint rule and reports differences as individual Stylelint issues. It's similar to eslint-plugin-prettier but for stylesheets and integrates with Stylelint instead of ESLint.
Disables TSLint formatting rules that might conflict with Prettier. It's similar to eslint-config-prettier but for TypeScript projects using TSLint instead of ESLint.
Runs Prettier as an ESLint rule and reports differences as individual ESLint issues.
error: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
20 | import {
21 | observeActiveEditorsDebounced,
> 22 | editorChangesDebounced
| ^
23 | } from './debounced';;
24 |
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
21 | observeActiveEditorsDebounced,
22 | editorChangesDebounced
> 23 | } from './debounced';;
| ^
24 |
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
26 | import {cacheWhileSubscribed} from '../commons-node/observable';
2 errors found.
./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js
(code from nuclide).
npm install --save-dev eslint-plugin-prettier
npm install --save-dev --save-exact prettier
eslint-plugin-prettier
does not install Prettier or ESLint for you. You must install these yourself.
Then, in your .eslintrc.json
:
{
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": "error"
}
}
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect patterns in the AST. (If another active ESLint rule disagrees with prettier
about how code should be formatted, it will be impossible to avoid lint errors.) You can use eslint-config-prettier to disable all formatting-related ESLint rules.
If your desired formatting does not match the prettier
output, you should use a different tool such as prettier-eslint instead.
To integrate this plugin with eslint-config-prettier
, you can use the "recommended"
configuration:
eslint-config-prettier
:npm install --save-dev eslint-config-prettier
.eslintrc.json
is:{
"extends": [
"plugin:prettier/recommended"
]
}
This does three things:
eslint-plugin-prettier
.prettier/prettier
rule to "error"
.eslint-config-prettier
configuration.You can then set Prettier's own options inside a .prettierrc
file.
Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as
prettier-atom
andprettier-vscode
will read.prettierrc
, but won't read settings from ESLint, which can lead to an inconsistent experience.
The first option:
Objects are passed directly to Prettier as options. Example:
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
Or the string "fb"
may be used to set "Facebook style" defaults:
"prettier/prettier": ["error", "fb"]
Equivalent to:
"prettier/prettier": ["error", {
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"jsxBracketSameLine": true,
"parser": "flow"
}]
NB: This option will merge and override any config set with .prettierrc
files (for Prettier < 1.7.0, config files are ignored)
The second option:
A string with a pragma that triggers this rule. By default, this rule applies to all files. However, if you set a pragma (this option), only files with that pragma in the heading docblock will be checked. All pragmas must start with @
. Example:
"prettier/prettier": ["error", null, "@prettier"]
Only files with @prettier
in the heading docblock will be checked:
/** @prettier */
console.log(1 + 2 + 3);
Or:
/**
* @prettier
*/
console.log(4 + 5 + 6);
This option is useful if you're migrating a large codebase and already use pragmas like @flow
.
An object with the following options
pragma
: Also sets the aforementioned pragma
: a string with a pragma that triggers this rule. By default, this rule applies to all files. However, if you set a pragma (this option), only files with that pragma in the heading docblock will be checked. All pragmas must start with @
.
"prettier/prettier": ["error", null, {
"pragma": "@prettier"
}]
usePrettierrc
: Enables loading of the Prettier configuration file, (default: true
). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration.
"prettier/prettier": ["error", null, {
"usePrettierrc": false
}]
The rule is autofixable -- if you run eslint
with the --fix
flag, your code will be formatted according to prettier
style.
See CONTRIBUTING.md
FAQs
Runs prettier as an eslint rule
The npm package eslint-plugin-prettier receives a total of 6,989,185 weekly downloads. As such, eslint-plugin-prettier popularity was classified as popular.
We found that eslint-plugin-prettier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.