Bump packages to fix linter

This commit is contained in:
Henry Mercer 2023-01-18 20:50:03 +00:00
parent ed9506bbaf
commit 0a11e3fdd9
6063 changed files with 378752 additions and 306784 deletions

1044
node_modules/eslint/lib/rule-tester/flat-rule-tester.js generated vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
*/
"use strict";
/* global describe, it */
/* globals describe, it -- Mocha globals */
/*
* This is a wrapper around mocha to allow for DRY unittests for eslint
@ -55,15 +55,19 @@ const ajv = require("../shared/ajv")({ strictDefaults: true });
const espreePath = require.resolve("espree");
const parserSymbol = Symbol.for("eslint.RuleTester.parser");
const { SourceCode } = require("../source-code");
//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------
/** @typedef {import("../shared/types").Parser} Parser */
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
/**
* A test case that is expected to pass lint.
* @typedef {Object} ValidTestCase
* @property {string} [name] Name for the test case.
* @property {string} code Code for the test case.
* @property {any[]} [options] Options for the test case.
* @property {{ [name: string]: any }} [settings] Settings for the test case.
@ -78,6 +82,7 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
/**
* A test case that is expected to fail lint.
* @typedef {Object} InvalidTestCase
* @property {string} [name] Name for the test case.
* @property {string} code Code for the test case.
* @property {number | Array<TestCaseError | string | RegExp>} errors Expected errors.
* @property {string | null} [output] The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
@ -103,6 +108,7 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
* @property {number} [endLine] The 1-based line number of the reported end location.
* @property {number} [endColumn] The 1-based column number of the reported end location.
*/
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
//------------------------------------------------------------------------------
// Private Members
@ -120,6 +126,7 @@ let defaultConfig = { rules: {} };
* configuration
*/
const RuleTesterParameters = [
"name",
"code",
"filename",
"options",
@ -209,8 +216,11 @@ function freezeDeeply(x) {
* @returns {string} The sanitized text.
*/
function sanitize(text) {
if (typeof text !== "string") {
return "";
}
return text.replace(
/[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex
/[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex -- Escaping controls
c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
);
}
@ -284,6 +294,47 @@ function wrapParser(parser) {
};
}
/**
* Function to replace `SourceCode.prototype.getComments`.
* @returns {void}
* @throws {Error} Deprecation message.
*/
function getCommentsDeprecation() {
throw new Error(
"`SourceCode#getComments()` is deprecated and will be removed in a future major version. Use `getCommentsBefore()`, `getCommentsAfter()`, and `getCommentsInside()` instead."
);
}
/**
* Emit a deprecation warning if function-style format is being used.
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitLegacyRuleAPIWarning(ruleName) {
if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) {
emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/latest/extend/custom-rules`,
"DeprecationWarning"
);
}
}
/**
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitMissingSchemaWarning(ruleName) {
if (!emitMissingSchemaWarning[`warned-${ruleName}`]) {
emitMissingSchemaWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/latest/extend/custom-rules#options-schemas`,
"DeprecationWarning"
);
}
}
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
@ -298,6 +349,7 @@ const IT_ONLY = Symbol("itOnly");
* @this {Mocha}
* @param {string} text The description of the test case.
* @param {Function} method The logic of the test case.
* @throws {Error} Any error upon execution of `method`.
* @returns {any} Returned value of `method`.
*/
function itDefaultHandler(text, method) {
@ -322,6 +374,9 @@ function describeDefaultHandler(text, method) {
return method.call(this);
}
/**
* Mocha test wrapper.
*/
class RuleTester {
/**
@ -353,6 +408,7 @@ class RuleTester {
/**
* Set the configuration to use for all future tests
* @param {Object} config the configuration to use.
* @throws {TypeError} If non-object config.
* @returns {void}
*/
static setDefaultConfig(config) {
@ -437,7 +493,7 @@ class RuleTester {
if (typeof this[DESCRIBE] === "function" || typeof this[IT] === "function") {
throw new Error(
"Set `RuleTester.itOnly` to use `only` with a custom test framework.\n" +
"See https://eslint.org/docs/developer-guide/nodejs-api#customizing-ruletester for more."
"See https://eslint.org/docs/latest/integrate/nodejs-api#customizing-ruletester for more."
);
}
if (typeof it === "function") {
@ -468,6 +524,8 @@ class RuleTester {
* valid: (ValidTestCase | string)[],
* invalid: InvalidTestCase[]
* }} test The collection of tests to run.
* @throws {TypeError|Error} If non-object `test`, or if a required
* scenario of the given type is missing.
* @returns {void}
*/
run(ruleName, rule, test) {
@ -493,6 +551,9 @@ class RuleTester {
].concat(scenarioErrors).join("\n"));
}
if (typeof rule === "function") {
emitLegacyRuleAPIWarning(ruleName);
}
linter.defineRule(ruleName, Object.assign({}, rule, {
@ -511,6 +572,7 @@ class RuleTester {
/**
* Run the rule for the given item
* @param {string|Object} item Item to run the rule against
* @throws {Error} If an invalid schema.
* @returns {Object} Eslint run result
* @private
*/
@ -549,6 +611,15 @@ class RuleTester {
if (hasOwnProperty(item, "options")) {
assert(Array.isArray(item.options), "options must be an array");
if (
item.options.length > 0 &&
typeof rule === "object" &&
(
!rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null))
)
) {
emitMissingSchemaWarning(ruleName);
}
config.rules[ruleName] = [1].concat(item.options);
} else {
config.rules[ruleName] = 1;
@ -561,14 +632,18 @@ class RuleTester {
* The goal is to check whether or not AST was modified when
* running the rule under test.
*/
linter.defineRule("rule-tester/validate-ast", () => ({
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
linter.defineRule("rule-tester/validate-ast", {
create() {
return {
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
}
};
}
}));
});
if (typeof config.parser === "string") {
assert(path.isAbsolute(config.parser), "Parsers provided as strings to RuleTester must be absolute paths");
@ -607,7 +682,16 @@ class RuleTester {
validate(config, "rule-tester", id => (id === ruleName ? rule : null));
// Verify the code.
const messages = linter.verify(code, config, filename);
const { getComments } = SourceCode.prototype;
let messages;
try {
SourceCode.prototype.getComments = getCommentsDeprecation;
messages = linter.verify(code, config, filename);
} finally {
SourceCode.prototype.getComments = getComments;
}
const fatalErrorMessage = messages.find(m => m.fatal);
assert(!fatalErrorMessage, `A fatal parsing error occurred: ${fatalErrorMessage && fatalErrorMessage.message}`);
@ -656,6 +740,13 @@ class RuleTester {
* @private
*/
function testValidTemplate(item) {
const code = typeof item === "object" ? item.code : item;
assert.ok(typeof code === "string", "Test case must specify a string value for 'code'");
if (item.name) {
assert.ok(typeof item.name === "string", "Optional test case property 'name' must be a string");
}
const result = runRuleForItem(item);
const messages = result.messages;
@ -696,6 +787,10 @@ class RuleTester {
* @private
*/
function testInvalidTemplate(item) {
assert.ok(typeof item.code === "string", "Test case must specify a string value for 'code'");
if (item.name) {
assert.ok(typeof item.name === "string", "Optional test case property 'name' must be a string");
}
assert.ok(item.errors || item.errors === 0,
`Did not specify errors for an invalid test of ${ruleName}`);
@ -921,16 +1016,6 @@ class RuleTester {
);
}
// Rules that produce fixes must have `meta.fixable` property.
if (result.output !== item.code) {
assert.ok(
hasOwnProperty(rule, "meta"),
"Fixable rules should export a `meta.fixable` property."
);
// Linter throws if a rule that produced a fix has `meta` but doesn't have `meta.fixable`.
}
assertASTDidntChange(result.beforeAST, result.afterAST);
}
@ -938,11 +1023,11 @@ class RuleTester {
* This creates a mocha test suite and pipes all supplied info through
* one of the templates above.
*/
RuleTester.describe(ruleName, () => {
RuleTester.describe("valid", () => {
this.constructor.describe(ruleName, () => {
this.constructor.describe("valid", () => {
test.valid.forEach(valid => {
RuleTester[valid.only ? "itOnly" : "it"](
sanitize(typeof valid === "object" ? valid.code : valid),
this.constructor[valid.only ? "itOnly" : "it"](
sanitize(typeof valid === "object" ? valid.name || valid.code : valid),
() => {
testValidTemplate(valid);
}
@ -950,10 +1035,10 @@ class RuleTester {
});
});
RuleTester.describe("invalid", () => {
this.constructor.describe("invalid", () => {
test.invalid.forEach(invalid => {
RuleTester[invalid.only ? "itOnly" : "it"](
sanitize(invalid.code),
this.constructor[invalid.only ? "itOnly" : "it"](
sanitize(invalid.name || invalid.code),
() => {
testInvalidTemplate(invalid);
}