Skip to content

Commit 6de494f

Browse files
authored
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)
1 parent 6b69492 commit 6de494f

33 files changed

+881
-221
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.eslintrc.js

.eslintrc.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
'use strict';
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const PACKAGE_NAME = require('./package').name;
6-
const SYMLINK_LOCATION = path.join(__dirname, 'node_modules', PACKAGE_NAME);
7-
8-
// Symlink node_modules/{package name} to this directory so that ESLint resolves this plugin name correctly.
9-
if (!fs.existsSync(SYMLINK_LOCATION)) {
10-
fs.symlinkSync(__dirname, SYMLINK_LOCATION);
11-
}
3+
// Register ourselves as a plugin to avoid `node_modules` trickery.
4+
const Plugins = require('eslint/lib/config/plugins');
5+
Plugins.define('prettier', require('.'));
126

137
module.exports = {
14-
plugins: ['node', 'eslint-plugin', PACKAGE_NAME],
8+
plugins: ['node', 'eslint-plugin', 'prettier'],
159
extends: [
1610
'not-an-aardvark/node',
1711
'plugin:node/recommended',

CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@
1616
* Breaking: Make prettier a peerDependency ([#1](https://github.com/not-an-aardvark/eslint-plugin-prettier/issues/1)) ([d8a8992](https://github.com/not-an-aardvark/eslint-plugin-prettier/commit/d8a89922ddc6b747c474b62a0948deba6ea2657d))
1717
* Docs: add repo url to package.json ([2474bc9](https://github.com/not-an-aardvark/eslint-plugin-prettier/commit/2474bc9dd3f05dbd0b1fec38e27bc91a9cb0f1c7))
1818
* Docs: suggest prettier-eslint if eslint rules disagree with prettier ([3414437](https://github.com/not-an-aardvark/eslint-plugin-prettier/commit/341443754ae231a17d82f037f8b35663257d282a))
19-
20-

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ npm test
1818

1919
This is an [ESLint](http://eslint.org) plugin. Documentation for the APIs that it uses can be found on ESLint's [Working with Plugins](http://eslint.org/docs/developer-guide/working-with-plugins) page.
2020

21-
This plugin is used to lint itself. The style is checked when `npm test` is run, and the build will fail if there are any linting errors. You can use `npm run lint -- --fix` to fix some linting errors. To run the tests without running the linter, you can use `node_modules/.bin/mocha tests --recursive`.
21+
This plugin is used to lint itself. The style is checked when `npm test` is run, and the build will fail if there are any linting errors. You can use `npm run lint -- --fix` to fix some linting errors. To run the tests without running the linter, you can use `node_modules/.bin/mocha`.

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22
=====================
33

4-
Copyright © 2017 Teddy Katz
4+
Copyright © 2017 Andres Suarez and Teddy Katz
55

66
Permission is hereby granted, free of charge, to any person
77
obtaining a copy of this software and associated documentation

README.md

+85-45
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,118 @@
11
# eslint-plugin-prettier [![Build Status](https://travis-ci.org/prettier/eslint-plugin-prettier.svg?branch=master)](https://travis-ci.org/prettier/eslint-plugin-prettier)
22

3-
Runs [prettier](https://github.com/jlongster/prettier) as an eslint rule
3+
Runs [Prettier](https://github.com/prettier/prettier) as an [ESLint](http://eslint.org) rule and reports differences as individual ESLint issues.
44

5-
## Installation
5+
## Sample
66

7-
You'll first need to install [ESLint](http://eslint.org):
7+
```js
8+
error: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
9+
20 | import {
10+
21 | observeActiveEditorsDebounced,
11+
> 22 | editorChangesDebounced
12+
| ^
13+
23 | } from './debounced';;
14+
24 |
15+
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
816

9-
```
10-
$ npm install eslint --save-dev
11-
```
1217

13-
Next, install `prettier`:
18+
error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
19+
21 | observeActiveEditorsDebounced,
20+
22 | editorChangesDebounced
21+
> 23 | } from './debounced';;
22+
| ^
23+
24 |
24+
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
25+
26 | import {cacheWhileSubscribed} from '../commons-node/observable';
1426

15-
```
16-
$ npm install prettier --save-dev
27+
28+
2 errors found.
1729
```
1830

19-
Finally, install `eslint-plugin-prettier`:
31+
> `./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js` (code from [nuclide](https://github.com/facebook/nuclide)).
2032
21-
```
22-
$ npm install eslint-plugin-prettier --save-dev
23-
```
33+
## Installation
2434

25-
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-prettier` globally.
35+
```sh
36+
npm install --save-dev prettier eslint-plugin-prettier
37+
```
2638

27-
## Usage
39+
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
2840

29-
Add `prettier` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
41+
Then, in your `.eslintrc`:
3042

3143
```json
3244
{
33-
"plugins": [
34-
"prettier"
35-
]
45+
"plugins": [
46+
"prettier"
47+
],
48+
"rules": {
49+
"prettier/prettier": "error"
50+
}
3651
}
3752
```
3853

54+
## Options
3955

40-
Then configure the `prettier` rule under the `rules` section:
56+
* The first option:
4157

42-
```json
43-
{
44-
"rules": {
45-
"prettier/prettier": "error"
46-
}
47-
}
48-
```
58+
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#api). Example:
59+
60+
```json
61+
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
62+
```
4963

50-
You can also pass [`prettier` configuration](https://github.com/prettier/prettier#api) as an option:
64+
- Or the string `"fb"` may be used to set "Facebook style" defaults:
5165

52-
```json
53-
{
54-
"rules": {
55-
"prettier/prettier": ["error", {"trailingComma": "es5", "singleQuote": true}]
56-
}
57-
}
58-
```
66+
```json
67+
"prettier/prettier": ["error", "fb"]
68+
```
5969

60-
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.
70+
Equivalent to:
6171

62-
---
72+
```json
73+
"prettier/prettier": ["error", {
74+
"singleQuote": true,
75+
"trailingComma": "all",
76+
"bracketSpacing": false,
77+
"jsxBracketSameLine": true,
78+
"parser": "flow"
79+
}]
80+
```
6381

64-
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.
82+
* The second option:
6583

66-
## Migrating to 2.0.0
84+
- 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:
6785

68-
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.
86+
```json
87+
"prettier/prettier": ["error", null, "@prettier"]
88+
```
6989

70-
To install `prettier`, use:
90+
Only files with `@prettier` in the heading docblock will be checked:
7191

72-
```bash
73-
npm install prettier --save-dev
74-
```
92+
```js
93+
/** @prettier */
94+
95+
console.log(1 + 2 + 3);
96+
```
97+
98+
Or:
99+
100+
```js
101+
/**
102+
* @prettier
103+
*/
104+
105+
console.log(4 + 5 + 6);
106+
```
107+
108+
_This option is useful if you're migrating a large codebase and already use pragmas like `@flow`._
109+
110+
* The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
111+
112+
---
113+
114+
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.
75115

76116
## Contributing
77117

78-
See [CONTRIBUTING.md](https://github.com/not-an-aardvark/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
118+
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)

0 commit comments

Comments
 (0)