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

View file

@ -15,7 +15,6 @@ const Rules = require("../rules");
// Helpers
//-----------------------------------------------------------------------------
exports.defaultConfig = [
{
plugins: {
@ -26,7 +25,7 @@ exports.defaultConfig = [
/*
* Because we try to delay loading rules until absolutely
* necessary, a proxy allows us to hook into the lazy-loading
* necessary, a proxy allows us to hook into the lazy-loading
* aspect of the rules map while still keeping all of the
* relevant configuration inside of the config array.
*/
@ -41,12 +40,31 @@ exports.defaultConfig = [
})
}
},
ignores: [
"**/node_modules/**",
".git/**"
],
languageOptions: {
parser: "@/espree"
sourceType: "module",
ecmaVersion: "latest",
parser: "@/espree",
parserOptions: {}
}
},
// default ignores are listed here
{
ignores: [
"**/node_modules/*",
".git/"
]
},
// intentionally empty config to ensure these files are globbed by default
{
files: ["**/*.js", "**/*.mjs"]
},
{
files: ["**/*.cjs"],
languageOptions: {
sourceType: "commonjs",
ecmaVersion: "latest"
}
}
];

View file

@ -14,7 +14,6 @@ const { flatConfigSchema } = require("./flat-config-schema");
const { RuleValidator } = require("./rule-validator");
const { defaultConfig } = require("./default-config");
const recommendedConfig = require("../../conf/eslint-recommended");
const allConfig = require("../../conf/eslint-all");
//-----------------------------------------------------------------------------
// Helpers
@ -37,6 +36,8 @@ function splitPluginIdentifier(identifier) {
};
}
const originalBaseConfig = Symbol("originalBaseConfig");
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
@ -49,19 +50,43 @@ class FlatConfigArray extends ConfigArray {
/**
* Creates a new instance.
* @param {*[]} configs An array of configuration information.
* @param {{basePath: string, baseConfig: FlatConfig}} options The options
* @param {{basePath: string, shouldIgnore: boolean, baseConfig: FlatConfig}} options The options
* to use for the config array instance.
*/
constructor(configs, { basePath, baseConfig = defaultConfig }) {
constructor(configs, {
basePath,
shouldIgnore = true,
baseConfig = defaultConfig
} = {}) {
super(configs, {
basePath,
schema: flatConfigSchema
});
this.unshift(baseConfig);
if (baseConfig[Symbol.iterator]) {
this.unshift(...baseConfig);
} else {
this.unshift(baseConfig);
}
/**
* The base config used to build the config array.
* @type {Array<FlatConfig>}
*/
this[originalBaseConfig] = baseConfig;
Object.defineProperty(this, originalBaseConfig, { writable: false });
/**
* Determines if `ignores` fields should be honored.
* If true, then all `ignores` fields are honored.
* if false, then only `ignores` fields in the baseConfig are honored.
* @type {boolean}
*/
this.shouldIgnore = shouldIgnore;
Object.defineProperty(this, "shouldIgnore", { writable: false });
}
/* eslint-disable class-methods-use-this */
/* eslint-disable class-methods-use-this -- Desired as instance method */
/**
* Replaces a config with another config to allow us to put strings
* in the config array that will be replaced by objects before
@ -75,7 +100,30 @@ class FlatConfigArray extends ConfigArray {
}
if (config === "eslint:all") {
return allConfig;
/*
* Load `eslint-all.js` here instead of at the top level to avoid loading all rule modules
* when it isn't necessary. `eslint-all.js` reads `meta` of rule objects to filter out deprecated ones,
* so requiring `eslint-all.js` module loads all rule modules as a consequence.
*/
return require("../../conf/eslint-all");
}
/*
* If `shouldIgnore` is false, we remove any ignore patterns specified
* in the config so long as it's not a default config and it doesn't
* have a `files` entry.
*/
if (
!this.shouldIgnore &&
!this[originalBaseConfig].includes(config) &&
config.ignores &&
!config.files
) {
/* eslint-disable-next-line no-unused-vars -- need to strip off other keys */
const { ignores, ...otherKeys } = config;
return otherKeys;
}
return config;
@ -91,34 +139,75 @@ class FlatConfigArray extends ConfigArray {
[ConfigArraySymbol.finalizeConfig](config) {
const { plugins, languageOptions, processor } = config;
let parserName, processorName;
let invalidParser = false,
invalidProcessor = false;
// Check parser value
if (languageOptions && languageOptions.parser && typeof languageOptions.parser === "string") {
const { pluginName, objectName: parserName } = splitPluginIdentifier(languageOptions.parser);
if (languageOptions && languageOptions.parser) {
if (typeof languageOptions.parser === "string") {
const { pluginName, objectName: localParserName } = splitPluginIdentifier(languageOptions.parser);
if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[parserName]) {
throw new TypeError(`Key "parser": Could not find "${parserName}" in plugin "${pluginName}".`);
parserName = languageOptions.parser;
if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[localParserName]) {
throw new TypeError(`Key "parser": Could not find "${localParserName}" in plugin "${pluginName}".`);
}
languageOptions.parser = plugins[pluginName].parsers[localParserName];
} else {
invalidParser = true;
}
languageOptions.parser = plugins[pluginName].parsers[parserName];
}
// Check processor value
if (processor && typeof processor === "string") {
const { pluginName, objectName: processorName } = splitPluginIdentifier(processor);
if (processor) {
if (typeof processor === "string") {
const { pluginName, objectName: localProcessorName } = splitPluginIdentifier(processor);
if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[processorName]) {
throw new TypeError(`Key "processor": Could not find "${processorName}" in plugin "${pluginName}".`);
processorName = processor;
if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[localProcessorName]) {
throw new TypeError(`Key "processor": Could not find "${localProcessorName}" in plugin "${pluginName}".`);
}
config.processor = plugins[pluginName].processors[localProcessorName];
} else {
invalidProcessor = true;
}
config.processor = plugins[pluginName].processors[processorName];
}
ruleValidator.validate(config);
// apply special logic for serialization into JSON
/* eslint-disable object-shorthand -- shorthand would change "this" value */
Object.defineProperty(config, "toJSON", {
value: function() {
if (invalidParser) {
throw new Error("Caching is not supported when parser is an object.");
}
if (invalidProcessor) {
throw new Error("Caching is not supported when processor is an object.");
}
return {
...this,
plugins: Object.keys(plugins),
languageOptions: {
...languageOptions,
parser: parserName
},
processor: processorName
};
}
});
/* eslint-enable object-shorthand -- ok to enable now */
return config;
}
/* eslint-enable class-methods-use-this */
/* eslint-enable class-methods-use-this -- Desired as instance method */
}

111
node_modules/eslint/lib/config/flat-config-helpers.js generated vendored Normal file
View file

@ -0,0 +1,111 @@
/**
* @fileoverview Shared functions to work with configs.
* @author Nicholas C. Zakas
*/
"use strict";
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
/**
* Parses a ruleId into its plugin and rule parts.
* @param {string} ruleId The rule ID to parse.
* @returns {{pluginName:string,ruleName:string}} The plugin and rule
* parts of the ruleId;
*/
function parseRuleId(ruleId) {
let pluginName, ruleName;
// distinguish between core rules and plugin rules
if (ruleId.includes("/")) {
// mimic scoped npm packages
if (ruleId.startsWith("@")) {
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
} else {
pluginName = ruleId.slice(0, ruleId.indexOf("/"));
}
ruleName = ruleId.slice(pluginName.length + 1);
} else {
pluginName = "@";
ruleName = ruleId;
}
return {
pluginName,
ruleName
};
}
/**
* Retrieves a rule instance from a given config based on the ruleId.
* @param {string} ruleId The rule ID to look for.
* @param {FlatConfig} config The config to search.
* @returns {import("../shared/types").Rule|undefined} The rule if found
* or undefined if not.
*/
function getRuleFromConfig(ruleId, config) {
const { pluginName, ruleName } = parseRuleId(ruleId);
const plugin = config.plugins && config.plugins[pluginName];
let rule = plugin && plugin.rules && plugin.rules[ruleName];
// normalize function rules into objects
if (rule && typeof rule === "function") {
rule = {
create: rule
};
}
return rule;
}
/**
* Gets a complete options schema for a rule.
* @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
* @returns {Object} JSON Schema for the rule's options.
*/
function getRuleOptionsSchema(rule) {
if (!rule) {
return null;
}
const schema = rule.schema || rule.meta && rule.meta.schema;
if (Array.isArray(schema)) {
if (schema.length) {
return {
type: "array",
items: schema,
minItems: 0,
maxItems: schema.length
};
}
return {
type: "array",
minItems: 0,
maxItems: 0
};
}
// Given a full schema, leave it alone
return schema || null;
}
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
module.exports = {
parseRuleId,
getRuleFromConfig,
getRuleOptionsSchema
};

View file

@ -195,13 +195,6 @@ function assertIsObjectOrString(value) {
// Low-Level Schemas
//-----------------------------------------------------------------------------
/** @type {ObjectPropertySchema} */
const numberSchema = {
merge: "replace",
validate: "number"
};
/** @type {ObjectPropertySchema} */
const booleanSchema = {
merge: "replace",
@ -336,7 +329,7 @@ const rulesSchema = {
// avoid hairy edge case
if (ruleId === "__proto__") {
/* eslint-disable-next-line no-proto */
/* eslint-disable-next-line no-proto -- Though deprecated, may still be present */
delete result.__proto__;
continue;
}
@ -415,6 +408,18 @@ const rulesSchema = {
}
};
/** @type {ObjectPropertySchema} */
const ecmaVersionSchema = {
merge: "replace",
validate(value) {
if (typeof value === "number" || value === "latest") {
return;
}
throw new TypeError("Expected a number or \"latest\".");
}
};
/** @type {ObjectPropertySchema} */
const sourceTypeSchema = {
merge: "replace",
@ -439,7 +444,7 @@ exports.flatConfigSchema = {
},
languageOptions: {
schema: {
ecmaVersion: numberSchema,
ecmaVersion: ecmaVersionSchema,
sourceType: sourceTypeSchema,
globals: globalsSchema,
parser: parserSchema,

View file

@ -10,74 +10,59 @@
//-----------------------------------------------------------------------------
const ajv = require("../shared/ajv")();
const {
parseRuleId,
getRuleFromConfig,
getRuleOptionsSchema
} = require("./flat-config-helpers");
const ruleReplacements = require("../../conf/replacements.json");
//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------
/**
* Finds a rule with the given ID in the given config.
* @param {string} ruleId The ID of the rule to find.
* Throws a helpful error when a rule cannot be found.
* @param {Object} ruleId The rule identifier.
* @param {string} ruleId.pluginName The ID of the rule to find.
* @param {string} ruleId.ruleName The ID of the rule to find.
* @param {Object} config The config to search in.
* @returns {{create: Function, schema: (Array|null)}} THe rule object.
* @throws {TypeError} For missing plugin or rule.
* @returns {void}
*/
function findRuleDefinition(ruleId, config) {
const ruleIdParts = ruleId.split("/");
let pluginName, ruleName;
function throwRuleNotFoundError({ pluginName, ruleName }, config) {
// built-in rule
if (ruleIdParts.length === 1) {
pluginName = "@";
ruleName = ruleIdParts[0];
} else {
ruleName = ruleIdParts.pop();
pluginName = ruleIdParts.join("/");
}
const ruleId = pluginName === "@" ? ruleName : `${pluginName}/${ruleName}`;
if (!config.plugins || !config.plugins[pluginName]) {
throw new TypeError(`Key "rules": Key "${ruleId}": Could not find plugin "${pluginName}".`);
}
const errorMessageHeader = `Key "rules": Key "${ruleId}"`;
let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}".`;
if (!config.plugins[pluginName].rules || !config.plugins[pluginName].rules[ruleName]) {
throw new TypeError(`Key "rules": Key "${ruleId}": Could not find "${ruleName}" in plugin "${pluginName}".`);
}
// if the plugin exists then we need to check if the rule exists
if (config.plugins && config.plugins[pluginName]) {
const replacementRuleName = ruleReplacements.rules[ruleName];
return config.plugins[pluginName].rules[ruleName];
if (pluginName === "@" && replacementRuleName) {
}
errorMessage = `${errorMessageHeader}: Rule "${ruleName}" was removed and replaced by "${replacementRuleName}".`;
/**
* Gets a complete options schema for a rule.
* @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
* @returns {Object} JSON Schema for the rule's options.
*/
function getRuleOptionsSchema(rule) {
} else {
if (!rule) {
return null;
}
errorMessage = `${errorMessageHeader}: Could not find "${ruleName}" in plugin "${pluginName}".`;
const schema = rule.schema || rule.meta && rule.meta.schema;
// otherwise, let's see if we can find the rule name elsewhere
for (const [otherPluginName, otherPlugin] of Object.entries(config.plugins)) {
if (otherPlugin.rules && otherPlugin.rules[ruleName]) {
errorMessage += ` Did you mean "${otherPluginName}/${ruleName}"?`;
break;
}
}
if (Array.isArray(schema)) {
if (schema.length) {
return {
type: "array",
items: schema,
minItems: 0,
maxItems: schema.length
};
}
return {
type: "array",
minItems: 0,
maxItems: 0
};
// falls through to throw error
}
// Given a full schema, leave it alone
return schema || null;
throw new TypeError(errorMessage);
}
//-----------------------------------------------------------------------------
@ -98,7 +83,6 @@ class RuleValidator {
* A collection of compiled validators for rules that have already
* been validated.
* @type {WeakMap}
* @property validators
*/
this.validators = new WeakMap();
}
@ -137,7 +121,11 @@ class RuleValidator {
continue;
}
const rule = findRuleDefinition(ruleId, config);
const rule = getRuleFromConfig(ruleId, config);
if (!rule) {
throwRuleNotFoundError(parseRuleId(ruleId), config);
}
// Precompile and cache validator the first time
if (!this.validators.has(rule)) {