Skip to content

Commit

Permalink
Fix format with newline case for same behiver with lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jan 4, 2022
1 parent db5fd5f commit 58b8dff
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build:
cargo build --release --target aarch64-apple-darwin
sudo ln -f target/aarch64-apple-darwin/release/autocorrect /usr/local/bin/autocorrect
test:
@cargo test --manifest-path src/lib/Cargo.toml
@cargo test --manifest-path autocorrect/Cargo.toml
@cargo test
test\:lint:
@cargo run -q -- --debug --lint tests/fixtures/*.fixed.*
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/grammar/html.pest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// HTML
//
// Fork from:
// https://github.com/mathiversen/html-parser/blob/0.4.2/s../grammar//rules.pest
// https://github.com/mathiversen/html-parser/blob/0.4.2/s../grammar/rules.pest
//
item = _{
SOI
Expand Down
9 changes: 8 additions & 1 deletion autocorrect/src/code/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ pub fn format_or_lint<R: RuleType, O: Results>(results: &mut O, rule_name: &str,
}
} else {
let mut new_part = String::from(part);

// only for on enable
if results.is_enabled() {
new_part = format(part);
let lines = part.split('\n');

new_part = lines
.into_iter()
.map(|line_str| format(line_str))
.collect::<Vec<_>>()
.join("\n");
}

results.push(LineResult {
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/dart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/elixir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use autocorrect_derive::GrammarParser;
use pest::Parser as P;
use pest_derive::Parser;
#[derive(GrammarParser, Parser)]
#[grammar = "../grammar//go.pest"]
#[grammar = "../grammar/go.pest"]
struct GoParser;

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion autocorrect/src/code/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down Expand Up @@ -63,6 +63,7 @@ mod tests {
<h2>Rust和WebAssembly用例</h2>
<div @click.prevent="hello" :name="foo" #bar="dar"><p>Rust 和 WebAssembly 有两大主要用例:</p>
<ul>
引荐来源网址:
<li>构建完整应用——整个Web应用都基于Rust开发!</li>
<li>构建应用的组成部分——在现存的JavaScript前端中使用Rust。</li>
<%= link_to "FTP管理", "/", class: "subnav-item #{(params[:title_tab].blank? || params[:title_tab] == 'sftp_index') ? 'active' : ''}" %>
Expand Down Expand Up @@ -104,6 +105,7 @@ mod tests {
<h2>Rust 和 WebAssembly 用例</h2>
<div @click.prevent="hello" :name="foo" #bar="dar"><p>Rust 和 WebAssembly 有两大主要用例:</p>
<ul>
引荐来源网址:
<li>构建完整应用——整个 Web 应用都基于 Rust 开发!</li>
<li>构建应用的组成部分——在现存的 JavaScript 前端中使用 Rust。</li>
<%= link_to "FTP管理", "/", class: "subnav-item #{(params[:title_tab].blank? || params[:title_tab] == 'sftp_index') ? 'active' : ''}" %>
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/kotlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/objective_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/php.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use autocorrect_derive::GrammarParser;
use pest::Parser as P;
use pest_derive::Parser;
#[derive(GrammarParser, Parser)]
#[grammar = "../grammar//python.pest"]
#[grammar = "../grammar/python.pest"]
struct PythonParser;

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/scala.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion autocorrect/src/code/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::Parser as P;
use pest_derive::Parser;

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

#[cfg(test)]
Expand Down

0 comments on commit 58b8dff

Please sign in to comment.