-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge with eslint-plugin-prettify (#21)
* Chore: Use eslint-plugin-prettier without symlink * Chore: Lint .eslintrc.js via CLI automatically * Chore: Update remaining repo links * New: Replace implementation with line-by-line reporting (fixes #17) This code is originally from zertosh/eslint-plugin-prettify@2fb5dfb. It's has been adjusted to conform to the existing ESLint style. * Fix: Use non-global line ending regex * Fix: Use unicode literals instead of escapes in showInvisibles * Fix: Use documented range form when calling insertTextAfterRange * Fix: Un-shebang test file * Fix: ESLint 4.x compat (handle shebangs and no deprecated APIs)
- Loading branch information
Showing
33 changed files
with
881 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!.eslintrc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,118 @@ | ||
# eslint-plugin-prettier [](https://travis-ci.org/prettier/eslint-plugin-prettier) | ||
|
||
Runs [prettier](https://github.com/jlongster/prettier) as an eslint rule | ||
Runs [Prettier](https://github.com/prettier/prettier) as an [ESLint](http://eslint.org) rule and reports differences as individual ESLint issues. | ||
|
||
## Installation | ||
## Sample | ||
|
||
You'll first need to install [ESLint](http://eslint.org): | ||
```js | ||
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'; | ||
|
||
``` | ||
$ npm install eslint --save-dev | ||
``` | ||
|
||
Next, install `prettier`: | ||
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'; | ||
|
||
``` | ||
$ npm install prettier --save-dev | ||
|
||
2 errors found. | ||
``` | ||
|
||
Finally, install `eslint-plugin-prettier`: | ||
> `./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js` (code from [nuclide](https://github.com/facebook/nuclide)). | ||
``` | ||
$ npm install eslint-plugin-prettier --save-dev | ||
``` | ||
## Installation | ||
|
||
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-prettier` globally. | ||
```sh | ||
npm install --save-dev prettier eslint-plugin-prettier | ||
``` | ||
|
||
## Usage | ||
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._ | ||
|
||
Add `prettier` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix: | ||
Then, in your `.eslintrc`: | ||
|
||
```json | ||
{ | ||
"plugins": [ | ||
"prettier" | ||
] | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"prettier/prettier": "error" | ||
} | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
Then configure the `prettier` rule under the `rules` section: | ||
* The first option: | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"prettier/prettier": "error" | ||
} | ||
} | ||
``` | ||
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#api). Example: | ||
|
||
```json | ||
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}] | ||
``` | ||
|
||
You can also pass [`prettier` configuration](https://github.com/prettier/prettier#api) as an option: | ||
- Or the string `"fb"` may be used to set "Facebook style" defaults: | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"prettier/prettier": ["error", {"trailingComma": "es5", "singleQuote": true}] | ||
} | ||
} | ||
``` | ||
```json | ||
"prettier/prettier": ["error", "fb"] | ||
``` | ||
|
||
The rule will report an error if your code does not match `prettier` style. The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style. | ||
Equivalent to: | ||
|
||
--- | ||
```json | ||
"prettier/prettier": ["error", { | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"bracketSpacing": false, | ||
"jsxBracketSameLine": true, | ||
"parser": "flow" | ||
}] | ||
``` | ||
|
||
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](https://github.com/lydell/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](https://github.com/kentcdodds/prettier-eslint) instead. | ||
* The second option: | ||
|
||
## Migrating to 2.0.0 | ||
- 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: | ||
|
||
Starting in 2.0.0, `prettier` is a peerDependency of this module, rather than a dependency. This means that you can use any version of `prettier` with this plugin, but it also means that you need to install it separately and include it as a devDependency in your project. | ||
```json | ||
"prettier/prettier": ["error", null, "@prettier"] | ||
``` | ||
|
||
To install `prettier`, use: | ||
Only files with `@prettier` in the heading docblock will be checked: | ||
|
||
```bash | ||
npm install prettier --save-dev | ||
``` | ||
```js | ||
/** @prettier */ | ||
|
||
console.log(1 + 2 + 3); | ||
``` | ||
|
||
Or: | ||
|
||
```js | ||
/** | ||
* @prettier | ||
*/ | ||
|
||
console.log(4 + 5 + 6); | ||
``` | ||
|
||
_This option is useful if you're migrating a large codebase and already use pragmas like `@flow`._ | ||
|
||
* The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style. | ||
|
||
--- | ||
|
||
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](https://github.com/prettier/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](https://github.com/prettier/prettier-eslint) instead. | ||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING.md](https://github.com/not-an-aardvark/eslint-plugin-prettier/blob/master/CONTRIBUTING.md) | ||
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md) |
Oops, something went wrong.