Bump packages to fix linter
This commit is contained in:
parent
ed9506bbaf
commit
0a11e3fdd9
6063 changed files with 378752 additions and 306784 deletions
173
node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js
generated
vendored
173
node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @fileoverview Runs `prettier` as an ESLint rule.
|
||||
* @file Runs `prettier` as an ESLint rule.
|
||||
* @author Andres Suarez
|
||||
*/
|
||||
|
||||
|
|
@ -9,12 +9,9 @@
|
|||
// Requirements
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
showInvisibles,
|
||||
generateDifferences
|
||||
generateDifferences,
|
||||
} = require('prettier-linter-helpers');
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
|
@ -39,6 +36,7 @@ let prettier;
|
|||
|
||||
/**
|
||||
* 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}
|
||||
|
|
@ -47,42 +45,20 @@ function reportDifference(context, difference) {
|
|||
const { operation, offset, deleteText = '', insertText = '' } = difference;
|
||||
const range = [offset, offset + deleteText.length];
|
||||
const [start, end] = range.map(index =>
|
||||
context.getSourceCode().getLocFromIndex(index)
|
||||
context.getSourceCode().getLocFromIndex(index),
|
||||
);
|
||||
|
||||
context.report({
|
||||
messageId: operation,
|
||||
data: {
|
||||
deleteText: showInvisibles(deleteText),
|
||||
insertText: showInvisibles(insertText)
|
||||
insertText: showInvisibles(insertText),
|
||||
},
|
||||
loc: { start, end },
|
||||
fix: fixer => fixer.replaceTextRange(range, insertText)
|
||||
fix: fixer => fixer.replaceTextRange(range, insertText),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a filepath, get the nearest path that is a regular file.
|
||||
* The filepath provided by eslint may be a virtual filepath rather than a file
|
||||
* on disk. This attempts to transform a virtual path into an on-disk path
|
||||
* @param {string} filepath
|
||||
* @returns {string}
|
||||
*/
|
||||
function getOnDiskFilepath(filepath) {
|
||||
try {
|
||||
if (fs.statSync(filepath).isFile()) {
|
||||
return filepath;
|
||||
}
|
||||
} catch (err) {
|
||||
// https://github.com/eslint/eslint/issues/11989
|
||||
if (err.code === 'ENOTDIR') {
|
||||
return getOnDiskFilepath(path.dirname(filepath));
|
||||
}
|
||||
}
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Module Definition
|
||||
// ------------------------------------------------------------------------------
|
||||
|
|
@ -95,15 +71,15 @@ module.exports = {
|
|||
rules: {
|
||||
'prettier/prettier': 'error',
|
||||
'arrow-body-style': 'off',
|
||||
'prefer-arrow-callback': 'off'
|
||||
}
|
||||
}
|
||||
'prefer-arrow-callback': 'off',
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
prettier: {
|
||||
meta: {
|
||||
docs: {
|
||||
url: 'https://github.com/prettier/eslint-plugin-prettier#options'
|
||||
url: 'https://github.com/prettier/eslint-plugin-prettier#options',
|
||||
},
|
||||
type: 'layout',
|
||||
fixable: 'code',
|
||||
|
|
@ -112,7 +88,7 @@ module.exports = {
|
|||
{
|
||||
type: 'object',
|
||||
properties: {},
|
||||
additionalProperties: true
|
||||
additionalProperties: true,
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
|
|
@ -121,17 +97,17 @@ module.exports = {
|
|||
fileInfoOptions: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
additionalProperties: true
|
||||
}
|
||||
additionalProperties: true,
|
||||
},
|
||||
},
|
||||
additionalProperties: true
|
||||
}
|
||||
additionalProperties: true,
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
[INSERT]: 'Insert `{{ insertText }}`',
|
||||
[DELETE]: 'Delete `{{ deleteText }}`',
|
||||
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`'
|
||||
}
|
||||
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`',
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
const usePrettierrc =
|
||||
|
|
@ -145,12 +121,11 @@ module.exports = {
|
|||
// 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.
|
||||
// See https://github.com/eslint/eslint/issues/11989 for ideas around
|
||||
// being able to get this value directly from eslint in the future.
|
||||
const onDiskFilepath = getOnDiskFilepath(filepath);
|
||||
const onDiskFilepath = context.getPhysicalFilename();
|
||||
const source = sourceCode.text;
|
||||
|
||||
return {
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
Program() {
|
||||
if (!prettier) {
|
||||
// Prettier is expensive to load, so only load it if needed.
|
||||
|
|
@ -161,21 +136,23 @@ module.exports = {
|
|||
|
||||
const prettierRcOptions = usePrettierrc
|
||||
? prettier.resolveConfig.sync(onDiskFilepath, {
|
||||
editorconfig: true
|
||||
editorconfig: true,
|
||||
})
|
||||
: null;
|
||||
|
||||
const prettierFileInfo = prettier.getFileInfo.sync(
|
||||
const { ignored, inferredParser } = prettier.getFileInfo.sync(
|
||||
onDiskFilepath,
|
||||
Object.assign(
|
||||
{},
|
||||
{ resolveConfig: true, ignorePath: '.prettierignore' },
|
||||
eslintFileInfoOptions
|
||||
)
|
||||
{
|
||||
resolveConfig: false,
|
||||
withNodeModules: false,
|
||||
ignorePath: '.prettierignore',
|
||||
plugins: prettierRcOptions ? prettierRcOptions.plugins : null,
|
||||
...eslintFileInfoOptions,
|
||||
},
|
||||
);
|
||||
|
||||
// Skip if file is ignored using a .prettierignore file
|
||||
if (prettierFileInfo.ignored) {
|
||||
if (ignored) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -206,27 +183,75 @@ module.exports = {
|
|||
// * Prettier supports parsing the file type
|
||||
// * There is an ESLint processor that extracts JavaScript snippets
|
||||
// from the file type.
|
||||
const parserBlocklist = [null, 'graphql', 'markdown', 'html'];
|
||||
if (
|
||||
filepath === onDiskFilepath &&
|
||||
parserBlocklist.indexOf(prettierFileInfo.inferredParser) !== -1
|
||||
) {
|
||||
// Prettier v1.16.0 renamed the `babylon` parser to `babel`
|
||||
// Use the modern name if available
|
||||
const supportBabelParser = prettier
|
||||
.getSupportInfo()
|
||||
.languages.some(language => language.parsers.includes('babel'));
|
||||
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'];
|
||||
|
||||
initialOptions.parser = supportBabelParser ? 'babel' : 'babylon';
|
||||
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 = Object.assign(
|
||||
{},
|
||||
initialOptions,
|
||||
prettierRcOptions,
|
||||
eslintPrettierOptions,
|
||||
{ filepath }
|
||||
);
|
||||
const prettierOptions = {
|
||||
...initialOptions,
|
||||
...prettierRcOptions,
|
||||
...eslintPrettierOptions,
|
||||
filepath,
|
||||
};
|
||||
|
||||
// prettier.format() may throw a SyntaxError if it cannot parse the
|
||||
// source code it is given. Usually for JS files this isn't a
|
||||
|
|
@ -269,9 +294,9 @@ module.exports = {
|
|||
reportDifference(context, difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue