Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/todomvc/static/css/todomvc-app-css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ label[for='toggle-all'] {
}

.todo-list li .toggle:after {
content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="#ededed" stroke-width="3"/></svg>');
content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="%23ededed" stroke-width="3"/></svg>');
}

.todo-list li .toggle:checked:after {
content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="#bddad5" stroke-width="3"/><path fill="#5dc2af" d="M72 25L42 71 27 56l-4 4 20 20 34-52z"/></svg>');
content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="%23bddad5" stroke-width="3"/><path fill="%235dc2af" d="M72 25L42 71 27 56l-4 4 20 20 34-52z"/></svg>');
}

.todo-list li label {
Expand Down
18 changes: 9 additions & 9 deletions src/ecosystem/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ impl Serialize for Value {
} else if Object::instance_of( reference ) {
let object: Object = reference.try_into().unwrap();
let value: BTreeMap< String, Value > = object.into();
let mut map = try!( serializer.serialize_map( Some( value.len() ) ) );
let mut map = serializer.serialize_map( Some( value.len() ) )?;
for (key, value) in value {
try!( map.serialize_key( &key ) );
try!( map.serialize_value( &value ) );
map.serialize_key( &key )?;
map.serialize_value( &value )?;
}

map.end()
} else {
let map = try!( serializer.serialize_map( None ) );
let map = serializer.serialize_map( None )?;
map.end()
}
}
Expand Down Expand Up @@ -377,7 +377,7 @@ impl From< ConversionError > for value::ConversionError {
}
}

#[derive(Debug)]
#[derive(Default, Debug)]
pub struct Serializer {
}

Expand Down Expand Up @@ -526,7 +526,7 @@ impl< 'a > ser::Serializer for &'a mut Serializer {
}

#[doc(hidden)]
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
#[allow(clippy::needless_pass_by_value)]
#[inline]
pub fn to_value< T: Serialize >( value: T ) -> Result< Value, ConversionError > {
let mut serializer = Serializer {};
Expand Down Expand Up @@ -869,8 +869,8 @@ impl< 'de > de::Deserializer< 'de > for Value {
};

visitor.visit_enum( EnumDeserializer {
variant: variant,
value: value,
variant,
value,
})
}

Expand Down Expand Up @@ -1254,7 +1254,7 @@ impl< T: fmt::Debug > fmt::Debug for Serde< T > {

impl< T: Serialize > JsSerialize for Serde< T > {
#[inline]
fn _into_js< 'a >( &'a self ) -> SerializedValue< 'a > {
fn _into_js( &self ) -> SerializedValue {
let value = to_value( &self.0 ).unwrap();
global_arena::serialize_value( value )
}
Expand Down
2 changes: 1 addition & 1 deletion src/ecosystem/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl TryFrom< JsonValue > for Value {
JsonValue::Object( value ) => {
let mut map: BTreeMap< String, Value > = BTreeMap::new();
for (key, value) in value.into_iter() {
map.insert( key.into(), value.try_into()? );
map.insert( key, value.try_into()? );
}

map.into()
Expand Down
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,17 @@ pub mod traits {
pub use super::web::midi::IMidiPort;
}

#[cfg(test)]
mod tests {
#[test]
fn bla() {
// use webcore::try_from::TryInto;
// let res:bool = js!{ false }.try_into().unwrap();
// assert!(res);
println!("hi");
}
}

#[doc(hidden)]
pub mod private {
#[cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown", not(cargo_web)))]
Expand All @@ -551,7 +562,7 @@ pub mod private {
pub use webcore::serialization::{
JsSerialize,
JsSerializeOwned,
SerializedValue
SerializedValue,
};

pub use webcore::newtype::{
Expand Down
8 changes: 6 additions & 2 deletions src/webapi/array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ impl ArrayBuffer {
// https://www.ecma-international.org/ecma-262/6.0/#sec-get-arraybuffer.prototype.bytelength
pub fn len( &self ) -> u64 {
let reference = self.as_ref();
let length = js!( return @{reference}.byteLength; ).try_into().unwrap();
length
js!( return @{reference}.byteLength; ).try_into().unwrap()
}

/// Returns `true` if the buffer contains no bytes.
pub fn is_empty( &self ) -> bool {
self.len() == 0
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/webapi/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ pub trait IBlob: ReferenceType {
{
slice_blob(self, range, Some(content_type))
}

/// Returns `true` if the `Blob` contains no bytes.
fn is_empty( &self ) -> bool {
self.len() == 0
}
}

/// A reference to a JavaScript object which implements the [IBlob](trait.IBlob.html)
Expand All @@ -90,6 +95,12 @@ pub struct Blob( Reference );

impl IBlob for Blob {}

impl Default for Blob {
fn default() -> Self {
Self::new()
}
}

impl Blob {
/// Creates a new `Blob`.
///
Expand Down
2 changes: 2 additions & 0 deletions src/webapi/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl Date {
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
// https://www.ecma-international.org/ecma-262/6.0/#sec-date-constructor-date
#[allow(clippy::new_without_default)] // Because this generates a different value every time, Default is not appropriate.
pub fn new() -> Self {
js!(
return new Date();
Expand Down Expand Up @@ -485,6 +486,7 @@ impl Date {
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
// https://www.ecma-international.org/ecma-262/6.0/#sec-date.prototype.tostring
#[inline]
#[allow(clippy::inherent_to_string)] // We're matching the JS api here.
pub fn to_string(&self) -> String {
js!(
return @{self}.toString();
Expand Down
2 changes: 2 additions & 0 deletions src/webapi/document.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use webcore::value::{Reference, Value};
use webcore::try_from::{TryInto, TryFrom};
#[cfg(feature = "experimental_features_which_may_break_on_minor_version_bumps")]
use webcore::promise::{Promise, TypedPromise};
#[cfg(feature = "experimental_features_which_may_break_on_minor_version_bumps")]
use webapi::error::TypeError;
use webapi::event_target::{IEventTarget, EventTarget};
use webapi::node::{INode, Node, CloneKind};
Expand Down
4 changes: 3 additions & 1 deletion src/webapi/element.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use webcore::value::Reference;
use webcore::try_from::{TryFrom, TryInto};
#[cfg(feature = "experimental_features_which_may_break_on_minor_version_bumps")]
use webcore::promise::{Promise, TypedPromise};
#[cfg(feature = "experimental_features_which_may_break_on_minor_version_bumps")]
use webapi::error::TypeError;
use webapi::dom_exception::{InvalidCharacterError, InvalidPointerId, NoModificationAllowedError, SyntaxError};
use webapi::event_target::{IEventTarget, EventTarget};
Expand Down Expand Up @@ -315,8 +317,8 @@ pub enum InsertPosition {
AfterEnd,
}

/// Errors thrown by `Element::insert_adjacent_html`.
error_enum_boilerplate! {
/// Errors thrown by `Element::insert_adjacent_html`.
InsertAdjacentError,
NoModificationAllowedError, SyntaxError
}
Expand Down
2 changes: 1 addition & 1 deletion src/webapi/event_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub trait IEventTarget: ReferenceType {
EventListenerHandle {
event_type: T::EVENT_TYPE,
reference: reference.clone(),
listener_reference: listener_reference
listener_reference
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/webapi/events/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ impl DataTransferItemList {
index: 0,
}
}

/// Returns `true` if there are no drag items in the list.
pub fn is_empty( &self ) -> bool {
self.len() == 0
}
}

impl IntoIterator for DataTransferItemList {
Expand Down Expand Up @@ -598,10 +603,8 @@ impl DataTransferItem {
pub fn get_as_string_future( &self ) -> oneshot::Receiver<String> {
let (sender, receiver) = oneshot::channel();
let callback = |s: String| {
match sender.send(s) {
Ok(_) => {},
Err(_) => {},
};
// Ignore the Result, Ok gives () and Err only happens if the receiver is dropped before this is called, which is fine.
let _ = sender.send(s);
};

js!(@(no_return)
Expand Down
2 changes: 1 addition & 1 deletion src/webapi/events/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub struct MouseButtonsState(u8);

impl MouseButtonsState {
/// Check if a [MouseButton](enum.MouseButton.html) is currently pressed
pub fn is_down(&self, button: MouseButton) -> bool {
pub fn is_down(self, button: MouseButton) -> bool {
match button {
MouseButton::Left => self.0 & 0b1 != 0,
MouseButton::Right => self.0 & 0b10 != 0,
Expand Down
5 changes: 5 additions & 0 deletions src/webapi/file_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ impl FileList {
index: 0
}
}

/// Returns `true` if the list contains no Files
pub fn is_empty( &self ) -> bool {
self.len() == 0
}
}

impl IntoIterator for FileList {
Expand Down
6 changes: 6 additions & 0 deletions src/webapi/file_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub enum FileReaderReadyState {
Done
}

impl Default for FileReader {
fn default() -> Self {
Self::new()
}
}

impl FileReader {
/// Returns a newly constructed `FileReader`.
///
Expand Down
6 changes: 6 additions & 0 deletions src/webapi/form_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ impl TryFrom< Value > for Option< FormDataEntry > {
}
}

impl Default for FormData {
fn default() -> Self {
Self::new()
}
}

impl FormData {
/// Creates a new `FormData`.
///
Expand Down
2 changes: 1 addition & 1 deletion src/webapi/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ pub fn alert( message: &str ) {

/// An alias for [window.confirm](struct.Window.html#method.confirm).
pub fn confirm( message: &str ) -> bool {
return window().confirm( message );
window().confirm( message )
}
5 changes: 5 additions & 0 deletions src/webapi/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ impl History {
return @{self}.length;
).try_into().unwrap()
}

/// Returns `true` if there are no history entries.
pub fn is_empty( &self ) -> bool {
self.len() == 0
}
}
5 changes: 5 additions & 0 deletions src/webapi/html_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ impl HtmlCollection {
index: 0
}
}

/// Returns true if the collection contains no elements
pub fn is_empty( &self ) -> bool {
self.len() == 0
}
}


Expand Down
6 changes: 6 additions & 0 deletions src/webapi/html_elements/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ impl INode for ImageElement {}
impl IElement for ImageElement {}
impl IHtmlElement for ImageElement {}

impl Default for ImageElement {
fn default() -> Self {
Self::new()
}
}

impl ImageElement {
/// Constructs a new ImageElement.
///
Expand Down
4 changes: 2 additions & 2 deletions src/webapi/html_elements/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub enum SlotContentKind {
}

impl SlotContentKind {
fn to_bool(&self) -> bool {
match *self {
fn to_bool(self) -> bool {
match self {
SlotContentKind::AssignedOnly => false,
SlotContentKind::WithFallback => true,
}
Expand Down
10 changes: 5 additions & 5 deletions src/webapi/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ impl MidiAccess {
/// The MIDI input ports available to the system.
// https://webaudio.github.io/web-midi-api/#dom-midiaccess-inputs
pub fn inputs( &self ) -> MidiInputMap {
return js!(
js!(
return @{self}.inputs;
).try_into().unwrap()
}

/// The MIDI output ports available to the system.
// https://webaudio.github.io/web-midi-api/#dom-midiaccess-outputs
pub fn outputs( &self ) -> MidiOutputMap {
return js!(
js!(
return @{self}.outputs;
).try_into().unwrap()
}

/// This attribute informs the user whether system exclusive support is enabled.
// https://webaudio.github.io/web-midi-api/#dom-midiaccess-sysexenabled
pub fn sysex_enabled( &self ) -> bool {
return js!(
js!(
return @{self}.sysexEnabled;
).try_into().unwrap()
}
Expand Down Expand Up @@ -189,13 +189,13 @@ pub trait IMidiPort: IEventTarget {
/// has chosen for their application.
// https://webaudio.github.io/web-midi-api/#dom-midiport-id
fn id( &self ) -> String {
return js!( return @{self.as_ref()}.id; ).try_into().unwrap();
js!( return @{self.as_ref()}.id; ).try_into().unwrap()
}

/// The system name of the port.
// https://webaudio.github.io/web-midi-api/#dom-midiport-name
fn name( &self ) -> Option< String > {
return js!( return @{self.as_ref()}.name; ).try_into().unwrap();
js!( return @{self.as_ref()}.name; ).try_into().unwrap()
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/webapi/mutation_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl MutationObserver {
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#Constructor)
// https://dom.spec.whatwg.org/#ref-for-dom-mutationobserver-mutationobserver
#[allow(clippy::new_ret_no_self)]
pub fn new< F >( callback: F ) -> MutationObserverHandle
where F: FnMut( Vec< MutationRecord >, Self ) + 'static {
let callback_reference: Reference = js! ( return @{Mut(callback)}; ).try_into().unwrap();
Expand Down Expand Up @@ -252,19 +253,19 @@ impl TryFrom< Value > for MutationRecord {

match kind.as_str() {
"attributes" => Ok( MutationRecord::Attribute {
target: target,
target,
name: js!( return @{r}.attributeName; ).try_into()?,
namespace: js!( return @{r}.attributeNamespace; ).try_into()?,
old_value: js!( return @{r}.oldValue; ).try_into()?,
} ),

"characterData" => Ok( MutationRecord::CharacterData {
target: target,
target,
old_data: js!( return @{r}.oldValue; ).try_into()?,
} ),

"childList" => Ok( MutationRecord::ChildList {
target: target,
target,
inserted_nodes: js!( return @{r}.addedNodes; ).try_into()?,
removed_nodes: js!( return @{r}.removedNodes; ).try_into()?,
previous_sibling: js!( return @{r}.previousSibling; ).try_into()?,
Expand Down
Loading