Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

flat-config-array.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @fileoverview Flat Config Array
  3. * @author Nicholas C. Zakas
  4. */
  5. "use strict";
  6. //-----------------------------------------------------------------------------
  7. // Requirements
  8. //-----------------------------------------------------------------------------
  9. const { ConfigArray, ConfigArraySymbol } = require("@humanwhocodes/config-array");
  10. const { flatConfigSchema } = require("./flat-config-schema");
  11. const { RuleValidator } = require("./rule-validator");
  12. const { defaultConfig } = require("./default-config");
  13. const recommendedConfig = require("../../conf/eslint-recommended");
  14. const allConfig = require("../../conf/eslint-all");
  15. //-----------------------------------------------------------------------------
  16. // Helpers
  17. //-----------------------------------------------------------------------------
  18. const ruleValidator = new RuleValidator();
  19. /**
  20. * Splits a plugin identifier in the form a/b/c into two parts: a/b and c.
  21. * @param {string} identifier The identifier to parse.
  22. * @returns {{objectName: string, pluginName: string}} The parts of the plugin
  23. * name.
  24. */
  25. function splitPluginIdentifier(identifier) {
  26. const parts = identifier.split("/");
  27. return {
  28. objectName: parts.pop(),
  29. pluginName: parts.join("/")
  30. };
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Exports
  34. //-----------------------------------------------------------------------------
  35. /**
  36. * Represents an array containing configuration information for ESLint.
  37. */
  38. class FlatConfigArray extends ConfigArray {
  39. /**
  40. * Creates a new instance.
  41. * @param {*[]} configs An array of configuration information.
  42. * @param {{basePath: string, baseConfig: FlatConfig}} options The options
  43. * to use for the config array instance.
  44. */
  45. constructor(configs, { basePath, baseConfig = defaultConfig }) {
  46. super(configs, {
  47. basePath,
  48. schema: flatConfigSchema
  49. });
  50. this.unshift(baseConfig);
  51. }
  52. /* eslint-disable class-methods-use-this */
  53. /**
  54. * Replaces a config with another config to allow us to put strings
  55. * in the config array that will be replaced by objects before
  56. * normalization.
  57. * @param {Object} config The config to preprocess.
  58. * @returns {Object} The preprocessed config.
  59. */
  60. [ConfigArraySymbol.preprocessConfig](config) {
  61. if (config === "eslint:recommended") {
  62. return recommendedConfig;
  63. }
  64. if (config === "eslint:all") {
  65. return allConfig;
  66. }
  67. return config;
  68. }
  69. /**
  70. * Finalizes the config by replacing plugin references with their objects
  71. * and validating rule option schemas.
  72. * @param {Object} config The config to finalize.
  73. * @returns {Object} The finalized config.
  74. * @throws {TypeError} If the config is invalid.
  75. */
  76. [ConfigArraySymbol.finalizeConfig](config) {
  77. const { plugins, languageOptions, processor } = config;
  78. // Check parser value
  79. if (languageOptions && languageOptions.parser && typeof languageOptions.parser === "string") {
  80. const { pluginName, objectName: parserName } = splitPluginIdentifier(languageOptions.parser);
  81. if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[parserName]) {
  82. throw new TypeError(`Key "parser": Could not find "${parserName}" in plugin "${pluginName}".`);
  83. }
  84. languageOptions.parser = plugins[pluginName].parsers[parserName];
  85. }
  86. // Check processor value
  87. if (processor && typeof processor === "string") {
  88. const { pluginName, objectName: processorName } = splitPluginIdentifier(processor);
  89. if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[processorName]) {
  90. throw new TypeError(`Key "processor": Could not find "${processorName}" in plugin "${pluginName}".`);
  91. }
  92. config.processor = plugins[pluginName].processors[processorName];
  93. }
  94. ruleValidator.validate(config);
  95. return config;
  96. }
  97. /* eslint-enable class-methods-use-this */
  98. }
  99. exports.FlatConfigArray = FlatConfigArray;