diff --git a/README.md b/README.md index ff3e00e6..8ca2efd6 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ Format markdown code snippets using your favorite code formatters. - [npm/npx](#npmnpx) - [Homebrew](#homebrew) - [Usage](#usage) - - [Verify code is formatted](#verify-code-is-formatted) + - [Formatting code](#formatting-code) + - [Verifying code](#verifying-code) - [Configuration](#configuration) - [Tools](#tools) - [Commands](#commands) @@ -35,30 +36,6 @@ Format markdown code snippets using your favorite code formatters. - - -``` -mdsf 0.3.1-dev -Format markdown code snippets using your favorite code formatters -Mads Hougesen - -Usage: mdsf - -Commands: - format Run formatters on input files - verify Verify files are formatted - init Create a new mdsf config - completions Generate shell completion - cache-prune Remove old caches - help Print this message or the help of the given subcommand(s) - -Options: - -h, --help Print help - -V, --version Print version -``` - - - ## Installation The latest version of `mdsf` can be downloaded directly from [github.com/hougesen/mdsf/releases](https://github.com/hougesen/mdsf/releases). @@ -117,6 +94,32 @@ brew install hougesen/tap/mdsf ## Usage + + +``` +mdsf 0.3.1-dev +Format markdown code snippets using your favorite code formatters +Mads Hougesen + +Usage: mdsf + +Commands: + format Run formatters on input files + verify Verify files are formatted + init Create a new mdsf config + completions Generate shell completion + cache-prune Remove old caches + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help + -V, --version Print version +``` + + + +### Formatting code + ```shell mdsf format file.md ``` @@ -143,7 +146,7 @@ Options: -### Verify code is formatted +### Verifying code ```shell mdsf verify docs/ @@ -210,13 +213,13 @@ mdsf init -`mdsf` currently supports 208 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 209 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | | [alejandra](https://github.com/kamadorueda/alejandra) | The Uncompromising Nix Code Formatter | `formatter` | `nix` | | [ameba](https://github.com/crystal-ameba/ameba) | A static code analysis tool for Crystal | `linter` | `crystal` | -| [asmfmt](https://github.com/klauspost/asmfmt) | Go Assembler Formatter | `formatter` | | +| [asmfmt](https://github.com/klauspost/asmfmt) | Go Assembler Formatter | `formatter` | `go` | | [astyle](https://gitlab.com/saalen/astyle) | A Free, Fast, and Small Automatic Formatter for C, C++, C++/CLI, Objective-C, C#, and Java Source Code | `formatter` | `c#`, `c++`, `c`, `java`, `objective-c` | | [auto-optional](https://github.com/Luttik/auto-optional) | Adds the Optional type-hint to arguments where the default value is None | `formatter` | `python` | | [autocorrect](https://github.com/huacnlee/autocorrect) | A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean) | `autocorrection` | | @@ -319,7 +322,7 @@ mdsf init | [luaformatter](https://github.com/Koihik/LuaFormatter) | Code formatter for Lua | `formatter` | `lua` | | [markdownfmt](https://github.com/shurcooL/markdownfmt) | Like gofmt, but for Markdown | `formatter` | `markdown` | | [markdownlint-cli2](https://github.com/davidanson/markdownlint-cli2) | A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the markdownlint library | `linter` | `markdown` | -| [markdownlint](https://github.com/davidanson/markdownlint) | A Node.js style checker and lint tool for Markdown/CommonMark files | `linter` | | +| [markdownlint](https://github.com/davidanson/markdownlint) | A Node.js style checker and lint tool for Markdown/CommonMark files | `linter` | `markdown` | | [markuplint](https://markuplint.dev/) | An HTML linter for all markup developers | `linter` | `html` | | [mdformat](https://github.com/executablebooks/mdformat) | CommonMark compliant Markdown formatter | `formatter` | `markdwon` | | [mdslw](https://github.com/razziel89/mdslw) | Prepare your markdown for easy diff'ing! | `formatter` | `markdown` | @@ -348,6 +351,7 @@ mdsf init | [prettier](https://github.com/prettier/prettier) | Prettier is an opinionated code formatter | `formatter` | `css`, `html`, `javascript`, `json`, `typescript` | | [pretty-php](https://github.com/lkrms/pretty-php) | The opinionated PHP code formatter | `formatter` | `php` | | [prettypst](https://github.com/antonWetzel/prettypst) | Formatter for Typst | `formatter` | `typst` | +| [prisma](https://www.prisma.io) | Commands for interacting with the prisma ORM | `formatter` | `prisma` | | [protolint](https://github.com/yoheimuta/protolint) | A pluggable linter and fixer to enforce Protocol Buffer style and conventions | `linter` | `protobuf` | | [ptop](https://www.freepascal.org/tools/ptop.html) | Free Pascal source formatter | `formatter` | `pascal` | | [puppet-lint](https://github.com/puppetlabs/puppet-lint) | Check that your Puppet manifests conform to the style guide | `linter` | `puppet` | diff --git a/justfile b/justfile index 39783d0c..84132b35 100644 --- a/justfile +++ b/justfile @@ -30,6 +30,7 @@ changelog: codegen: just changelog cargo run --package mdsf-codegen + cargo run --package mdsf-codegen dist init --yes just format diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 5784b5fe..0af227b4 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -138,6 +138,7 @@ pub mod pint; pub mod prettier; pub mod pretty_php; pub mod prettypst; +pub mod prisma_format; pub mod protolint; pub mod ptop; pub mod puppet_lint; @@ -779,6 +780,10 @@ pub enum Tooling { /// `prettypst $PATH` Prettypst, + #[serde(rename = "prisma:format")] + /// `prisma format --schema={$PATH_STRING}` + PrismaFormat, + #[serde(rename = "protolint")] /// `protolint lint -fix $PATH` Protolint, @@ -1232,6 +1237,7 @@ impl Tooling { Self::Prettier => prettier::run(snippet_path), Self::PrettyPhp => pretty_php::run(snippet_path), Self::Prettypst => prettypst::run(snippet_path), + Self::PrismaFormat => prisma_format::run(snippet_path), Self::Protolint => protolint::run(snippet_path), Self::Ptop => ptop::run(snippet_path), Self::PuppetLint => puppet_lint::run(snippet_path), @@ -1457,6 +1463,7 @@ impl AsRef for Tooling { Self::Prettier => "prettier", Self::PrettyPhp => "pretty_php", Self::Prettypst => "prettypst", + Self::PrismaFormat => "prisma_format", Self::Protolint => "protolint", Self::Ptop => "ptop", Self::PuppetLint => "puppet_lint", diff --git a/mdsf/src/tools/prisma_format.rs b/mdsf/src/tools/prisma_format.rs new file mode 100644 index 00000000..ef9ea6c6 --- /dev/null +++ b/mdsf/src/tools/prisma_format.rs @@ -0,0 +1,66 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_prisma_format_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("format"); + let fps = file_path.to_string_lossy(); + cmd.arg(format!("--schema={fps}")); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [ + CommandType::NodeModules("prisma"), + CommandType::Direct("prisma"), + CommandType::Npm("prisma"), + ]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_prisma_format_args(cmd.build(), file_path); + let execution_result = execute_command(cmd, file_path); + + if index == commands.len() - 1 { + return execution_result; + } + + if let Ok(r) = execution_result { + if !r.0 { + return Ok(r); + } + } + } + + Ok((true, None)) +} + +#[cfg(test)] +mod test_prisma_format { + #[test_with::executable(npx)] + fn test_prisma_format_schema_f14c422420ff523a() { + let input = r#"datasource db { + provider = "postgresql" + url = env("DATABASE_URL") + directUrl = env("DIRECT_DATABASE_URL") +} + + +"#; + let output = r#"datasource db { + provider = "postgresql" + url = env("DATABASE_URL") + directUrl = env("DIRECT_DATABASE_URL") +} +"#; + let file_ext = crate::fttype::get_file_extension("schema"); + let snippet = + crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file"); + let result = crate::tools::prisma_format::run(snippet.path()) + .expect("it to be successful") + .1 + .expect("it to be some"); + assert_eq!(result, output); + } +} diff --git a/schemas/v0.3.1-dev/mdsf.schema.json b/schemas/v0.3.1-dev/mdsf.schema.json index 4a0fb3c4..1087a62c 100644 --- a/schemas/v0.3.1-dev/mdsf.schema.json +++ b/schemas/v0.3.1-dev/mdsf.schema.json @@ -758,6 +758,11 @@ "type": "string", "enum": ["prettypst"] }, + { + "description": "`prisma format --schema={$PATH_STRING}`", + "type": "string", + "enum": ["prisma:format"] + }, { "description": "`protolint lint -fix $PATH`", "type": "string", diff --git a/tools/asmfmt/plugin.json b/tools/asmfmt/plugin.json index 072aa934..d2ea4ea5 100644 --- a/tools/asmfmt/plugin.json +++ b/tools/asmfmt/plugin.json @@ -7,7 +7,7 @@ }, "description": "Go Assembler Formatter", "homepage": "https://github.com/klauspost/asmfmt", - "languages": [], + "languages": ["go"], "name": null, "npm": null, "php": null, diff --git a/tools/markdownlint/plugin.json b/tools/markdownlint/plugin.json index b41b0f60..b42214a2 100644 --- a/tools/markdownlint/plugin.json +++ b/tools/markdownlint/plugin.json @@ -7,7 +7,7 @@ }, "description": "A Node.js style checker and lint tool for Markdown/CommonMark files", "homepage": "https://github.com/davidanson/markdownlint", - "languages": [], + "languages": ["markdown"], "name": null, "npm": "markdownlint", "php": null, diff --git a/tools/prisma/plugin.json b/tools/prisma/plugin.json new file mode 100644 index 00000000..4df137ad --- /dev/null +++ b/tools/prisma/plugin.json @@ -0,0 +1,22 @@ +{ + "$schema": "../tool.schema.json", + "binary": "prisma", + "categories": ["formatter"], + "commands": { + "format": ["format", "--schema={$PATH_STRING}"] + }, + "description": "Commands for interacting with the prisma ORM", + "homepage": "https://www.prisma.io", + "languages": ["prisma"], + "name": null, + "npm": "prisma", + "php": null, + "tests": [ + { + "command": "format", + "language": "schema", + "test_input": "datasource db {\n provider = \"postgresql\"\n url = env(\"DATABASE_URL\")\n directUrl = env(\"DIRECT_DATABASE_URL\")\n}\n\n\n", + "test_output": "datasource db {\n provider = \"postgresql\"\n url = env(\"DATABASE_URL\")\n directUrl = env(\"DIRECT_DATABASE_URL\")\n}\n" + } + ] +}