diff --git a/README.md b/README.md index 867dfc2f..3df75cc4 100644 --- a/README.md +++ b/README.md @@ -125,46 +125,11 @@ For the list of every available exclusion rule set, please see the [readme of es }] ``` - 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)) + NB: This option will merge and override any config set with `.prettierrc` files - The second option: - - 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: - - ```json - "prettier/prettier": ["error", null, "@prettier"] - ``` - - Only files with `@prettier` in the heading docblock will be checked: - - ```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`._ - - An object with the following options - - - `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 `@`. - - ```json - "prettier/prettier": ["error", null, { - "pragma": "@prettier" - }] - ``` - - `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. ```json diff --git a/eslint-plugin-prettier.js b/eslint-plugin-prettier.js index 0f32f6db..54712782 100644 --- a/eslint-plugin-prettier.js +++ b/eslint-plugin-prettier.js @@ -10,7 +10,6 @@ // ------------------------------------------------------------------------------ const diff = require('fast-diff'); -const docblock = require('jest-docblock'); // ------------------------------------------------------------------------------ // Constants @@ -285,25 +284,6 @@ function reportReplace(context, offset, deleteText, insertText) { }); } -/** - * Get the pragma from the ESLint rule context. - * @param {RuleContext} context - The ESLint rule context. - * @returns {string|null} - */ -function getPragma(context) { - const pluginOptions = context.options[1]; - - if (!pluginOptions) { - return null; - } - - const pragmaRef = - typeof pluginOptions === 'string' ? pluginOptions : pluginOptions.pragma; - - // Remove leading @ - return pragmaRef ? pragmaRef.slice(1) : null; -} - // ------------------------------------------------------------------------------ // Module Definition // ------------------------------------------------------------------------------ @@ -337,12 +317,9 @@ module.exports = { }, { anyOf: [ - // Pragma: - { type: 'string', pattern: '^@\\w+$' }, { type: 'object', properties: { - pragma: { type: 'string', pattern: '^@\\w+$' }, usePrettierrc: { type: 'boolean' } }, additionalProperties: true @@ -352,37 +329,12 @@ module.exports = { ] }, create(context) { - const pragma = getPragma(context); const usePrettierrc = !context.options[1] || context.options[1].usePrettierrc !== false; const sourceCode = context.getSourceCode(); const filepath = context.getFilename(); const source = sourceCode.text; - // The pragma is only valid if it is found in a block comment at the very - // start of the file. - if (pragma) { - // ESLint 3.x reports the shebang as a "Line" node, while ESLint 4.x - // reports it as a "Shebang" node. This works for both versions: - const hasShebang = source.startsWith('#!'); - const allComments = sourceCode.getAllComments(); - const firstComment = hasShebang ? allComments[1] : allComments[0]; - if ( - !( - firstComment && - firstComment.type === 'Block' && - firstComment.loc.start.line === (hasShebang ? 2 : 1) && - firstComment.loc.start.column === 0 - ) - ) { - return {}; - } - const parsed = docblock.parse(firstComment.value); - if (parsed[pragma] !== '') { - return {}; - } - } - if (prettier && prettier.clearConfigCache) { prettier.clearConfigCache(); } diff --git a/package.json b/package.json index c2b7190f..cf8a07bc 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,7 @@ }, "homepage": "https://github.com/prettier/eslint-plugin-prettier#readme", "dependencies": { - "fast-diff": "^1.1.1", - "jest-docblock": "^21.0.0" + "fast-diff": "^1.1.1" }, "peerDependencies": { "prettier": ">= 1.13.0" diff --git a/test/invalid/11-c.txt b/test/invalid/11-c.txt deleted file mode 100644 index 5f4db24a..00000000 --- a/test/invalid/11-c.txt +++ /dev/null @@ -1,22 +0,0 @@ -CODE: -/** @format */ -var a = { - b: "" -}; - -OUTPUT: -/** @format */ -var a = { - b: '', -}; - -OPTIONS: -['fb'] - -ERRORS: -[ - { - message: 'Replace `""` with `\'\',`', - line: 3, column: 6, endLine: 3, endColumn: 8, - }, -] diff --git a/test/invalid/12.txt b/test/invalid/12.txt deleted file mode 100644 index 1373e442..00000000 --- a/test/invalid/12.txt +++ /dev/null @@ -1,18 +0,0 @@ -CODE: -/** @format */ -var foo = ''; - -OUTPUT: -/** @format */ -var foo = ""; - -OPTIONS: -[null, "@format"] - -ERRORS: -[ - { - message: 'Replace `\'\'` with `""`', - line: 2, column: 11, endLine: 2, endColumn: 13, - }, -] diff --git a/test/invalid/19.txt b/test/invalid/19.txt deleted file mode 100644 index be5cf6b8..00000000 --- a/test/invalid/19.txt +++ /dev/null @@ -1,20 +0,0 @@ -CODE: -#!/usr/bin/env node -/** @format */ -var foo = ''; - -OUTPUT: -#!/usr/bin/env node -/** @format */ -var foo = ""; - -OPTIONS: -[null, '@format'] - -ERRORS: -[ - { - message: 'Replace `\'\'` with `""`', - line: 3, column: 11, endLine: 3, endColumn: 13, - }, -] diff --git a/test/prettier.js b/test/prettier.js index 09610d0c..060c3cfd 100644 --- a/test/prettier.js +++ b/test/prettier.js @@ -31,21 +31,8 @@ ruleTester.run('prettier', rule, { valid: [ // Correct style. { code: '"";\n' }, - // No pragma = No prettier check. - { code: '""\n', options: [null, '@format'] }, // Facebook style uses single quotes. { code: `('');\n`, options: ['fb'] }, - // Facebook style but missing pragma. - { code: `"";\n`, options: ['fb', '@format'] }, - // Facebook style with pragma. - { code: `/** @format */\n('');\n`, options: ['fb', '@format'] }, - // Shebang with pragma. - { code: `#!/bin/node\n/** @format */\n"";\n`, options: [null, '@format'] }, - // Shebang with pragma from options. - { - code: `#!/bin/node\n/** @format */\n"";\n`, - options: [null, { pragma: '@format' }] - }, // Single quote from .prettierrc. { code: `'';\n`, filename: getPrettierRcJsFilename('single-quote') }, // Override .prettierrc from object option. @@ -98,15 +85,12 @@ ruleTester.run('prettier', rule, { '10', '11-a', '11-b', - '11-c', - '12', '13', '14', '15', '16', '17', - '18', - '19' + '18' ].map(loadInvalidFixture) }); diff --git a/yarn.lock b/yarn.lock index 425debbd..84af430f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -553,10 +553,6 @@ isexe@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" -jest-docblock@^21.0.0: - version "21.1.0" - resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.1.0.tgz#43154be2441fb91403e36bb35cb791a5017cea81" - js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"