Skip to content

Commit 5c6d040

Browse files
authored
Fix clippy lints (#1188)
1 parent f27697e commit 5c6d040

File tree

32 files changed

+344
-383
lines changed

32 files changed

+344
-383
lines changed

pgml-dashboard/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
println!("cargo:rerun-if-changed=migrations");
66

77
let output = Command::new("git")
8-
.args(&["rev-parse", "HEAD"])
8+
.args(["rev-parse", "HEAD"])
99
.output()
1010
.unwrap();
1111
let git_hash = String::from_utf8(output.stdout).unwrap();

pgml-dashboard/src/api/chatbot.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ pub async fn wrapped_chatbot_get_answer(
298298
history.reverse();
299299
let history = history.join("\n");
300300

301-
let mut pipeline = Pipeline::new("v1", None, None, None);
301+
let pipeline = Pipeline::new("v1", None, None, None);
302302
let context = collection
303303
.query()
304-
.vector_recall(&data.question, &mut pipeline, Some(json!({
304+
.vector_recall(&data.question, &pipeline, Some(json!({
305305
"instruction": "Represent the Wikipedia question for retrieving supporting documents: "
306306
}).into()))
307307
.limit(5)
@@ -312,9 +312,8 @@ pub async fn wrapped_chatbot_get_answer(
312312
.collect::<Vec<String>>()
313313
.join("\n");
314314

315-
let answer = match brain {
316-
_ => get_openai_chatgpt_answer(knowledge_base, &history, &context, &data.question).await,
317-
}?;
315+
let answer =
316+
get_openai_chatgpt_answer(knowledge_base, &history, &context, &data.question).await?;
318317

319318
let new_history_messages: Vec<pgml::types::Json> = vec![
320319
serde_json::to_value(user_document).unwrap().into(),

pgml-dashboard/src/api/cms.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,20 @@ impl Collection {
8888
fn build_index(&mut self, hide_root: bool) {
8989
let summary_path = self.root_dir.join("SUMMARY.md");
9090
let summary_contents = std::fs::read_to_string(&summary_path)
91-
.expect(format!("Could not read summary: {summary_path:?}").as_str());
91+
.unwrap_or_else(|_| panic!("Could not read summary: {summary_path:?}"));
9292
let mdast = markdown::to_mdast(&summary_contents, &::markdown::ParseOptions::default())
93-
.expect(format!("Could not parse summary: {summary_path:?}").as_str());
93+
.unwrap_or_else(|_| panic!("Could not parse summary: {summary_path:?}"));
9494

9595
for node in mdast
9696
.children()
97-
.expect(format!("Summary has no content: {summary_path:?}").as_str())
97+
.unwrap_or_else(|| panic!("Summary has no content: {summary_path:?}"))
9898
.iter()
9999
{
100100
match node {
101101
Node::List(list) => {
102-
self.index = self.get_sub_links(&list).expect(
103-
format!("Could not parse list of index links: {summary_path:?}").as_str(),
104-
);
102+
self.index = self.get_sub_links(list).unwrap_or_else(|_| {
103+
panic!("Could not parse list of index links: {summary_path:?}")
104+
});
105105
break;
106106
}
107107
_ => {
@@ -221,13 +221,13 @@ impl Collection {
221221
let root = parse_document(&arena, &contents, &crate::utils::markdown::options());
222222

223223
// Title of the document is the first (and typically only) <h1>
224-
let title = crate::utils::markdown::get_title(&root).unwrap();
225-
let toc_links = crate::utils::markdown::get_toc(&root).unwrap();
226-
let image = crate::utils::markdown::get_image(&root);
227-
crate::utils::markdown::wrap_tables(&root, &arena).unwrap();
224+
let title = crate::utils::markdown::get_title(root).unwrap();
225+
let toc_links = crate::utils::markdown::get_toc(root).unwrap();
226+
let image = crate::utils::markdown::get_image(root);
227+
crate::utils::markdown::wrap_tables(root, &arena).unwrap();
228228

229229
// MkDocs syntax support, e.g. tabs, notes, alerts, etc.
230-
crate::utils::markdown::mkdocs(&root, &arena).unwrap();
230+
crate::utils::markdown::mkdocs(root, &arena).unwrap();
231231

232232
// Style headings like we like them
233233
let mut plugins = ComrakPlugins::default();
@@ -255,7 +255,7 @@ impl Collection {
255255
.iter_mut()
256256
.map(|nav_link| {
257257
let mut nav_link = nav_link.clone();
258-
nav_link.should_open(&path);
258+
nav_link.should_open(path);
259259
nav_link
260260
})
261261
.collect();
@@ -273,11 +273,11 @@ impl Collection {
273273
let image_path = collection.url_root.join(".gitbook/assets").join(parts[1]);
274274
layout.image(config::asset_url(image_path.to_string_lossy()).as_ref());
275275
}
276-
if description.is_some() {
277-
layout.description(&description.unwrap());
276+
if let Some(description) = &description {
277+
layout.description(description);
278278
}
279-
if user.is_some() {
280-
layout.user(&user.unwrap());
279+
if let Some(user) = &user {
280+
layout.user(user);
281281
}
282282

283283
let layout = layout
@@ -375,7 +375,7 @@ SELECT * FROM test;
375375
"#;
376376

377377
let arena = Arena::new();
378-
let root = parse_document(&arena, &code, &options());
378+
let root = parse_document(&arena, code, &options());
379379

380380
// Style headings like we like them
381381
let mut plugins = ComrakPlugins::default();
@@ -404,11 +404,11 @@ This is the end of the markdown
404404
"#;
405405

406406
let arena = Arena::new();
407-
let root = parse_document(&arena, &markdown, &options());
407+
let root = parse_document(&arena, markdown, &options());
408408

409409
let plugins = ComrakPlugins::default();
410410

411-
crate::utils::markdown::wrap_tables(&root, &arena).unwrap();
411+
crate::utils::markdown::wrap_tables(root, &arena).unwrap();
412412

413413
let mut html = vec![];
414414
format_html_with_plugins(root, &options(), &mut html, &plugins).unwrap();
@@ -436,11 +436,11 @@ This is the end of the markdown
436436
"#;
437437

438438
let arena = Arena::new();
439-
let root = parse_document(&arena, &markdown, &options());
439+
let root = parse_document(&arena, markdown, &options());
440440

441441
let plugins = ComrakPlugins::default();
442442

443-
crate::utils::markdown::wrap_tables(&root, &arena).unwrap();
443+
crate::utils::markdown::wrap_tables(root, &arena).unwrap();
444444

445445
let mut html = vec![];
446446
format_html_with_plugins(root, &options(), &mut html, &plugins).unwrap();

pgml-dashboard/src/components/chatbot/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const EXAMPLE_QUESTIONS: ExampleQuestions = [
4141
),
4242
];
4343

44-
const KNOWLEDGE_BASES: [&'static str; 0] = [
44+
const KNOWLEDGE_BASES: [&str; 0] = [
4545
// "Knowledge Base 1",
4646
// "Knowledge Base 2",
4747
// "Knowledge Base 3",
@@ -117,8 +117,8 @@ pub struct Chatbot {
117117
knowledge_bases_with_logo: &'static [KnowledgeBaseWithLogo; 4],
118118
}
119119

120-
impl Chatbot {
121-
pub fn new() -> Chatbot {
120+
impl Default for Chatbot {
121+
fn default() -> Self {
122122
Chatbot {
123123
brains: &CHATBOT_BRAINS,
124124
example_questions: &EXAMPLE_QUESTIONS,
@@ -128,4 +128,10 @@ impl Chatbot {
128128
}
129129
}
130130

131+
impl Chatbot {
132+
pub fn new() -> Self {
133+
Self::default()
134+
}
135+
}
136+
131137
component!(Chatbot);

pgml-dashboard/src/components/inputs/range_group/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl RangeGroup {
2525
pub fn new(title: &str) -> RangeGroup {
2626
RangeGroup {
2727
title: title.to_owned(),
28-
identifier: title.replace(" ", "_").to_lowercase(),
28+
identifier: title.replace(' ', "_").to_lowercase(),
2929
min: 0,
3030
max: 100,
3131
step: 1.0,
@@ -42,7 +42,7 @@ impl RangeGroup {
4242
}
4343

4444
pub fn identifier(mut self, identifier: &str) -> Self {
45-
self.identifier = identifier.replace(" ", "_").to_owned();
45+
self.identifier = identifier.replace(' ', "_").to_owned();
4646
self
4747
}
4848

pgml-dashboard/src/components/inputs/switch/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub struct Switch {
3030
target: StimulusTarget,
3131
}
3232

33-
impl Switch {
34-
pub fn new() -> Switch {
33+
impl Default for Switch {
34+
fn default() -> Self {
3535
Switch {
3636
left_value: String::from("left"),
3737
left_icon: String::from(""),
@@ -42,6 +42,12 @@ impl Switch {
4242
target: StimulusTarget::new(),
4343
}
4444
}
45+
}
46+
47+
impl Switch {
48+
pub fn new() -> Self {
49+
Self::default()
50+
}
4551

4652
pub fn left(mut self, value: &str, icon: &str) -> Switch {
4753
self.left_value = value.into();

pgml-dashboard/src/components/inputs/text/editable_header/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,22 @@ pub struct EditableHeader {
3535
id: String,
3636
}
3737

38-
impl EditableHeader {
39-
pub fn new() -> EditableHeader {
40-
EditableHeader {
38+
impl Default for EditableHeader {
39+
fn default() -> Self {
40+
Self {
4141
value: String::from("Title Goes Here"),
4242
header_type: Headers::H3,
4343
input_target: StimulusTarget::new(),
4444
input_name: None,
4545
id: String::from(""),
4646
}
4747
}
48+
}
49+
50+
impl EditableHeader {
51+
pub fn new() -> Self {
52+
Self::default()
53+
}
4854

4955
pub fn header_type(mut self, header_type: Headers) -> Self {
5056
self.header_type = header_type;

pgml-dashboard/src/components/navigation/tabs/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ pub mod tab;
66
pub use tab::Tab;
77

88
// src/components/navigation/tabs/tabs
9+
#[allow(clippy::module_inception)]
910
pub mod tabs;
1011
pub use tabs::Tabs;

pgml-dashboard/src/components/navigation/tabs/tab/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Tab {
3737
}
3838

3939
pub fn id(&self) -> String {
40-
format!("tab-{}", self.name.to_lowercase().replace(" ", "-"))
40+
format!("tab-{}", self.name.to_lowercase().replace(' ', "-"))
4141
}
4242

4343
pub fn selected(&self) -> String {

pgml-dashboard/src/components/profile_icon/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct ProfileIcon;
77

88
impl ProfileIcon {
99
pub fn new() -> ProfileIcon {
10-
ProfileIcon::default()
10+
ProfileIcon
1111
}
1212
}
1313

0 commit comments

Comments
 (0)