eslint-plugin-prettier
Advanced tools
Comparing version 4.1.0 to 4.2.0
/** | ||
* @fileoverview Runs `prettier` as an ESLint rule. | ||
* @file Runs `prettier` as an ESLint rule. | ||
* @author Andres Suarez | ||
@@ -39,2 +39,3 @@ */ | ||
* Reports a difference. | ||
* | ||
* @param {import('eslint').Rule.RuleContext} context - The ESLint rule context. | ||
@@ -47,4 +48,4 @@ * @param {import('prettier-linter-helpers').Difference} difference - The difference object. | ||
const range = [offset, offset + deleteText.length]; | ||
const [start, end] = range.map((index) => | ||
context.getSourceCode().getLocFromIndex(index) | ||
const [start, end] = range.map(index => | ||
context.getSourceCode().getLocFromIndex(index), | ||
); | ||
@@ -59,3 +60,3 @@ | ||
loc: { start, end }, | ||
fix: (fixer) => fixer.replaceTextRange(range, insertText), | ||
fix: fixer => fixer.replaceTextRange(range, insertText), | ||
}); | ||
@@ -130,2 +131,3 @@ } | ||
return { | ||
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
Program() { | ||
@@ -147,7 +149,7 @@ if (!prettier) { | ||
onDiskFilepath, | ||
Object.assign( | ||
{}, | ||
{ resolveConfig: true, ignorePath: '.prettierignore' }, | ||
eslintFileInfoOptions | ||
) | ||
{ | ||
resolveConfig: true, | ||
ignorePath: '.prettierignore', | ||
...eslintFileInfoOptions, | ||
}, | ||
); | ||
@@ -193,16 +195,29 @@ | ||
// 1. `eslint-plugin-graphql` (replacement: `@graphql-eslint/eslint-plugin`) | ||
// 2. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`) | ||
// 3. `eslint-plugin-html` | ||
// 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.indexOf(inferredParser) !== -1; | ||
let inferParserToBabel = parserBlocklist.includes(inferredParser); | ||
if ( | ||
switch (inferredParser) { | ||
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql` | ||
inferredParser === 'graphql' && | ||
// for `eslint-plugin-graphql`, see https://github.com/apollographql/eslint-plugin-graphql/blob/master/src/index.js#L416 | ||
source.startsWith('ESLintPluginGraphQLFile`') | ||
) { | ||
inferParserToBabel = true; | ||
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; | ||
} | ||
} | ||
} | ||
@@ -231,4 +246,5 @@ | ||
'angular', | ||
'svelte', | ||
]; | ||
if (parserBlocklist.indexOf(inferredParser) !== -1) { | ||
if (parserBlocklist.includes(inferredParser)) { | ||
return; | ||
@@ -238,9 +254,8 @@ } | ||
const prettierOptions = Object.assign( | ||
{}, | ||
initialOptions, | ||
prettierRcOptions, | ||
eslintPrettierOptions, | ||
{ filepath } | ||
); | ||
const prettierOptions = { | ||
...initialOptions, | ||
...prettierRcOptions, | ||
...eslintPrettierOptions, | ||
filepath, | ||
}; | ||
@@ -247,0 +262,0 @@ // prettier.format() may throw a SyntaxError if it cannot parse the |
{ | ||
"name": "eslint-plugin-prettier", | ||
"version": "4.1.0", | ||
"version": "4.2.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", | ||
"author": "Teddy Katz", | ||
"contributors": [ | ||
"JounQin (https://github.com/JounQin) <admin@1stg.me>" | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"main": "eslint-plugin-prettier.js", | ||
"files": [ | ||
"eslint-plugin-prettier.js" | ||
], | ||
"keywords": [ | ||
@@ -11,34 +25,30 @@ "eslint", | ||
], | ||
"author": "Teddy Katz", | ||
"files": [ | ||
"eslint-plugin-prettier.js" | ||
], | ||
"main": "eslint-plugin-prettier.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "npm run lint && mocha", | ||
"format": "yarn run prettier '**/*.{js,json,md,yml}' --write && yarn run lint --fix", | ||
"generate-release": "node-release-script" | ||
"format": "yarn prettier '**/*.{js,json,md,yml}' --write && yarn 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", | ||
"release": "changeset publish", | ||
"test": "yarn lint && mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/prettier/eslint-plugin-prettier.git" | ||
"peerDependencies": { | ||
"eslint": ">=7.28.0", | ||
"prettier": ">=2.0.0" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/prettier/eslint-plugin-prettier/issues" | ||
"peerDependenciesMeta": { | ||
"eslint-config-prettier": { | ||
"optional": true | ||
} | ||
}, | ||
"homepage": "https://github.com/prettier/eslint-plugin-prettier#readme", | ||
"dependencies": { | ||
"prettier-linter-helpers": "^1.0.0" | ||
}, | ||
"peerDependencies": { | ||
"eslint": ">=7.28.0", | ||
"prettier": ">=2.0.0" | ||
}, | ||
"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", | ||
"@not-an-aardvark/node-release-script": "^0.1.0", | ||
"@ota-meshi/eslint-plugin-svelte": "^0.34.1", | ||
"@typescript-eslint/parser": "^5.29.0", | ||
"eslint": "^8.18.0", | ||
"eslint-config-not-an-aardvark": "^2.1.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
@@ -48,22 +58,16 @@ "eslint-mdx": "^1.17.0", | ||
"eslint-plugin-mdx": "^1.17.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "link:.", | ||
"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", | ||
"prettier": "^2.7.1", | ||
"svelte": "^3.48.0", | ||
"vue-eslint-parser": "^8.3.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"eslint-config-prettier": { | ||
"optional": true | ||
} | ||
}, | ||
"resolutions": { | ||
"@babel/traverse": "^7.18.5" | ||
"@babel/traverse": "^7.18.5", | ||
"eslint-plugin-prettier": "link:." | ||
}, | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"license": "MIT" | ||
"packageManager": "yarn@1.22.19" | ||
} |
@@ -98,2 +98,6 @@ # 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) | ||
## `Svelte` support | ||
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. | ||
## `arrow-body-style` and `prefer-arrow-callback` issue | ||
@@ -118,3 +122,5 @@ | ||
```json | ||
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}] | ||
{ | ||
"prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }] | ||
} | ||
``` | ||
@@ -131,5 +137,11 @@ | ||
```json | ||
"prettier/prettier": ["error", {}, { | ||
"usePrettierrc": false | ||
}] | ||
{ | ||
"prettier/prettier": [ | ||
"error", | ||
{}, | ||
{ | ||
"usePrettierrc": false | ||
} | ||
] | ||
} | ||
``` | ||
@@ -140,10 +152,16 @@ | ||
```json | ||
"prettier/prettier": ["error", {}, { | ||
"fileInfoOptions": { | ||
"withNodeModules": true | ||
} | ||
}] | ||
{ | ||
"prettier/prettier": [ | ||
"error", | ||
{}, | ||
{ | ||
"fileInfoOptions": { | ||
"withNodeModules": true | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
- The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style. | ||
- The rule is auto fixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style. | ||
@@ -155,1 +173,9 @@ --- | ||
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md) | ||
## Changelog | ||
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md). | ||
## License | ||
[MIT](http://opensource.org/licenses/MIT) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
22021
270
177
0
19