Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split fish from shell #257

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ mdsf init
| Erlang | `efmt`, `erlfmt` |
| FSharp | `fantomas` |
| Fennel | `fnlfmt` |
| Fish | `fish_indent` |
| Fortran | `findent`, `fprettify` |
| GDScript | `gdformat` |
| Gleam | `gleam_format` |
Expand Down
4 changes: 4 additions & 0 deletions mdsf.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
"enabled": true,
"formatter": "fantomas"
},
"fish": {
"enabled": true,
"formatter": "fish_indent"
},
"gdscript": {
"enabled": true,
"formatter": "gdformat"
Expand Down
41 changes: 41 additions & 0 deletions schemas/v0.0.7/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@
}
]
},
"fish": {
"default": {
"enabled": true,
"formatter": "fish_indent"
},
"allOf": [
{
"$ref": "#/definitions/Lang_for_Fish"
}
]
},
"format_finished_document": {
"description": "Format the processed document with the selected markdown formatter.",
"default": false,
Expand Down Expand Up @@ -823,6 +834,10 @@
"type": "string",
"enum": ["fnlfmt"]
},
"Fish": {
"type": "string",
"enum": ["fish_indent"]
},
"Fortran": {
"type": "string",
"enum": ["fprettify", "findent"]
Expand Down Expand Up @@ -1150,6 +1165,19 @@
},
"additionalProperties": false
},
"Lang_for_Fish": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"$ref": "#/definitions/MdsfFormatter_for_Fish"
}
},
"additionalProperties": false
},
"Lang_for_Fortran": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2010,6 +2038,19 @@
}
]
},
"MdsfFormatter_for_Fish": {
"anyOf": [
{
"$ref": "#/definitions/Fish"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/MdsfFormatter_for_Fish"
}
}
]
},
"MdsfFormatter_for_Fortran": {
"anyOf": [
{
Expand Down
22 changes: 13 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use crate::{
languages::{
assembly::Assembly, bazel::Bazel, bicep::Bicep, blade::Blade, c::C, cabal::Cabal,
clojure::Clojure, cpp::Cpp, crystal::Crystal, csharp::CSharp, css::Css, d::D, dart::Dart,
elixir::Elixir, elm::Elm, erb::Erb, erlang::Erlang, fennel::Fennel, fortran::Fortran,
fsharp::FSharp, gdscript::GDScript, gleam::Gleam, go::Go, graphql::GraphQL, groovy::Groovy,
handlebars::Handlebars, haskell::Haskell, hcl::Hcl, html::Html, java::Java,
javascript::JavaScript, json::Json, julia::Julia, just::Just, kcl::Kcl, kotlin::Kotlin,
lua::Lua, markdown::Markdown, mustache::Mustache, nim::Nim, nix::Nix, nunjucks::Nunjucks,
objective_c::ObjectiveC, ocaml::OCaml, perl::Perl, protobuf::Protobuf, puppet::Puppet,
purescript::PureScript, python::Python, rescript::ReScript,
restructuredtext::ReStructuredText, roc::Roc, ruby::Ruby, rust::Rust, scala::Scala,
shell::Shell, solidity::Solidity, sql::Sql, swift::Swift, toml::Toml,
elixir::Elixir, elm::Elm, erb::Erb, erlang::Erlang, fennel::Fennel, fish::Fish,
fortran::Fortran, fsharp::FSharp, gdscript::GDScript, gleam::Gleam, go::Go,
graphql::GraphQL, groovy::Groovy, handlebars::Handlebars, haskell::Haskell, hcl::Hcl,
html::Html, java::Java, javascript::JavaScript, json::Json, julia::Julia, just::Just,
kcl::Kcl, kotlin::Kotlin, lua::Lua, markdown::Markdown, mustache::Mustache, nim::Nim,
nix::Nix, nunjucks::Nunjucks, objective_c::ObjectiveC, ocaml::OCaml, perl::Perl,
protobuf::Protobuf, puppet::Puppet, purescript::PureScript, python::Python,
rescript::ReScript, restructuredtext::ReStructuredText, roc::Roc, ruby::Ruby, rust::Rust,
scala::Scala, shell::Shell, solidity::Solidity, sql::Sql, swift::Swift, toml::Toml,
typescript::TypeScript, vue::Vue, xml::Xml, yaml::Yaml, zig::Zig, Lang,
},
runners::JavaScriptRuntime,
Expand Down Expand Up @@ -104,6 +104,9 @@ pub struct MdsfConfig {
#[serde(default)]
pub fsharp: Lang<FSharp>,

#[serde(default)]
pub fish: Lang<Fish>,

#[serde(default)]
pub gdscript: Lang<GDScript>,

Expand Down Expand Up @@ -267,6 +270,7 @@ impl Default for MdsfConfig {
erlang: Lang::<Erlang>::default(),
fennel: Lang::<Fennel>::default(),
fortran: Lang::<Fortran>::default(),
fish: Lang::<Fish>::default(),
fsharp: Lang::<FSharp>::default(),
gdscript: Lang::<GDScript>::default(),
gleam: Lang::<Gleam>::default(),
Expand Down
1 change: 1 addition & 0 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub fn format_snippet(config: &MdsfConfig, info: &LineInfo, code: &str) -> Strin
Language::Erb => config.erb.format(snippet_path, info),
Language::Erlang => config.erlang.format(snippet_path, info),
Language::Fennel => config.fennel.format(snippet_path, info),
Language::Fish => config.fish.format(snippet_path, info),
Language::FSharp => config.fsharp.format(snippet_path, info),
Language::Fortran => config.fortran.format(snippet_path, info),
Language::Gdscript => config.gdscript.format(snippet_path, info),
Expand Down
64 changes: 64 additions & 0 deletions src/languages/fish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use schemars::JsonSchema;

use super::{Lang, LanguageFormatter};
use crate::{
error::MdsfError,
formatters::{fish_indent::format_using_fish_indent, MdsfFormatter},
};

#[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)]
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
pub enum Fish {
#[default]
#[serde(rename = "fish_indent")]
FishIndent,
}

impl Default for Lang<Fish> {
#[inline]
fn default() -> Self {
Self {
enabled: true,
formatter: MdsfFormatter::<Fish>::default(),
}
}
}

impl Default for MdsfFormatter<Fish> {
#[inline]
fn default() -> Self {
Self::Single(Fish::FishIndent)
}
}

impl LanguageFormatter for Fish {
#[inline]
fn format_snippet(
&self,
snippet_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
match self {
Self::FishIndent => format_using_fish_indent(snippet_path),
}
}
}

impl core::fmt::Display for Fish {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::FishIndent => write!(f, "fish_indent"),
}
}
}

#[cfg(test)]
mod test_fish {
use super::Fish;
use crate::languages::Lang;

#[test]
fn it_should_be_enabled_by_default() {
assert!(Lang::<Fish>::default().enabled);
}
}
9 changes: 5 additions & 4 deletions src/languages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod elm;
pub mod erb;
pub mod erlang;
pub mod fennel;
pub mod fish;
pub mod fortran;
pub mod fsharp;
pub mod gdscript;
Expand Down Expand Up @@ -119,7 +120,6 @@ pub enum ShellFlavor {
Shell,
Bash,
Zsh,
Fish,
}

impl core::fmt::Display for ShellFlavor {
Expand All @@ -129,7 +129,6 @@ impl core::fmt::Display for ShellFlavor {
Self::Shell => f.write_str("shell"),
Self::Bash => f.write_str("bash"),
Self::Zsh => f.write_str("zsh"),
Self::Fish => f.write_str("fish"),
}
}
}
Expand Down Expand Up @@ -188,6 +187,7 @@ pub enum Language {
Fennel,
FSharp,
Fortran,
Fish,
Gdscript,
Gleam,
Go,
Expand Down Expand Up @@ -259,6 +259,7 @@ impl core::fmt::Display for Language {
Self::Fennel => f.write_str("fennel"),
Self::FSharp => f.write_str("f#"),
Self::Fortran => f.write_str("fortran"),
Self::Fish => f.write_str("fish"),
Self::Gdscript => f.write_str("gdscript"),
Self::Gleam => f.write_str("gleam"),
Self::Go => f.write_str("go"),
Expand Down Expand Up @@ -338,7 +339,7 @@ impl Language {
"erb" => Some(Self::Erb),
"erlang" => Some(Self::Erlang),
"fennel" | "fnl" => Some(Self::Fennel),
"fish" => Some(Self::Shell(ShellFlavor::Fish)),
"fish" => Some(Self::Fish),
"fortran" => Some(Self::Fortran),
"fsharp" => Some(Self::FSharp),
"gdscript" => Some(Self::Gdscript),
Expand Down Expand Up @@ -466,7 +467,7 @@ impl Language {
Self::Scala => ".scala",
Self::Shell(ShellFlavor::Bash) => ".bash",
Self::Shell(ShellFlavor::Shell) => ".sh",
Self::Shell(ShellFlavor::Fish) => ".fish",
Self::Fish => ".fish",
Self::Shell(ShellFlavor::Zsh) => ".zsh",
Self::Solidity => ".sol",
Self::Sql => ".sql",
Expand Down
1 change: 0 additions & 1 deletion src/languages/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub enum Shell {
Shfmt,
#[serde(rename = "beautysh")]
Beautysh,

#[serde(rename = "fish_indent")]
FishIndent,
}
Expand Down
Loading