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.0.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.0
Choose a head ref
  • 19 commits
  • 14 files changed
  • 7 contributors

Commits on Oct 14, 2023

  1. Copy the full SHA
    e81b66d View commit details
  2. Copy the full SHA
    075523d View commit details
  3. Copy the full SHA
    8337f5b View commit details
  4. Copy the full SHA
    71ccf0e View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    41d4c62 View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    19791ad View commit details
  7. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b5536f8 View commit details
  8. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    17c3c10 View commit details

Commits on Oct 29, 2023

  1. chore: use context properties where context methods are deprecated (#594

    )
    
    * chore: use context properties where context methods are deprecated
    
    But keep supporting the methods for now.
    
    ---------
    
    Co-authored-by: Ben Scott <ben@reload.me.uk>
    filiptammergard and BPScott authored Oct 29, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e65b459 View commit details

Commits on Nov 7, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    df71356 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a63a570 View commit details

Commits on Nov 24, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2ed98fa View commit details
  2. build(deps): Bump the actions group with 1 update (#608)

    Bumps the actions group with 1 update: [actions/setup-node](https://github.com/actions/setup-node).
    
    - [Release notes](https://github.com/actions/setup-node/releases)
    - [Commits](actions/setup-node@v3...v4)
    
    ---
    updated-dependencies:
    - dependency-name: actions/setup-node
      dependency-type: direct:production
      update-type: version-update:semver-major
      dependency-group: actions
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 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
    f18bf8e View commit details
  3. build(deps-dev): Bump @babel/traverse from 7.22.8 to 7.23.2 (#593)

    Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.22.8 to 7.23.2.
    - [Release notes](https://github.com/babel/babel/releases)
    - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)
    
    ---
    updated-dependencies:
    - dependency-name: "@babel/traverse"
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 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
    1882a36 View commit details

Commits on Dec 2, 2023

  1. build(deps-dev): Bump the dev-dependencies group with 8 updates (#611)

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Dec 2, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    79765cc View commit details

Commits on Dec 3, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5270877 View commit details
  2. Use flat config for the project's eslint configuration (#615)

    * chore: use flat config for the project's eslint configuration
    
    This shall let us dogfood the recommended eslint config when we add it
    
    * chore: skip perf step in node 14 as eslint plugin isn't compatible with v14
    BPScott authored Dec 3, 2023
    Copy the full SHA
    78c8b80 View commit details

Commits on Dec 19, 2023

  1. Add flat recommended config (#616)

    recommended.js is a flat config version of the recommended config.
    
    It follows the pattern of the legacy recommended config by automatically
    configuring eslint-config-prettier.
    BPScott authored Dec 19, 2023
    Copy the full SHA
    3856413 View commit details
  2. chore: release eslint-plugin-prettier (#604)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Dec 19, 2023
    Copy the full SHA
    183f45c View commit details
Showing with 1,157 additions and 1,021 deletions.
  1. +0 −2 .eslintignore
  2. +0 −22 .eslintrc
  3. +10 −0 .github/dependabot.yml
  4. +5 −2 .github/workflows/ci.yml
  5. +0 −26 .github/workflows/pkg-size.yml
  6. +2 −2 .github/workflows/release.yml
  7. +26 −0 CHANGELOG.md
  8. +27 −38 README.md
  9. +21 −4 eslint-plugin-prettier.js
  10. +46 −0 eslint.config.js
  11. +13 −9 package.json
  12. +985 −916 pnpm-lock.yaml
  13. +5 −0 recommended.d.ts
  14. +17 −0 recommended.js
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

22 changes: 0 additions & 22 deletions .eslintrc

This file was deleted.

10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -11,10 +11,20 @@ updates:
- dependency-name: 'eslint'
- dependency-name: 'eslint-*'
- dependency-name: 'prettier'
- dependency-name: '@types/eslint'
- dependency-name: 'vue-eslint-parser'
- dependency-name: 'mocha'
groups:
dev-dependencies:
dependency-type: development
patterns:
- '*'

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
groups:
actions:
patterns:
- '*'
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,12 +19,12 @@ jobs:
- 20

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
@@ -36,4 +36,7 @@ jobs:
run: pnpm mocha

- name: Perf
# Skip on node 14, as eslint-plugin-n contains syntax that doesn't work
# with node 14
if: ${{ matrix.node-version != 14 }}
run: TIMING=1 pnpm lint
26 changes: 0 additions & 26 deletions .github/workflows/pkg-size.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
cache: pnpm
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 5.1.0

### Minor Changes

- [#616](https://github.com/prettier/eslint-plugin-prettier/pull/616) [`3856413`](https://github.com/prettier/eslint-plugin-prettier/commit/3856413420d3d026e5ae84f29c4bd0d558697135) Thanks [@BPScott](https://github.com/BPScott)! - Add recommended config for the flat config format.

If you are using flat config, import the recommended config from `eslint-plugin-prettier/recommended`. Like the legacy format recommended config, this automatically includes the contents of `eslint-config-prettier`.

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

module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
];
```

### Patch Changes

- [#614](https://github.com/prettier/eslint-plugin-prettier/pull/614) [`5270877`](https://github.com/prettier/eslint-plugin-prettier/commit/5270877d169bec05449861c8ad7e6338b0ad47c0) Thanks [@BPScott](https://github.com/BPScott)! - Add meta block to plugin. This improves debugging and cachebusting when using the new flat config

- [#603](https://github.com/prettier/eslint-plugin-prettier/pull/603) [`a63a570`](https://github.com/prettier/eslint-plugin-prettier/commit/a63a570f8f3e3d53b90b1cf35e06fd7e3c387a5a) Thanks [@filiptammergard](https://github.com/filiptammergard)! - fix: specify `eslint-config-prettier` as peer dependency

It's already added to `peerDependenciesMeta` as optional, which means it should also be specified in `peerDependencies`.

## 5.0.1

### Patch Changes
65 changes: 27 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -37,63 +37,52 @@ error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.j
## Installation

```sh
npm install --save-dev eslint-plugin-prettier
npm install --save-dev eslint-plugin-prettier eslint-config-prettier
npm install --save-dev --save-exact prettier
```

**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._

Then, in your `.eslintrc.json`:
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs. If another active ESLint rule disagrees with `prettier` about how code should be formatted, it will be impossible to avoid lint errors. Our recommended configuration automatically enables [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules.

## Configuration (legacy: `.eslintrc*`)

For [legacy configuration](https://eslint.org/docs/latest/use/configure/configuration-files), this plugin ships with a `plugin:prettier/recommended` config that sets up both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.

Add `plugin:prettier/recommended` as the _last_ item in the extends array in your `.eslintrc*` config file, so that `eslint-config-prettier` has the opportunity to override other configs:

```json
{
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
"extends": ["plugin:prettier/recommended"]
}
```

## Recommended Configuration

This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs. (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.

This plugin ships with a `plugin:prettier/recommended` config that sets up both the plugin and `eslint-config-prettier` in one go.

1. In addition to the above installation instructions, install `eslint-config-prettier`:
This will:

```sh
npm install --save-dev eslint-config-prettier
```
- Enable the `prettier/prettier` rule.
- Disable the `arrow-body-style` and `prefer-arrow-callback` rules which are problematic with this plugin - see the below for why.
- Enable the `eslint-config-prettier` config which will turn off ESLint rules that conflict with Prettier.

2. Then you need to add `plugin:prettier/recommended` as the _last_ extension in your `.eslintrc.json`:
## Configuration (new: `eslint.config.js`)

```json
{
"extends": ["plugin:prettier/recommended"]
}
```
For [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new), this plugin ships with an `eslint-plugin-prettier/recommended` config that sets up both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.

You can then set Prettier's own options inside a `.prettierrc` file.
Import `eslint-plugin-prettier/recommended` and add it as the _last_ item in the configuration array in your `eslint.config.js` file so that `eslint-config-prettier` has the opportunity to override other configs:

Exactly what does `plugin:prettier/recommended` do? Well, this is what it expands to:
```js
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');

```json
{
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"arrow-body-style": "off",
"prefer-arrow-callback": "off"
}
}
module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
];
```

- `"extends": ["prettier"]` enables the config from `eslint-config-prettier`, which turns off some ESLint rules that conflict with Prettier.
- `"plugins": ["prettier"]` registers this plugin.
- `"prettier/prettier": "error"` turns on the rule provided by this plugin, which runs Prettier from within ESLint.
- `"arrow-body-style": "off"` and `"prefer-arrow-callback": "off"` turns off two ESLint core rules that unfortunately are problematic with this plugin – see the next section.
This will:

- Enable the `prettier/prettier` rule.
- Disable the `arrow-body-style` and `prefer-arrow-callback` rules which are problematic with this plugin - see the below for why.
- Enable the `eslint-config-prettier` config which will turn off ESLint rules that conflict with Prettier.

## `Svelte` support

25 changes: 21 additions & 4 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ const {
showInvisibles,
generateDifferences,
} = require('prettier-linter-helpers');
const { name, version } = require('./package.json');

// ------------------------------------------------------------------------------
// Constants
@@ -54,8 +55,11 @@ let prettierFormat;
function reportDifference(context, difference) {
const { operation, offset, deleteText = '', insertText = '' } = difference;
const range = /** @type {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.
const [start, end] = range.map(index =>
context.getSourceCode().getLocFromIndex(index),
(context.sourceCode ?? context.getSourceCode()).getLocFromIndex(index),
);

context.report({
@@ -77,6 +81,7 @@ function reportDifference(context, difference) {
* @type {Plugin}
*/
const eslintPluginPrettier = {
meta: { name, version },
configs: {
recommended: {
extends: ['prettier'],
@@ -130,14 +135,26 @@ const eslintPluginPrettier = {
*/
const fileInfoOptions =
(context.options[1] && context.options[1].fileInfoOptions) || {};
const sourceCode = context.getSourceCode();
const filepath = context.getFilename();

// `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();
// `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.
const filepath = context.filename ?? context.getFilename();

// Processors that extract content from a file, such as the markdown
// plugin extracting fenced code blocks may choose to specify virtual
// file paths. If this is the case then we need to resolve prettier
// config and file info using the on-disk path instead of the virtual
// path.
const onDiskFilepath = context.getPhysicalFilename();
// `context.getPhysicalFilename()` was deprecated in ESLint v8.40.0 and replaced
// with the `physicalFilename` property.
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
const onDiskFilepath =
context.physicalFilename ?? context.getPhysicalFilename();
const source = sourceCode.text;

return {
46 changes: 46 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { configs: eslintConfigs } = require('@eslint/js');
const eslintPluginN = require('eslint-plugin-n');
const eslintPluginEslintComments = require('@eslint-community/eslint-plugin-eslint-comments');
const eslintPluginEslintPluginRecommended = require('eslint-plugin-eslint-plugin/configs/recommended');
const eslintPluginMdx = require('eslint-plugin-mdx');
const eslintPluginPrettierRecommended = require('./recommended');

module.exports = [
eslintConfigs.recommended,
eslintPluginN.configs['flat/recommended'],
// eslint-community/eslint-comments does not expose a reusable flat config,
// so create one from its legacy config
{
plugins: {
'@eslint-community/eslint-comments': eslintPluginEslintComments,
},
rules: eslintPluginEslintComments.configs.recommended.rules,
},
eslintPluginEslintPluginRecommended,
eslintPluginMdx.flat,
eslintPluginMdx.flatCodeBlocks,
eslintPluginPrettierRecommended,
{
rules: {
'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
{
ignores: [
'CHANGELOG.md',
'.github/ISSUE_TEMPLATE.md',
'test/fixtures/**/*',
],
},
];
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-prettier",
"version": "5.0.1",
"version": "5.1.0",
"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",
@@ -19,6 +19,8 @@
"files": [
"eslint-plugin-prettier.d.ts",
"eslint-plugin-prettier.js",
"recommended.d.ts",
"recommended.js",
"worker.js"
],
"keywords": [
@@ -38,6 +40,7 @@
"peerDependencies": {
"@types/eslint": ">=8.0.0",
"eslint": ">=8.0.0",
"eslint-config-prettier": "*",
"prettier": ">=3.0.0"
},
"peerDependenciesMeta": {
@@ -54,26 +57,27 @@
},
"devDependencies": {
"@1stg/remark-preset": "^2.0.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.26.2",
"@commitlint/config-conventional": "^17.6.6",
"@eslint-community/eslint-plugin-eslint-comments": "^3.2.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",
"@types/eslint": "^8.44.0",
"@types/eslint": "^8.44.7",
"@types/prettier-linter-helpers": "^1.0.1",
"commitlint": "^17.6.6",
"commitlint": "^18.4.3",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-formatter-friendly": "^7.0.0",
"eslint-mdx": "^2.1.0",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-mdx": "^2.1.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-mdx": "^2.2.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-prettier": "link:.",
"eslint-plugin-svelte": "^2.32.2",
"eslint-plugin-svelte3": "^4.0.0",
"graphql": "^16.7.1",
"lint-staged": "^13.2.3",
"lint-staged": "^15.1.0",
"mocha": "^10.2.0",
"prettier": "^3.0.0",
"prettier-plugin-pkg": "^0.18.0",
1,901 changes: 985 additions & 916 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions recommended.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Linter } from 'eslint';

declare const recommendedConfig: Linter.FlatConfig;

export = recommendedConfig;
17 changes: 17 additions & 0 deletions recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const eslintConfigPrettier = require('eslint-config-prettier');
const eslintPluginPrettier = require('./eslint-plugin-prettier');

// Merge the contents of eslint-config-prettier into every
module.exports = {
...eslintConfigPrettier,
plugins: {
...eslintConfigPrettier.plugins,
prettier: eslintPluginPrettier,
},
rules: {
...eslintConfigPrettier.rules,
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
};