Skip to content

Commit

Permalink
Merge pull request #698 from neon-bindings/kv/rustfmt
Browse files Browse the repository at this point in the history
Lint CI enforcement and cargo fmt
  • Loading branch information
kjvalencik authored Mar 14, 2021
2 parents bd69a89 + 111d2ac commit b730df7
Show file tree
Hide file tree
Showing 69 changed files with 1,729 additions and 1,295 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
# Neon defines mutually exclusive feature flags which prevents using `cargo clippy --all-features`
# The following aliases simplify linting the entire workspace
clippy-legacy = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,try-catch-api,legacy-runtime -- -A clippy::missing_safety_doc"
clippy-napi = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features proc-macros,try-catch-api,napi-experimental -- -A clippy::missing_safety_doc"
39 changes: 39 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Lints

on:
push:
# Prevent duplicate runs of this workflow on our own internal PRs.
branches:
- main
pull_request:
branches:
- main

jobs:
lint:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]
rust-toolchain: [nightly]

steps:
- uses: actions/checkout@v2
- name: Use Rust ${{ matrix.rust-toolchain }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust-toolchain }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install build-essential
run: sudo apt-get install -y build-essential
- name: Formatting
run: cargo fmt --all -- --check
- name: Clippy (N-API)
run: cargo clippy-napi
- name: Clippy (Legacy)
run: cargo clippy-legacy
12 changes: 5 additions & 7 deletions crates/neon-build/src/napi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ impl Setup {
}

fn absolute_output_file(&self) -> PathBuf {
let output_file = self.output_file.clone()
let output_file = self
.output_file
.clone()
.unwrap_or_else(|| PathBuf::from("index.node"));

// Don't prepend `output_dir` if `output_file` is absolute
Expand Down Expand Up @@ -145,19 +147,15 @@ fn test_absolute_output_file_absolute_file() {
#[test]
fn test_absolute_output_file_absolute_dir() {
let expected = PathBuf::from("/tmp/index.node");
let actual = Setup::options()
.output_dir("/tmp")
.absolute_output_file();
let actual = Setup::options().output_dir("/tmp").absolute_output_file();

assert_eq!(actual, expected);
}

#[test]
fn test_absolute_output_file_relative_dir() {
let expected = manifest_dir().join("lib").join("index.node");
let actual = Setup::options()
.output_dir("lib")
.absolute_output_file();
let actual = Setup::options().output_dir("lib").absolute_output_file();

assert_eq!(actual, expected);
}
Expand Down
5 changes: 0 additions & 5 deletions crates/neon-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ napi = []
[dependencies]
quote = "1"
syn = { version = "1", features = ["full"] }

[dev-dependencies.neon]
version = "*"
path = "../.."
features = ["proc-macros"]
6 changes: 3 additions & 3 deletions crates/neon-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use legacy as macros;
/// module. This attribute should only be used _once_ in a module and will
/// be called each time the module is initialized in a context.
///
/// ```no_run
/// ```ignore
/// # use neon::prelude::*;
/// #[neon::main]
/// fn my_module(mut cx: ModuleContext) -> NeonResult<()> {
/// let version = cx.string("1.0.0");
///
///
/// cx.export_value("version", version)?;
///
///
/// Ok(())
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion crates/neon-macros/src/napi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) fn main(
::std::mem::transmute(m),
#name,
);

m
}

Expand Down
4 changes: 3 additions & 1 deletion crates/neon-runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(all(not(feature = "neon-sys"), not(feature = "napi")))]
compile_error!("The Neon runtime must have at least one of the `neon-sys` or `napi` backends enabled.");
compile_error!(
"The Neon runtime must have at least one of the `neon-sys` or `napi` backends enabled."
);

use cfg_if::cfg_if;

Expand Down
26 changes: 13 additions & 13 deletions crates/neon-runtime/src/nan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
pub mod raw;
pub mod call;
pub mod scope;
pub mod object;
pub mod array;
pub mod string;
pub mod primitive;
pub mod error;
pub mod arraybuffer;
pub mod buffer;
pub mod tag;
pub mod module;
pub mod mem;
pub mod fun;
pub mod convert;
pub mod call;
pub mod class;
pub mod task;
pub mod convert;
pub mod error;
pub mod fun;
pub mod handler;
pub mod mem;
pub mod module;
pub mod object;
pub mod primitive;
pub mod raw;
pub mod scope;
pub mod string;
pub mod tag;
pub mod task;
pub mod try_catch;
4 changes: 3 additions & 1 deletion crates/neon-runtime/src/nan/raw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Fundamental definitions for mapping to the V8 memory space.
pub use neon_sys::{Local, FunctionCallbackInfo, Isolate, HandleScope, EscapableHandleScope, InheritedHandleScope};
pub use neon_sys::{
EscapableHandleScope, FunctionCallbackInfo, HandleScope, InheritedHandleScope, Isolate, Local,
};
18 changes: 12 additions & 6 deletions crates/neon-runtime/src/nan/scope.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Facilities for working with `v8::HandleScope`s and `v8::EscapableHandleScope`s.
use crate::raw::{HandleScope, EscapableHandleScope, InheritedHandleScope, Isolate};
use crate::raw::{EscapableHandleScope, HandleScope, InheritedHandleScope, Isolate};

pub trait Root {
/// # Safety
Expand All @@ -15,7 +15,9 @@ pub trait Root {
}

impl Root for HandleScope {
unsafe fn allocate() -> Self { HandleScope::new() }
unsafe fn allocate() -> Self {
HandleScope::new()
}
unsafe fn enter(&mut self, isolate: Isolate) {
enter(self, isolate)
}
Expand All @@ -25,7 +27,9 @@ impl Root for HandleScope {
}

impl Root for EscapableHandleScope {
unsafe fn allocate() -> Self { EscapableHandleScope::new() }
unsafe fn allocate() -> Self {
EscapableHandleScope::new()
}
unsafe fn enter(&mut self, isolate: Isolate) {
enter_escapable(self, isolate)
}
Expand All @@ -35,9 +39,11 @@ impl Root for EscapableHandleScope {
}

impl Root for InheritedHandleScope {
unsafe fn allocate() -> Self { InheritedHandleScope }
unsafe fn enter(&mut self, _: Isolate) { }
unsafe fn exit(&mut self, _: Isolate) { }
unsafe fn allocate() -> Self {
InheritedHandleScope
}
unsafe fn enter(&mut self, _: Isolate) {}
unsafe fn exit(&mut self, _: Isolate) {}
}

/// Mutates the `out` argument provided to refer to the newly escaped `v8::Local` value.
Expand Down
4 changes: 2 additions & 2 deletions crates/neon-runtime/src/napi/arraybuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub unsafe fn data(env: Env, base_out: &mut *mut c_void, obj: Local) -> usize {
}

pub unsafe fn new_external<T>(env: Env, data: T) -> Local
where
T: AsMut<[u8]> + Send,
where
T: AsMut<[u8]> + Send,
{
// Safety: Boxing could move the data; must box before grabbing a raw pointer
let mut data = Box::new(data);
Expand Down
Loading

0 comments on commit b730df7

Please sign in to comment.