Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESLint plugin for Prettier formatting

License

NotificationsYou must be signed in to change notification settings

prettier/eslint-plugin-prettier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RunsPrettier as anESLint rule and reports differences as individual ESLint issues.

If your desired formatting does not match Prettier’s output, you should use a different tool such asprettier-eslint instead.

Please readIntegrating with linters before installing.

TOC

Sample

error:Insert`,`(prettier/prettier)atpkg/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)atpkg/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';2errorsfound.

./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js (code fromnuclide).

Installation

npm install --save-dev eslint-plugin-prettier eslint-config-prettiernpm install --save-dev --save-exact prettier

eslint-plugin-prettier does not install Prettier or ESLint for you.You must install these yourself.

This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs. If another active ESLint rule disagrees withprettier about how code should be formatted, it will be impossible to avoid lint errors. Our recommended configuration automatically enableseslint-config-prettier to disable all formatting-related ESLint rules.

Configuration (legacy:.eslintrc*)

Forlegacy configuration, this plugin ships with aplugin:prettier/recommended config that sets up botheslint-plugin-prettier andeslint-config-prettier in one go.

Addplugin:prettier/recommended as thelast item in the extends array in your.eslintrc* config file, so thateslint-config-prettier has the opportunity to override other configs:

{"extends": ["plugin:prettier/recommended"]}

This will:

  • Enable theprettier/prettier rule.
  • Disable thearrow-body-style andprefer-arrow-callback rules which are problematic with this plugin - see the below for why.
  • Enable theeslint-config-prettier config which will turn off ESLint rules that conflict with Prettier.

Configuration (new:eslint.config.js)

Forflat configuration, this plugin ships with aneslint-plugin-prettier/recommended config that sets up botheslint-plugin-prettier andeslint-config-prettier in one go.

Importeslint-plugin-prettier/recommended and add it as thelast item in the configuration array in youreslint.config.js file so thateslint-config-prettier has the opportunity to override other configs:

consteslintPluginPrettierRecommended=require('eslint-plugin-prettier/recommended');module.exports=[// Any other config imports go at the topeslintPluginPrettierRecommended,];

This will:

  • Enable theprettier/prettier rule.
  • Disable thearrow-body-style andprefer-arrow-callback rules which are problematic with this plugin - see the below for why.
  • Enable theeslint-config-prettier config which will turn off ESLint rules that conflict with Prettier.

Svelte support

We recommend to useeslint-plugin-svelte instead ofeslint-plugin-svelte3 becauseeslint-plugin-svelte has a correcteslint-svelte-parser instead of hacking.

When use witheslint-plugin-svelte3,eslint-plugin-prettier will just ignore the text passed byeslint-plugin-svelte3, because the text has been modified.

If you still decide to useeslint-plugin-svelte3, you'll need to runprettier --write *.svelte manually.

arrow-body-style andprefer-arrow-callback issue

If you usearrow-body-style orprefer-arrow-callback together with theprettier/prettier rule from this plugin, you can in some cases end up with invalid code due to a bug in ESLint’s autofix – seeissue #65.

For this reason, it’s recommended to turn off these rules. Theplugin:prettier/recommended config does that for you.

Youcan still use these rules together with this plugin if you want, because the bug does not occurall the time. But if you do, you need to keep in mind that you might end up with invalid code, where you manually have to insert a missing closing parenthesis to get going again.

If you’re fixing large of amounts of previously unformatted code, consider temporarily disabling theprettier/prettier rule and runningeslint --fix andprettier --write separately.

Options

Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such asprettier-atom andprettier-vscodewill read.prettierrc, butwon't read settings from ESLint, which can lead to an inconsistent experience.

  • The first option:

    • An object representingoptions that will be passed into prettier. Example:

      {"prettier/prettier": ["error",    {"singleQuote":true,"parser":"flow"    }  ]}

      NB: This option will merge and override any config set with.prettierrc files

  • The second option:

    • An object with the following options
      • 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. And also, it is possible to run prettier without loading the prettierrc config filevia the CLI's --no-config option or through the API bycalling prettier.format() without passing through the options generated by calling resolveConfig.

        {"prettier/prettier": ["error",    {},    {"usePrettierrc":false    }  ]}
      • fileInfoOptions: Options that are passed toprettier.getFileInfo to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located innode_modules directories.

        {"prettier/prettier": ["error",    {},    {"fileInfoOptions": {"withNodeModules":true      }    }  ]}
  • The rule is auto fixable -- if you runeslint with the--fix flag, your code will be formatted according toprettier style.


Sponsors

@prettier/plugin-eslinteslint-config-prettiereslint-plugin-prettierprettier-eslintprettier-eslint-cli
@prettier/plugin-eslint Open Collective sponsorseslint-config-prettier Open Collective backerseslint-plugin-prettier Open Collective backersprettier-eslint Open Collective sponsorsprettier-eslint-cli Open Collective backers

Backers

@prettier/plugin-eslinteslint-config-prettiereslint-plugin-prettierprettier-eslintprettier-eslint-cli
@prettier/plugin-eslint Open Collective backerseslint-config-prettier Open Collective backerseslint-plugin-prettier Open Collective backersprettier-eslint Open Collective backersprettier-eslint-cli Open Collective backers

Contributing

SeeCONTRIBUTING.md

Changelog

Detailed changes for each release are documented inCHANGELOG.md.

License

MIT

About

ESLint plugin for Prettier formatting

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp