Skip to content

Commit

Permalink
Add to support Zig language.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Sep 7, 2023
1 parent 8b6dff7 commit c533ca5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autocorrect/src/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod strings;
mod swift;
mod xml;
mod yaml;
mod zig;

pub use code::*;
pub use types::*;
Expand Down Expand Up @@ -62,6 +63,9 @@ pub use strings::*;
pub use swift::*;
pub use xml::*;
pub use yaml::*;
pub use zig::*;

use self::zig::lint_zig;

/// Lint a file content with filetype.
///
Expand Down Expand Up @@ -111,6 +115,7 @@ pub fn lint_for(raw: &str, filename_or_ext: &str) -> LintResult {
"c" => lint_c(raw),
"xml" => lint_xml(raw),
"jupyter" => lint_jupyter(raw),
"zig" => lint_zig(raw),
"text" => lint_markdown(raw),
_ => LintResult::new(raw),
};
Expand Down Expand Up @@ -168,6 +173,7 @@ pub fn format_for(raw: &str, filename_or_ext: &str) -> FormatResult {
"c" => format_c(raw),
"xml" => format_xml(raw),
"jupyter" => format_jupyter(raw),
"zig" => format_zig(raw),
"text" => format_markdown(raw),
_ => {
let mut result = FormatResult::new(raw);
Expand Down
43 changes: 43 additions & 0 deletions autocorrect/src/code/zig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// autocorrect: false
use super::*;
use autocorrect_derive::GrammarParser;
use pest::Parser as P;
use pest_derive::Parser;

#[derive(GrammarParser, Parser)]
#[grammar = "../grammar/rust.pest"]
struct ZigParser;

#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
use pretty_assertions::assert_eq;

#[test]
fn it_format_yaml() {
let example = indoc! {r###"
//! 这是top-level文档注释
const std = @import("std");
/// 这是main函数
pub fn main() !void {
// 这是comment
const text = "hello你好";
}
"###};

let expect = indoc! {r###"
//! 这是 top-level 文档注释
const std = @import("std");
/// 这是 main 函数
pub fn main() !void {
// 这是 comment
const text = "hello 你好";
}
"###};

assert_eq!(expect, format_for(example, "zig").to_string())
}
}

0 comments on commit c533ca5

Please sign in to comment.