Skip to content

Commit

Permalink
Fixed a lot of clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Sep 23, 2023
1 parent 4952fb2 commit 17d2e41
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 319 deletions.
103 changes: 91 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,110 @@ env:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt, clippy
- name: Cache Cargo registry
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache target
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}

key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --verbose

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --verbose
- name: Check formatting
run: cargo fmt -- --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true
- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run Clippy
run: cargo clippy -- -D warnings

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true
- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run fmt
run: cargo fmt -- --check
5 changes: 3 additions & 2 deletions src/bin/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn run_tree_test(test_idx: usize, test: &Test, results: &mut TestResults) {
let mut parser = Html5Parser::new(&mut is);
let (document, _parse_errors) = parser.parse();

match_document_tree(&document, &test.document);
match_document_tree(document, &test.document);

// if parse_errors.len() != test.errors.len() {
// println!("❌ Unexpected errors found (wanted {}, got {}): ", test.errors.len(), parse_errors.len());
Expand Down Expand Up @@ -349,5 +349,6 @@ fn match_error(got_err: &Error, expected_err: &Error) -> ErrorResult {
"⚠️ Unexpected error position '{}' at {}:{} (got: {}:{})",
expected_err.code, expected_err.line, expected_err.col, got_err.line, got_err.col
);
return ErrorResult::PositionFailure;

ErrorResult::PositionFailure
}
16 changes: 7 additions & 9 deletions src/bin/tokenizer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn run_token_test(test: &Test, results: &mut TestResults) {

// Check error messages
for error in &test.errors {
match match_error(&tokenizer, &error) {
match match_error(&tokenizer, error) {
ErrorResult::Failure => {
results.assertions += 1;
results.failed += 1;
Expand Down Expand Up @@ -223,12 +223,10 @@ fn match_error(tokenizer: &Tokenizer, expected_err: &Error) -> ErrorResult {
// it's not always correct, it might be a off-by-one position.
let mut result = ErrorResult::Failure;
for got_err in tokenizer.get_error_logger().get_errors() {
if got_err.message == expected_err.code {
if got_err.line as i64 != expected_err.line || got_err.col as i64 != expected_err.col {
// println!("❌ Expected error '{}' at {}:{}", expected_err.code, expected_err.line, expected_err.col);
result = ErrorResult::PositionFailure;
break;
}
if got_err.message == expected_err.code && (got_err.line as i64 != expected_err.line || got_err.col as i64 != expected_err.col) {
// println!("❌ Expected error '{}' at {}:{}", expected_err.code, expected_err.line, expected_err.col);
result = ErrorResult::PositionFailure;
break;
}
}

Expand Down Expand Up @@ -342,7 +340,7 @@ fn check_match_starttag(
return Err(());
}

if expected_attrs.is_none() && attributes.len() == 0 {
if expected_attrs.is_none() && attributes.is_empty() {
// No attributes to check
return Ok(());
}
Expand Down Expand Up @@ -452,7 +450,7 @@ fn check_match_doctype(
let expected_sys = expected.get(3).unwrap().as_str();
let expected_quirk = expected.get(4).unwrap().as_bool();

if expected_name.is_none() && !name.is_none() {
if expected_name.is_none() && name.is_some() {
println!(
"❌ Incorrect doctype (no name expected, but got '{}')",
name.unwrap()
Expand Down
65 changes: 0 additions & 65 deletions src/html5_parser/dom/dom.rs

This file was deleted.

66 changes: 65 additions & 1 deletion src/html5_parser/dom/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
pub mod dom;
use std::collections::HashMap;

pub struct ShadowRoot {
pub mode: ShadowRootMode,
pub delegates_focus: bool,
pub slot_assignment: SlotAssignmentMode,
pub host: Box<Element>,
// pub onslotchange: Option<EventHandler>,
}

pub enum SlotAssignmentMode {
Manual,
Named,
}

pub enum ShadowRootMode {
Open,
Closed,
}

pub struct Element {
pub namespace_uri: Option<String>,
pub prefix: Option<String>,
pub local_name: String,
pub tag_name: String,
pub id: String,
pub class_name: String,
pub class_list: Vec<String>,
pub slot: String,
pub attributes: HashMap<String, String>,
pub shadow_root: Option<Box<ShadowRoot>>,
}

pub struct HtmlElement {
// Element fields
pub namespace_uri: Option<String>,
pub prefix: Option<String>,
pub local_name: String,
pub tag_name: String,
pub id: String,
pub class_name: String,
pub class_list: Vec<String>,
pub slot: String,
pub attributes: HashMap<String, String>,
pub shadow_root: Option<ShadowRoot>,

// HTML Element
pub title: String,
pub lang: String,
pub translate: bool,
pub dir: String,

pub hidden: Option<bool>,
pub insert: bool,
pub access_key: String,
pub access_key_label: String,
pub draggable: bool,
pub spellcheck: bool,
pub autocapitalize: String,

pub inner_text: String,
pub outer_text: String,

pub popover: Option<String>,
}
8 changes: 7 additions & 1 deletion src/html5_parser/error_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ impl ErrorLogger {
}
}

impl Default for ErrorLogger {
fn default() -> Self {
Self::new()
}
}

impl ErrorLogger {
// Returns a cloned instance of the errors
pub fn get_errors(&self) -> Vec<ParseError> {
Expand All @@ -183,7 +189,7 @@ impl ErrorLogger {
pub fn add_error(&mut self, pos: Position, message: &str) {
// Check if the error already exists, if so, don't add it again
for err in &self.errors {
if err.line == pos.line && err.col == pos.col && err.message == message.to_string() {
if err.line == pos.line && err.col == pos.col && err.message == *message {
return;
}
}
Expand Down
Loading

0 comments on commit 17d2e41

Please sign in to comment.