Skip to content

Commit 7d4b8e6

Browse files
committed
style: Make clippy happy
1 parent 66b82df commit 7d4b8e6

33 files changed

+219
-218
lines changed

Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@ rest_pat_in_fully_bound_structs = "warn"
7676
same_functions_in_if_condition = "warn"
7777
self_named_module_files = "warn"
7878
semicolon_if_nothing_returned = "warn"
79-
str_to_string = "warn"
80-
string_add = "warn"
79+
# str_to_string = "warn"
80+
# string_add = "warn"
8181
string_add_assign = "warn"
8282
string_lit_as_bytes = "warn"
83-
string_to_string = "warn"
83+
# string_to_string = "warn"
8484
todo = "warn"
8585
trait_duplication_in_bounds = "warn"
8686
verbose_file_reads = "warn"
87-
wildcard_imports = "warn"
87+
# wildcard_imports = "warn"
8888
zero_sized_map_values = "warn"
89+
assigning_clones = "allow" # TODO
8990

9091
[package]
9192
name = "cobalt-bin"

crates/config/src/collection.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use super::*;
88
pub struct Collection {
99
pub title: Option<liquid_core::model::KString>,
1010
pub description: Option<liquid_core::model::KString>,
11-
pub dir: Option<crate::RelPath>,
12-
pub drafts_dir: Option<crate::RelPath>,
11+
pub dir: Option<RelPath>,
12+
pub drafts_dir: Option<RelPath>,
1313
pub order: SortOrder,
14-
pub rss: Option<crate::RelPath>,
15-
pub jsonfeed: Option<crate::RelPath>,
14+
pub rss: Option<RelPath>,
15+
pub jsonfeed: Option<RelPath>,
1616
pub publish_date_in_filename: bool,
1717
pub default: Frontmatter,
1818
}
@@ -54,7 +54,7 @@ impl From<PageCollection> for Collection {
5454
});
5555
Self {
5656
default,
57-
dir: Some(crate::RelPath::new()),
57+
dir: Some(RelPath::new()),
5858
order: SortOrder::None,
5959
..Default::default()
6060
}
@@ -78,11 +78,11 @@ pub struct PageCollection {
7878
pub struct PostCollection {
7979
pub title: Option<liquid_core::model::KString>,
8080
pub description: Option<liquid_core::model::KString>,
81-
pub dir: crate::RelPath,
82-
pub drafts_dir: Option<crate::RelPath>,
81+
pub dir: RelPath,
82+
pub drafts_dir: Option<RelPath>,
8383
pub order: SortOrder,
84-
pub rss: Option<crate::RelPath>,
85-
pub jsonfeed: Option<crate::RelPath>,
84+
pub rss: Option<RelPath>,
85+
pub jsonfeed: Option<RelPath>,
8686
pub publish_date_in_filename: bool,
8787
pub default: Frontmatter,
8888
}
@@ -92,7 +92,7 @@ impl Default for PostCollection {
9292
Self {
9393
title: Default::default(),
9494
description: Default::default(),
95-
dir: crate::RelPath::from_unchecked("posts"),
95+
dir: RelPath::from_unchecked("posts"),
9696
drafts_dir: Default::default(),
9797
order: Default::default(),
9898
rss: Default::default(),

crates/config/src/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use super::*;
1212
pub struct Config {
1313
#[serde(skip)]
1414
pub root: path::PathBuf,
15-
pub source: crate::RelPath,
16-
pub destination: crate::RelPath,
15+
pub source: RelPath,
16+
pub destination: RelPath,
1717
#[serde(skip)]
1818
pub abs_dest: Option<path::PathBuf>,
1919
pub include_drafts: bool,
20-
pub default: frontmatter::Frontmatter,
20+
pub default: Frontmatter,
2121
pub pages: PageCollection,
2222
pub posts: PostCollection,
2323
pub site: Site,
@@ -79,8 +79,8 @@ impl Config {
7979

8080
let mut root = path;
8181
root.pop(); // Remove filename
82-
if root == std::path::Path::new("") {
83-
root = std::path::Path::new(".").to_owned();
82+
if root == path::Path::new("") {
83+
root = path::Path::new(".").to_owned();
8484
}
8585
config.root = root;
8686

@@ -111,7 +111,7 @@ impl Config {
111111
}
112112

113113
impl fmt::Display for Config {
114-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
114+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
115115
let mut converted = serde_yaml::to_string(self).map_err(|_| fmt::Error)?;
116116
converted.drain(..4);
117117
write!(f, "{}", converted)

crates/config/src/document.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::Status;
66

77
#[derive(Debug, Eq, PartialEq, Default, Clone)]
88
pub struct Document {
9-
front: crate::Frontmatter,
9+
front: Frontmatter,
1010
content: liquid_core::model::KString,
1111
}
1212

@@ -33,7 +33,7 @@ impl Document {
3333
}
3434

3535
impl fmt::Display for Document {
36-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3737
let front = self.front.to_string();
3838
if front.is_empty() {
3939
write!(f, "{}", self.content)

crates/config/src/frontmatter.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ impl Frontmatter {
5353

5454
pub fn merge_path(mut self, relpath: &relative_path::RelativePath) -> Self {
5555
if let Some(name) = relpath.file_name() {
56-
let mut split_name = crate::path::split_ext(name);
56+
let mut split_name = path::split_ext(name);
5757

5858
#[cfg(feature = "preview_unstable")]
5959
if split_name.1 == Some("liquid") {
6060
self.templated.get_or_insert(true);
61-
split_name = crate::path::split_ext(split_name.0);
61+
split_name = path::split_ext(split_name.0);
6262
} else {
6363
self.templated.get_or_insert(false);
6464
}
@@ -70,19 +70,19 @@ impl Frontmatter {
7070
self.format.get_or_insert(format);
7171

7272
while split_name.1.is_some() {
73-
split_name = crate::path::split_ext(split_name.0);
73+
split_name = path::split_ext(split_name.0);
7474
}
7575

7676
if self.published_date.is_none() || self.slug.is_none() {
7777
let file_stem = split_name.0;
78-
let (file_date, file_stem) = crate::path::parse_file_stem(file_stem);
78+
let (file_date, file_stem) = path::parse_file_stem(file_stem);
7979
if self.published_date.is_none() {
8080
self.published_date = file_date;
8181
}
8282
if self.slug.is_none() {
83-
let slug = crate::path::slugify(file_stem);
83+
let slug = path::slugify(file_stem);
8484
if self.title.is_none() {
85-
self.title = Some(crate::path::titleize_slug(&slug));
85+
self.title = Some(path::titleize_slug(&slug));
8686
}
8787
self.slug = Some(slug);
8888
}
@@ -135,7 +135,7 @@ impl Frontmatter {
135135
}
136136

137137
impl fmt::Display for Frontmatter {
138-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
138+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139139
let converted = serde_yaml::to_string(self).expect("should always be valid");
140140
let subset = converted
141141
.strip_prefix("---")
@@ -199,7 +199,7 @@ impl Default for Permalink {
199199
}
200200

201201
impl fmt::Display for Permalink {
202-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
202+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
203203
write!(f, "{}", self.as_str())
204204
}
205205
}
@@ -230,13 +230,13 @@ impl ExplicitPermalink {
230230
}
231231
}
232232

233-
impl std::fmt::Display for ExplicitPermalink {
234-
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
233+
impl fmt::Display for ExplicitPermalink {
234+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
235235
self.0.fmt(fmt)
236236
}
237237
}
238238

239-
impl<'s> std::convert::TryFrom<&'s str> for ExplicitPermalink {
239+
impl<'s> TryFrom<&'s str> for ExplicitPermalink {
240240
type Error = &'static str;
241241

242242
fn try_from(value: &str) -> Result<Self, Self::Error> {
@@ -249,7 +249,7 @@ impl<'s> std::convert::TryFrom<&'s str> for ExplicitPermalink {
249249
}
250250
}
251251

252-
impl std::convert::TryFrom<String> for ExplicitPermalink {
252+
impl TryFrom<String> for ExplicitPermalink {
253253
type Error = &'static str;
254254

255255
fn try_from(value: String) -> Result<Self, Self::Error> {

crates/config/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
22
#![warn(clippy::print_stderr)]
33
#![warn(clippy::print_stdout)]
4+
#![allow(clippy::self_named_module_files)] // false positive
45

56
mod assets;
67
mod collection;

crates/config/src/path.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ impl<'s> PartialEq<&'s str> for RelPath {
100100
}
101101

102102
impl std::fmt::Display for RelPath {
103-
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
103+
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104104
self.0.fmt(fmt)
105105
}
106106
}
107107

108-
impl<'s> std::convert::TryFrom<&'s str> for RelPath {
108+
impl<'s> TryFrom<&'s str> for RelPath {
109109
type Error = &'static str;
110110

111111
fn try_from(value: &str) -> Result<Self, Self::Error> {
@@ -118,7 +118,7 @@ impl<'s> std::convert::TryFrom<&'s str> for RelPath {
118118
}
119119
}
120120

121-
impl std::convert::TryFrom<String> for RelPath {
121+
impl TryFrom<String> for RelPath {
122122
type Error = &'static str;
123123

124124
fn try_from(value: String) -> Result<Self, Self::Error> {

crates/core/src/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Source {
1313
ignores: impl IntoIterator<Item = &'i str>,
1414
) -> Result<Self> {
1515
let mut ignore = ignore::gitignore::GitignoreBuilder::new(root);
16-
for line in ignores.into_iter() {
16+
for line in ignores {
1717
ignore
1818
.add_line(None, line)
1919
.map_err(|e| Status::new("Invalid ignore entry").with_source(e))?;

src/bin/cobalt/args.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::path;
33

44
use anyhow::Context as _;
55

6-
use crate::error::*;
6+
use crate::error::Result;
77

88
#[derive(Clone, Debug, PartialEq, Eq, clap::Args)]
9-
pub struct ConfigArgs {
9+
pub(crate) struct ConfigArgs {
1010
/// Config file to use [default: _cobalt.yml]
1111
#[arg(short, long, value_name = "FILE")]
1212
config: Option<path::PathBuf>,
@@ -25,7 +25,7 @@ pub struct ConfigArgs {
2525
}
2626

2727
impl ConfigArgs {
28-
pub fn load_config(&self) -> Result<cobalt_config::Config> {
28+
pub(crate) fn load_config(&self) -> Result<cobalt_config::Config> {
2929
let config_path = self.config.as_deref();
3030

3131
// Fetch config information if available
@@ -53,7 +53,7 @@ impl ConfigArgs {
5353
Ok(config)
5454
}
5555

56-
pub fn drafts(&self) -> Option<bool> {
56+
pub(crate) fn drafts(&self) -> Option<bool> {
5757
resolve_bool_arg(self.drafts, self.no_drafts)
5858
}
5959
}
@@ -67,7 +67,7 @@ fn resolve_bool_arg(yes: bool, no: bool) -> Option<bool> {
6767
}
6868
}
6969

70-
pub fn init_logging(
70+
pub(crate) fn init_logging(
7171
level: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
7272
colored: bool,
7373
) {
@@ -132,7 +132,7 @@ struct Palette {
132132
}
133133

134134
impl Palette {
135-
pub fn colored() -> Self {
135+
pub(crate) fn colored() -> Self {
136136
Self {
137137
error: yansi::Style::new(yansi::Color::Red).bold(),
138138
warn: yansi::Style::new(yansi::Color::Yellow),
@@ -141,7 +141,7 @@ impl Palette {
141141
}
142142
}
143143

144-
pub fn plain() -> Self {
144+
pub(crate) fn plain() -> Self {
145145
Self {
146146
error: yansi::Style::default(),
147147
warn: yansi::Style::default(),

src/bin/cobalt/build.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use std::env;
22
use std::fs;
33

44
use crate::args;
5-
use crate::error::*;
5+
use crate::error::Result;
66

77
/// Build the cobalt project at the source dir
88
#[derive(Clone, Debug, PartialEq, Eq, clap::Args)]
9-
pub struct BuildArgs {
9+
pub(crate) struct BuildArgs {
1010
#[command(flatten, next_help_heading = "Config")]
11-
pub config: args::ConfigArgs,
11+
pub(crate) config: args::ConfigArgs,
1212
}
1313

1414
impl BuildArgs {
15-
pub fn run(&self) -> Result<()> {
15+
pub(crate) fn run(&self) -> Result<()> {
1616
let config = self.config.load_config()?;
1717
let config = cobalt::cobalt_model::Config::from_config(config)?;
1818

@@ -23,7 +23,7 @@ impl BuildArgs {
2323
}
2424
}
2525

26-
pub fn build(config: cobalt::Config) -> Result<()> {
26+
pub(crate) fn build(config: cobalt::Config) -> Result<()> {
2727
info!(
2828
"Building from `{}` into `{}`",
2929
config.source.display(),
@@ -36,21 +36,21 @@ pub fn build(config: cobalt::Config) -> Result<()> {
3636

3737
/// Cleans `destination` directory
3838
#[derive(Clone, Debug, PartialEq, Eq, clap::Args)]
39-
pub struct CleanArgs {
39+
pub(crate) struct CleanArgs {
4040
#[command(flatten, next_help_heading = "Config")]
41-
pub config: args::ConfigArgs,
41+
pub(crate) config: args::ConfigArgs,
4242
}
4343

4444
impl CleanArgs {
45-
pub fn run(&self) -> Result<()> {
45+
pub(crate) fn run(&self) -> Result<()> {
4646
let config = self.config.load_config()?;
4747
let config = cobalt::cobalt_model::Config::from_config(config)?;
4848

4949
clean(&config)
5050
}
5151
}
5252

53-
pub fn clean(config: &cobalt::Config) -> Result<()> {
53+
pub(crate) fn clean(config: &cobalt::Config) -> Result<()> {
5454
let cwd = env::current_dir().unwrap_or_default();
5555
let destdir = dunce::canonicalize(&config.destination);
5656
let destdir = match destdir {

src/bin/cobalt/debug.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::args;
2-
use crate::error::*;
2+
use crate::error::Result;
33

44
/// Print site debug information
55
#[derive(Clone, Debug, PartialEq, Eq, clap::Subcommand)]
6-
pub enum DebugCommands {
6+
pub(crate) enum DebugCommands {
77
/// Prints post-processed config
88
Config {
99
#[command(flatten, next_help_heading = "Confg")]
@@ -25,7 +25,7 @@ pub enum DebugCommands {
2525
}
2626

2727
#[derive(Clone, Debug, PartialEq, Eq, clap::Subcommand)]
28-
pub enum HighlightCommands {
28+
pub(crate) enum HighlightCommands {
2929
Themes {
3030
#[command(flatten, next_help_heading = "Config")]
3131
config: args::ConfigArgs,
@@ -37,7 +37,7 @@ pub enum HighlightCommands {
3737
}
3838

3939
impl DebugCommands {
40-
pub fn run(&self) -> Result<()> {
40+
pub(crate) fn run(&self) -> Result<()> {
4141
match self {
4242
Self::Config { config } => {
4343
let config = config.load_config()?;

src/bin/cobalt/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub use anyhow::Error;
2-
pub type Result<T> = std::result::Result<T, Error>;
1+
pub(crate) use anyhow::Error;
2+
pub(crate) type Result<T> = std::result::Result<T, Error>;

0 commit comments

Comments
 (0)