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 4.2.1 to 5.0.1

eslint-plugin-prettier.d.ts

30

CHANGELOG.md
# Changelog
## 5.0.1
### Patch Changes
- [#588](https://github.com/prettier/eslint-plugin-prettier/pull/588) [`21a7146`](https://github.com/prettier/eslint-plugin-prettier/commit/21a7146d78161307dcc7eaa96f41dac51f7ce89f) Thanks [@krist7599555](https://github.com/krist7599555)! - fix: `parserPath` type might be `undefined` on Eslint Falt Config
## 5.0.0
### Major Changes
- [#508](https://github.com/prettier/eslint-plugin-prettier/pull/508) [`910aeb6`](https://github.com/prettier/eslint-plugin-prettier/commit/910aeb60a7456beb6193c634bb8dec1b7181312d) Thanks [@JounQin](https://github.com/JounQin)! - feat!: bump peer eslint to ">=8.0.0" and node to "^14.18.0 || >=16.0.0"
- [#508](https://github.com/prettier/eslint-plugin-prettier/pull/508) [`910aeb6`](https://github.com/prettier/eslint-plugin-prettier/commit/910aeb60a7456beb6193c634bb8dec1b7181312d) Thanks [@JounQin](https://github.com/JounQin)! - feat!: upgrade to prettier v3
### Minor Changes
- [#508](https://github.com/prettier/eslint-plugin-prettier/pull/508) [`910aeb6`](https://github.com/prettier/eslint-plugin-prettier/commit/910aeb60a7456beb6193c634bb8dec1b7181312d) Thanks [@JounQin](https://github.com/JounQin)! - feat: add typings support
### Patch Changes
- [#548](https://github.com/prettier/eslint-plugin-prettier/pull/548) [`82a3db8`](https://github.com/prettier/eslint-plugin-prettier/commit/82a3db878baf1a8f8ef53393069fe23c3a80ce15) Thanks [@fisker](https://github.com/fisker)! - fix: add missing dependency `synckit`
- [#564](https://github.com/prettier/eslint-plugin-prettier/pull/564) [`ae7a73c`](https://github.com/prettier/eslint-plugin-prettier/commit/ae7a73c6c4b306c617c5dd9baaaa2ae7c0f9f44b) Thanks [@auvred](https://github.com/auvred)! - fix: compatibility with prettier@3 without plugins
## 4.2.2
### Patch Changes
- [`2373d0c`](https://github.com/prettier/eslint-plugin-prettier/commit/2373d0c0c9f30aee30e6059ba386fdc4435ed333) Thanks [@JounQin](https://github.com/JounQin)! - docs: add Sponsors and Backers sections
## 4.2.1

@@ -4,0 +34,0 @@

189

eslint-plugin-prettier.js

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

// @ts-check
/**
* @typedef {import('eslint').AST.Range} Range
* @typedef {import('eslint').AST.SourceLocation} SourceLocation
* @typedef {import('eslint').ESLint.Plugin} Plugin
* @typedef {import('prettier').FileInfoOptions} FileInfoOptions
* @typedef {import('prettier').Options & { onDiskFilepath: string, parserPath: string, usePrettierrc?: boolean }} Options
*/
'use strict';

@@ -30,5 +40,5 @@

/**
* @type {import('prettier')}
* @type {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string}
*/
let prettier;
let prettierFormat;

@@ -48,3 +58,3 @@ // ------------------------------------------------------------------------------

const { operation, offset, deleteText = '', insertText = '' } = difference;
const range = [offset, offset + deleteText.length];
const range = /** @type {Range} */ ([offset, offset + deleteText.length]);
const [start, end] = range.map(index =>

@@ -69,3 +79,6 @@ context.getSourceCode().getLocFromIndex(index),

module.exports = {
/**
* @type {Plugin}
*/
const eslintPluginPrettier = {
configs: {

@@ -119,3 +132,6 @@ recommended: {

!context.options[1] || context.options[1].usePrettierrc !== false;
const eslintFileInfoOptions =
/**
* @type {FileInfoOptions}
*/
const fileInfoOptions =
(context.options[1] && context.options[1].fileInfoOptions) || {};

@@ -133,130 +149,15 @@ const sourceCode = context.getSourceCode();

return {
// eslint-disable-next-line sonarjs/cognitive-complexity
Program() {
if (!prettier) {
if (!prettierFormat) {
// Prettier is expensive to load, so only load it if needed.
prettier = require('prettier');
prettierFormat = require('synckit').createSyncFn(
require.resolve('./worker'),
);
}
/**
* @type {{}}
*/
const eslintPrettierOptions = context.options[0] || {};
const prettierRcOptions = usePrettierrc
? prettier.resolveConfig.sync(onDiskFilepath, {
editorconfig: true,
})
: null;
const { ignored, inferredParser } = prettier.getFileInfo.sync(
onDiskFilepath,
{
resolveConfig: false,
withNodeModules: false,
ignorePath: '.prettierignore',
plugins: prettierRcOptions ? prettierRcOptions.plugins : null,
...eslintFileInfoOptions,
},
);
// Skip if file is ignored using a .prettierignore file
if (ignored) {
return;
}
const initialOptions = {};
// ESLint supports processors that let you extract and lint JS
// fragments within a non-JS language. In the cases where prettier
// supports the same language as a processor, we want to process
// the provided source code as javascript (as ESLint provides the
// rules with fragments of JS) instead of guessing the parser
// based off the filename. Otherwise, for instance, on a .md file we
// end up trying to run prettier over a fragment of JS using the
// markdown parser, which throws an error.
// Processors may set virtual filenames for these extracted blocks.
// If they do so then we want to trust the file extension they
// provide, and no override is needed.
// If the processor does not set any virtual filename (signified by
// `filepath` and `onDiskFilepath` being equal) AND we can't
// infer the parser from the filename, either because no filename
// was provided or because there is no parser found for the
// filename, use javascript.
// This is added to the options first, so that
// prettierRcOptions and eslintPrettierOptions can still override
// the parser.
//
// `parserBlocklist` should contain the list of prettier parser
// names for file types where:
// * Prettier supports parsing the file type
// * There is an ESLint processor that extracts JavaScript snippets
// from the file type.
if (filepath === onDiskFilepath) {
// The following list means the plugin process source into js content
// but with same filename, so we need to change the parser to `babel`
// by default.
// Related ESLint plugins are:
// 1. `eslint-plugin-graphql` (replacement: `@graphql-eslint/eslint-plugin`)
// 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'];
let inferParserToBabel = parserBlocklist.includes(inferredParser);
switch (inferredParser) {
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
case 'graphql': {
if (
// for `eslint-plugin-graphql`, see https://github.com/apollographql/eslint-plugin-graphql/blob/master/src/index.js#L416
source.startsWith('ESLintPluginGraphQLFile`')
) {
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 (!context.parserPath.includes('svelte-eslint-parser')) {
// We do not support `eslint-plugin-svelte3`,
// the users should run `prettier` on `.svelte` files manually
return;
}
}
}
if (inferParserToBabel) {
initialOptions.parser = 'babel';
}
} else {
// Similar to https://github.com/prettier/stylelint-prettier/pull/22
// In all of the following cases ESLint extracts a part of a file to
// be formatted and there exists a prettier parser for the whole file.
// If you're interested in prettier you'll want a fully formatted file so
// you're about to run prettier over the whole file anyway.
// Therefore running prettier over just the style section is wasteful, so
// skip it.
const parserBlocklist = [
'babel',
'babylon',
'flow',
'typescript',
'vue',
'markdown',
'html',
'mdx',
'angular',
'svelte',
];
if (parserBlocklist.includes(inferredParser)) {
return;
}
}
const prettierOptions = {
...initialOptions,
...prettierRcOptions,
...eslintPrettierOptions,
filepath,
};
// prettier.format() may throw a SyntaxError if it cannot parse the

@@ -270,5 +171,18 @@ // source code it is given. Usually for JS files this isn't a

// point at which parsing failed.
/**
* @type {string}
*/
let prettierSource;
try {
prettierSource = prettier.format(source, prettierOptions);
prettierSource = prettierFormat(
source,
{
...eslintPrettierOptions,
filepath,
onDiskFilepath,
parserPath: context.parserPath,
usePrettierrc,
},
fileInfoOptions,
);
} catch (err) {

@@ -281,2 +195,7 @@ if (!(err instanceof SyntaxError)) {

const error =
/** @type {SyntaxError & {codeFrame: string; loc: SourceLocation}} */ (
err
);
// Prettier's message contains a codeframe style preview of the

@@ -286,10 +205,10 @@ // invalid code and the line/column at which the error occurred.

// remove them from the message
if (err.codeFrame) {
message = message.replace(`\n${err.codeFrame}`, '');
if (error.codeFrame) {
message = message.replace(`\n${error.codeFrame}`, '');
}
if (err.loc) {
if (error.loc) {
message = message.replace(/ \(\d+:\d+\)$/, '');
}
context.report({ message, loc: err.loc });
context.report({ message, loc: error.loc });

@@ -299,2 +218,6 @@ return;

if (prettierSource == null) {
return;
}
if (source !== prettierSource) {

@@ -313,1 +236,3 @@ const differences = generateDifferences(source, prettierSource);

};
module.exports = eslintPluginPrettier;
{
"name": "eslint-plugin-prettier",
"version": "4.2.1",
"version": "5.0.1",
"description": "Runs prettier as an eslint rule",

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

],
"funding": "https://opencollective.com/prettier",
"license": "MIT",
"packageManager": "pnpm@7.33.3",
"engines": {
"node": ">=12.0.0"
"node": "^14.18.0 || >=16.0.0"
},
"main": "eslint-plugin-prettier.js",
"types": "eslint-plugin-prettier.d.ts",
"files": [
"eslint-plugin-prettier.js"
"eslint-plugin-prettier.d.ts",
"eslint-plugin-prettier.js",
"worker.js"
],

@@ -27,14 +32,18 @@ "keywords": [

"scripts": {
"format": "yarn prettier '**/*.{js,json,md,yml}' --write && yarn lint --fix",
"format": "prettier --write . && pnpm lint --fix",
"lint": "eslint . --cache -f friendly --max-warnings 10",
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "yarn format && yarn test",
"prepare": "simple-git-hooks",
"prerelease": "pnpm format && pnpm test",
"release": "changeset publish",
"test": "yarn lint && mocha"
"test": "pnpm lint && mocha"
},
"peerDependencies": {
"eslint": ">=7.28.0",
"prettier": ">=2.0.0"
"@types/eslint": ">=8.0.0",
"eslint": ">=8.0.0",
"prettier": ">=3.0.0"
},
"peerDependenciesMeta": {
"@types/eslint": {
"optional": true
},
"eslint-config-prettier": {

@@ -45,30 +54,39 @@ "optional": true

"dependencies": {
"prettier-linter-helpers": "^1.0.0"
"prettier-linter-helpers": "^1.0.0",
"synckit": "^0.8.5"
},
"devDependencies": {
"@1stg/common-config": "~3.0.0",
"@1stg/eslint-config": "~3.0.0",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.0",
"@graphql-eslint/eslint-plugin": "^2.5.0",
"@ota-meshi/eslint-plugin-svelte": "^0.34.1",
"@typescript-eslint/parser": "^5.29.0",
"eslint-config-prettier": "^8.5.0",
"eslint-mdx": "^1.17.0",
"eslint-plugin-eslint-plugin": "^4.3.0",
"eslint-plugin-mdx": "^1.17.0",
"eslint-plugin-self": "^1.2.1",
"eslint-plugin-utils": "^0.1.0",
"graphql": "^16.5.0",
"mocha": "^9.2.2",
"patch-package": "^6.4.7",
"svelte": "^3.48.0",
"vue-eslint-parser": "^8.3.0"
},
"resolutions": {
"@babel/traverse": "^7.18.5",
"@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",
"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-prettier": "link:.",
"prettier": "^2.7.1"
"eslint-plugin-svelte": "^2.32.2",
"eslint-plugin-svelte3": "^4.0.0",
"graphql": "^16.7.1",
"lint-staged": "^13.2.3",
"mocha": "^10.2.0",
"prettier": "^3.0.0",
"prettier-plugin-pkg": "^0.18.0",
"simple-git-hooks": "^2.8.1",
"svelte": "^4.0.5",
"vue-eslint-parser": "^9.3.1"
},
"packageManager": "yarn@1.22.19"
"pnpm": {
"patchedDependencies": {
"@graphql-eslint/eslint-plugin@3.20.0": "patches/@graphql-eslint__eslint-plugin@3.20.0.patch"
}
}
}

@@ -100,4 +100,8 @@ # 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)

We recommend to use [`eslint-plugin-svelte`](https://github.com/ota-meshi/eslint-plugin-svelte) instead of [`eslint-plugin-svelte3`](https://github.com/sveltejs/eslint-plugin-svelte3) because `eslint-plugin-svelte` has a correct [`eslint-svelte-parser`](https://github.com/ota-meshi/svelte-eslint-parser) instead of hacking, when use with `eslint-plugin-svelte3`, `eslint-plugin-prettier` will just ignore the text passed by `eslint-plugin-svelte3`, because the text they has been modified.
We recommend to use [`eslint-plugin-svelte`](https://github.com/ota-meshi/eslint-plugin-svelte) instead of [`eslint-plugin-svelte3`](https://github.com/sveltejs/eslint-plugin-svelte3) because `eslint-plugin-svelte` has a correct [`eslint-svelte-parser`](https://github.com/ota-meshi/svelte-eslint-parser) instead of hacking.
When use with `eslint-plugin-svelte3`, `eslint-plugin-prettier` will just ignore the text passed by `eslint-plugin-svelte3`, because the text has been modified.
If you still decide to use `eslint-plugin-svelte3`, you'll need to run `prettier --write *.svelte` manually.
## `arrow-body-style` and `prefer-arrow-callback` issue

@@ -123,3 +127,9 @@

{
"prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }]
"prettier/prettier": [
"error",
{
"singleQuote": true,
"parser": "flow"
}
]
}

@@ -134,3 +144,3 @@ ```

- `usePrettierrc`: Enables loading of the Prettier configuration file, (default: `true`). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration.
- `usePrettierrc`: Enables loading of the Prettier configuration file, (default: `true`). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration. And also, it is possible to run prettier without loading the prettierrc config file [via the CLI's --no-config option](https://prettier.io/docs/en/cli.html#--no-config) or through the API by [calling prettier.format() without passing through the options generated by calling resolveConfig](https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath--options).

@@ -137,0 +147,0 @@ ```json

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