Socket
Socket
Sign inDemoInstall

eslint-plugin-prettier

Package Overview
Dependencies
98
Maintainers
6
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.1 to 5.1.0

recommended.d.ts

25

eslint-plugin-prettier.js

@@ -26,2 +26,3 @@ /**

} = require('prettier-linter-helpers');
const { name, version } = require('./package.json');

@@ -58,4 +59,7 @@ // ------------------------------------------------------------------------------

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),
);

@@ -82,2 +86,3 @@

const eslintPluginPrettier = {
meta: { name, version },
configs: {

@@ -136,4 +141,12 @@ recommended: {

(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

@@ -144,3 +157,7 @@ // plugin extracting fenced code blocks may choose to specify 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;

@@ -147,0 +164,0 @@

42

package.json
{
"name": "eslint-plugin-prettier",
"version": "5.0.1",
"version": "5.1.0",
"description": "Runs prettier as an eslint rule",

@@ -22,2 +22,4 @@ "repository": "git+https://github.com/prettier/eslint-plugin-prettier.git",

"eslint-plugin-prettier.js",
"recommended.d.ts",
"recommended.js",
"worker.js"

@@ -31,13 +33,6 @@ ],

],
"scripts": {
"format": "prettier --write . && pnpm lint --fix",
"lint": "eslint . --cache -f friendly --max-warnings 10",
"prepare": "simple-git-hooks",
"prerelease": "pnpm format && pnpm test",
"release": "changeset publish",
"test": "pnpm lint && mocha"
},
"peerDependencies": {
"@types/eslint": ">=8.0.0",
"eslint": ">=8.0.0",
"eslint-config-prettier": "*",
"prettier": ">=3.0.0"

@@ -59,10 +54,11 @@ },

"@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",

@@ -73,4 +69,4 @@ "eslint-config-prettier": "^8.8.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:.",

@@ -80,3 +76,3 @@ "eslint-plugin-svelte": "^2.32.2",

"graphql": "^16.7.1",
"lint-staged": "^13.2.3",
"lint-staged": "^15.1.0",
"mocha": "^10.2.0",

@@ -89,7 +85,9 @@ "prettier": "^3.0.0",

},
"pnpm": {
"patchedDependencies": {
"@graphql-eslint/eslint-plugin@3.20.0": "patches/@graphql-eslint__eslint-plugin@3.20.0.patch"
}
"scripts": {
"format": "prettier --write . && pnpm lint --fix",
"lint": "eslint . --cache -f friendly --max-warnings 10",
"prerelease": "pnpm format && pnpm test",
"release": "changeset publish",
"test": "pnpm lint && mocha"
}
}
}

@@ -40,3 +40,3 @@ # eslint-plugin-prettier [![Build Status](https://github.com/prettier/eslint-plugin-prettier/workflows/CI/badge.svg?branch=master)](https://github.com/prettier/eslint-plugin-prettier/actions?query=workflow%3ACI+branch%3Amaster)

```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

@@ -47,54 +47,43 @@ ```

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 will:
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.
- 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.
This plugin ships with a `plugin:prettier/recommended` config that sets up both the plugin and `eslint-config-prettier` in one go.
## Configuration (new: `eslint.config.js`)
1. In addition to the above installation instructions, install `eslint-config-prettier`:
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.
```sh
npm install --save-dev eslint-config-prettier
```
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:
2. Then you need to add `plugin:prettier/recommended` as the _last_ extension in your `.eslintrc.json`:
```js
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
```json
{
"extends": ["plugin:prettier/recommended"]
}
```
module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
];
```
You can then set Prettier's own options inside a `.prettierrc` file.
This will:
Exactly what does `plugin:prettier/recommended` do? Well, this is what it expands to:
- 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.
```json
{
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"arrow-body-style": "off",
"prefer-arrow-callback": "off"
}
}
```
- `"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.
## `Svelte` support

@@ -101,0 +90,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc