Skip to content

Commit 3af422c

Browse files
BPScottnot-an-aardvark
authored andcommitted
Breaking: Remove pragma support
Prettier now provides native pragma support using @Format or @prettier notation. Use that instead of our implementation Fixes #48, Fixes #54
1 parent 29c0506 commit 3af422c

File tree

8 files changed

+3
-167
lines changed

8 files changed

+3
-167
lines changed

README.md

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -125,46 +125,11 @@ For the list of every available exclusion rule set, please see the [readme of es
125125
}]
126126
```
127127

128-
NB: This option will merge and override any config set with `.prettierrc` files (for Prettier < 1.7.0, [config files are ignored](https://github.com/prettier/eslint-plugin-prettier/issues/46))
128+
NB: This option will merge and override any config set with `.prettierrc` files
129129

130130
- The second option:
131131

132-
- 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:
133-
134-
```json
135-
"prettier/prettier": ["error", null, "@prettier"]
136-
```
137-
138-
Only files with `@prettier` in the heading docblock will be checked:
139-
140-
```js
141-
/** @prettier */
142-
143-
console.log(1 + 2 + 3);
144-
```
145-
146-
Or:
147-
148-
```js
149-
/**
150-
* @prettier
151-
*/
152-
153-
console.log(4 + 5 + 6);
154-
```
155-
156-
_This option is useful if you're migrating a large codebase and already use pragmas like `@flow`._
157-
158132
- An object with the following options
159-
160-
- `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 `@`.
161-
162-
```json
163-
"prettier/prettier": ["error", null, {
164-
"pragma": "@prettier"
165-
}]
166-
```
167-
168133
- `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.
169134

170135
```json

eslint-plugin-prettier.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// ------------------------------------------------------------------------------
1111

1212
const diff = require('fast-diff');
13-
const docblock = require('jest-docblock');
1413

1514
// ------------------------------------------------------------------------------
1615
// Constants
@@ -285,25 +284,6 @@ function reportReplace(context, offset, deleteText, insertText) {
285284
});
286285
}
287286

288-
/**
289-
* Get the pragma from the ESLint rule context.
290-
* @param {RuleContext} context - The ESLint rule context.
291-
* @returns {string|null}
292-
*/
293-
function getPragma(context) {
294-
const pluginOptions = context.options[1];
295-
296-
if (!pluginOptions) {
297-
return null;
298-
}
299-
300-
const pragmaRef =
301-
typeof pluginOptions === 'string' ? pluginOptions : pluginOptions.pragma;
302-
303-
// Remove leading @
304-
return pragmaRef ? pragmaRef.slice(1) : null;
305-
}
306-
307287
// ------------------------------------------------------------------------------
308288
// Module Definition
309289
// ------------------------------------------------------------------------------
@@ -337,12 +317,9 @@ module.exports = {
337317
},
338318
{
339319
anyOf: [
340-
// Pragma:
341-
{ type: 'string', pattern: '^@\\w+$' },
342320
{
343321
type: 'object',
344322
properties: {
345-
pragma: { type: 'string', pattern: '^@\\w+$' },
346323
usePrettierrc: { type: 'boolean' }
347324
},
348325
additionalProperties: true
@@ -352,37 +329,12 @@ module.exports = {
352329
]
353330
},
354331
create(context) {
355-
const pragma = getPragma(context);
356332
const usePrettierrc =
357333
!context.options[1] || context.options[1].usePrettierrc !== false;
358334
const sourceCode = context.getSourceCode();
359335
const filepath = context.getFilename();
360336
const source = sourceCode.text;
361337

362-
// The pragma is only valid if it is found in a block comment at the very
363-
// start of the file.
364-
if (pragma) {
365-
// ESLint 3.x reports the shebang as a "Line" node, while ESLint 4.x
366-
// reports it as a "Shebang" node. This works for both versions:
367-
const hasShebang = source.startsWith('#!');
368-
const allComments = sourceCode.getAllComments();
369-
const firstComment = hasShebang ? allComments[1] : allComments[0];
370-
if (
371-
!(
372-
firstComment &&
373-
firstComment.type === 'Block' &&
374-
firstComment.loc.start.line === (hasShebang ? 2 : 1) &&
375-
firstComment.loc.start.column === 0
376-
)
377-
) {
378-
return {};
379-
}
380-
const parsed = docblock.parse(firstComment.value);
381-
if (parsed[pragma] !== '') {
382-
return {};
383-
}
384-
}
385-
386338
if (prettier && prettier.clearConfigCache) {
387339
prettier.clearConfigCache();
388340
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
},
2929
"homepage": "https://github.com/prettier/eslint-plugin-prettier#readme",
3030
"dependencies": {
31-
"fast-diff": "^1.1.1",
32-
"jest-docblock": "^21.0.0"
31+
"fast-diff": "^1.1.1"
3332
},
3433
"peerDependencies": {
3534
"prettier": ">= 1.13.0"

test/invalid/11-c.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/invalid/12.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/invalid/19.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/prettier.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,8 @@ ruleTester.run('prettier', rule, {
3131
valid: [
3232
// Correct style.
3333
{ code: '"";\n' },
34-
// No pragma = No prettier check.
35-
{ code: '""\n', options: [null, '@format'] },
3634
// Facebook style uses single quotes.
3735
{ code: `('');\n`, options: ['fb'] },
38-
// Facebook style but missing pragma.
39-
{ code: `"";\n`, options: ['fb', '@format'] },
40-
// Facebook style with pragma.
41-
{ code: `/** @format */\n('');\n`, options: ['fb', '@format'] },
42-
// Shebang with pragma.
43-
{ code: `#!/bin/node\n/** @format */\n"";\n`, options: [null, '@format'] },
44-
// Shebang with pragma from options.
45-
{
46-
code: `#!/bin/node\n/** @format */\n"";\n`,
47-
options: [null, { pragma: '@format' }]
48-
},
4936
// Single quote from .prettierrc.
5037
{ code: `'';\n`, filename: getPrettierRcJsFilename('single-quote') },
5138
// Override .prettierrc from object option.
@@ -98,15 +85,12 @@ ruleTester.run('prettier', rule, {
9885
'10',
9986
'11-a',
10087
'11-b',
101-
'11-c',
102-
'12',
10388
'13',
10489
'14',
10590
'15',
10691
'16',
10792
'17',
108-
'18',
109-
'19'
93+
'18'
11094
].map(loadInvalidFixture)
11195
});
11296

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,6 @@ isexe@^2.0.0:
553553
version "2.0.0"
554554
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
555555

556-
jest-docblock@^21.0.0:
557-
version "21.1.0"
558-
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.1.0.tgz#43154be2441fb91403e36bb35cb791a5017cea81"
559-
560556
js-tokens@^4.0.0:
561557
version "4.0.0"
562558
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"

0 commit comments

Comments
 (0)