Skip to content

Commit

Permalink
feat: add support for clang-format (#54)
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
hougesen authored Mar 9, 2024
1 parent ee963d9 commit 76f834d
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ jobs:
- name: Install autopep
run: pip install autopep8 && autopep8 --version

- name: Install clang-format
run: pip install clang-format && clang-format --version

- run: cargo test
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,30 @@ mdsf init
>
> Only formatters that are already installed will be used.
| Language | Formatters |
| ---------- | ------------------------------------------- |
| CSS | `prettier` |
| Dart | `dart_format` |
| Elixir | `mix_format` |
| Gleam | `gleam_format` |
| Go | `gofmt`, `gofumpt` |
| HTML | `prettier` |
| JSON | `prettier`, `biome` |
| JavaScript | `prettier`, `biome` |
| Lua | `stylua` |
| Nim | `nimpretty` |
| Python | `ruff`, `black`, `blue`, `yapf`, `autopep8` |
| Ruby | `rubocop` |
| Rust | `rustfmt` |
| SQL | `sqlfluff`, `sql-formatter` |
| Shell | `shfmt` |
| TOML | `taplo` |
| TypeScript | `prettier`, `biome` |
| Vue | `prettier` |
| YAML | `prettier` |
| Zig | `zigfmt` |
| Language | Formatters |
| ----------- | ------------------------------------------- |
| C | `clang-format` |
| CSS | `prettier` |
| Cpp | `clang-format` |
| Dart | `dart_format` |
| Elixir | `mix_format` |
| Gleam | `gleam_format` |
| Go | `gofmt`, `gofumpt` |
| HTML | `prettier` |
| JSON | `prettier`, `biome`, `clang-format` |
| Java | `clang-format` |
| JavaScript | `prettier`, `biome`, `clang-format` |
| Lua | `stylua` |
| Nim | `nimpretty` |
| Objective C | `clang-format` |
| Protobuf | `clang-format` |
| Python | `ruff`, `black`, `blue`, `yapf`, `autopep8` |
| Ruby | `rubocop` |
| Rust | `rustfmt` |
| SQL | `sqlfluff`, `sql-formatter` |
| Shell | `shfmt` |
| TOML | `taplo` |
| TypeScript | `prettier`, `biome` |
| Vue | `prettier` |
| YAML | `prettier` |
| Zig | `zigfmt` |
196 changes: 194 additions & 2 deletions schemas/v0.0.0/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
"title": "MdsfConfig",
"type": "object",
"properties": {
"c": {
"default": {
"enabled": true,
"formatter": "clang-format"
},
"allOf": [
{
"$ref": "#/definitions/C"
}
]
},
"cpp": {
"default": {
"enabled": true,
"formatter": "clang-format"
},
"allOf": [
{
"$ref": "#/definitions/Cpp"
}
]
},
"csharp": {
"default": {
"enabled": true,
"formatter": "clang-format"
},
"allOf": [
{
"$ref": "#/definitions/CSharp"
}
]
},
"css": {
"default": {
"enabled": true,
Expand Down Expand Up @@ -69,6 +102,17 @@
}
]
},
"java": {
"default": {
"enabled": true,
"formatter": "clang-format"
},
"allOf": [
{
"$ref": "#/definitions/Java"
}
]
},
"javascript": {
"default": {
"enabled": true,
Expand Down Expand Up @@ -124,6 +168,28 @@
}
]
},
"objective_c": {
"default": {
"enabled": true,
"formatter": "clang-format"
},
"allOf": [
{
"$ref": "#/definitions/ObjectiveC"
}
]
},
"protobuf": {
"default": {
"enabled": true,
"formatter": "clang-format"
},
"allOf": [
{
"$ref": "#/definitions/Protobuf"
}
]
},
"python": {
"default": {
"enabled": true,
Expand Down Expand Up @@ -236,6 +302,69 @@
}
},
"definitions": {
"C": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"default": "clang-format",
"allOf": [
{
"$ref": "#/definitions/CFormatter"
}
]
}
}
},
"CFormatter": {
"type": "string",
"enum": ["clang-format"]
},
"CSharp": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"default": "clang-format",
"allOf": [
{
"$ref": "#/definitions/CSharpFormatter"
}
]
}
}
},
"CSharpFormatter": {
"type": "string",
"enum": ["clang-format"]
},
"Cpp": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"default": "clang-format",
"allOf": [
{
"$ref": "#/definitions/CppFormatter"
}
]
}
}
},
"CppFormatter": {
"type": "string",
"enum": ["clang-format"]
},
"Css": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -362,6 +491,27 @@
"type": "string",
"enum": ["prettier"]
},
"Java": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"default": "clang-format",
"allOf": [
{
"$ref": "#/definitions/JavaFormatter"
}
]
}
}
},
"JavaFormatter": {
"type": "string",
"enum": ["clang-format"]
},
"JavaScript": {
"type": "object",
"properties": {
Expand All @@ -381,7 +531,7 @@
},
"JavaScriptFormatter": {
"type": "string",
"enum": ["prettier", "biome"]
"enum": ["prettier", "biome", "clang-format"]
},
"Json": {
"type": "object",
Expand All @@ -402,7 +552,7 @@
},
"JsonFormatter": {
"type": "string",
"enum": ["prettier", "biome"]
"enum": ["prettier", "biome", "clang-format"]
},
"Lua": {
"type": "object",
Expand Down Expand Up @@ -467,6 +617,48 @@
"type": "string",
"enum": ["nimpretty"]
},
"ObjectiveC": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"default": "clang-format",
"allOf": [
{
"$ref": "#/definitions/ObjectiveCFormatter"
}
]
}
}
},
"ObjectiveCFormatter": {
"type": "string",
"enum": ["clang-format"]
},
"Protobuf": {
"type": "object",
"properties": {
"enabled": {
"default": true,
"type": "boolean"
},
"formatter": {
"default": "clang-format",
"allOf": [
{
"$ref": "#/definitions/ProtobufFormatter"
}
]
}
}
},
"ProtobufFormatter": {
"type": "string",
"enum": ["clang-format"]
},
"Python": {
"type": "object",
"properties": {
Expand Down
29 changes: 27 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use schemars::JsonSchema;

use crate::languages::{
css::Css, dart::Dart, elixir::Elixir, gleam::Gleam, go::Go, html::Html, javascript::JavaScript,
json::Json, lua::Lua, markdown::Markdown, nim::Nim, python::Python, ruby::Ruby, rust::Rust,
c::C, cpp::Cpp, csharp::CSharp, css::Css, dart::Dart, elixir::Elixir, gleam::Gleam, go::Go,
html::Html, java::Java, javascript::JavaScript, json::Json, lua::Lua, markdown::Markdown,
nim::Nim, objective_c::ObjectiveC, protobuf::Protobuf, python::Python, ruby::Ruby, rust::Rust,
shell::Shell, sql::Sql, toml::Toml, typescript::TypeScript, vue::Vue, yaml::Yaml, zig::Zig,
};

Expand All @@ -12,6 +13,15 @@ pub struct MdsfConfig {
#[serde(rename = "$schema", default = "default_schema_location")]
pub schema: String,

#[serde(default)]
pub c: C,

#[serde(default)]
pub cpp: Cpp,

#[serde(default)]
pub csharp: CSharp,

#[serde(default)]
pub css: Css,

Expand All @@ -30,6 +40,9 @@ pub struct MdsfConfig {
#[serde(default)]
pub html: Html,

#[serde(default)]
pub java: Java,

#[serde(default)]
pub javascript: JavaScript,

Expand All @@ -45,6 +58,12 @@ pub struct MdsfConfig {
#[serde(default)]
pub nim: Nim,

#[serde(default)]
pub objective_c: ObjectiveC,

#[serde(default)]
pub protobuf: Protobuf,

#[serde(default)]
pub python: Python,

Expand Down Expand Up @@ -82,17 +101,23 @@ impl Default for MdsfConfig {
Self {
schema: default_schema_location(),

c: C::default(),
cpp: Cpp::default(),
csharp: CSharp::default(),
css: Css::default(),
dart: Dart::default(),
elixir: Elixir::default(),
gleam: Gleam::default(),
go: Go::default(),
html: Html::default(),
java: Java::default(),
javascript: JavaScript::default(),
json: Json::default(),
lua: Lua::default(),
markdown: Markdown::default(),
nim: Nim::default(),
objective_c: ObjectiveC::default(),
protobuf: Protobuf::default(),
python: Python::default(),
ruby: Ruby::default(),
rust: Rust::default(),
Expand Down
Loading

0 comments on commit 76f834d

Please sign in to comment.