Skip to content

Commit

Permalink
Apply lint suggestions, add lint workflow (#829)
Browse files Browse the repository at this point in the history
* Apply lint suggestions

* Add lint workflow for node bindings
  • Loading branch information
rygine authored Jun 7, 2024
1 parent de09cd2 commit ba01940
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 54 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/lint-node-bindings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint Node Bindings

on:
pull_request:
paths:
- "bindings_node/**"
- ".github/workflows/lint-node-bindings.yaml"

jobs:
lint:
runs-on: warp-ubuntu-latest-x64-8x
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run clippy and fail on warnings
run: cargo clippy --manifest-path bindings_node/Cargo.toml --all-features --all-targets --no-deps -- -Dwarnings
- name: Run format check
run: cargo fmt --manifest-path bindings_node/Cargo.toml --check
5 changes: 1 addition & 4 deletions bindings_node/src/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ impl NapiConversations {
account_addresses: Vec<String>,
permissions: Option<GroupPermissions>,
) -> Result<NapiGroup> {
let group_permissions = match permissions {
Some(group_permissions) => Some(group_permissions.into()),
_ => None,
};
let group_permissions = permissions.map(|group_permissions| group_permissions.into());

let convo = self
.inner_client
Expand Down
39 changes: 16 additions & 23 deletions bindings_node/src/encoded_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ impl From<ContentTypeId> for NapiContentTypeId {
}
}

impl Into<ContentTypeId> for NapiContentTypeId {
fn into(self) -> ContentTypeId {
impl From<NapiContentTypeId> for ContentTypeId {
fn from(content_type_id: NapiContentTypeId) -> Self {
ContentTypeId {
authority_id: self.authority_id,
type_id: self.type_id,
version_major: self.version_major,
version_minor: self.version_minor,
authority_id: content_type_id.authority_id,
type_id: content_type_id.type_id,
version_major: content_type_id.version_major,
version_minor: content_type_id.version_minor,
}
}
}
Expand All @@ -46,10 +46,7 @@ pub struct NapiEncodedContent {

impl From<EncodedContent> for NapiEncodedContent {
fn from(content: EncodedContent) -> NapiEncodedContent {
let r#type = match content.r#type {
Some(v) => Some(v.into()),
None => None,
};
let r#type = content.r#type.map(|v| v.into());

NapiEncodedContent {
r#type,
Expand All @@ -61,21 +58,17 @@ impl From<EncodedContent> for NapiEncodedContent {
}
}

impl Into<EncodedContent> for NapiEncodedContent {
fn into(self) -> EncodedContent {
let content_type = match self.r#type {
Some(v) => Some(v.into()),
None => None,
};

let content: Vec<u8> = self.content.deref().to_vec();
impl From<NapiEncodedContent> for EncodedContent {
fn from(content: NapiEncodedContent) -> Self {
let r#type = content.r#type.map(|v| v.into());
let content_bytes: Vec<u8> = content.content.deref().to_vec();

EncodedContent {
r#type: content_type,
parameters: self.parameters,
fallback: self.fallback,
compression: self.compression,
content,
r#type,
parameters: content.parameters,
fallback: content.fallback,
compression: content.compression,
content: content_bytes,
}
}
}
28 changes: 11 additions & 17 deletions bindings_node/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl From<PreconfiguredPolicies> for GroupPermissions {
}
}

impl Into<PreconfiguredPolicies> for GroupPermissions {
fn into(self) -> PreconfiguredPolicies {
match self {
impl From<GroupPermissions> for PreconfiguredPolicies {
fn from(permissions: GroupPermissions) -> Self {
match permissions {
GroupPermissions::EveryoneIsAdmin => PreconfiguredPolicies::AllMembers,
GroupPermissions::GroupCreatorIsAdmin => PreconfiguredPolicies::AdminsOnly,
}
Expand Down Expand Up @@ -131,10 +131,9 @@ impl NapiGroup {
#[napi]
pub async fn send(&self, encoded_content: NapiEncodedContent) -> Result<String> {
let encoded_content: EncodedContent = encoded_content.into();
let group_id: Vec<u8> = self.group_id.clone().into();
let group = MlsGroup::new(
self.inner_client.context().clone(),
group_id,
self.group_id.clone(),
self.created_at_ns,
);

Expand All @@ -150,10 +149,9 @@ impl NapiGroup {

#[napi]
pub async fn sync(&self) -> Result<()> {
let group_id: Vec<u8> = self.group_id.clone().into();
let group = MlsGroup::new(
self.inner_client.context().clone(),
group_id,
self.group_id.clone(),
self.created_at_ns,
);

Expand Down Expand Up @@ -504,11 +502,9 @@ impl NapiGroup {
self.created_at_ns,
);

Ok(
group
.is_active()
.map_err(|e| Error::from_reason(format!("{}", e)))?,
)
group
.is_active()
.map_err(|e| Error::from_reason(format!("{}", e)))
}

#[napi]
Expand All @@ -519,11 +515,9 @@ impl NapiGroup {
self.created_at_ns,
);

Ok(
group
.added_by_inbox_id()
.map_err(|e| Error::from_reason(format!("{}", e)))?,
)
group
.added_by_inbox_id()
.map_err(|e| Error::from_reason(format!("{}", e)))
}

#[napi]
Expand Down
11 changes: 6 additions & 5 deletions bindings_node/src/mls_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ impl NapiClient {
.await
.map_err(|e| Error::from_reason(format!("{}", e)))?;

return Ok(());
Ok(())
}

#[napi]
pub fn signature_text(&self) -> Option<String> {
match self.inner_client.identity().signature_request() {
Some(signature_req) => Some(signature_req.signature_text()),
None => None,
}
self
.inner_client
.identity()
.signature_request()
.map(|signature_req| signature_req.signature_text())
}

#[napi]
Expand Down
7 changes: 2 additions & 5 deletions bindings_node/src/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ impl NapiStreamCloser {

#[napi]
pub fn end(&self) {
match self.close_fn.lock() {
Ok(mut close_fn_option) => {
let _ = close_fn_option.take().map(|close_fn| close_fn.send(()));
}
_ => {}
if let Ok(mut close_fn_option) = self.close_fn.lock() {
let _ = close_fn_option.take().map(|close_fn| close_fn.send(()));
}
}

Expand Down

0 comments on commit ba01940

Please sign in to comment.