lhl 6ff0e96ad3 8-4-1 | 1 년 전 | |
---|---|---|
.. | ||
CHANGELOG.md | 1 년 전 | |
LICENSE.md | 1 년 전 | |
README.md | 1 년 전 | |
eslint-plugin-prettier.js | 1 년 전 | |
package.json | 1 년 전 |
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
plugin:prettier/recommended
as the last extension in your .eslintrc.json
: {
"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.
{
"extends": [
"plugin:prettier/recommended",
"prettier/flowtype",
"prettier/react",
"prettier/standard"
]
}
For the list of every available exclusion rule set, please see the readme of eslint-config-prettier.
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:
"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.
"prettier/prettier": ["error", {}, {
"usePrettierrc": false
}]
fileInfoOptions
: Options that are passed to prettier.getFileInfo to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located in node_modules
directories. "prettier/prettier": ["error", {}, {
"fileInfoOptions": {
"withNodeModules": true
}
}]
eslint
with the --fix
flag, your code will be formatted according to prettier
style.See CONTRIBUTING.md