/** * @fileoverview A collection of rules that help enforce JavaScript coding * standard and avoid common errors in the Mozilla project. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** * Clones a legacy configuration section, adjusting fields so that ESLint won't * fail. * * @param {object} section * The section to clone. * @returns {object} * The cloned section.
*/ function cloneLegacySection(section) {
let config = structuredClone(section);
if (config.overrides) { for (let overridesSection of config.overrides) { // The legacy config doesn't support names in sections, so get rid of those. delete overridesSection.name; // Also, the legacy config supports "excludedFiles" rather than "ignores". if (overridesSection.ignores) {
overridesSection.excludedFiles = overridesSection.ignores; delete overridesSection.ignores;
}
}
}
return config;
}
/** * Clones a flat configuration section, adjusting fields so that ESLint won't * fail. * * @param {object} section * The section to clone. * @returns {object} * The cloned section.
*/ function cloneFlatSection(section) {
let config = structuredClone(section);
// We assume all parts of the flat config need the plugins defined. In // practice, they only need to be defined where they are used, but for // now this is simpler.
config.plugins = {
mozilla: plugin, "no-unsanitized": require("eslint-plugin-no-unsanitized"), "@microsoft/sdl": require("@microsoft/eslint-plugin-sdl"),
promise: require("eslint-plugin-promise"),
}; if (!config.languageOptions) {
config.languageOptions = {};
}
// Handle changing the location of the sourceType. if (config.parserOptions?.sourceType) {
config.languageOptions.sourceType = config.parserOptions.sourceType; delete config.parserOptions;
}
// Convert any environments into a list of globals. for (let [key, value] of Object.entries(config.env ?? {})) { if (!value) { thrownew Error( "Removing environments is not supported by eslint-plugin-mozilla"
);
} if (!config.languageOptions.globals) {
config.languageOptions.globals = {};
} if (key.startsWith("mozilla/")) {
config.languageOptions.globals = {
...config.languageOptions.globals,
...plugin.environments[key.substring("mozilla/".length)].globals,
};
} else {
config.languageOptions.globals = {
...config.languageOptions.globals,
...globals[key],
};
}
} delete config.env;
return config;
}
for (let configName of configurations) {
let config = require(`./configs/${configName}`);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.