mirror of https://github.com/rwf2/Rocket.git
Require source lines to be under 100 chars.
This commit is contained in:
parent
078cf1725f
commit
068aacd79d
|
@ -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) {
|
if CompressionUtils::already_encoded(response) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +128,8 @@ impl CompressionUtils {
|
||||||
#[cfg(feature = "gzip_compression")]
|
#[cfg(feature = "gzip_compression")]
|
||||||
{
|
{
|
||||||
if let Some(plain) = response.take_body() {
|
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);
|
CompressionUtils::set_body_and_encoding(response, compressor, Encoding::Gzip);
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,7 +239,14 @@ impl Parse for InternalUriParams {
|
||||||
None => vec![]
|
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
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@ struct FieldAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn derive_responder(input: proc_macro::TokenStream) -> TokenStream {
|
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)
|
.support(Support::Struct | Support::Enum | Support::Lifetime | Support::Type)
|
||||||
.replace_generic(1, 0)
|
.replace_generic(1, 0)
|
||||||
.type_bound(quote!(::rocket::response::Responder<'__r, '__o>))
|
.type_bound(quote!(::rocket::response::Responder<'__r, '__o>))
|
||||||
|
|
|
@ -339,7 +339,7 @@ impl Config {
|
||||||
warn!("found set deprecated profile `{}`", Paint::white(profile));
|
warn!("found set deprecated profile `{}`", Paint::white(profile));
|
||||||
|
|
||||||
if let Some(new_profile) = replacement {
|
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 {
|
} else {
|
||||||
launch_info_!("profile `{}` has no special meaning", profile);
|
launch_info_!("profile `{}` has no special meaning", profile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,9 +60,9 @@ fn login_page(flash: Option<FlashMessage<'_>>) -> Template {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/login", data = "<login>")]
|
#[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" {
|
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)))
|
Ok(Redirect::to(uri!(index)))
|
||||||
} else {
|
} else {
|
||||||
Err(Flash::error(Redirect::to(uri!(login_page)), "Invalid username/password."))
|
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")]
|
#[post("/logout")]
|
||||||
fn logout(cookies: &CookieJar<'_>) -> Flash<Redirect> {
|
fn logout(jar: &CookieJar<'_>) -> Flash<Redirect> {
|
||||||
cookies.remove_private(Cookie::named("user_id"));
|
jar.remove_private(Cookie::named("user_id"));
|
||||||
Flash::success(Redirect::to(uri!(login_page)), "Successfully logged out.")
|
Flash::success(Redirect::to(uri!(login_page)), "Successfully logged out.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,20 +30,27 @@ function check_versions_match() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ensures there are no tabs in any file.
|
function check_style() {
|
||||||
function ensure_tab_free() {
|
# Ensure there are no tabs in any file.
|
||||||
local tab=$(printf '\t')
|
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
|
if ! [ -z "${matches}" ]; then
|
||||||
echo "Tab characters were found in the following:"
|
echo "Tab characters were found in the following:"
|
||||||
echo "${matches}"
|
echo "${matches}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
# Ensures there are no files with trailing whitespace.
|
# Ensure non-comment lines are under 100 characters.
|
||||||
function ensure_trailing_whitespace_free() {
|
local n=100
|
||||||
local matches=$(git grep -E -I "\s+$" "${PROJECT_ROOT}" | grep -v -F '.stderr:')
|
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
|
if ! [ -z "${matches}" ]; then
|
||||||
echo "Trailing whitespace was found in the following:"
|
echo "Trailing whitespace was found in the following:"
|
||||||
echo "${matches}"
|
echo "${matches}"
|
||||||
|
@ -148,11 +155,8 @@ echo " EXTRA FLAGS: $@"
|
||||||
echo ":: Ensuring all crate versions match..."
|
echo ":: Ensuring all crate versions match..."
|
||||||
check_versions_match "${ALL_PROJECT_DIRS[@]}"
|
check_versions_match "${ALL_PROJECT_DIRS[@]}"
|
||||||
|
|
||||||
echo ":: Checking for tabs..."
|
echo ":: Ensuring minimum style requirements are met..."
|
||||||
ensure_tab_free
|
check_style
|
||||||
|
|
||||||
echo ":: Checking for trailing whitespace..."
|
|
||||||
ensure_trailing_whitespace_free
|
|
||||||
|
|
||||||
echo ":: Updating dependencies..."
|
echo ":: Updating dependencies..."
|
||||||
if ! $CARGO update ; then
|
if ! $CARGO update ; then
|
||||||
|
|
Loading…
Reference in New Issue