Skip to content

Commit

Permalink
Remove unused dependencies, and improve to avoid str clone (#185)
Browse files Browse the repository at this point in the history
* Remove unused dependencies
* Improve `format_or_lint_with_disable_rules` method for avoid str clone.
  • Loading branch information
huacnlee authored Apr 30, 2024
1 parent dba71ae commit e9be92e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 30 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ on:
pull_request:
push:
branches:
- '*'
- "*"
tags:
- '*'
- "*"

jobs:
build:
Expand All @@ -26,8 +26,10 @@ jobs:
key: ubuntu-test-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Test
run: |
cargo test
cargo install cargo-machete
cargo machete
cargo clippy
cargo test
- name: Lint output
run: make test:lint
- name: Init test
Expand Down Expand Up @@ -58,7 +60,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 21
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Test Node.js
run: |
Expand All @@ -83,7 +85,7 @@ jobs:
key: ubuntu-test-cargo-python-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
- name: Install pytest
run: python3 -m pip install pytest
- name: Test Python
Expand Down Expand Up @@ -138,7 +140,7 @@ jobs:
- name: Install JDK
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
java-version: "11"
distribution: "temurin"
- name: Test Java
run: make test:java
30 changes: 20 additions & 10 deletions autocorrect-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,44 @@ name = "autocorrect"
path = "src/main.rs"

[dependencies]
autocorrect = {path = "../autocorrect", version = ">1.0.0"}
clap = {version = "4", features = ['derive']}
autocorrect = { path = "../autocorrect", version = ">1.0.0" }
clap = { version = "4", features = ['derive'] }
ignore = "0.4"
lazy_static = "1.4.0"
log = "0.4"
num_cpus = "1.13.0"
owo-colors = "3"
threadpool = "1.8.1"
walkdir = "2.3.2"

# Config template from remote
# Request features:
# - blocking - for blocking request
# - rustls-tls - for use native rustls without system openssl dependency
reqwest = {version = "0.11.18", features = ["rustls-tls"], default-features = false}
tokio = {version = "1", features = ["macros", "sync", "rt", "rt-multi-thread", "time"], default-features = false}
reqwest = { version = "0.11.18", features = [
"rustls-tls",
], default-features = false }
tokio = { version = "1", features = [
"macros",
"sync",
"rt",
"rt-multi-thread",
"time",
], default-features = false }

# Self Update
# - archive-tar + compression-flate2 - for tar.gz
# - rustls - for use native rustls without system openssl dependency
self_update = {version = "0.30.0", features = ["archive-tar", "compression-flate2", "rustls"], default-features = false, optional = true}
sudo = {version = "0.5", optional = true}
self_update = { version = "0.30.0", features = [
"archive-tar",
"compression-flate2",
"rustls",
], default-features = false, optional = true }
sudo = { version = "0.5", optional = true }

[features]
default = ["update"]
update = ["self_update", "sudo"]

[profile.release]
lto = true
lto = true
opt-level = "z" # Optimize for size.
strip = true # Automatically strip symbols from the binary.
strip = true # Automatically strip symbols from the binary.
12 changes: 9 additions & 3 deletions autocorrect-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ crate-type = ["cdylib"]

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
autocorrect = {path = "../autocorrect", version = ">= 1.0.0"}
autocorrect-cli = {path = "../autocorrect-cli", version = ">= 2.6", default-features = false}
napi = {version = "2.14.1", default-features = false, features = ["napi4", "async"]}
autocorrect = { path = "../autocorrect", version = ">= 1.0.0" }
autocorrect-cli = { path = "../autocorrect-cli", version = ">= 2.6", default-features = false }
napi = { version = "2.14.1", default-features = false, features = [
"napi4",
"async",
] }
napi-derive = "2.14.2"

[build-dependencies]
napi-build = "2.1.0"

[profile.release]
lto = true

[package.metadata.cargo-machete]
ignored = ["napi"]
1 change: 0 additions & 1 deletion autocorrect-rb/ext/autocorrect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ name = "autocorrect"
[dependencies]
autocorrect = "2"
magnus = "0.6"
rb-sys = { version = "*", default-features = false, features = ["stable-api-compiled-fallback"] }
5 changes: 2 additions & 3 deletions autocorrect-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ version = "2.9.0"
crate-type = ["cdylib", "rlib"]

[dependencies]
autocorrect = {path = "../autocorrect", version = "^2.0"}
serde = {version = "1.0.127", features = ["derive"]}
autocorrect = { path = "../autocorrect", version = "^2.0" }
serde_json = "1.0.66"
wasm-bindgen = {version = "0.2.83", features = ["serde-serialize"]}
wasm-bindgen = { version = "0.2.83", features = ["serde-serialize"] }

[package.metadata.wasm-pack.profile.release]
wasm-opt = false
6 changes: 6 additions & 0 deletions autocorrect/src/result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub enum Severity {
Warning = 2,
}

impl Default for Severity {
fn default() -> Self {
Severity::Pass
}
}

impl Severity {
pub fn is_error(&self) -> bool {
self == &Severity::Error
Expand Down
1 change: 1 addition & 0 deletions autocorrect/src/rule/halfwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ lazy_static! {
);
}

#[allow(dead_code)]
trait CharMatching {
fn is_ascii_alphanumeric_punctuation(&self) -> bool;
fn is_alphanumeric_or_space(&self) -> bool;
Expand Down
11 changes: 6 additions & 5 deletions autocorrect/src/rule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,17 @@ pub(crate) fn format_or_lint_with_disable_rules(
lint: bool,
disable_rules: &HashMap<String, bool>,
) -> RuleResult {
let mut result = RuleResult::new(text);
let mut result = RuleResult::default();

// skip if not has CJK
if CJK_RE.is_match(text) {
result.out = String::from("");
let mut part = String::new();
for ch in text.chars() {
part.push(ch);

// Is next char is newline or space, break part to format
if ch == ' ' || ch == '\n' || ch == '\r' {
let mut sub_result = RuleResult::new(&part.clone());
if matches!(ch, ' ' | '\n' | '\r') {
let mut sub_result = RuleResult::new(&part);
sub_result.severity = result.severity;

part.clear();
Expand All @@ -110,14 +109,16 @@ pub(crate) fn format_or_lint_with_disable_rules(
}

if !part.is_empty() {
let mut sub_result = RuleResult::new(&part.clone());
let mut sub_result = RuleResult::new(&part);
sub_result.severity = result.severity;

format_part(&mut sub_result, lint, disable_rules);

result.out.push_str(&sub_result.out);
result.severity = sub_result.severity;
}
} else {
result.out = text.to_string();
}

format_after_rules(&mut result, lint, disable_rules);
Expand Down
3 changes: 2 additions & 1 deletion autocorrect/src/rule/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) struct Rule {
pub format_fn: fn(input: &str) -> String,
}

#[derive(Default)]
pub(crate) struct RuleResult {
pub out: String,
pub severity: Severity,
Expand All @@ -16,7 +17,7 @@ impl RuleResult {
pub fn new(input: &str) -> Self {
Self {
out: input.to_string(),
severity: Severity::Pass,
..Default::default()
}
}
}
Expand Down

0 comments on commit e9be92e

Please sign in to comment.