Apply new Clippy lints, examples deployment, and stdweb integration tests (#1651)

* make clippy happy

* fix publish-examples workflow

* disable yew-stdweb integration tests on stable
This commit is contained in:
Simon 2020-11-22 22:50:33 +01:00 committed by GitHub
parent efd8547ef0
commit c72d990bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 234 additions and 212 deletions

View File

@ -31,8 +31,7 @@ jobs:
- name: Install trunk - name: Install trunk
run: | run: |
brew install trunk cargo install trunk wasm-bindgen-cli
cargo install wasm-bindgen-cli
- name: Build examples - name: Build examples
run: | run: |

View File

@ -174,6 +174,7 @@ jobs:
wasm-pack test --chrome --firefox --headless -- --features "wasm_test httpbin_test" wasm-pack test --chrome --firefox --headless -- --features "wasm_test httpbin_test"
- name: Run tests - yew-stdweb - name: Run tests - yew-stdweb
if: matrix.toolchain != 'stable'
env: env:
HTTPBIN_URL: "http://localhost:8080" HTTPBIN_URL: "http://localhost:8080"
run: | run: |

View File

@ -161,7 +161,7 @@ fn make_tag(t: Tag) -> VTag {
let mut el = VTag::new("a"); let mut el = VTag::new("a");
el.add_attribute("href", href.to_string()); el.add_attribute("href", href.to_string());
let title = title.clone().into_string(); let title = title.clone().into_string();
if title != "" { if !title.is_empty() {
el.add_attribute("title", title); el.add_attribute("title", title);
} }
el el
@ -170,7 +170,7 @@ fn make_tag(t: Tag) -> VTag {
let mut el = VTag::new("img"); let mut el = VTag::new("img");
el.add_attribute("src", src.to_string()); el.add_attribute("src", src.to_string());
let title = title.clone().into_string(); let title = title.clone().into_string();
if title != "" { if !title.is_empty() {
el.add_attribute("title", title); el.add_attribute("title", title);
} }
el el

View File

@ -1,7 +1,6 @@
use super::{Prop, Props, SpecialProps}; use super::{Prop, Props, SpecialProps};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::collections::HashSet; use std::collections::HashSet;
use std::iter::FromIterator;
use syn::parse::{Parse, ParseStream}; use syn::parse::{Parse, ParseStream};
use syn::{Expr, ExprTuple}; use syn::{Expr, ExprTuple};
@ -93,189 +92,186 @@ impl Parse for ElementProps {
lazy_static! { lazy_static! {
static ref BOOLEAN_SET: HashSet<&'static str> = { static ref BOOLEAN_SET: HashSet<&'static str> = {
HashSet::from_iter( vec![
vec![ "async",
"async", "autofocus",
"autofocus", "controls",
"controls", "default",
"default", "defer",
"defer", "disabled",
"disabled", "hidden",
"hidden", "ismap",
"ismap", "loop",
"loop", "multiple",
"multiple", "muted",
"muted", "novalidate",
"novalidate", "open",
"open", "readonly",
"readonly", "required",
"required", "selected",
"selected", ]
] .into_iter()
.into_iter(), .collect()
)
}; };
} }
lazy_static! { lazy_static! {
static ref LISTENER_SET: HashSet<&'static str> = { static ref LISTENER_SET: HashSet<&'static str> = {
HashSet::from_iter( vec![
vec![ // Living Standard
// Living Standard // From: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
// From: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers "onabort",
"onabort", "onauxclick",
"onauxclick", "onblur",
"onblur", "oncancel",
"oncancel", "oncanplay",
"oncanplay", "oncanplaythrough",
"oncanplaythrough", "onchange",
"onchange", "onclick",
"onclick", "onclose",
"onclose", "oncontextmenu",
"oncontextmenu", "oncuechange",
"oncuechange", "ondblclick",
"ondblclick", "ondrag",
"ondrag", "ondragend",
"ondragend", "ondragenter",
"ondragenter", "ondragexit",
"ondragexit", "ondragleave",
"ondragleave", "ondragover",
"ondragover", "ondragstart",
"ondragstart", "ondrop",
"ondrop", "ondurationchange",
"ondurationchange", "onemptied",
"onemptied", "onended",
"onended", "onerror",
"onerror", "onfocus",
"onfocus", "onformdata",
"onformdata", "oninput",
"oninput", "oninvalid",
"oninvalid", "onkeydown",
"onkeydown", "onkeypress",
"onkeypress", "onkeyup",
"onkeyup", "onload",
"onload", "onloadeddata",
"onloadeddata", "onloadedmetadata",
"onloadedmetadata", "onloadstart",
"onloadstart", "onmousedown",
"onmousedown", "onmouseenter",
"onmouseenter", "onmouseleave",
"onmouseleave", "onmousemove",
"onmousemove", "onmouseout",
"onmouseout", "onmouseover",
"onmouseover", "onmouseup",
"onmouseup", "onpause",
"onpause", "onplay",
"onplay", "onplaying",
"onplaying", "onprogress",
"onprogress", "onratechange",
"onratechange", "onreset",
"onreset", "onresize",
"onresize", "onscroll",
"onscroll", "onsecuritypolicyviolation",
"onsecuritypolicyviolation", "onseeked",
"onseeked", "onseeking",
"onseeking", "onselect",
"onselect", "onslotchange",
"onslotchange", "onstalled",
"onstalled", "onsubmit",
"onsubmit", "onsuspend",
"onsuspend", "ontimeupdate",
"ontimeupdate", "ontoggle",
"ontoggle", "onvolumechange",
"onvolumechange", "onwaiting",
"onwaiting", "onwheel",
"onwheel",
// Standard HTML Document and Element // Standard HTML Document and Element
// From: https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers // From: https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers
"oncopy", "oncopy",
"oncut", "oncut",
"onpaste", "onpaste",
// Others // Others
// From: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers // From: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
"onanimationcancel", "onanimationcancel",
"onanimationend", "onanimationend",
"onanimationiteration", "onanimationiteration",
"onanimationstart", "onanimationstart",
"ongotpointercapture", "ongotpointercapture",
"onloadend", "onloadend",
"onlostpointercapture", "onlostpointercapture",
"onpointercancel", "onpointercancel",
"onpointerdown", "onpointerdown",
"onpointerenter", "onpointerenter",
"onpointerleave", "onpointerleave",
"onpointerlockchange", "onpointerlockchange",
"onpointerlockerror", "onpointerlockerror",
"onpointermove", "onpointermove",
"onpointerout", "onpointerout",
"onpointerover", "onpointerover",
"onpointerup", "onpointerup",
"onselectionchange", "onselectionchange",
"onselectstart", "onselectstart",
"onshow", "onshow",
"ontouchcancel", "ontouchcancel",
"ontouchend", "ontouchend",
"ontouchmove", "ontouchmove",
"ontouchstart", "ontouchstart",
"ontransitioncancel", "ontransitioncancel",
"ontransitionend", "ontransitionend",
"ontransitionrun", "ontransitionrun",
"ontransitionstart", "ontransitionstart",
] ]
.into_iter(), .into_iter()
) .collect()
}; };
} }
#[cfg(feature = "std_web")] #[cfg(feature = "std_web")]
lazy_static! { lazy_static! {
static ref UNSUPPORTED_LISTENER_SET: HashSet<&'static str> = { static ref UNSUPPORTED_LISTENER_SET: HashSet<&'static str> = {
HashSet::from_iter( vec![
vec![ "oncancel",
"oncancel", "oncanplay",
"oncanplay", "oncanplaythrough",
"oncanplaythrough", "onclose",
"onclose", "oncuechange",
"oncuechange", "ondurationchange",
"ondurationchange", "onemptied",
"onemptied", "onended",
"onended", "onformdata",
"onformdata", "oninvalid",
"oninvalid", "onloadeddata",
"onloadeddata", "onloadedmetadata",
"onloadedmetadata", "onpause",
"onpause", "onplay",
"onplay", "onplaying",
"onplaying", "onratechange",
"onratechange", "onreset",
"onreset", "onsecuritypolicyviolation",
"onsecuritypolicyviolation", "onseeked",
"onseeked", "onseeking",
"onseeking", "onselect",
"onselect", "onstalled",
"onstalled", "onsuspend",
"onsuspend", "ontimeupdate",
"ontimeupdate", "ontoggle",
"ontoggle", "onvolumechange",
"onvolumechange", "onwaiting",
"onwaiting", "oncopy",
"oncopy", "oncut",
"oncut", "onpaste",
"onpaste", "onanimationcancel",
"onanimationcancel", "onanimationend",
"onanimationend", "onanimationiteration",
"onanimationiteration", "onanimationstart",
"onanimationstart", "onselectstart",
"onselectstart", "onshow",
"onshow", "ontransitioncancel",
"ontransitioncancel", "ontransitionend",
"ontransitionend", "ontransitionrun",
"ontransitionrun", "ontransitionstart",
"ontransitionstart", ]
] .into_iter()
.into_iter(), .collect()
)
}; };
} }

View File

@ -39,11 +39,10 @@ impl<'a> fmt::Debug for PrettyParseError<'a> {
f.write_str("Expected: ")?; f.write_str("Expected: ")?;
self.error.expected[..self.error.expected.len() - 1] self.error.expected[..self.error.expected.len() - 1]
.iter() .iter()
.map(|expected| { .try_for_each(|expected| {
<ExpectedToken as fmt::Display>::fmt(expected, f) <ExpectedToken as fmt::Display>::fmt(expected, f)
.and_then(|_| f.write_str(", ")) .and_then(|_| f.write_str(", "))
}) })?;
.collect::<Result<(), fmt::Error>>()?;
self.error self.error
.expected .expected
.last() .last()

View File

@ -139,11 +139,11 @@ impl<U: Switch + std::fmt::Debug> Switch for AllowMissing<U> {
if inner.is_some() { if inner.is_some() {
(Some(AllowMissing(inner)), inner_state) (Some(AllowMissing(inner)), inner_state)
} else if &route == "" } else if route.is_empty()
|| (&route).starts_with('/') || route.starts_with('/')
|| (&route).starts_with('?') || route.starts_with('?')
|| (&route).starts_with('&') || route.starts_with('&')
|| (&route).starts_with('#') || route.starts_with('#')
{ {
(Some(AllowMissing(None)), inner_state) (Some(AllowMissing(None)), inner_state)
} else { } else {

View File

@ -19,16 +19,45 @@ fn is_c0_control(c: char) -> bool {
/// Returns true when the string provided is a "noncharacter" as defined /// Returns true when the string provided is a "noncharacter" as defined
/// in [the WhatWG spec](https://infra.spec.whatwg.org/#noncharacter) /// in [the WhatWG spec](https://infra.spec.whatwg.org/#noncharacter)
fn is_noncharacter(c: char) -> bool { fn is_noncharacter(c: char) -> bool {
match c { matches!(
'\u{FDD0}'..='\u{FDEF}' => true, c,
'\u{FFFE}' | '\u{FFFF}' | '\u{1FFFE}' | '\u{1FFFF}' | '\u{2FFFE}' | '\u{2FFFF}' '\u{FDD0}'
| '\u{3FFFE}' | '\u{3FFFF}' | '\u{4FFFE}' | '\u{4FFFF}' | '\u{5FFFE}' | '\u{5FFFF}' ..='\u{FDEF}'
| '\u{6FFFE}' | '\u{6FFFF}' | '\u{7FFFE}' | '\u{7FFFF}' | '\u{8FFFE}' | '\u{8FFFF}' | '\u{FFFE}'
| '\u{9FFFE}' | '\u{9FFFF}' | '\u{AFFFE}' | '\u{AFFFF}' | '\u{BFFFE}' | '\u{BFFFF}' | '\u{FFFF}'
| '\u{CFFFE}' | '\u{CFFFF}' | '\u{DFFFE}' | '\u{DFFFF}' | '\u{EFFFE}' | '\u{EFFFF}' | '\u{1FFFE}'
| '\u{FFFFE}' | '\u{FFFFF}' | '\u{10FFFE}' | '\u{10FFFF}' => true, | '\u{1FFFF}'
_ => false, | '\u{2FFFE}'
} | '\u{2FFFF}'
| '\u{3FFFE}'
| '\u{3FFFF}'
| '\u{4FFFE}'
| '\u{4FFFF}'
| '\u{5FFFE}'
| '\u{5FFFF}'
| '\u{6FFFE}'
| '\u{6FFFF}'
| '\u{7FFFE}'
| '\u{7FFFF}'
| '\u{8FFFE}'
| '\u{8FFFF}'
| '\u{9FFFE}'
| '\u{9FFFF}'
| '\u{AFFFE}'
| '\u{AFFFF}'
| '\u{BFFFE}'
| '\u{BFFFF}'
| '\u{CFFFE}'
| '\u{CFFFF}'
| '\u{DFFFE}'
| '\u{DFFFF}'
| '\u{EFFFE}'
| '\u{EFFFF}'
| '\u{FFFFE}'
| '\u{FFFFF}'
| '\u{10FFFE}'
| '\u{10FFFF}'
)
} }
/// Returns true when the string provided is a valid "attribute name" as defined /// Returns true when the string provided is a valid "attribute name" as defined
@ -53,23 +82,21 @@ pub fn is_valid_html_attribute_name(attr: &str) -> bool {
/// Returns true when the character provided is a valid PCENChar as defined /// Returns true when the character provided is a valid PCENChar as defined
/// in [the WhatWG spec](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-pcenchar) /// in [the WhatWG spec](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-pcenchar)
fn is_pcen_char(c: char) -> bool { fn is_pcen_char(c: char) -> bool {
match c { matches!(c, '-' | '.' | '0'..='9' | 'a'..='z' | '_'
'-' | '.' | '0'..='9' | 'a'..='z' | '_' => true, | '\u{B7}'
'\u{B7}' => true, | '\u{C0}'..='\u{D6}'
'\u{C0}'..='\u{D6}' => true, | '\u{D8}'..='\u{F6}'
'\u{D8}'..='\u{F6}' => true, | '\u{F8}'..='\u{37D}'
'\u{F8}'..='\u{37D}' => true, | '\u{37F}'..='\u{1FFF}'
'\u{37F}'..='\u{1FFF}' => true, | '\u{200C}'..='\u{200D}'
'\u{200C}'..='\u{200D}' => true, | '\u{203F}'..='\u{2040}'
'\u{203F}'..='\u{2040}' => true, | '\u{2070}'..='\u{218F}'
'\u{2070}'..='\u{218F}' => true, | '\u{2C00}'..='\u{2FEF}'
'\u{2C00}'..='\u{2FEF}' => true, | '\u{3001}'..='\u{D7FF}'
'\u{3001}'..='\u{D7FF}' => true, | '\u{F900}'..='\u{FDCF}'
'\u{F900}'..='\u{FDCF}' => true, | '\u{FDF0}'..='\u{FFFD}'
'\u{FDF0}'..='\u{FFFD}' => true, | '\u{10000}'..='\u{EFFFF}'
'\u{10000}'..='\u{EFFFF}' => true, )
_ => false,
}
} }
/// Returns true when the tag name provided would be a valid "custom element" per /// Returns true when the tag name provided would be a valid "custom element" per
@ -93,7 +120,7 @@ fn is_valid_html_custom_element_name(tag: &str) -> bool {
None => false, None => false,
Some(first_char) => { Some(first_char) => {
// must begin with [a-z] // must begin with [a-z]
if first_char < 'a' || first_char > 'z' { if !('a'..='z').contains(&first_char) {
return false; return false;
} }