mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-11 22:24:37 +08:00
99 lines
2.5 KiB
JavaScript
99 lines
2.5 KiB
JavaScript
/**
|
|
* @fileoverview `ExtractedConfig` class.
|
|
*
|
|
* `ExtractedConfig` class expresses a final configuration for a specific file.
|
|
*
|
|
* It provides one method.
|
|
*
|
|
* - `toCompatibleObjectAsConfigFileContent()`
|
|
* Convert this configuration to the compatible object as the content of
|
|
* config files. It converts the loaded parser and plugins to strings.
|
|
* `CLIEngine#getConfigForFile(filePath)` method uses this method.
|
|
*
|
|
* `ConfigArray#extractConfig(filePath)` creates a `ExtractedConfig` instance.
|
|
*
|
|
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
*/
|
|
"use strict";
|
|
|
|
// For VSCode intellisense
|
|
/** @typedef {import("../../shared/types").ConfigData} ConfigData */
|
|
/** @typedef {import("../../shared/types").GlobalConf} GlobalConf */
|
|
/** @typedef {import("../../shared/types").SeverityConf} SeverityConf */
|
|
/** @typedef {import("./config-dependency").DependentParser} DependentParser */
|
|
/** @typedef {import("./config-dependency").DependentPlugin} DependentPlugin */
|
|
|
|
/**
|
|
* The class for extracted config data.
|
|
*/
|
|
class ExtractedConfig {
|
|
constructor() {
|
|
|
|
/**
|
|
* Environments.
|
|
* @type {Record<string, boolean>}
|
|
*/
|
|
this.env = {};
|
|
|
|
/**
|
|
* Global variables.
|
|
* @type {Record<string, GlobalConf>}
|
|
*/
|
|
this.globals = {};
|
|
|
|
/**
|
|
* Parser definition.
|
|
* @type {DependentParser|null}
|
|
*/
|
|
this.parser = null;
|
|
|
|
/**
|
|
* Options for the parser.
|
|
* @type {Object}
|
|
*/
|
|
this.parserOptions = {};
|
|
|
|
/**
|
|
* Plugin definitions.
|
|
* @type {Record<string, DependentPlugin>}
|
|
*/
|
|
this.plugins = {};
|
|
|
|
/**
|
|
* Processor ID.
|
|
* @type {string|null}
|
|
*/
|
|
this.processor = null;
|
|
|
|
/**
|
|
* Rule settings.
|
|
* @type {Record<string, [SeverityConf, ...any[]]>}
|
|
*/
|
|
this.rules = {};
|
|
|
|
/**
|
|
* Shared settings.
|
|
* @type {Object}
|
|
*/
|
|
this.settings = {};
|
|
}
|
|
|
|
/**
|
|
* Convert this config to the compatible object as a config file content.
|
|
* @returns {ConfigData} The converted object.
|
|
*/
|
|
toCompatibleObjectAsConfigFileContent() {
|
|
const {
|
|
processor: _ignore, // eslint-disable-line no-unused-vars
|
|
...config
|
|
} = this;
|
|
|
|
config.parser = config.parser && config.parser.filePath;
|
|
config.plugins = Object.keys(config.plugins).filter(Boolean).reverse();
|
|
|
|
return config;
|
|
}
|
|
}
|
|
|
|
module.exports = { ExtractedConfig };
|