Skip to content

Commit

Permalink
Cleaned up lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Mar 11, 2023
1 parent 4e37bbd commit 687ce4c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "twyne"
description = "A Rust library for parsing Twine story/game export files (JSON format)"
readme = "README.md"
version = "0.2.0-dev"
version = "0.2.0"
license = "Apache-2.0"
authors = ["Duncan McGreggor <[email protected]>"]
repository = "https://github.com/oxur/twyne"
Expand Down
46 changes: 43 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
PROJ = twyne

default: all

all: deps build test demos
all: clean deps build lint test examples

auth:
@echo "Copy and paste the following in the terminal where you"
Expand All @@ -12,14 +14,52 @@ auth:
build:
@cargo build

clean:
@cargo clean
@rm -f $(BIN_DIR)/$(PROJ)

clean-all: clean
@rm .crates.toml .crates2.json Cargo.lock

fresh-all: clean-all all

fresh: clean all

lint:
@cargo +nightly clippy --version
@cargo +nightly clippy --all-targets --all-features -- --no-deps -D clippy::all

cicd-lint:
@cargo clippy --version
@cargo clippy --all-targets --all-features -- --no-deps -D clippy::all

check:
@cargo deny check
@cargo +nightly udeps

test:
@cargo test
@RUST_BACKTRACE=1 cargo test

demos:
examples:
@cargo run --example=demo

deps:
@cargo update

publish:
@cargo publish

nightly:
@rustup toolchain install nightly

install-cargo-deny:
@echo ">> Installing cargo deny ..."
@cargo install --locked cargo-deny

setup-cargo-deny: install-cargo-deny
@echo ">> Setting up cargo deny ..."
@cargo deny init

install-udeps:
@echo ">> Setting up cargo udeps ..."
@cargo install cargo-udeps --locked
10 changes: 5 additions & 5 deletions src/harlowe/json/parser.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use super::schema;
use serde_json;
use std::error::Error;
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use serde_json;
use super::schema;

pub fn parse_file<P: AsRef<Path>>(path: P) -> Result<schema::Game, Box<dyn Error>> {
let file = File::open(path)?;
let file = File::open(path)?;
let reader = BufReader::new(file);
let g = serde_json::from_reader(reader)?;
Ok(g)
}

pub fn parse_bytes<'a>(data: &'a [u8]) -> serde_json::Result<schema::Game> {
pub fn parse_bytes(data: &[u8]) -> serde_json::Result<schema::Game> {
serde_json::from_slice(data)
}

pub fn parse_str<'a>(data: &'a str) -> serde_json::Result<schema::Game> {
pub fn parse_str(data: &str) -> serde_json::Result<schema::Game> {
serde_json::from_str(data)
}
4 changes: 2 additions & 2 deletions src/harlowe/json/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// this tool:
// * https://github.com/jtschoonhoven/twine-to-json

use serde::{Deserialize, Serialize};
use semver;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct Passage {

impl Passage {
pub fn tags(&self) -> Vec<String> {
let mut tags: Vec<String> = self.tags.split(" ").map(|s| s.trim().to_string()).collect();
let mut tags: Vec<String> = self.tags.split(' ').map(|s| s.trim().to_string()).collect();
tags.sort();
tags
}
Expand Down
4 changes: 2 additions & 2 deletions tests/harlowe/html/parser.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use twyne::harlowe::html::{parse_file};
use twyne::harlowe::html::parse_file;

use super::utils;

#[test]
fn test_parse_file() {
let game = parse_file(&utils::LOBBY_GAME).unwrap();
let game = parse_file(utils::LOBBY_GAME).unwrap();
// TODO: current html parser is a hack that we'll be moving
// away from ... So not going to bother figuring out how to
// get string literals from the source with no quotes.
Expand Down
7 changes: 5 additions & 2 deletions tests/harlowe/html/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn lobby_game() -> Game {
let data = lobby_game_data_str();
let g: Game = match serde_json::from_str(&data) {
Ok(parsed) => parsed,
Err(error) => panic!("Tests can't run without the sample file: {:?}", error),
Err(error) => panic!("Tests can't run without the sample file: {error:?}"),
};
g
}
Expand Down Expand Up @@ -48,7 +48,10 @@ pub fn check_passages_data(game: &Game) {
let passage: Passage = game.passages[0].clone();
let text: String = passage.text.chars().take(31).collect();
assert_eq!(text, "You are in a lobby -- THE lobby");
assert_eq!(passage.tags(), ["home", "initial-area", "starting-place", "starting-zone"]);
assert_eq!(
passage.tags(),
["home", "initial-area", "starting-place", "starting-zone"]
);
}

#[allow(dead_code)]
Expand Down
4 changes: 2 additions & 2 deletions tests/harlowe/json/parser.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use twyne::harlowe::json::{Game, parse_file, parse_str, parse_bytes};
use twyne::harlowe::json::{parse_bytes, parse_file, parse_str, Game};

use super::utils;

#[test]
fn test_parse_file() {
let game: Game = parse_file(&utils::LOBBY_GAME).unwrap();
let game: Game = parse_file(utils::LOBBY_GAME).unwrap();
utils::check_all_data(&game);
}

Expand Down
7 changes: 5 additions & 2 deletions tests/harlowe/json/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn lobby_game() -> Game {
let data = lobby_game_data_str();
let g: Game = match serde_json::from_str(&data) {
Ok(parsed) => parsed,
Err(error) => panic!("Tests can't run without the sample file: {:?}", error),
Err(error) => panic!("Tests can't run without the sample file: {error:?}"),
};
g
}
Expand Down Expand Up @@ -48,7 +48,10 @@ pub fn check_passages_data(game: &Game) {
let passage: Passage = game.passages[0].clone();
let text: String = passage.text.chars().take(31).collect();
assert_eq!(text, "You are in a lobby -- THE lobby");
assert_eq!(passage.tags(), ["home", "initial-area", "starting-place", "starting-zone"]);
assert_eq!(
passage.tags(),
["home", "initial-area", "starting-place", "starting-zone"]
);
}

#[allow(dead_code)]
Expand Down

0 comments on commit 687ce4c

Please sign in to comment.