-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | |
|
||
<!-- END_SECTION:toc --> | ||
|
||
<!-- START_SECTION:base-command-help --> | ||
|
||
``` | ||
mdsf 0.3.1-dev | ||
Format markdown code snippets using your favorite code formatters | ||
Mads Hougesen <[email protected]> | ||
Usage: mdsf <COMMAND> | ||
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 | ||
``` | ||
|
||
<!-- END_SECTION:base-command-help --> | ||
|
||
## 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 | ||
|
||
<!-- START_SECTION:base-command-help --> | ||
|
||
``` | ||
mdsf 0.3.1-dev | ||
Format markdown code snippets using your favorite code formatters | ||
Mads Hougesen <[email protected]> | ||
Usage: mdsf <COMMAND> | ||
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 | ||
``` | ||
|
||
<!-- END_SECTION:base-command-help --> | ||
|
||
### Formatting code | ||
|
||
```shell | ||
mdsf format file.md | ||
``` | ||
|
@@ -143,7 +146,7 @@ Options: | |
|
||
<!-- END_SECTION:format-command-help --> | ||
|
||
### Verify code is formatted | ||
### Verifying code | ||
|
||
```shell | ||
mdsf verify docs/ | ||
|
@@ -210,13 +213,13 @@ mdsf init | |
<!-- START_SECTION:supported-tools --> | ||
|
||
`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` | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>), 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] | ||
} |