Socket
Socket
Sign inDemoInstall

eslint-plugin-prettier

Package Overview
Dependencies
Maintainers
6
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-prettier - npm Package Compare versions

Comparing version 5.0.1 to 5.1.2

recommended.d.ts

39

eslint-plugin-prettier.js

@@ -12,4 +12,6 @@ /**

* @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
*/

@@ -27,2 +29,3 @@

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

@@ -59,4 +62,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),
);

@@ -83,2 +89,3 @@

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

@@ -137,4 +144,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

@@ -145,3 +160,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;

@@ -159,6 +178,8 @@

/**
* @type {{}}
* @type {PrettierOptions}
*/
const eslintPrettierOptions = context.options[0] || {};
const parser = context.languageOptions?.parser;
// prettier.format() may throw a SyntaxError if it cannot parse the

@@ -183,2 +204,8 @@ // source code it is given. Usually for JS files this isn't a

onDiskFilepath,
parserMeta:
parser &&
(parser.meta ?? {
name: parser.name,
version: parser.version,
}),
parserPath: context.parserPath,

@@ -185,0 +212,0 @@ usePrettierrc,

86

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

@@ -11,5 +11,5 @@ "repository": "git+https://github.com/prettier/eslint-plugin-prettier.git",

],
"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": {

@@ -19,2 +19,12 @@ "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",

@@ -24,2 +34,4 @@ "files": [

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

@@ -33,13 +45,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"

@@ -57,38 +62,43 @@ },

"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.4.8",
"@changesets/cli": "^2.26.2",
"@commitlint/config-conventional": "^17.6.6",
"@eslint-community/eslint-plugin-eslint-comments": "^3.2.1",
"@graphql-eslint/eslint-plugin": "^3.20.0",
"@types/eslint": "^8.44.0",
"@types/prettier-linter-helpers": "^1.0.1",
"commitlint": "^17.6.6",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commitlint/config-conventional": "^18.4.3",
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@eslint/js": "^8.56.0",
"@graphql-eslint/eslint-plugin": "^3.20.1",
"@prettier/plugin-pug": "^3.0.0",
"@types/eslint": "^8.56.0",
"@types/prettier-linter-helpers": "^1.0.4",
"commitlint": "^18.4.3",
"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.1.0",
"eslint-plugin-n": "^16.0.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-svelte": "^2.32.2",
"eslint-plugin-pug": "^1.2.5",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-svelte3": "^4.0.0",
"graphql": "^16.7.1",
"lint-staged": "^13.2.3",
"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"
}
"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"
}
}
}

@@ -9,2 +9,17 @@ # 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)

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

@@ -41,3 +56,3 @@

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

@@ -48,54 +63,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

@@ -179,2 +183,14 @@

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

@@ -181,0 +197,0 @@

@@ -5,3 +5,4 @@ // @ts-check

* @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
*/

@@ -28,2 +29,3 @@

onDiskFilepath,
parserMeta,
parserPath,

@@ -63,3 +65,3 @@ usePrettierrc,

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

@@ -100,5 +102,5 @@ // ESLint supports processors that let you extract and lint JS

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

@@ -116,2 +118,14 @@ switch (inferredParser) {

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

@@ -122,3 +136,3 @@ case 'svelte': {

typeof parserPath === 'string' &&
!parserPath.includes('svelte-eslint-parser')
!/([\\/])svelte-eslint-parser\1/.test(parserPath)
) {

@@ -154,2 +168,3 @@ // We do not support `eslint-plugin-svelte3`,

'svelte',
'pug',
];

@@ -161,2 +176,5 @@ if (parserBlocklist.includes(/** @type {string} */ (inferredParser))) {

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

@@ -163,0 +181,0 @@ ...initialOptions,

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc