Skip to content

Commit

Permalink
formatting: clean up strings and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMichaelTDM committed May 3, 2024
1 parent 500c06d commit 29e16f0
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 80 deletions.
8 changes: 4 additions & 4 deletions create-rust-app/src/auth/mail/auth_activated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ use crate::Mailer;
#[allow(dead_code)]
pub fn send(mailer: &Mailer, to_email: &str) {
let subject = "Account activated";
let text = r#"
let text = r"
(This is an automated message.)
Hello,
Your account has been activated!
"#
"
.to_string();
let html = r#"
let html = r"
<p>(This is an automated message.)</p>
<p>Hello,</p>
<p>Your account has been activated!</p>
"#
"
.to_string();

mailer.send(to_email, subject, &text, &html);
Expand Down
8 changes: 4 additions & 4 deletions create-rust-app/src/auth/mail/auth_password_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ use crate::Mailer;
#[allow(dead_code)]
pub fn send(mailer: &Mailer, to_email: &str) {
let subject = "Your password was changed";
let text = r#"
let text = r"
(This is an automated message.)
Hello,
Your password was changed successfully!
"#
"
.to_string();
let html = r#"
let html = r"
<p>(This is an automated message.)</p>
<p>Hello,</p>
<p>Your password was changed successfully!</p>
"#
"
.to_string();

mailer.send(to_email, subject, &text, &html);
Expand Down
8 changes: 4 additions & 4 deletions create-rust-app/src/auth/mail/auth_password_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ use crate::Mailer;
#[allow(dead_code)]
pub fn send(mailer: &Mailer, to_email: &str) {
let subject = "Your password was reset";
let text = r#"
let text = r"
(This is an automated message.)
Hello,
Your password was successfully reset!
"#
"
.to_string();

let html = r#"
let html = r"
<p>(This is an automated message.)</p>
<p>Hello,</p>
<p>Your password was successfully reset!</p>
"#
"
.to_string();

mailer.send(to_email, subject, &text, &html);
Expand Down
4 changes: 2 additions & 2 deletions create-rust-app/src/auth/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl Permission {
/// * [`diesel::result::Error`](`diesel::result::Error`) if the query fails
pub fn fetch_all(db: &mut Connection, user_id: ID) -> Result<Vec<Self>> {
let permissions = sql_query(
r#"
r"
SELECT
permission AS permission,
NULL AS from_role
Expand All @@ -354,7 +354,7 @@ impl Permission {
FROM user_roles
INNER JOIN role_permissions ON user_roles.role = role_permissions.role
WHERE user_roles.user_id = $1
"#,
",
);

let permissions = permissions
Expand Down
5 changes: 4 additions & 1 deletion create-rust-app/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ impl Database {
}

/// get a [`Connection`] to a database
#[must_use]
///
/// # Errors
///
/// * if the pool is unable to get a connection
pub fn get_connection(&self) -> Result<Connection, anyhow::Error> {
Ok(LoggingConnection::new(self.pool.get()?))
}
Expand Down
1 change: 0 additions & 1 deletion create-rust-app/src/dev/backend_compiling_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ pub async fn start(
println!("backend compilation server stopped.");
}

/// TODO: do we need to pass the `ws_s` by value here?
#[allow(clippy::needless_pass_by_value)]
fn compile(project_dir: &'static str, ws_s: Sender<DevServerEvent>) -> bool {
println!("🔨 Compiling backend...");
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct AppConfig {
}

#[derive(Clone)]
///
/// Struct that holds shared data for the application
pub struct AppData {
/// wrapper for SMTP mailing server accessed by chosen web framework
///
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app/src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Mailer {
pub smtp_username: String,
/// the password used to log into `SMTP_SERVER`
///
/// set by the `SMTP_PASSWORD' environment variable
/// set by the `SMTP_PASSWORD` environment variable
pub smtp_password: String,
/// whether or not emails should actually be sent when requested
///
Expand Down
4 changes: 2 additions & 2 deletions create-rust-app/src/util/workspace_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;
use std::sync::OnceLock; // use LazyLock instead once that's stable

/// OnceLock wrapper around output of `cargo locate-project --workspace --message-format=plain`
/// `OnceLock` wrapper around output of `cargo locate-project --workspace --message-format=plain`
///
/// if the command fails (e.g. if we're in a container or otherwise don't have access to the projects source code), or output can't be parsed, we return None
fn cargo_locate_project_workspace() -> Option<&'static str> {
Expand All @@ -26,7 +26,7 @@ fn cargo_locate_project_workspace() -> Option<&'static str> {
.as_deref()
}

/// OnceLock wrapper around output of `cargo locate-project --message-format=plain`
/// `OnceLock` wrapper around output of `cargo locate-project --message-format=plain`
///
/// if the command fails (e.g. if we're in a container or otherwise don't have access to the projects source code), or output can't be parsed, we return None
fn cargo_locate_project() -> Option<&'static str> {
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app_cli/qsync/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use inflector::Inflector;

/// Converts a `/home/user/path/to/file.rs` to ["home", "user", "path", "to", "file"]
/// Converts a `/home/user/path/to/file.rs` to `["home", "user", "path", "to", "file"]`
/// Note: this trims the `.rs` extension from the filename (the last element in the vec)
pub fn file_path_to_vec_string(input_path: &std::path::Path) -> Vec<String> {
let mut s: Vec<String> = vec![];
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fn create_project(
.expect("Error: Tried to read .env.example contents but an error occurred");
std::fs::write(
env_file,
format!("{}DATABASE_URL={}", contents, backend_database_url),
format!("{contents}DATABASE_URL={backend_database_url}"),
)?;
logger::add_file_msg(".env");

Expand Down
22 changes: 11 additions & 11 deletions create-rust-app_cli/src/plugins/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ impl Plugin for Auth {
// currently, this works because we assume the current working directory is the project's root
fs::prepend(
"frontend/src/App.tsx",
r#"import { useAuth, useAuthCheck } from './hooks/useAuth'
r"import { useAuth, useAuthCheck } from './hooks/useAuth'
import { AccountPage } from './containers/AccountPage'
import { LoginPage } from './containers/LoginPage'
import { ActivationPage } from './containers/ActivationPage'
import { RegistrationPage } from './containers/RegistrationPage'
import { RecoveryPage } from './containers/RecoveryPage'
import { ResetPage } from './containers/ResetPage'"#,
import { ResetPage } from './containers/ResetPage'",
)?;
fs::prepend(
"frontend/bundles/index.tsx",
Expand All @@ -55,14 +55,14 @@ import { ResetPage } from './containers/ResetPage'"#,
fs::replace(
"frontend/src/App.tsx",
"const App = () => {",
r#"const App = () => {
r"const App = () => {
useAuthCheck()
const auth = useAuth()
"#,
",
)?;
fs::replace(
"frontend/src/App.tsx",
r#"{/* CRA: routes */}"#,
r"{/* CRA: routes */}",
r#"{/* CRA: routes */}
<Route path="/login" element={<LoginPage />} />
<Route path="/recovery" element={<RecoveryPage />} />
Expand Down Expand Up @@ -99,7 +99,7 @@ import { ResetPage } from './containers/ResetPage'"#,
crate::content::migration::create(
"plugin_auth",
match install_config.backend_database {
BackendDatabase::Postgres => indoc! {r#"
BackendDatabase::Postgres => indoc! {r"
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL,
Expand Down Expand Up @@ -142,8 +142,8 @@ import { ResetPage } from './containers/ResetPage'"#,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (role, permission)
);
"#},
BackendDatabase::Sqlite => indoc! {r#"
"},
BackendDatabase::Sqlite => indoc! {r"
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
email TEXT NOT NULL,
Expand Down Expand Up @@ -180,15 +180,15 @@ import { ResetPage } from './containers/ResetPage'"#,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (role, permission)
);
"#},
"},
},
indoc! {r#"
indoc! {r"
DROP TABLE user_permissions;
DROP TABLE role_permissions;
DROP TABLE user_roles;
DROP TABLE user_sessions;
DROP TABLE users;
"#},
"},
)?;

match install_config.backend_framework {
Expand Down
28 changes: 14 additions & 14 deletions create-rust-app_cli/src/plugins/auth_oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Plugin for AuthOIDC {
crate::content::migration::create(
"plugin_auth-oidc",
match install_config.backend_database {
BackendDatabase::Postgres => indoc! {r#"
BackendDatabase::Postgres => indoc! {r"
CREATE TABLE user_oauth2_links (
id SERIAL PRIMARY KEY,
provider TEXT NOT NULL,
Expand All @@ -145,8 +145,8 @@ impl Plugin for AuthOIDC {
);
SELECT manage_updated_at('user_oauth2_links');
"#},
BackendDatabase::Sqlite => indoc! {r#"
"},
BackendDatabase::Sqlite => indoc! {r"
CREATE TABLE user_oauth2_links (
id SERIAL PRIMARY KEY,
provider TEXT NOT NULL,
Expand All @@ -166,11 +166,11 @@ impl Plugin for AuthOIDC {
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
);
"#},
"},
},
indoc! {r#"
indoc! {r"
DROP TABLE user_oauth2_links;
"#},
"},
)?;

// ===============================
Expand All @@ -180,15 +180,15 @@ impl Plugin for AuthOIDC {
fs::replace(
"frontend/src/hooks/useAuth.tsx",
"logout,",
indoc! {r#"logout,
indoc! {r"logout,
loginOIDC,
completeOIDCLogin"#},
completeOIDCLogin"},
)?;

fs::replace(
"frontend/src/hooks/useAuth.tsx",
"const logout = async ()",
indoc! {r#"
indoc! {r"
const loginOIDC = async (
provider: string,
options?: { redirectUrl?: 'current-url' | string }
Expand Down Expand Up @@ -239,14 +239,14 @@ const completeOIDCLogin = (): boolean => {
}
}
const logout = async ()"#},
const logout = async ()"},
)?;

fs::replace(
"frontend/src/App.tsx",
"import { LoginPage } from './containers/LoginPage'",
r#"import { LoginPage } from './containers/LoginPage'
import { OauthLoginResultPage } from './containers/OauthLoginResultPage'"#,
r"import { LoginPage } from './containers/LoginPage'
import { OauthLoginResultPage } from './containers/OauthLoginResultPage'",
)?;

fs::replace(
Expand All @@ -259,11 +259,11 @@ import { OauthLoginResultPage } from './containers/OauthLoginResultPage'"#,

fs::replace(
"frontend/src/containers/LoginPage.tsx",
r#"<div style={{ display: 'flex', flexFlow: 'column' }}>
r"<div style={{ display: 'flex', flexFlow: 'column' }}>
<button disabled={processing} onClick={login}>
Login
</button>
</div>"#,
</div>",
r##"<div style={{ display: 'flex', flexFlow: 'column' }}>
<button disabled={processing} onClick={login}>
Login
Expand Down
4 changes: 2 additions & 2 deletions create-rust-app_cli/src/plugins/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Plugin for Container {
// currently, this works because we assume the current working directory is the project's root
fs::append(
"README.md",
r##"
r"
# Containerize your application
## Building a container
Expand All @@ -48,7 +48,7 @@ impl Plugin for Container {
## Running the container
`docker run -e SECRET_KEY=123 -e DATABASE_URL=postgres://postgres:postgres@localhost/database -p 3000:3000 image-name`
"##,
",
)?;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions create-rust-app_cli/src/plugins/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if (import.meta.env.DEV_SERVER_PORT) {
register_service_msg("(dev-only) /admin");
fs::replace(
"backend/main.rs",
r#"/* Development-only routes */"#,
r"/* Development-only routes */",
r#"/* Development-only routes */
// Mount development-only API routes
api_scope = api_scope.service(create_rust_app::dev::endpoints(web::scope("/development")));
Expand All @@ -80,7 +80,7 @@ if (import.meta.env.DEV_SERVER_PORT) {
register_service_msg("(dev-only) /admin");
fs::replace(
"backend/main.rs",
r#"/* Development-only routes */"#,
r"/* Development-only routes */",
r#"/* Development-only routes */
// Mount development-only API routes
api_routes = api_routes.nest("/development", create_rust_app::dev::api());
Expand Down
Loading

0 comments on commit 29e16f0

Please sign in to comment.