1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
mod code;
mod types;

mod asciidoc;
mod c;
mod conf;
mod csharp;
mod css;
mod dart;
mod elixir;
mod gettext;
mod go;
mod html;
mod java;
mod javascript;
mod json;
mod kotlin;
mod latex;
mod markdown;
mod objective_c;
mod php;
mod python;
mod ruby;
mod rust;
mod scala;
mod sql;
mod strings;
mod swift;
mod yaml;

pub use code::*;
pub use types::*;

pub use asciidoc::*;
pub use c::*;
pub use conf::*;
pub use csharp::*;
pub use css::*;
pub use dart::*;
pub use elixir::*;
pub use gettext::*;
pub use go::*;
pub use html::*;
pub use java::*;
pub use javascript::*;
pub use json::*;
pub use kotlin::*;
pub use latex::*;
pub use markdown::*;
pub use objective_c::*;
pub use php::*;
pub use python::*;
pub use ruby::*;
pub use rust::*;
pub use scala::*;
pub use sql::*;
pub use strings::*;
pub use swift::*;
pub use yaml::*;

/// Lint a file content with filetype.
///
/// Example:
///
/// ```
//  extern crate autocorrect;
//
/// let raw = r#"
/// <article>
///   <h1>这是 Heading 标题</h1>
///   <div class="content">
///     <p>你好 Rust 世界<strong>Bold 文本</strong></p>
///     <p>这是第二行 p 标签</p>
///   </div>
/// </article>
/// "#;
/// autocorrect::lint_for(raw, "html");
/// autocorrect::lint_for(raw, "index.html");
/// ```
pub fn lint_for(raw: &str, filename_or_ext: &str) -> LintResult {
    let mut result = match types::match_filename(filename_or_ext) {
        "html" => lint_html(raw),
        "yaml" => lint_yaml(raw),
        "sql" => lint_sql(raw),
        "rust" => lint_rust(raw),
        "ruby" => lint_ruby(raw),
        "elixir" => lint_elixir(raw),
        "go" => lint_go(raw),
        "javascript" => lint_javascript(raw),
        "css" => lint_css(raw),
        "json" => lint_json(raw),
        "python" => lint_python(raw),
        "objective_c" => lint_objectivec(raw),
        "strings" => lint_strings(raw),
        "csharp" => lint_csharp(raw),
        "swift" => lint_swift(raw),
        "java" => lint_java(raw),
        "scala" => lint_scala(raw),
        "kotlin" => lint_kotlin(raw),
        "php" => lint_php(raw),
        "dart" => lint_dart(raw),
        "markdown" => lint_markdown(raw),
        "latex" => lint_latex(raw),
        "asciidoc" => lint_asciidoc(raw),
        "gettext" => lint_gettext(raw),
        "conf" => lint_conf(raw),
        "c" => lint_c(raw),
        "text" => lint_markdown(raw),
        _ => LintResult::new(raw),
    };

    result.filepath = String::from(filename_or_ext);

    result
}

/// Format a file content with filetype.
///
/// Example:
///
/// ```
//  extern crate autocorrect;
//
/// let raw = r#"
/// <article>
///   <h1>这是 Heading 标题</h1>
///   <div class="content">
///     <p>你好 Rust 世界<strong>Bold 文本</strong></p>
///     <p>这是第二行 p 标签</p>
///   </div>
/// </article>
/// "#;
/// autocorrect::format_for(raw, "html");
/// autocorrect::format_for(raw, "index.html");
/// ```
pub fn format_for(raw: &str, filename_or_ext: &str) -> FormatResult {
    let result = match types::match_filename(filename_or_ext) {
        "html" => format_html(raw),
        "yaml" => format_yaml(raw),
        "sql" => format_sql(raw),
        "rust" => format_rust(raw),
        "ruby" => format_ruby(raw),
        "elixir" => format_elixir(raw),
        "go" => format_go(raw),
        "javascript" => format_javascript(raw),
        "css" => format_css(raw),
        "json" => format_json(raw),
        "python" => format_python(raw),
        "objective_c" => format_objectivec(raw),
        "strings" => format_strings(raw),
        "csharp" => format_csharp(raw),
        "swift" => format_swift(raw),
        "java" => format_java(raw),
        "scala" => format_scala(raw),
        "kotlin" => format_kotlin(raw),
        "php" => format_php(raw),
        "dart" => format_dart(raw),
        "markdown" => format_markdown(raw),
        "latex" => format_latex(raw),
        "asciidoc" => format_asciidoc(raw),
        "gettext" => format_gettext(raw),
        "conf" => format_conf(raw),
        "c" => format_c(raw),
        "text" => format_markdown(raw),
        _ => {
            let mut result = FormatResult::new(raw);
            result.out = String::from(raw);
            result
        }
    };

    result
}