Initial import with skill sheet working

This commit is contained in:
2024-12-04 00:11:23 +01:00
commit 9050c80ab4
4488 changed files with 671048 additions and 0 deletions

24
node_modules/eslint-plugin-prettier/LICENSE.md generated vendored Normal file
View File

@ -0,0 +1,24 @@
# The MIT License (MIT)
Copyright © 2017 Andres Suarez and Teddy Katz
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

202
node_modules/eslint-plugin-prettier/README.md generated vendored Normal file
View File

@ -0,0 +1,202 @@
# 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)
Runs [Prettier](https://github.com/prettier/prettier) as an [ESLint](https://eslint.org) rule and reports differences as individual ESLint issues.
If your desired formatting does not match Prettiers output, you should use a different tool such as [prettier-eslint](https://github.com/prettier/prettier-eslint) instead.
Please read [Integrating with linters](https://prettier.io/docs/en/integrating-with-linters.html) before installing.
## 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
```js
error: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
20 | import {
21 | observeActiveEditorsDebounced,
> 22 | editorChangesDebounced
| ^
23 | } from './debounced';;
24 |
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
21 | observeActiveEditorsDebounced,
22 | editorChangesDebounced
> 23 | } from './debounced';;
| ^
24 |
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
26 | import {cacheWhileSubscribed} from '../commons-node/observable';
2 errors found.
```
> `./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js` (code from [nuclide](https://github.com/facebook/nuclide)).
## Installation
```sh
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._
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
{
"extends": ["plugin:prettier/recommended"]
}
```
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.
## Configuration (new: `eslint.config.js`)
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.
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:
```js
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
];
```
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
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
If you use [arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) or [prefer-arrow-callback](https://eslint.org/docs/rules/prefer-arrow-callback) together with the `prettier/prettier` rule from this plugin, you can in some cases end up with invalid code due to a bug in ESLints autofix see [issue #65](https://github.com/prettier/eslint-plugin-prettier/issues/65).
For this reason, its recommended to turn off these rules. The `plugin:prettier/recommended` config does that for you.
You _can_ still use these rules together with this plugin if you want, because the bug does not occur _all the time._ But if you do, you need to keep in mind that you might end up with invalid code, where you manually have to insert a missing closing parenthesis to get going again.
If youre fixing large of amounts of previously unformatted code, consider temporarily disabling the `prettier/prettier` rule and running `eslint --fix` and `prettier --write` separately.
## Options
> Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as `prettier-atom` and `prettier-vscode` **will** read [`.prettierrc`](https://prettier.io/docs/en/configuration.html), but **won't** read settings from ESLint, which can lead to an inconsistent experience.
- The first option:
- An object representing [options](https://prettier.io/docs/en/options.html) that will be passed into prettier. Example:
```json
{
"prettier/prettier": [
"error",
{
"singleQuote": true,
"parser": "flow"
}
]
}
```
NB: This option will merge and override any config set with `.prettierrc` files
- The second option:
- An object with the following options
- `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).
```json
{
"prettier/prettier": [
"error",
{},
{
"usePrettierrc": false
}
]
}
```
- `fileInfoOptions`: Options that are passed to [prettier.getFileInfo](https://prettier.io/docs/en/api.html#prettiergetfileinfofilepath--options) to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located in `node_modules` directories.
```json
{
"prettier/prettier": [
"error",
{},
{
"fileInfoOptions": {
"withNodeModules": true
}
}
]
}
```
- The rule is auto fixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
---
## 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
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)

View File

@ -0,0 +1,5 @@
import { ESLint } from 'eslint';
declare const eslintPluginPrettier: ESLint.Plugin;
export = eslintPluginPrettier;

View File

@ -0,0 +1,254 @@
/**
* @file Runs `prettier` as an ESLint rule.
* @author Andres Suarez
*/
// @ts-check
/**
* @typedef {import('eslint').AST.Range} Range
* @typedef {import('eslint').AST.SourceLocation} SourceLocation
* @typedef {import('eslint').ESLint.Plugin} Plugin
* @typedef {import('eslint').ESLint.ObjectMetaProperties} ObjectMetaProperties
* @typedef {import('prettier').FileInfoOptions} FileInfoOptions
* @typedef {import('prettier').Options} PrettierOptions
* @typedef {PrettierOptions & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean }} Options
*/
'use strict';
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const {
showInvisibles,
generateDifferences,
} = require('prettier-linter-helpers');
const { name, version } = require('./package.json');
// ------------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------------
const { INSERT, DELETE, REPLACE } = generateDifferences;
// ------------------------------------------------------------------------------
// Privates
// ------------------------------------------------------------------------------
// Lazily-loaded Prettier.
/**
* @type {(source: string, options: Options, fileInfoOptions: FileInfoOptions) => string}
*/
let prettierFormat;
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
/**
* Reports a difference.
*
* @param {import('eslint').Rule.RuleContext} context - The ESLint rule context.
* @param {import('prettier-linter-helpers').Difference} difference - The difference object.
* @returns {void}
*/
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.sourceCode ?? context.getSourceCode()).getLocFromIndex(index),
);
context.report({
messageId: operation,
data: {
deleteText: showInvisibles(deleteText),
insertText: showInvisibles(insertText),
},
loc: { start, end },
fix: fixer => fixer.replaceTextRange(range, insertText),
});
}
// ------------------------------------------------------------------------------
// Module Definition
// ------------------------------------------------------------------------------
/**
* @type {Plugin}
*/
const eslintPluginPrettier = {
meta: { name, version },
configs: {
recommended: {
extends: ['prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
},
},
rules: {
prettier: {
meta: {
docs: {
url: 'https://github.com/prettier/eslint-plugin-prettier#options',
},
type: 'layout',
fixable: 'code',
schema: [
// Prettier options:
{
type: 'object',
properties: {},
additionalProperties: true,
},
{
type: 'object',
properties: {
usePrettierrc: { type: 'boolean' },
fileInfoOptions: {
type: 'object',
properties: {},
additionalProperties: true,
},
},
additionalProperties: true,
},
],
messages: {
[INSERT]: 'Insert `{{ insertText }}`',
[DELETE]: 'Delete `{{ deleteText }}`',
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`',
},
},
create(context) {
const usePrettierrc =
!context.options[1] || context.options[1].usePrettierrc !== false;
/**
* @type {FileInfoOptions}
*/
const fileInfoOptions =
(context.options[1] && context.options[1].fileInfoOptions) || {};
// `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.
// `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 {
Program() {
if (!prettierFormat) {
// Prettier is expensive to load, so only load it if needed.
prettierFormat = require('synckit').createSyncFn(
require.resolve('./worker'),
);
}
/**
* @type {PrettierOptions}
*/
const eslintPrettierOptions = context.options[0] || {};
const parser = context.languageOptions?.parser;
// prettier.format() may throw a SyntaxError if it cannot parse the
// source code it is given. Usually for JS files this isn't a
// problem as ESLint will report invalid syntax before trying to
// pass it to the prettier plugin. However this might be a problem
// for non-JS languages that are handled by a plugin. Notably Vue
// files throw an error if they contain unclosed elements, such as
// `<template><div></template>. In this case report an error at the
// point at which parsing failed.
/**
* @type {string}
*/
let prettierSource;
try {
prettierSource = prettierFormat(
source,
{
...eslintPrettierOptions,
filepath,
onDiskFilepath,
parserMeta:
parser &&
(parser.meta ?? {
name: parser.name,
version: parser.version,
}),
parserPath: context.parserPath,
usePrettierrc,
},
fileInfoOptions,
);
} catch (err) {
if (!(err instanceof SyntaxError)) {
throw err;
}
let message = 'Parsing error: ' + err.message;
const error =
/** @type {SyntaxError & {codeFrame: string; loc: SourceLocation}} */ (
err
);
// Prettier's message contains a codeframe style preview of the
// invalid code and the line/column at which the error occurred.
// ESLint shows those pieces of information elsewhere already so
// remove them from the message
if (error.codeFrame) {
message = message.replace(`\n${error.codeFrame}`, '');
}
if (error.loc) {
message = message.replace(/ \(\d+:\d+\)$/, '');
}
context.report({ message, loc: error.loc });
return;
}
if (prettierSource == null) {
return;
}
if (source !== prettierSource) {
const differences = generateDifferences(source, prettierSource);
for (const difference of differences) {
reportDifference(context, difference);
}
}
},
};
},
},
},
};
module.exports = eslintPluginPrettier;

102
node_modules/eslint-plugin-prettier/package.json generated vendored Normal file
View File

@ -0,0 +1,102 @@
{
"name": "eslint-plugin-prettier",
"version": "5.2.1",
"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>"
],
"funding": "https://opencollective.com/eslint-plugin-prettier",
"license": "MIT",
"packageManager": "pnpm@7.33.5",
"engines": {
"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"
},
"./package.json": "./package.json"
},
"types": "eslint-plugin-prettier.d.ts",
"files": [
"eslint-plugin-prettier.d.ts",
"eslint-plugin-prettier.js",
"recommended.d.ts",
"recommended.js",
"worker.js"
],
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"prettier"
],
"peerDependencies": {
"@types/eslint": ">=8.0.0",
"eslint": ">=8.0.0",
"eslint-config-prettier": "*",
"prettier": ">=3.0.0"
},
"peerDependenciesMeta": {
"@types/eslint": {
"optional": true
},
"eslint-config-prettier": {
"optional": true
}
},
"dependencies": {
"prettier-linter-helpers": "^1.0.0",
"synckit": "^0.9.1"
},
"devDependencies": {
"@1stg/remark-preset": "^2.0.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",
"@html-eslint/parser": "^0.24.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.3.0",
"eslint-plugin-eslint-plugin": "^5.2.1",
"eslint-plugin-mdx": "^2.3.0",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-prettier": "link:.",
"eslint-plugin-pug": "^1.2.5",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-svelte3": "^4.0.0",
"graphql": "^16.8.1",
"lint-staged": "^15.2.0",
"mocha": "^10.2.0",
"prettier": "^3.1.1",
"prettier-plugin-pkg": "^0.18.0",
"prettier-plugin-svelte": "^3.1.2",
"simple-git-hooks": "^2.9.0",
"svelte": "^4.2.8",
"vue-eslint-parser": "^9.3.2"
},
"scripts": {
"check": "prettier --check . && pnpm lint",
"format": "prettier --write . && pnpm lint --fix",
"lint": "eslint . --cache -f friendly --max-warnings 10",
"release": "pnpm check && pnpm test && changeset publish",
"test": "pnpm lint && mocha"
}
}

5
node_modules/eslint-plugin-prettier/recommended.d.ts generated vendored Normal file
View File

@ -0,0 +1,5 @@
import { Linter } from 'eslint';
declare const recommendedConfig: Linter.FlatConfig;
export = recommendedConfig;

17
node_modules/eslint-plugin-prettier/recommended.js generated vendored Normal file
View File

@ -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',
},
};

191
node_modules/eslint-plugin-prettier/worker.js generated vendored Normal file
View File

@ -0,0 +1,191 @@
// @ts-check
/**
* @typedef {import('prettier').FileInfoOptions} FileInfoOptions
* @typedef {import('eslint').ESLint.ObjectMetaProperties} ObjectMetaProperties
* @typedef {import('prettier').Options & { onDiskFilepath: string, parserMeta?: ObjectMetaProperties['meta'], parserPath?: string, usePrettierrc?: boolean }} Options
*/
const { runAsWorker } = require('synckit');
/**
* @type {typeof import('prettier')}
*/
let prettier;
runAsWorker(
/**
* @param {string} source - The source code to format.
* @param {Options} options - The prettier options.
* @param {FileInfoOptions} eslintFileInfoOptions - The file info options.
* @returns {Promise<string | undefined>} The formatted source code.
*/
async (
source,
{
filepath,
onDiskFilepath,
parserMeta,
parserPath,
usePrettierrc,
...eslintPrettierOptions
},
eslintFileInfoOptions,
) => {
if (!prettier) {
prettier = await import('prettier');
}
const prettierRcOptions = usePrettierrc
? await prettier.resolveConfig(onDiskFilepath, {
editorconfig: true,
})
: null;
const { ignored, inferredParser } = await prettier.getFileInfo(
onDiskFilepath,
{
resolveConfig: false,
withNodeModules: false,
ignorePath: '.prettierignore',
plugins: /** @type {string[] | undefined} */ (
prettierRcOptions ? prettierRcOptions.plugins : undefined
),
...eslintFileInfoOptions,
},
);
// Skip if file is ignored using a .prettierignore file
if (ignored) {
return;
}
const initialOptions = { parser: inferredParser ?? 'babel' };
// 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+`)
let inferParserToBabel = false;
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;
}
case 'html': {
// it could be processed by `eslint-plugin-html` or correctly parsed by `@html-eslint/parser`
if (
(typeof parserMeta !== 'undefined' &&
parserMeta.name !== '@html-eslint/parser') ||
(typeof parserPath === 'string' &&
!/([\\/])@html-eslint\1parser\1/.test(parserPath))
) {
inferParserToBabel = true;
}
break;
}
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`
case 'svelte': {
// The `source` would be modified by `eslint-plugin-svelte3`
if (
typeof parserPath === 'string' &&
!/([\\/])svelte-eslint-parser\1/.test(parserPath)
) {
// 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',
'pug',
];
if (parserBlocklist.includes(/** @type {string} */ (inferredParser))) {
return;
}
}
/**
* @type {import('prettier').Options}
*/
const prettierOptions = {
...initialOptions,
...prettierRcOptions,
...eslintPrettierOptions,
filepath,
};
return prettier.format(source, prettierOptions);
},
);