Skip to content

Commit

Permalink
Update precious config and make all code tidy and lint-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Jan 2, 2025
1 parent 5320ade commit c05c5e9
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 57 deletions.
1 change: 0 additions & 1 deletion gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ heck = "0.4"
itertools = "0.11"
scraper = "0.17"
walkdir = "2"

3 changes: 1 addition & 2 deletions gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl crate::IconShape for Shape {
VIEW_BOX
}
#[allow(clippy::too_many_lines)]
fn path(&self) -> LazyNodes {
match self {
{PATHS}
Expand Down Expand Up @@ -153,15 +154,13 @@ fn write_icons_file(icons: &[Icon], to: &PathBuf) {
.collect::<Vec<_>>()
.join("\n");
PATH_TEMPLATE
.clone()
.replace("{NAME}", &i.name)
.replace("{ATTRS}", attrs)
})
.collect::<Vec<_>>()
.join("");

let code = TEMPLATE
.clone()
.replace("{VIEWBOX}", &icons[0].viewbox)
.replace("{NAMES}", &names)
.replace("{PATHS}", &paths);
Expand Down
4 changes: 2 additions & 2 deletions git/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

declare -i status
status=0

PRECIOUS=$(which precious)
if [[ -z $PRECIOUS ]]; then
PRECIOUS=./bin/precious
fi

"$PRECIOUS" lint -s
if (( $? != 0 )); then
if ! "$PRECIOUS" lint -s; then
status+=1
fi

Expand Down
112 changes: 88 additions & 24 deletions precious.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,112 @@
exclude = [
"target",
]
exclude = ["target"]

[commands.rustfmt]
type = "both"
[commands.clippy]
type = "lint"
include = "**/*.rs"
cmd = [ "rustfmt", "--edition", "2021" ]
lint_flags = "--check"
invoke = "once"
path-args = "none"
working-dir = "root"
cmd = [
"cargo",
"clippy",
"--color",
"always",
"--all-targets",
"--all-features",
"--",
"-D",
"clippy::pedantic",
]
ok_exit_codes = 0
lint_failure_exit_codes = 1
lint_failure_exit_codes = 101
expect_stderr = true
labels = ["default"]

[commands.clippy]
type = "lint"
include = "**/*.rs"
invoke = "once"
path_args = "none"
[commands."clippy --fix"]
type = "tidy"
include = "**/*.rs"
invoke = "once"
path-args = "none"
working-dir = "root"
cmd = [
"cargo",
"clippy",
"--fix",
"--allow-dirty",
"--all-targets",
"--all-features",
"--workspace",
"--",
"-D", "clippy::all",
"-D",
"clippy::pedantic",
]
ok_exit_codes = 0
lint_failure_exit_codes = 101
ignore_stderr = [ "Checking.+", "Finished.+dev", "could not compile" ]
expect_stderr = true
labels = ["default"]

[commands.rustfmt]
type = "both"
include = "**/*.rs"
cmd = ["rustfmt", "--edition", "2021"]
lint_flags = "--check"
ok_exit_codes = [0]
lint_failure_exit_codes = [1]
labels = ["default", "fast-tidy"]

[commands.omegasort-gitignore]
type = "both"
include = "**/.gitignore"
cmd = ["omegasort", "--sort=path"]
lint_flags = "--check"
tidy_flags = "--in-place"
ok_exit_codes = 0
lint_failure_exit_codes = 1
expect_stderr = true
labels = ["default", "fast-tidy"]

[commands.prettier]
type = "both"
include = [ "**/*.md", "**/*.yml" ]
cmd = [ "./node_modules/.bin/prettier", "--no-config", "--print-width", "100", "--prose-wrap", "always" ]
type = "both"
include = ["**/*.md", "**/*.yml"]
cmd = ["prettier", "--no-config", "--prose-wrap", "always", "--print-width", "100"]
lint_flags = "--check"
tidy_flags = "--write"
ok_exit_codes = 0
lint_failure_exit_codes = 1
ignore_stderr = [ "Code style issues" ]
ignore_stderr = "Code style issues"
labels = ["default", "fast-tidy"]

[commands.omegasort-gitignore]
[commands.shellcheck]
type = "lint"
include = "**/*.sh"
cmd = "shellcheck"
ok_exit_codes = 0
lint_failure_exit_codes = 1

[commands.shfmt]
type = "both"
include = "**/.gitignore"
cmd = [ "omegasort", "--sort", "path", "--unique" ]
include = "**/*.sh"
cmd = ["shfmt", "--simplify", "--indent", "4"]
lint_flags = "--diff"
tidy_flags = "--write"
ok_exit_codes = 0
lint_failure_exit_codes = 1
labels = ["default", "fast-tidy"]

[commands.typos]
type = "lint"
include = "**/*"
exclude = "**/*.tar.gz"
cmd = "typos"
invoke = "once"
ok-exit-codes = 0
lint-failure-exit-codes = 2

[commands.taplo]
type = "both"
include = "**/*.toml"
cmd = ["taplo", "format", "--option", "indent_string= ", "--option", "column_width=100"]
lint_flags = "--check"
tidy_flags = "--in-place"
ok_exit_codes = 0
lint_failure_exit_codes = 1
ignore_stderr = "INFO taplo.+"
labels = ["default", "fast-tidy"]
50 changes: 22 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Dioxus components for [heroicons](https://heroicons.com/)
//!
//! This library provides two components. The [`Icon`] component produces the
//! SVG for a heroicon. The [`IconButton`] component wraps the icon with a
//! HTML `button`.
//! This library provides two components. The [`Icon`] component produces the SVG for a heroicon. The
//! [`IconButton`] component wraps the icon with a HTML `button`.
//!
//! In your own components, you can call them like this:
//!
Expand Down Expand Up @@ -38,9 +37,8 @@
//! }
//! ```
//!
//! Check out https://jkelleyrtp.github.io/icon-chooser/ for an icon chooser
//! that shows you all the solid icons and lets you copy the relevant
//! component code to the clipboard.
//! Check out <https://jkelleyrtp.github.io/icon-chooser/> for an icon chooser that shows you all the
//! solid icons and lets you copy the relevant component code to the clipboard.
/// This module contains all the mini icon shapes.
pub mod mini;
Expand All @@ -51,9 +49,8 @@ pub mod solid;

use dioxus::{events::MouseEvent, prelude::*};

/// This trait is used to abstract the icon shape so you can use shapes from
/// the [`outline`] or [`solid`] modules for any property that accepts a
/// shape.
/// This trait is used to abstract the icon shape so you can use shapes from the [`outline`] or
/// [`solid`] modules for any property that accepts a shape.
pub trait IconShape: Clone + std::fmt::Debug {
fn view_box(&self) -> &str;
fn path(&self) -> LazyNodes;
Expand All @@ -77,13 +74,12 @@ pub struct IconButtonProps<'a, S: IconShape> {
/// The fill color to use for the icon. This defaults to "currentColor".
#[props(default = "currentColor")]
pub fill: &'a str,
/// If this is true then the button's `disabled` attribute will be true,
/// and this will be passed to the `Icon` when it is rendered.
/// If this is true then the button's `disabled` attribute will be true, and this will be passed
/// to the `Icon` when it is rendered.
#[props(default = false)]
pub disabled: bool,
/// The fill color to use when `disabled` is true. This is only relevant
/// for solid icons. This defaults to "#9CA3AF", which is "coolGray 400"
/// from tailwindcss.
/// The fill color to use when `disabled` is true. This is only relevant for solid icons. This
/// defaults to "#9CA3AF", which is "coolGray 400" from tailwindcss.
#[props(default = "#9CA3AF")]
pub disabled_fill: &'a str,
/// The icon shape to use.
Expand Down Expand Up @@ -112,12 +108,12 @@ pub struct IconButtonProps<'a, S: IconShape> {
/// </button>
/// ```
///
/// See the [`IconButtonProps`] field documentation for details on the
/// properties it accepts.
/// See the [`IconButtonProps`] field documentation for details on the properties it accepts.
///
/// The child elements are optional, and are there so you can add some
/// additional text or other HTML to the button.
/// The child elements are optional, and are there so you can add some additional text or other HTML
/// to the button.
#[allow(non_snake_case)]
#[must_use]
pub fn IconButton<'a, S: IconShape>(cx: Scope<'a, IconButtonProps<'a, S>>) -> Element<'a> {
cx.render(rsx! {
button {
Expand Down Expand Up @@ -153,13 +149,12 @@ pub struct IconProps<'a, S: IconShape> {
/// An optional class for the `<svg>` element.
#[props(default)]
pub class: Option<&'a str>,
/// The size of the `<svg>` element. All the heroicons are square, so this
/// will be turned into the `height` and `width` attributes for the
/// `<svg>`. Defaults to 20.
/// The size of the `<svg>` element. All the heroicons are square, so this will be turned into
/// the `height` and `width` attributes for the `<svg>`. Defaults to 20.
#[props(default = 20)]
pub size: u32,
/// The color to use for filling the icon. This is only relevant for solid
/// icons. Defaults to "currentColor".
/// The color to use for filling the icon. This is only relevant for solid icons. Defaults to
/// "currentColor".
#[props(default = "currentColor")]
pub fill: &'a str,
/// The icon shape to use.
Expand All @@ -168,18 +163,17 @@ pub struct IconProps<'a, S: IconShape> {
/// `disabled_fill` instead of `fill`.
#[props(default = false)]
pub disabled: bool,
/// The fill color to use when `disabled` is true. This is only relevant
/// for solid icons. This defaults to "#9CA3AF", which is "coolGray 400"
/// from tailwindcss.
/// The fill color to use when `disabled` is true. This is only relevant for solid icons. This
/// defaults to "#9CA3AF", which is "coolGray 400" from tailwindcss.
#[props(default = "#9CA3AF")]
pub disabled_fill: &'a str,
}

/// Renders an `<svg>` element for a heroicon.
///
/// See the [`IconProps`] field documentation for details on the properties it
/// accepts.
/// See the [`IconProps`] field documentation for details on the properties it accepts.
#[allow(non_snake_case)]
#[must_use]
pub fn Icon<'a, S: IconShape>(cx: Scope<'a, IconProps<S>>) -> Element<'a> {
let fill = if cx.props.disabled {
cx.props.disabled_fill
Expand Down
1 change: 1 addition & 0 deletions src/mini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl crate::IconShape for Shape {
VIEW_BOX
}

#[allow(clippy::too_many_lines)]
fn path(&self) -> LazyNodes {
match self {
Shape::AcademicCap => rsx! {
Expand Down
1 change: 1 addition & 0 deletions src/outline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl crate::IconShape for Shape {
VIEW_BOX
}

#[allow(clippy::too_many_lines)]
fn path(&self) -> LazyNodes {
match self {
Shape::AcademicCap => rsx! {
Expand Down
1 change: 1 addition & 0 deletions src/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl crate::IconShape for Shape {
VIEW_BOX
}

#[allow(clippy::too_many_lines)]
fn path(&self) -> LazyNodes {
match self {
Shape::AcademicCap => rsx! {
Expand Down

0 comments on commit c05c5e9

Please sign in to comment.