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.2.6
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.4.0
Choose a head ref
  • 8 commits
  • 12 files changed
  • 5 contributors

Commits on May 4, 2025

  1. chore(deps): update all dependencies (#727)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    Co-authored-by: JounQin <[email protected]>
    renovate[bot] and JounQin committed May 4, 2025
    Copy the full SHA
    27030dd View commit details
  2. chore: migrate @typedefjsdoc to @import (#729)

    Co-authored-by: JounQin <[email protected]>
    yashtech00 and JounQin committed May 4, 2025
    Copy the full SHA
    9e37575 View commit details
  3. feat: prefer Config over FlatConfig when they're equal (#674)

    Co-authored-by: JounQin <[email protected]>
    irsooti and JounQin authored May 4, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6fe0c90 View commit details
  4. chore: release eslint-plugin-prettier (#733)

    github-actions[bot] authored May 4, 2025
    Copy the full SHA
    3247172 View commit details
  5. ci: enable autofix.ci and pkg-pr-new workflows (#734)

    JounQin authored May 4, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    dcf2c80 View commit details
  6. chore: release eslint-plugin-prettier (#735)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored May 4, 2025
    Copy the full SHA
    5eaf8fd View commit details

Commits on May 5, 2025

  1. refactor: migrate worker.js to worker.mjs (#736)

    Co-authored-by: JounQin <[email protected]>
    yashtech00 and JounQin committed May 5, 2025
    Copy the full SHA
    59a0cae View commit details
  2. chore: release eslint-plugin-prettier (#737)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    Co-authored-by: JounQin <[email protected]>
    github-actions[bot] and JounQin authored May 5, 2025
    Copy the full SHA
    cd48a27 View commit details
Showing with 236 additions and 90 deletions.
  1. +39 −0 .github/workflows/autofix.yml
  2. +6 −4 .github/workflows/ci.yml
  3. +31 −0 .github/workflows/pkg-pr-new.yml
  4. +16 −3 .github/workflows/release.yml
  5. +1 −0 .prettierrc
  6. +18 −0 CHANGELOG.md
  7. +48 −38 eslint-plugin-prettier.js
  8. +8 −7 package.json
  9. +37 −11 pnpm-lock.yaml
  10. +8 −1 recommended.d.ts
  11. +13 −10 test/prettier.mjs
  12. +11 −16 worker.js → worker.mjs
39 changes: 39 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: autofix.ci # For security reasons, the workflow in which the autofix.ci action is used must be named "autofix.ci".

on:
pull_request:
types:
- opened
- reopened
- synchronize

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
cache: pnpm

- name: Install Dependencies
run: pnpm install --prefer-frozen-lockfile

- name: Format Codes
run: pnpm format

- name: Apply autofix.ci
uses: autofix-ci/action@2891949f3779a1cafafae1523058501de3d4e944 # v1.3.1
with:
fail-fast: false
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -31,12 +31,14 @@ jobs:
eslint: 8

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4
- name: Setup pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ matrix.node }}
cache: pnpm
31 changes: 31 additions & 0 deletions .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish Any Commit
on:
- push
- pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
cache: pnpm

- name: Install Dependencies
run: pnpm install --prefer-frozen-lockfile

- name: Publish
run: pnpm dlx pkg-pr-new publish --compact
19 changes: 16 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -5,16 +5,28 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
id-token: write
pull-requests: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4
- name: Setup pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
cache: pnpm
@@ -31,4 +43,5 @@ jobs:
title: 'chore: release eslint-plugin-prettier'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"singleQuote": true,
"plugins": [
"@prettier/plugin-pug",
"prettier-plugin-jsdoc",
"prettier-plugin-pkg",
"prettier-plugin-svelte"
],
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 5.4.0

### Minor Changes

- [#736](https://github.com/prettier/eslint-plugin-prettier/pull/736) [`59a0cae`](https://github.com/prettier/eslint-plugin-prettier/commit/59a0cae5f27801d7e00f257c6be059a848b32fbe) Thanks [@yashtech00](https://github.com/yashtech00)! - refactor: migrate `worker.js` to `worker.mjs`

## 5.3.1

### Patch Changes

- [#734](https://github.com/prettier/eslint-plugin-prettier/pull/734) [`dcf2c80`](https://github.com/prettier/eslint-plugin-prettier/commit/dcf2c8083e0f7146b7b7d641224ee2db8b318189) Thanks [@JounQin](https://github.com/JounQin)! - ci: enable `NPM_CONFIG_PROVENANCE` env

## 5.3.0

### Minor Changes

- [#674](https://github.com/prettier/eslint-plugin-prettier/pull/674) [`6fe0c90`](https://github.com/prettier/eslint-plugin-prettier/commit/6fe0c90e277acba301e5a5db445130374d4254ea) Thanks [@irsooti](https://github.com/irsooti)! - feat(types): prefer `Config` over `FlatConfig` when they're equal

## 5.2.6

### Patch Changes
86 changes: 48 additions & 38 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
@@ -6,14 +6,25 @@
// @ts-check

/**
* @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} PrettierOptions
* @typedef {PrettierOptions & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean }} Options
* @typedef {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string} PrettierFormat
* @import {AST, ESLint, Linter, Rule, SourceCode} from 'eslint'
* @import {FileInfoOptions, Options as PrettierOptions} from 'prettier'
* @import {Difference} from 'prettier-linter-helpers'
*/

/**
* @typedef {PrettierOptions & {
* onDiskFilepath: string;
* parserMeta?: ESLint.ObjectMetaProperties['meta'];
* parserPath?: string;
* usePrettierrc?: boolean;
* }} Options
*
*
* @typedef {(
* source: string,
* options: Options,
* fileInfoOptions: FileInfoOptions,
* ) => string} PrettierFormat
*/

'use strict';
@@ -39,9 +50,7 @@ const { INSERT, DELETE, REPLACE } = generateDifferences;
// ------------------------------------------------------------------------------

// Lazily-loaded Prettier.
/**
* @type {PrettierFormat}
*/
/** @type {PrettierFormat} */
let prettierFormat;

// ------------------------------------------------------------------------------
@@ -51,13 +60,14 @@ let prettierFormat;
/**
* Reports a difference.
*
* @param {import('eslint').Rule.RuleContext} context - The ESLint rule context.
* @param {import('prettier-linter-helpers').Difference} difference - The difference object.
* @param {Rule.RuleContext} context - The ESLint rule context.
* @param {Difference} difference - The difference object.
* @returns {void}
*/
function reportDifference(context, difference) {
const { operation, offset, deleteText = '', insertText = '' } = difference;
const range = /** @type {Range} */ ([offset, offset + deleteText.length]);
/** @type {AST.Range} */
const range = [offset, offset + deleteText.length];
// `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
// with the `sourceCode` property.
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
@@ -80,9 +90,7 @@ function reportDifference(context, difference) {
// Module Definition
// ------------------------------------------------------------------------------

/**
* @type {Plugin}
*/
/** @type {ESLint.Plugin} */
const eslintPluginPrettier = {
meta: { name, version },
configs: {
@@ -131,18 +139,17 @@ const eslintPluginPrettier = {
},
},
create(context) {
const usePrettierrc =
!context.options[1] || context.options[1].usePrettierrc !== false;
/**
* @type {FileInfoOptions}
*/
const fileInfoOptions =
(context.options[1] && context.options[1].fileInfoOptions) || {};
const options = /** @type {Options | undefined} */ (context.options[1]);
const usePrettierrc = !options || options.usePrettierrc !== false;
/** @type {FileInfoOptions} */
const fileInfoOptions = options?.fileInfoOptions || {};

// `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
// with the `sourceCode` property.
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
const sourceCode = context.sourceCode ?? context.getSourceCode();
const sourceCode = /** @type {SourceCode} */ (
context.sourceCode ?? context.getSourceCode()
);
// `context.getFilename()` was deprecated in ESLint v8.40.0 and replaced
// with the `filename` property.
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
@@ -165,16 +172,16 @@ const eslintPluginPrettier = {
if (!prettierFormat) {
// Prettier is expensive to load, so only load it if needed.
prettierFormat = /** @type {PrettierFormat} */ (
require('synckit').createSyncFn(require.resolve('./worker'))
require('synckit').createSyncFn(require.resolve('./worker.mjs'))
);
}

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

const parser = context.languageOptions?.parser;
const parser = /** @type {Linter.Parser | undefined} */ (
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
@@ -184,9 +191,7 @@ const eslintPluginPrettier = {
// files throw an error if they contain unclosed elements, such as
// `<template><div></template>. In this case report an error at the
// point at which parsing failed.
/**
* @type {string}
*/
/** @type {string} */
let prettierSource;
try {
prettierSource = prettierFormat(
@@ -213,10 +218,12 @@ const eslintPluginPrettier = {

let message = 'Parsing error: ' + err.message;

const error =
/** @type {SyntaxError & {codeFrame: string; loc?: SourceLocation}} */ (
err
);
const error = /**
* @type {SyntaxError & {
* codeFrame: string;
* loc?: AST.SourceLocation;
* }}
*/ (err);

// Prettier's message contains a codeframe style preview of the
// invalid code and the line/column at which the error occurred.
@@ -243,7 +250,10 @@ const eslintPluginPrettier = {
const differences = generateDifferences(source, prettierSource);

for (const difference of differences) {
reportDifference(context, difference);
reportDifference(
/** @type {Rule.RuleContext} */ (context),
difference,
);
}
}
},
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "eslint-plugin-prettier",
"version": "5.2.6",
"version": "5.4.0",
"description": "Runs prettier as an eslint rule",
"repository": "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>"
"maintainers": [
"JounQin <admin@1stg.me> (https://github.com/JounQin)"
],
"funding": "https://opencollective.com/eslint-plugin-prettier",
"license": "MIT",
@@ -15,6 +15,7 @@
"node": "^14.18.0 || >=16.0.0"
},
"main": "eslint-plugin-prettier.js",
"types": "eslint-plugin-prettier.d.ts",
"exports": {
".": {
"types": "./eslint-plugin-prettier.d.ts",
@@ -26,13 +27,12 @@
},
"./package.json": "./package.json"
},
"types": "eslint-plugin-prettier.d.ts",
"files": [
"eslint-plugin-prettier.d.ts",
"eslint-plugin-prettier.js",
"recommended.d.ts",
"recommended.js",
"worker.js"
"worker.mjs"
],
"keywords": [
"eslint",
@@ -75,7 +75,7 @@
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
"@eslint/js": "^9.23.0",
"@graphql-eslint/eslint-plugin": "^4.3.0",
"@html-eslint/parser": "^0.37.0",
"@html-eslint/parser": "^0.39.0",
"@prettier/plugin-pug": "^3.2.1",
"@types/prettier-linter-helpers": "^1.0.4",
"clean-pkg-json": "^1.2.1",
@@ -92,7 +92,8 @@
"lint-staged": "^15.5.0",
"mocha": "^11.1.0",
"prettier": "^3.5.3",
"prettier-plugin-pkg": "^0.18.1",
"prettier-plugin-jsdoc": "^1.3.2",
"prettier-plugin-pkg": "^0.19.0",
"prettier-plugin-svelte": "^3.3.3",
"simple-git-hooks": "^2.12.1",
"svelte": "^5.25.3",
Loading