dprint-core 0.78.0

Core library for dprint.
Documentation
use serde::Deserialize;
use serde::Serialize;

/// Information about a plugin.
#[derive(Clone, Serialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PluginInfo {
  /// The name of the plugin.
  pub name: String,
  /// The version of the plugin.
  pub version: String,
  /// Gets the key that can be used in the configuration JSON.
  pub config_key: String,
  /// A url the user can go to in order to get help information about the plugin.
  pub help_url: String,
  /// Schema url for the plugin configuration.
  ///
  /// Generally in the format: https://plugins.dprint.dev/<org-or-user>/<repo>/<tag-name>/schema.json
  /// For example: https://plugins.dprint.dev/dprint/dprint-plugin-typescript/0.60.0/schema.json
  pub config_schema_url: String,
  /// Plugin update url.
  ///
  /// Generally in the format: https://plugins.dprint.dev/<org-or-user>/<repo>/latest.json
  /// For example: https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json
  pub update_url: Option<String>,
  /// Whether the plugin formats the range of a format request.
  ///
  /// - `true` - Editors give the plugin the range as it is and use what it
  ///   formats, so it decides what to format around the range (ex. the nodes
  ///   it overlaps).
  /// - `false` - Editors don't format a range with the plugin.
  pub supports_range_formatting: bool,
  /// Whether dprint should skip formatting a file again until the output is
  /// stable when the plugin changes the file.
  ///
  /// By default, dprint formats the text a plugin changed again until it
  /// stops changing to catch plugins that format differently each time. Only
  /// set this to `true` when formatting the plugin's output again never
  /// changes it with any configuration. This saves formatting each changed
  /// file at least one more time and the output is still stored as formatted
  /// for incremental formatting.
  ///
  /// When the plugin formats embedded text with other plugins (ex. code
  /// blocks), dprint formats that text again until it's stable unless those
  /// plugins say the same.
  pub skip_stable_format: bool,
}

/// Information about a process plugin.
#[derive(Clone, Serialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ProcessPluginInfo {
  /// The information that every plugin provides.
  #[serde(flatten)]
  pub info: PluginInfo,
  /// Whether another plugin may change this plugin's non-global configuration
  /// when it asks dprint to format text with this plugin (ex. a Wasm plugin
  /// formatting a code block). Another plugin can always change the global
  /// configuration (ex. `lineWidth`). This doesn't affect configuration from
  /// anywhere else, such as a config file.
  ///
  /// Process plugins don't run sandboxed and the requesting plugin might be a
  /// Wasm plugin from an untrusted source (ex. remote configuration), so only
  /// set this to `true` when no configuration could make the plugin do
  /// something harmful, such as run a command provided in the configuration
  /// (ex. dprint-plugin-exec).
  pub allow_plugin_override_config: bool,
}

/// Message for when a plugin's [`FileMatchingInfo`] can't be deserialized. A
/// newer plugin may describe its file matching in a way this version of the CLI
/// doesn't understand, so point at upgrading rather than leaving the user with
/// only a deserialization error.
pub const FILE_MATCHING_INFO_ERROR_MESSAGE: &str =
  "Failed getting the plugin's file matching info. This plugin may require a newer version of the dprint CLI. Try running: dprint upgrade";

/// The plugin file matching information based on the configuration.
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct FileMatchingInfo {
  /// The file extensions this plugin should format.
  #[serde(default = "Vec::new")]
  pub file_extensions: Vec<String>,
  /// The file names this plugin should format.
  #[serde(default = "Vec::new")]
  pub file_names: Vec<String>,
  /// Whether the plugin formats a file it matches in addition to the plugin
  /// that claims the file, rather than claiming the file itself.
  ///
  /// This is for plugins that do something to a file other than format it
  /// from scratch (ex. sorting the keys of a `package.json`), which would
  /// otherwise stop the file's usual formatter from running.
  #[serde(default)]
  pub additive: bool,
}