From 601110c8ae7113a457b2abe6e9c7bf74fd646213 Mon Sep 17 00:00:00 2001 From: Ryan Russell Date: Tue, 20 Sep 2022 07:13:26 -0500 Subject: [PATCH] refactor(src): readability improvements Signed-off-by: Ryan Russell --- packages/perseus/src/build.rs | 6 +++--- packages/perseus/src/i18n/translations_manager.rs | 4 ++-- packages/perseus/src/init.rs | 4 ++-- packages/perseus/src/lib.rs | 2 +- packages/perseus/src/macros.rs | 2 +- packages/perseus/src/plugins/plugins_list.rs | 6 +++--- packages/perseus/src/router/match_route.rs | 2 +- packages/perseus/src/router/router_component.rs | 4 ++-- packages/perseus/src/server/html_shell.rs | 4 ++-- packages/perseus/src/server/render.rs | 2 +- packages/perseus/src/state/freeze.rs | 2 +- packages/perseus/src/state/freeze_idb.rs | 2 +- packages/perseus/src/state/live_reload.rs | 2 +- packages/perseus/src/template/core.rs | 12 ++++++------ packages/perseus/src/translator/fluent.rs | 2 +- packages/perseus/src/translator/lightweight.rs | 6 +++--- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/perseus/src/build.rs b/packages/perseus/src/build.rs index b9e4cc2d16..9392063159 100644 --- a/packages/perseus/src/build.rs +++ b/packages/perseus/src/build.rs @@ -91,7 +91,7 @@ async fn gen_state_for_path( global_state: &Option, ) -> Result<(), ServerError> { let template_path = template.get_path(); - // If needed, we'll contruct a full path that's URL encoded so we can easily + // If needed, we'll construct a full path that's URL encoded so we can easily // save it as a file let full_path_without_locale = match template.uses_build_paths() { true => format!("{}/{}", &template_path, path), @@ -130,7 +130,7 @@ async fn gen_state_for_path( let initial_state = template .get_build_state(full_path_without_locale.clone(), translator.get_locale()) .await?; - // Write that intial state to a static JSON file + // Write that initial state to a static JSON file mutable_store .write( &format!("static/{}.json", full_path_encoded), @@ -167,7 +167,7 @@ async fn gen_state_for_path( let initial_state = template .get_build_state(full_path_without_locale.clone(), translator.get_locale()) .await?; - // Write that intial state to a static JSON file + // Write that initial state to a static JSON file immutable_store .write( &format!("static/{}.json", full_path_encoded), diff --git a/packages/perseus/src/i18n/translations_manager.rs b/packages/perseus/src/i18n/translations_manager.rs index 604ce4c5d8..6131dea243 100644 --- a/packages/perseus/src/i18n/translations_manager.rs +++ b/packages/perseus/src/i18n/translations_manager.rs @@ -1,4 +1,4 @@ -// This file contains the logic for a universal interface to fecth `Translator` +// This file contains the logic for a universal interface to fetch `Translator` // instances for given locales At simplest, this is just a filesystem interface, // but it might be something like a database in production This has its own // error management logic because the user may implement it separately @@ -146,7 +146,7 @@ impl FsTranslationsManager { let cached_translations_kv_vec = join_all(futs).await; manager.cached_translations = cached_translations_kv_vec.iter().cloned().collect(); // We only declare the locales that are being cached after getting translations - // becuase otherwise those getters would be using undefined caches + // because otherwise those getters would be using undefined caches manager.cached_locales = locales_to_cache; manager diff --git a/packages/perseus/src/init.rs b/packages/perseus/src/init.rs index bfbf0929f4..cbf4de0ae2 100644 --- a/packages/perseus/src/init.rs +++ b/packages/perseus/src/init.rs @@ -567,7 +567,7 @@ impl PerseusAppBase { format!("\n{}", self.index_view) } /// Gets an HTML shell from an index view string. This is broken out so that - /// it can be executed after the app has been built (which requries getting + /// it can be executed after the app has been built (which requires getting /// the translations manager, consuming `self`). As inconvenient as this /// is, it's necessitated, otherwise exporting would try to access the built /// app before it had actually been built. @@ -582,7 +582,7 @@ impl PerseusAppBase { let mut html_shell = HtmlShell::new( index_view_str, root, - // TODO Handle this properly (good enough for now because that's what we weere already + // TODO Handle this properly (good enough for now because that's what we were already // doing) &get_render_cfg(immutable_store) .await diff --git a/packages/perseus/src/lib.rs b/packages/perseus/src/lib.rs index 3e7caca2fb..25e78a59d1 100644 --- a/packages/perseus/src/lib.rs +++ b/packages/perseus/src/lib.rs @@ -48,7 +48,7 @@ pub mod state; /// [`ImmutableStore`] and [`MutableStore`] for details. pub mod stores; /// Utilities for working with templates and state generation. This is by far -/// the module you'll procably access the most. +/// the module you'll probably access the most. pub mod template; /// General utilities that may be useful while building Perseus apps. pub mod utils; diff --git a/packages/perseus/src/macros.rs b/packages/perseus/src/macros.rs index 37dcd4c823..d703a7a642 100644 --- a/packages/perseus/src/macros.rs +++ b/packages/perseus/src/macros.rs @@ -174,7 +174,7 @@ macro_rules! define_app { // We need the filesystem here, and we don't need on it in the browser // We can't modify `app` if this is all in a block, so we compromise a bit let index_html = if cfg!(target_arch = "wasm32") { - // In the browser, this would turn into using the hardocded default, but we don't need the index view there anyway + // In the browser, this would turn into using the hardcoded default, but we don't need the index view there anyway ::std::result::Result::Err(::std::io::Error::from(::std::io::ErrorKind::NotFound)) } else { ::std::fs::read_to_string("../index.html") diff --git a/packages/perseus/src/plugins/plugins_list.rs b/packages/perseus/src/plugins/plugins_list.rs index 22b8c7c4f9..75de63a346 100644 --- a/packages/perseus/src/plugins/plugins_list.rs +++ b/packages/perseus/src/plugins/plugins_list.rs @@ -7,7 +7,7 @@ type PluginDataMap = HashMap>; /// A representation of all the plugins used by an app. /// -/// Due to the sheer number and compexity of nested fields, this is best +/// Due to the sheer number and complexity of nested fields, this is best /// transferred in an `Rc`, which unfortunately results in double indirection /// for runner functions. pub struct Plugins { @@ -49,7 +49,7 @@ impl Plugins { /// error if one has, noting the conflict explicitly in the error message. /// This can only register plugins that run exclusively on the /// server-side (including tinker-time and the build process). - // We allow unusued variables and the like for linting because otherwise any + // We allow unused variables and the like for linting because otherwise any // errors in Wasm compilation will show these up, which is annoying pub fn plugin( #[cfg_attr(target_arch = "wasm32", allow(unused_mut))] mut self, @@ -88,7 +88,7 @@ impl Plugins { } /// The same as `.plugin()`, but registers a plugin that can run on the /// client-side. This is deliberately separated out to make conditional - /// compilation feasible and to emphasize to users what's incrasing their + /// compilation feasible and to emphasize to users what's increasing their /// bundle sizes. Note that this should also be used for plugins that /// run on both the client and server. pub fn plugin_with_client_privilege( diff --git a/packages/perseus/src/router/match_route.rs b/packages/perseus/src/router/match_route.rs index d7c19c8291..ae8c54fa01 100644 --- a/packages/perseus/src/router/match_route.rs +++ b/packages/perseus/src/router/match_route.rs @@ -84,7 +84,7 @@ pub fn get_template_for_path( /// A version of `get_template_for_path` that accepts an `ArcTemplateMap`. /// This is used by `match_route_atomic`, which should be used in scenarios in -/// which the template map needs to be passed betgween threads. +/// which the template map needs to be passed between threads. /// /// Warning: this returns a `&Template` rather than a `Rc>`, and /// thus should only be used independently of the rest of Perseus (through diff --git a/packages/perseus/src/router/router_component.rs b/packages/perseus/src/router/router_component.rs index 59ea3ec8f3..32cdefab00 100644 --- a/packages/perseus/src/router/router_component.rs +++ b/packages/perseus/src/router/router_component.rs @@ -23,7 +23,7 @@ use sycamore_router::{HistoryIntegration, RouterBase}; use web_sys::Element; // We don't want to bring in a styling library, so we do this the old-fashioned -// way! We're particualrly comprehensive with these because the user could +// way! We're particularly comprehensive with these because the user could // *potentially* stuff things up with global rules https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe const ROUTE_ANNOUNCER_STYLES: &str = r#" margin: -1px; @@ -95,7 +95,7 @@ async fn get_view( RouteVerdict::LocaleDetection(path) => { let dest = detect_locale(path.clone(), &locales); // Since this is only for subsequent loads, we know the router is instantiated - // This shouldn't be a replacement navigation, since the user has deliberatley + // This shouldn't be a replacement navigation, since the user has deliberately // navigated here sycamore_router::navigate(&dest); View::empty() diff --git a/packages/perseus/src/server/html_shell.rs b/packages/perseus/src/server/html_shell.rs index 379ed22466..23ab0a193c 100644 --- a/packages/perseus/src/server/html_shell.rs +++ b/packages/perseus/src/server/html_shell.rs @@ -20,7 +20,7 @@ fn escape_page_data(data: &str) -> String { /// plugins. #[derive(Clone, Debug)] pub struct HtmlShell { - /// The actual shell content, on whcih interpolations will be performed. + /// The actual shell content, on which interpolations will be performed. pub shell: String, /// Additional contents of the head before the interpolation boundary. pub head_before_boundary: Vec, @@ -29,7 +29,7 @@ pub struct HtmlShell { /// Additional contents of the head after the interpolation boundary. These /// will be wiped out after a page transition. pub head_after_boundary: Vec, - /// Scripts to be interpolated after the interpolation bounary. These will + /// Scripts to be interpolated after the interpolation boundary. These will /// be wiped out after a page transition. pub scripts_after_boundary: Vec, /// Content to be interpolated into the body of the shell. diff --git a/packages/perseus/src/server/render.rs b/packages/perseus/src/server/render.rs index 419c762184..949a3d33de 100644 --- a/packages/perseus/src/server/render.rs +++ b/packages/perseus/src/server/render.rs @@ -218,7 +218,7 @@ async fn should_revalidate( req: Request, ) -> Result { let mut should_revalidate = false; - // If it revalidates after a certain period of time, we needd to check that + // If it revalidates after a certain period of time, we need to check that // BEFORE the custom logic if template.revalidates_with_time() { // Get the time when it should revalidate (RFC 3339) diff --git a/packages/perseus/src/state/freeze.rs b/packages/perseus/src/state/freeze.rs index dbdd933343..6e044aba4f 100644 --- a/packages/perseus/src/state/freeze.rs +++ b/packages/perseus/src/state/freeze.rs @@ -41,7 +41,7 @@ pub enum PageThawPrefs { /// Includes all pages in the app, making frozen state always override state /// that's already been initialized. IncludeAll, - /// Exludes the attached pages by their URLs (with no leading `/`). Pages + /// Excludes the attached pages by their URLs (with no leading `/`). Pages /// listed here will prioritize active state over frozen state as usual, and /// any pages not listed here will prioritize frozen state. /// `Exclude(Vec::new())` is equivalent to `IncludeAll`. diff --git a/packages/perseus/src/state/freeze_idb.rs b/packages/perseus/src/state/freeze_idb.rs index 82a200064d..f8d1989da2 100644 --- a/packages/perseus/src/state/freeze_idb.rs +++ b/packages/perseus/src/state/freeze_idb.rs @@ -24,7 +24,7 @@ pub enum IdbError { #[source] source: RexieError, }, - #[error("an error occured while trying to set a new value")] + #[error("an error occurred while trying to set a new value")] SetError { #[source] source: RexieError, diff --git a/packages/perseus/src/state/live_reload.rs b/packages/perseus/src/state/live_reload.rs index 972998bee6..28cdf7e36e 100644 --- a/packages/perseus/src/state/live_reload.rs +++ b/packages/perseus/src/state/live_reload.rs @@ -29,7 +29,7 @@ pub(crate) fn connect_to_reload_server(live_reload_tx: Sender<()>) { Ok(ws) => ws, Err(err) => return log(&format!("Connection failed: {:?}.", err)), }; - // This is apparently more efficient for small bianry messages + // This is apparently more efficient for small binary messages ws.set_binary_type(web_sys::BinaryType::Arraybuffer); // Set up a message handler diff --git a/packages/perseus/src/template/core.rs b/packages/perseus/src/template/core.rs index 80d1cfd3b2..4fc2944919 100644 --- a/packages/perseus/src/template/core.rs +++ b/packages/perseus/src/template/core.rs @@ -111,7 +111,7 @@ pub type GetBuildStateFn = Box; /// The type of functions that get request state. #[cfg(not(target_arch = "wasm32"))] pub type GetRequestStateFn = Box; -/// The type of functions that check if a template sghould revalidate. +/// The type of functions that check if a template should revalidate. #[cfg(not(target_arch = "wasm32"))] pub type ShouldRevalidateFn = Box; /// The type of functions that amalgamate build and request states. @@ -149,7 +149,7 @@ pub struct Template { /// A function that will be used to populate the document's `` with /// metadata such as the title. This will be passed state in /// the same way as `template`, but will always be rendered to a string, - /// whcih will then be interpolated directly into the ``, + /// which will then be interpolated directly into the ``, /// so reactivity here will not work! #[cfg(not(target_arch = "wasm32"))] head: TemplateFn, @@ -170,10 +170,10 @@ pub struct Template { /// prerendered and cached in production. This allows you to /// have potentially billions of templates and retain a super-fast build /// process. The first user will have an ever-so-slightly slower - /// experience, and everyone else gets the beneftis afterwards. This + /// experience, and everyone else gets the benefits afterwards. This /// requires `get_build_paths`. Note that the template root will NOT /// be rendered on demand, and must be explicitly defined if it's wanted. It - /// can uuse a different template. + /// can use a different template. #[cfg(not(target_arch = "wasm32"))] incremental_generation: bool, /// A function that gets the initial state to use to prerender the template @@ -331,7 +331,7 @@ impl Template { /// Gets the initial state for a template. This needs to be passed the full /// path of the template, which may be one of those generated by /// `.get_build_paths()`. This also needs the locale being rendered to so - /// that more compelx applications like custom documentation systems can + /// that more complex applications like custom documentation systems can /// be enabled. #[cfg(not(target_arch = "wasm32"))] pub async fn get_build_state( @@ -518,7 +518,7 @@ impl Template { self.get_build_state.is_some() } /// Checks if this template has custom logic to amalgamate build and - /// reqquest states if both are generated. + /// request states if both are generated. #[cfg(not(target_arch = "wasm32"))] pub fn can_amalgamate_states(&self) -> bool { self.amalgamate_states.is_some() diff --git a/packages/perseus/src/translator/fluent.rs b/packages/perseus/src/translator/fluent.rs index 101b825ffb..ad37f1f472 100644 --- a/packages/perseus/src/translator/fluent.rs +++ b/packages/perseus/src/translator/fluent.rs @@ -78,7 +78,7 @@ impl FluentTranslator { pub fn url(&self, url: &str) -> String { format!("{}{}", self.locale, url) } - /// Gets the locale for which this instancce is configured. + /// Gets the locale for which this instance is configured. pub fn get_locale(&self) -> String { self.locale.clone() } diff --git a/packages/perseus/src/translator/lightweight.rs b/packages/perseus/src/translator/lightweight.rs index 4dd525e6c6..a6eb69c7fa 100644 --- a/packages/perseus/src/translator/lightweight.rs +++ b/packages/perseus/src/translator/lightweight.rs @@ -22,7 +22,7 @@ pub const LIGHTWEIGHT_TRANSLATOR_FILE_EXT: &str = "json"; /// like pluralization with this system, you should use multiple separate /// translation IDs. /// -/// This system supports variants only in the msot basic way: you could create +/// This system supports variants only in the most basic way: you could create /// multiple 'sub-ids' on ID `x` by having one ID called `x.y` and another /// called `x.z`, etc., but the system doesn't particularly care, unlike Fluent, /// which explicitly handles these cases. @@ -64,7 +64,7 @@ impl LightweightTranslator { pub fn url(&self, url: &str) -> String { format!("{}{}", self.locale, url) } - /// Gets the locale for which this instancce is configured. + /// Gets the locale for which this instance is configured. pub fn get_locale(&self) -> String { self.locale.clone() } @@ -121,7 +121,7 @@ impl LightweightTranslator { } /// A *very* simple argument interpolation system based on a `HashMap`. Any more -/// complex functionality shoudl use `translator-fluent` instead. +/// complex functionality should use `translator-fluent` instead. #[doc(hidden)] #[allow(missing_debug_implementations)] pub struct TranslationArgs(pub HashMap);