Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prettier/eslint-plugin-prettier
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.1.1
Choose a base ref
...
head repository: prettier/eslint-plugin-prettier
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.1.2
Choose a head ref
  • 5 commits
  • 15 files changed
  • 4 contributors

Commits on Dec 21, 2023

  1. fix: add package.json exports field (#623)

    This allows users to use esm `import cfg from
    'eslint-plugin-prettier/recommended'
    BPScott authored Dec 21, 2023
    Copy the full SHA
    8210e44 View commit details

Commits on Dec 24, 2023

  1. Copy the full SHA
    5f762df View commit details
  2. Copy the full SHA
    2b09e7f View commit details
  3. Copy the full SHA
    b02fe90 View commit details
  4. chore: release eslint-plugin-prettier (#624)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Dec 24, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d102278 View commit details
Showing with 726 additions and 695 deletions.
  1. +1 −1 .github/FUNDING.yml
  2. +1 −1 .github/workflows/release.yml
  3. +1 −1 .nvmrc
  4. +9 −1 .prettierrc
  5. +11 −1 CHANGELOG.md
  6. +27 −0 README.md
  7. +12 −2 eslint-plugin-prettier.js
  8. +0 −8 eslint.config.js
  9. +33 −23 package.json
  10. +0 −74 patches/@graphql-eslint__eslint-plugin@3.20.0.patch
  11. +14 −0 patches/@types__eslint@8.56.0.patch
  12. +569 −577 pnpm-lock.yaml
  13. +5 −0 test/fixtures/md.md
  14. +21 −1 test/prettier.js
  15. +22 −5 worker.js
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ github:
- rx-ts
- un-ts
patreon: 1stG
open_collective: prettier
open_collective: eslint-plugin-prettier
custom:
- https://opencollective.com/1stG
- https://opencollective.com/rxts
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 16
node-version: lts/*
cache: pnpm

- name: Install Dependencies
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"arrowParens": "avoid",
"singleQuote": true,
"plugins": ["@prettier/plugin-pug", "prettier-plugin-pkg"]
"plugins": ["@prettier/plugin-pug", "prettier-plugin-pkg"],
"overrides": [
{
"files": ".changeset/**/*",
"options": {
"singleQuote": false
}
}
]
}
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 5.1.2

### Patch Changes

- [#623](https://github.com/prettier/eslint-plugin-prettier/pull/623) [`8210e44`](https://github.com/prettier/eslint-plugin-prettier/commit/8210e44309b168c7c06185eae8249b2d0eb65815) Thanks [@BPScott](https://github.com/BPScott)! - Add exports mapping to package.json, to allow `import eslintPluginRecommended from 'eslint-plugin-prettier/recommended'` to work as expected.

Strictly speaking this is a breaking change as it removes the ability for people to import from "eslint-plugin-prettier/eslint-plugin-prettier.js" and "eslint-plugin-prettier/recommended.js" but the former was never recommended in the first place and the latter has only been available for a few days.

- [#621](https://github.com/prettier/eslint-plugin-prettier/pull/621) [`2b09e7f`](https://github.com/prettier/eslint-plugin-prettier/commit/2b09e7fc64f38297c8ca39d087dba1f122ef999c) Thanks [@JounQin](https://github.com/JounQin)! - feat: support parsing `markdown` via `eslint-mdx` natively

## 5.1.1

### Patch Changes
@@ -16,7 +26,7 @@

```js
// eslint.config.js
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended");

module.exports = [
// Any other config imports go at the top
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,21 @@ If your desired formatting does not match Prettier’s output, you should use a

Please read [Integrating with linters](https://prettier.io/docs/en/integrating-with-linters.html) before installing.

## TOC <!-- omit in toc -->

- [Sample](#sample)
- [Installation](#installation)
- [Configuration (legacy: `.eslintrc*`)](#configuration-legacy-eslintrc)
- [Configuration (new: `eslint.config.js`)](#configuration-new-eslintconfigjs)
- [`Svelte` support](#svelte-support)
- [`arrow-body-style` and `prefer-arrow-callback` issue](#arrow-body-style-and-prefer-arrow-callback-issue)
- [Options](#options)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

## Sample

```js
@@ -162,6 +177,18 @@ If you’re fixing large of amounts of previously unformatted code, consider tem

---

## Sponsors

| @prettier/plugin-eslint | eslint-config-prettier | eslint-plugin-prettier | prettier-eslint | prettier-eslint-cli |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [![@prettier/plugin-eslint Open Collective sponsors](https://opencollective.com/prettier-plugin-eslint/tiers/sponsors.svg)](https://opencollective.com/prettier-plugin-eslint) | [![eslint-config-prettier Open Collective backers](https://opencollective.com/eslint-config-prettier/tiers/sponsors.svg)](https://opencollective.com/eslint-config-prettier) | [![eslint-plugin-prettier Open Collective backers](https://opencollective.com/eslint-plugin-prettier/tiers/sponsors.svg)](https://opencollective.com/rxts) | [![prettier-eslint Open Collective sponsors](https://opencollective.com/prettier-eslint/tiers/sponsors.svg)](https://opencollective.com/prettier-eslint) | [![prettier-eslint-cli Open Collective backers](https://opencollective.com/prettier-eslint-cli/tiers/sponsors.svg)](https://opencollective.com/prettier-eslint-cli) |

## Backers

| @prettier/plugin-eslint | eslint-config-prettier | eslint-plugin-prettier | prettier-eslint | prettier-eslint-cli |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [![@prettier/plugin-eslint Open Collective backers](https://opencollective.com/prettier-plugin-eslint/tiers/backers.svg)](https://opencollective.com/prettier-plugin-eslint) | [![eslint-config-prettier Open Collective backers](https://opencollective.com/eslint-config-prettier/tiers/backers.svg)](https://opencollective.com/eslint-config-prettier) | [![eslint-plugin-prettier Open Collective backers](https://opencollective.com/eslint-plugin-prettier/tiers/backers.svg)](https://opencollective.com/rxts) | [![prettier-eslint Open Collective backers](https://opencollective.com/prettier-eslint/tiers/backers.svg)](https://opencollective.com/prettier-eslint) | [![prettier-eslint-cli Open Collective backers](https://opencollective.com/prettier-eslint-cli/tiers/backers.svg)](https://opencollective.com/prettier-eslint-cli) |

## Contributing

See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
14 changes: 12 additions & 2 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
@@ -9,8 +9,10 @@
* @typedef {import('eslint').AST.Range} Range
* @typedef {import('eslint').AST.SourceLocation} SourceLocation
* @typedef {import('eslint').ESLint.Plugin} Plugin
* @typedef {import('eslint').ESLint.ObjectMetaProperties} ObjectMetaProperties
* @typedef {import('prettier').FileInfoOptions} FileInfoOptions
* @typedef {import('prettier').Options & { onDiskFilepath: string, parserPath: string, usePrettierrc?: boolean }} Options
* @typedef {import('prettier').Options} PrettierOptions
* @typedef {PrettierOptions & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean }} Options
*/

'use strict';
@@ -167,10 +169,12 @@ const eslintPluginPrettier = {
}

/**
* @type {{}}
* @type {PrettierOptions}
*/
const eslintPrettierOptions = context.options[0] || {};

const parser = context.languageOptions?.parser;

// prettier.format() may throw a SyntaxError if it cannot parse the
// source code it is given. Usually for JS files this isn't a
// problem as ESLint will report invalid syntax before trying to
@@ -190,6 +194,12 @@ const eslintPluginPrettier = {
...eslintPrettierOptions,
filepath,
onDiskFilepath,
parserMeta:
parser &&
(parser.meta ?? {
name: parser.name,
version: parser.version,
}),
parserPath: context.parserPath,
usePrettierrc,
},
8 changes: 0 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -25,14 +25,6 @@ module.exports = [
'eslint-plugin/report-message-format': ['error', '^[^a-z].*\\.$'],
},
},
{
files: ['**/*.md'],
rules: { 'prettier/prettier': ['error', { parser: 'markdown' }] },
},
{
files: ['**/*.mdx'],
rules: { 'prettier/prettier': ['error', { parser: 'mdx' }] },
},
// Global ignores
// If a config block only contains an `ignores` key, then the globs are
// ignored globally
56 changes: 33 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
{
"name": "eslint-plugin-prettier",
"version": "5.1.1",
"version": "5.1.2",
"description": "Runs prettier as an eslint rule",
"repository": "git+https://github.com/prettier/eslint-plugin-prettier.git",
"homepage": "https://github.com/prettier/eslint-plugin-prettier#readme",
"author": "Teddy Katz",
"contributors": [
"JounQin (https://github.com/JounQin) <admin@1stg.me>"
],
"funding": "https://opencollective.com/prettier",
"funding": "https://opencollective.com/eslint-plugin-prettier",
"license": "MIT",
"packageManager": "pnpm@7.33.3",
"packageManager": "pnpm@7.33.5",
"engines": {
"node": "^14.18.0 || >=16.0.0"
},
"main": "eslint-plugin-prettier.js",
"exports": {
".": {
"types": "./eslint-plugin-prettier.d.ts",
"default": "./eslint-plugin-prettier.js"
},
"./recommended": {
"types": "./recommended.d.ts",
"default": "./recommended.js"
}
},
"types": "eslint-plugin-prettier.d.ts",
"files": [
"eslint-plugin-prettier.d.ts",
@@ -53,43 +63,43 @@
},
"dependencies": {
"prettier-linter-helpers": "^1.0.0",
"synckit": "^0.8.5"
"synckit": "^0.8.6"
},
"devDependencies": {
"@1stg/remark-preset": "^2.0.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.26.2",
"@changesets/cli": "^2.27.1",
"@commitlint/config-conventional": "^18.4.3",
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@eslint/js": "^8.55.0",
"@graphql-eslint/eslint-plugin": "^3.20.0",
"@eslint/js": "^8.56.0",
"@graphql-eslint/eslint-plugin": "^3.20.1",
"@prettier/plugin-pug": "^3.0.0",
"@types/eslint": "^8.44.7",
"@types/prettier-linter-helpers": "^1.0.1",
"@types/eslint": "^8.56.0",
"@types/prettier-linter-helpers": "^1.0.4",
"commitlint": "^18.4.3",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-formatter-friendly": "^7.0.0",
"eslint-mdx": "^2.1.0",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-mdx": "^2.2.0",
"eslint-plugin-n": "^16.3.1",
"eslint-mdx": "^2.2.1",
"eslint-plugin-eslint-plugin": "^5.2.1",
"eslint-plugin-mdx": "^2.2.1",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-prettier": "link:.",
"eslint-plugin-pug": "^1.2.5",
"eslint-plugin-svelte": "^2.32.2",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-svelte3": "^4.0.0",
"graphql": "^16.7.1",
"lint-staged": "^15.1.0",
"graphql": "^16.8.1",
"lint-staged": "^15.2.0",
"mocha": "^10.2.0",
"prettier": "^3.0.0",
"prettier": "^3.1.1",
"prettier-plugin-pkg": "^0.18.0",
"simple-git-hooks": "^2.8.1",
"svelte": "^4.0.5",
"vue-eslint-parser": "^9.3.1"
"simple-git-hooks": "^2.9.0",
"svelte": "^4.2.8",
"vue-eslint-parser": "^9.3.2"
},
"pnpm": {
"patchedDependencies": {
"@graphql-eslint/eslint-plugin@3.20.0": "patches/@graphql-eslint__eslint-plugin@3.20.0.patch"
"@types/eslint@8.56.0": "patches/@types__eslint@8.56.0.patch"
}
}
}
74 changes: 0 additions & 74 deletions patches/@graphql-eslint__eslint-plugin@3.20.0.patch

This file was deleted.

14 changes: 14 additions & 0 deletions patches/@types__eslint@8.56.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/index.d.ts b/index.d.ts
index 75ae420e38148c632230763f26382ef0d9024427..6b8b08da2e25b54dedf41f1db0f2ba6e2c718b30 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -753,6 +753,9 @@ export namespace Rule {
id: string;
options: any[];
settings: { [name: string]: any };
+ languageOptions: {
+ parser: Linter.ParserModule;
+ } & Linter.ParserOptions;
parserPath: string;
parserOptions: Linter.ParserOptions;
parserServices: SourceCode.ParserServices;
1,146 changes: 569 additions & 577 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions test/fixtures/md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Heading

```ts
export declare const x = 1
```
22 changes: 21 additions & 1 deletion test/prettier.js
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ const eslint = new ESLint({
extends: 'plugin:prettier/recommended',
overrides: [
{
files: '*.mdx',
files: ['*.{md,mdx}'],
extends: 'plugin:mdx/recommended',
settings: {
'mdx/code-block': true,
@@ -228,6 +228,26 @@ mdxRuleTester.run('eslint-plugin-mdx', rule, {
],
});

runFixture('*.md', [
[
{
column: 27,
endColumn: 27,
endLine: 4,
fix: {
range: [43, 43],
text: ';',
},
line: 4,
message: 'Insert `;`',
messageId: 'insert',
nodeType: null,
ruleId: 'prettier/prettier',
severity: 2,
},
],
]);

runFixture('*.mdx', [
[
{
27 changes: 22 additions & 5 deletions worker.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

/**
* @typedef {import('prettier').FileInfoOptions} FileInfoOptions
* @typedef {import('prettier').Options & { onDiskFilepath: string, parserPath?: string, usePrettierrc?: boolean }} Options
* @typedef {import('eslint').ESLint.ObjectMetaProperties} ObjectMetaProperties
* @typedef {import('prettier').Options & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean }} Options
*/

const { runAsWorker } = require('synckit');
@@ -24,6 +25,7 @@ runAsWorker(
{
filepath,
onDiskFilepath,
parserMeta,
parserPath,
usePrettierrc,
...eslintPrettierOptions
@@ -58,7 +60,7 @@ runAsWorker(
return;
}

const initialOptions = {};
const initialOptions = { parser: inferredParser ?? 'babel' };

// ESLint supports processors that let you extract and lint JS
// fragments within a non-JS language. In the cases where prettier
@@ -94,9 +96,9 @@ runAsWorker(
// 2. `eslint-plugin-html`
// 3. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`)
// 4. `eslint-plugin-svelte3` (replacement: `eslint-plugin-svelte@2+`)
const parserBlocklist = [null, 'markdown', 'html'];
const parserBlocklist = ['html'];

let inferParserToBabel = parserBlocklist.includes(inferredParser);
let inferParserToBabel = parserBlocklist.includes(initialOptions.parser);

switch (inferredParser) {
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
@@ -109,12 +111,24 @@ runAsWorker(
}
break;
}
case 'markdown': {
// it could be processed by `eslint-plugin-markdown@1` or correctly parsed by `eslint-mdx`
if (
(typeof parserMeta !== 'undefined' &&
parserMeta.name !== 'eslint-mdx') ||
(typeof parserPath === 'string' &&
!/([\\/])eslint-mdx\1/.test(parserPath))
) {
inferParserToBabel = true;
}
break;
}
// it could be processed by `@ota-meshi/eslint-plugin-svelte`, `eslint-plugin-svelte` or `eslint-plugin-svelte3`
case 'svelte': {
// The `source` would be modified by `eslint-plugin-svelte3`
if (
typeof parserPath === 'string' &&
!parserPath.includes('svelte-eslint-parser')
!/([\\/])svelte-eslint-parser\1/.test(parserPath)
) {
// We do not support `eslint-plugin-svelte3`,
// the users should run `prettier` on `.svelte` files manually
@@ -152,6 +166,9 @@ runAsWorker(
}
}

/**
* @type {import('prettier').Options}
*/
const prettierOptions = {
...initialOptions,
...prettierRcOptions,