Require source lines to be under 100 chars.

This commit is contained in:
Sergio Benitez 2021-04-27 19:54:10 -07:00
parent 078cf1725f
commit 068aacd79d
6 changed files with 38 additions and 21 deletions

View File

@ -81,7 +81,11 @@ impl CompressionUtils {
}
}
fn compress_response(request: &Request<'_>, response: &mut Response<'_>, exclusions: &[MediaType]) {
fn compress_response(
request: &Request<'_>,
response: &mut Response<'_>,
exclusions: &[MediaType]
) {
if CompressionUtils::already_encoded(response) {
return;
}
@ -124,7 +128,8 @@ impl CompressionUtils {
#[cfg(feature = "gzip_compression")]
{
if let Some(plain) = response.take_body() {
let compressor = GzEncoder::new(plain.into_inner(), flate2::Compression::default());
let compressor =
GzEncoder::new(plain.into_inner(), flate2::Compression::default());
CompressionUtils::set_body_and_encoding(response, compressor, Encoding::Gzip);
}

View File

@ -239,7 +239,14 @@ impl Parse for InternalUriParams {
None => vec![]
};
Ok(InternalUriParams { route_uri, mount_params, path_params, query_params, fn_args, uri_params })
Ok(InternalUriParams {
route_uri,
mount_params,
path_params,
query_params,
fn_args,
uri_params
})
}
}

View File

@ -17,7 +17,8 @@ struct FieldAttr {
}
pub fn derive_responder(input: proc_macro::TokenStream) -> TokenStream {
DeriveGenerator::build_for(input, quote!(impl<'__r, '__o: '__r> ::rocket::response::Responder<'__r, '__o>))
let impl_tokens = quote!(impl<'__r, '__o: '__r> ::rocket::response::Responder<'__r, '__o>);
DeriveGenerator::build_for(input, impl_tokens)
.support(Support::Struct | Support::Enum | Support::Lifetime | Support::Type)
.replace_generic(1, 0)
.type_bound(quote!(::rocket::response::Responder<'__r, '__o>))

View File

@ -339,7 +339,7 @@ impl Config {
warn!("found set deprecated profile `{}`", Paint::white(profile));
if let Some(new_profile) = replacement {
launch_info_!("profile has been by replaced by `{}`", Paint::white(new_profile));
launch_info_!("profile was replaced by `{}`", Paint::white(new_profile));
} else {
launch_info_!("profile `{}` has no special meaning", profile);
}

View File

@ -60,9 +60,9 @@ fn login_page(flash: Option<FlashMessage<'_>>) -> Template {
}
#[post("/login", data = "<login>")]
fn post_login(cookies: &CookieJar<'_>, login: Form<Login<'_>>) -> Result<Redirect, Flash<Redirect>> {
fn post_login(jar: &CookieJar<'_>, login: Form<Login<'_>>) -> Result<Redirect, Flash<Redirect>> {
if login.username == "Sergio" && login.password == "password" {
cookies.add_private(Cookie::new("user_id", 1.to_string()));
jar.add_private(Cookie::new("user_id", 1.to_string()));
Ok(Redirect::to(uri!(index)))
} else {
Err(Flash::error(Redirect::to(uri!(login_page)), "Invalid username/password."))
@ -70,8 +70,8 @@ fn post_login(cookies: &CookieJar<'_>, login: Form<Login<'_>>) -> Result<Redirec
}
#[post("/logout")]
fn logout(cookies: &CookieJar<'_>) -> Flash<Redirect> {
cookies.remove_private(Cookie::named("user_id"));
fn logout(jar: &CookieJar<'_>) -> Flash<Redirect> {
jar.remove_private(Cookie::named("user_id"));
Flash::success(Redirect::to(uri!(login_page)), "Successfully logged out.")
}

View File

@ -30,20 +30,27 @@ function check_versions_match() {
done
}
# Ensures there are no tabs in any file.
function ensure_tab_free() {
function check_style() {
# Ensure there are no tabs in any file.
local tab=$(printf '\t')
local matches=$(git grep -E -I "${tab}" "${PROJECT_ROOT}" | grep -v 'LICENSE')
local matches=$(git grep -E -I -n "${tab}" "${PROJECT_ROOT}" | grep -v 'LICENSE')
if ! [ -z "${matches}" ]; then
echo "Tab characters were found in the following:"
echo "${matches}"
exit 1
fi
}
# Ensures there are no files with trailing whitespace.
function ensure_trailing_whitespace_free() {
local matches=$(git grep -E -I "\s+$" "${PROJECT_ROOT}" | grep -v -F '.stderr:')
# Ensure non-comment lines are under 100 characters.
local n=100
local matches=$(git grep -P -I -n "(?=^..{$n,}$)(?!^\s*\/\/[\/!].*$).*" '*.rs')
if ! [ -z "${matches}" ]; then
echo "Lines longer than $n characters were found in the following:"
echo "${matches}"
exit 1
fi
# Ensure there's no trailing whitespace.
local matches=$(git grep -E -I -n "\s+$" "${PROJECT_ROOT}" | grep -v -F '.stderr:')
if ! [ -z "${matches}" ]; then
echo "Trailing whitespace was found in the following:"
echo "${matches}"
@ -148,11 +155,8 @@ echo " EXTRA FLAGS: $@"
echo ":: Ensuring all crate versions match..."
check_versions_match "${ALL_PROJECT_DIRS[@]}"
echo ":: Checking for tabs..."
ensure_tab_free
echo ":: Checking for trailing whitespace..."
ensure_trailing_whitespace_free
echo ":: Ensuring minimum style requirements are met..."
check_style
echo ":: Updating dependencies..."
if ! $CARGO update ; then