Update checked-in dependencies
This commit is contained in:
parent
6b0d45a5c6
commit
cc1adb825a
4247 changed files with 144820 additions and 149530 deletions
178
node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js
generated
vendored
178
node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js
generated
vendored
|
|
@ -9,6 +9,9 @@
|
|||
// Requirements
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
showInvisibles,
|
||||
generateDifferences
|
||||
|
|
@ -25,6 +28,9 @@ const { INSERT, DELETE, REPLACE } = generateDifferences;
|
|||
// ------------------------------------------------------------------------------
|
||||
|
||||
// Lazily-loaded Prettier.
|
||||
/**
|
||||
* @type {import('prettier')}
|
||||
*/
|
||||
let prettier;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
|
@ -32,74 +38,51 @@ let prettier;
|
|||
// ------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reports an "Insert ..." issue where text must be inserted.
|
||||
* @param {RuleContext} context - The ESLint rule context.
|
||||
* @param {number} offset - The source offset where to insert text.
|
||||
* @param {string} text - The text to be inserted.
|
||||
* 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 reportInsert(context, offset, text) {
|
||||
const pos = context.getSourceCode().getLocFromIndex(offset);
|
||||
const range = [offset, offset];
|
||||
context.report({
|
||||
message: 'Insert `{{ code }}`',
|
||||
data: { code: showInvisibles(text) },
|
||||
loc: { start: pos, end: pos },
|
||||
fix(fixer) {
|
||||
return fixer.insertTextAfterRange(range, text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a "Delete ..." issue where text must be deleted.
|
||||
* @param {RuleContext} context - The ESLint rule context.
|
||||
* @param {number} offset - The source offset where to delete text.
|
||||
* @param {string} text - The text to be deleted.
|
||||
* @returns {void}
|
||||
*/
|
||||
function reportDelete(context, offset, text) {
|
||||
const start = context.getSourceCode().getLocFromIndex(offset);
|
||||
const end = context.getSourceCode().getLocFromIndex(offset + text.length);
|
||||
const range = [offset, offset + text.length];
|
||||
context.report({
|
||||
message: 'Delete `{{ code }}`',
|
||||
data: { code: showInvisibles(text) },
|
||||
loc: { start, end },
|
||||
fix(fixer) {
|
||||
return fixer.removeRange(range);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a "Replace ... with ..." issue where text must be replaced.
|
||||
* @param {RuleContext} context - The ESLint rule context.
|
||||
* @param {number} offset - The source offset where to replace deleted text
|
||||
with inserted text.
|
||||
* @param {string} deleteText - The text to be deleted.
|
||||
* @param {string} insertText - The text to be inserted.
|
||||
* @returns {void}
|
||||
*/
|
||||
function reportReplace(context, offset, deleteText, insertText) {
|
||||
const start = context.getSourceCode().getLocFromIndex(offset);
|
||||
const end = context
|
||||
.getSourceCode()
|
||||
.getLocFromIndex(offset + deleteText.length);
|
||||
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.report({
|
||||
message: 'Replace `{{ deleteCode }}` with `{{ insertCode }}`',
|
||||
messageId: operation,
|
||||
data: {
|
||||
deleteCode: showInvisibles(deleteText),
|
||||
insertCode: showInvisibles(insertText)
|
||||
deleteText: showInvisibles(deleteText),
|
||||
insertText: showInvisibles(insertText)
|
||||
},
|
||||
loc: { start, end },
|
||||
fix(fixer) {
|
||||
return 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
|
||||
// ------------------------------------------------------------------------------
|
||||
|
|
@ -110,7 +93,9 @@ module.exports = {
|
|||
extends: ['prettier'],
|
||||
plugins: ['prettier'],
|
||||
rules: {
|
||||
'prettier/prettier': 'error'
|
||||
'prettier/prettier': 'error',
|
||||
'arrow-body-style': 'off',
|
||||
'prefer-arrow-callback': 'off'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -141,7 +126,12 @@ module.exports = {
|
|||
},
|
||||
additionalProperties: true
|
||||
}
|
||||
]
|
||||
],
|
||||
messages: {
|
||||
[INSERT]: 'Insert `{{ insertText }}`',
|
||||
[DELETE]: 'Delete `{{ deleteText }}`',
|
||||
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`'
|
||||
}
|
||||
},
|
||||
create(context) {
|
||||
const usePrettierrc =
|
||||
|
|
@ -150,17 +140,16 @@ module.exports = {
|
|||
(context.options[1] && context.options[1].fileInfoOptions) || {};
|
||||
const sourceCode = context.getSourceCode();
|
||||
const filepath = 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.
|
||||
// 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 source = sourceCode.text;
|
||||
|
||||
// This allows long-running ESLint processes (e.g. vscode-eslint) to
|
||||
// pick up changes to .prettierrc without restarting the editor. This
|
||||
// will invalidate the prettier plugin cache on every file as well which
|
||||
// will make ESLint very slow, so it would probably be a good idea to
|
||||
// find a better way to do this.
|
||||
if (usePrettierrc && prettier && prettier.clearConfigCache) {
|
||||
prettier.clearConfigCache();
|
||||
}
|
||||
|
||||
return {
|
||||
Program() {
|
||||
if (!prettier) {
|
||||
|
|
@ -171,13 +160,13 @@ module.exports = {
|
|||
const eslintPrettierOptions = context.options[0] || {};
|
||||
|
||||
const prettierRcOptions = usePrettierrc
|
||||
? prettier.resolveConfig.sync(filepath, {
|
||||
? prettier.resolveConfig.sync(onDiskFilepath, {
|
||||
editorconfig: true
|
||||
})
|
||||
: null;
|
||||
|
||||
const prettierFileInfo = prettier.getFileInfo.sync(
|
||||
filepath,
|
||||
onDiskFilepath,
|
||||
Object.assign(
|
||||
{},
|
||||
{ resolveConfig: true, ignorePath: '.prettierignore' },
|
||||
|
|
@ -192,7 +181,7 @@ module.exports = {
|
|||
|
||||
const initialOptions = {};
|
||||
|
||||
// ESLint suppports processors that let you extract and lint JS
|
||||
// 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
|
||||
|
|
@ -200,9 +189,14 @@ module.exports = {
|
|||
// 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.
|
||||
// If we can't infer the parser from from the filename, either
|
||||
// because no filename was provided or because there is no parser
|
||||
// found for the filename, use javascript.
|
||||
// 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.
|
||||
|
|
@ -214,6 +208,7 @@ module.exports = {
|
|||
// 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`
|
||||
|
|
@ -234,7 +229,7 @@ module.exports = {
|
|||
);
|
||||
|
||||
// prettier.format() may throw a SyntaxError if it cannot parse the
|
||||
// source code it is given. Ususally for JS files this isn't a
|
||||
// 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
|
||||
|
|
@ -252,7 +247,7 @@ module.exports = {
|
|||
let message = 'Parsing error: ' + err.message;
|
||||
|
||||
// Prettier's message contains a codeframe style preview of the
|
||||
// invalid code and the line/column at which the error occured.
|
||||
// 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 (err.codeFrame) {
|
||||
|
|
@ -270,32 +265,9 @@ module.exports = {
|
|||
if (source !== prettierSource) {
|
||||
const differences = generateDifferences(source, prettierSource);
|
||||
|
||||
differences.forEach(difference => {
|
||||
switch (difference.operation) {
|
||||
case INSERT:
|
||||
reportInsert(
|
||||
context,
|
||||
difference.offset,
|
||||
difference.insertText
|
||||
);
|
||||
break;
|
||||
case DELETE:
|
||||
reportDelete(
|
||||
context,
|
||||
difference.offset,
|
||||
difference.deleteText
|
||||
);
|
||||
break;
|
||||
case REPLACE:
|
||||
reportReplace(
|
||||
context,
|
||||
difference.offset,
|
||||
difference.deleteText,
|
||||
difference.insertText
|
||||
);
|
||||
break;
|
||||
}
|
||||
});
|
||||
for (const difference of differences) {
|
||||
reportDifference(context, difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue