dprint_core/plugins/plugin_info.rs
1use serde::Deserialize;
2use serde::Serialize;
3
4/// Information about a plugin.
5#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
6#[serde(rename_all = "camelCase")]
7pub struct PluginInfo {
8 /// The name of the plugin.
9 pub name: String,
10 /// The version of the plugin.
11 pub version: String,
12 /// Gets the key that can be used in the configuration JSON.
13 pub config_key: String,
14 /// A url the user can go to in order to get help information about the plugin.
15 pub help_url: String,
16 /// Schema url for the plugin configuration.
17 ///
18 /// Generally in the format: https://plugins.dprint.dev/<org-or-user>/<repo>/<tag-name>/schema.json
19 /// For example: https://plugins.dprint.dev/dprint/dprint-plugin-typescript/0.60.0/schema.json
20 pub config_schema_url: String,
21 /// Plugin update url.
22 ///
23 /// Generally in the format: https://plugins.dprint.dev/<org-or-user>/<repo>/latest.json
24 /// For example: https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json
25 pub update_url: Option<String>,
26}
27
28/// Message for when a plugin's [`FileMatchingInfo`] can't be deserialized. A
29/// newer plugin may describe its file matching in a way this version of the CLI
30/// doesn't understand, so point at upgrading rather than leaving the user with
31/// only a deserialization error.
32pub const FILE_MATCHING_INFO_ERROR_MESSAGE: &str =
33 "Failed getting the plugin's file matching info. This plugin may require a newer version of the dprint CLI. Try running: dprint upgrade";
34
35/// The plugin file matching information based on the configuration.
36#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
37#[serde(rename_all = "camelCase")]
38pub struct FileMatchingInfo {
39 /// The file extensions this plugin should format.
40 #[serde(default = "Vec::new")]
41 pub file_extensions: Vec<String>,
42 /// The file names this plugin should format.
43 #[serde(default = "Vec::new")]
44 pub file_names: Vec<String>,
45 /// Whether the plugin formats a file it matches in addition to the plugin
46 /// that claims the file, rather than claiming the file itself.
47 ///
48 /// This is for plugins that do something to a file other than format it
49 /// from scratch (ex. sorting the keys of a `package.json`), which would
50 /// otherwise stop the file's usual formatter from running.
51 #[serde(default)]
52 pub additive: bool,
53}