Skip to content

Commit

Permalink
Format Rust in precommit and lint+format scripts (#6201)
Browse files Browse the repository at this point in the history
* Upgrade to husky@6

* Run cargo fmt on precommit

* Format

* Add cargo fmt to format and lint scripts
  • Loading branch information
Will Binns-Smith committed Apr 29, 2021
1 parent b54c2b6 commit c8e3747
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 88 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/pre-commit
@@ -0,0 +1,5 @@
#!/bin/sh
# Generated with husky-init and https://github.com/typicode/husky-4-to-6
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
18 changes: 12 additions & 6 deletions native-packages/fs-search/src/lib.rs
Expand Up @@ -2,8 +2,8 @@ extern crate napi;
#[macro_use]
extern crate napi_derive;

use napi::{CallContext, Either, JsNull, JsNumber, JsObject, JsString, Result};
use std::convert::TryInto;
use napi::{CallContext, JsNumber, JsString, JsNull, Either, JsObject, Result};
use std::path::Path;

#[js_function(2)]
Expand All @@ -29,12 +29,15 @@ fn find_ancestor_file(ctx: CallContext) -> Result<Either<JsNull, JsString>> {
for name in &filenames {
let fullpath = dir.join(name.as_str()?);
if fullpath.is_file() {
return ctx.env.create_string(fullpath.to_str().unwrap()).map(Either::B);
return ctx
.env
.create_string(fullpath.to_str().unwrap())
.map(Either::B);
}
}
}

return ctx.env.get_null().map(Either::A)
return ctx.env.get_null().map(Either::A);
}

#[js_function(1)]
Expand All @@ -50,7 +53,7 @@ fn find_first_file(ctx: CallContext) -> Result<Either<JsNull, JsString>> {
}
}

return ctx.env.get_null().map(Either::A)
return ctx.env.get_null().map(Either::A);
}

#[js_function(2)]
Expand All @@ -70,11 +73,14 @@ fn find_node_module(ctx: CallContext) -> Result<Either<JsNull, JsString>> {

let fullpath = dir.join("node_modules").join(module);
if fullpath.is_dir() {
return ctx.env.create_string(fullpath.to_str().unwrap()).map(Either::B);
return ctx
.env
.create_string(fullpath.to_str().unwrap())
.map(Either::B);
}
}

return ctx.env.get_null().map(Either::A)
return ctx.env.get_null().map(Either::A);
}

#[module_exports]
Expand Down
17 changes: 7 additions & 10 deletions package.json
Expand Up @@ -14,14 +14,14 @@
"build": "cross-env NODE_ENV=production PARCEL_BUILD_ENV=production gulp",
"clean-test": "rimraf packages/core/integration-tests/.parcel-cache && rimraf packages/core/integration-tests/dist",
"clean": "yarn clean-test && lerna clean --yes && lerna exec -- rimraf ./lib && yarn",
"format": "prettier --write \"./packages/*/*/{src,bin,test}/**/*.{js,json,md}\"",
"format": "prettier --write \"./packages/*/*/{src,bin,test}/**/*.{js,json,md}\" && cargo fmt --all",
"link-all": "node scripts/link-all.js packages",
"unlink-all": "node scripts/unlink-all.js packages",
"link-native": "node scripts/link-native.js && yarn",
"unlink-native": "rimraf packages/native-packages",
"postinstall": "node scripts/postinstall.js",
"check": "flow check",
"lint": "eslint . && prettier \"./packages/*/*/{src,bin,test}/**/*.{js,json,md}\" --list-different",
"lint": "eslint . && prettier \"./packages/*/*/{src,bin,test}/**/*.{js,json,md}\" --list-different && cargo fmt --all -- --check",
"lint:readme": "node scripts/validate-readme-toc.js",
"prepublishOnly": "yarn build && node scripts/update-config-dependencies.js",
"test:unit": "cross-env NODE_ENV=test mocha",
Expand All @@ -32,7 +32,8 @@
"nightly:release": "lerna publish -y --canary --preid nightly --dist-tag=nightly --exact --force-publish=* --no-git-tag-version --no-push",
"tag:prerelease": "lerna version --exact --force-publish=* --no-git-tag-version --no-push",
"tag:release": "lerna version --force-publish=* --no-git-tag-version --no-push",
"release": "lerna publish -y from-package --dist-tag=next --no-git-tag-version --no-push"
"release": "lerna publish -y from-package --dist-tag=next --no-git-tag-version --no-push",
"prepare": "husky install"
},
"devDependencies": {
"@babel/core": "^7.12.0",
Expand All @@ -43,7 +44,7 @@
"flow-bin": "0.148.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"husky": "^4.2.5",
"husky": "^6.0.0",
"lerna": "^3.3.2",
"lint-staged": "^10.2.11",
"mocha": "^8.3.0",
Expand All @@ -57,13 +58,9 @@
"engines": {
"node": ">= 12.0.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,json,md}": "prettier --write"
"*.{js,json,md}": "prettier --write",
"*.rs": "rustfmt"
},
"collective": {
"type": "opencollective",
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
@@ -0,0 +1 @@
tab_spaces = 2
77 changes: 5 additions & 72 deletions yarn.lock
Expand Up @@ -3997,11 +3997,6 @@ compare-func@^1.3.1:
array-ify "^1.0.0"
dot-prop "^3.0.0"

compare-versions@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"
integrity sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==

component-emitter@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
Expand Down Expand Up @@ -5987,21 +5982,6 @@ find-up@^3.0.0:
dependencies:
locate-path "^3.0.0"

find-up@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19"
integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==
dependencies:
locate-path "^5.0.0"
path-exists "^4.0.0"

find-versions@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-3.2.0.tgz#10297f98030a786829681690545ef659ed1d254e"
integrity sha512-P8WRou2S+oe222TOCHitLy8zj+SIsVJh52VP4lvXkaFVnOFFdoWv1H1Jjvel1aI6NCFOAaeAVm8qrI0odiLcww==
dependencies:
semver-regex "^2.0.0"

findup-sync@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-2.0.0.tgz#9326b1488c22d1a6088650a86901b2d9a90a2cbc"
Expand Down Expand Up @@ -7088,21 +7068,10 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"

husky@^4.2.5:
version "4.2.5"
resolved "https://registry.yarnpkg.com/husky/-/husky-4.2.5.tgz#2b4f7622673a71579f901d9885ed448394b5fa36"
integrity sha512-SYZ95AjKcX7goYVZtVZF2i6XiZcHknw50iXvY7b0MiGoj5RwdgRQNEHdb+gPDPCXKlzwrybjFjkL6FOj8uRhZQ==
dependencies:
chalk "^4.0.0"
ci-info "^2.0.0"
compare-versions "^3.6.0"
cosmiconfig "^6.0.0"
find-versions "^3.2.0"
opencollective-postinstall "^2.0.2"
pkg-dir "^4.2.0"
please-upgrade-node "^3.2.0"
slash "^3.0.0"
which-pm-runs "^1.0.0"
husky@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/husky/-/husky-6.0.0.tgz#810f11869adf51604c32ea577edbc377d7f9319e"
integrity sha512-SQS2gDTB7tBN486QSoKPKQItZw97BMOd+Kdb6ghfpBc0yXyzrddI0oDV5MkDAbuB4X2mO3/nj60TRMcYxwzZeQ==

iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@~0.4.13:
version "0.4.24"
Expand Down Expand Up @@ -8294,13 +8263,6 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==
dependencies:
p-locate "^4.1.0"

locate-path@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286"
Expand Down Expand Up @@ -9498,11 +9460,6 @@ open@^7.0.3:
is-docker "^2.0.0"
is-wsl "^2.1.1"

opencollective-postinstall@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==

optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
Expand Down Expand Up @@ -9606,7 +9563,7 @@ p-limit@^1.1.0:
dependencies:
p-try "^1.0.0"

p-limit@^2.0.0, p-limit@^2.2.0:
p-limit@^2.0.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
Expand Down Expand Up @@ -9634,13 +9591,6 @@ p-locate@^3.0.0:
dependencies:
p-limit "^2.0.0"

p-locate@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07"
integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==
dependencies:
p-limit "^2.2.0"

p-locate@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834"
Expand Down Expand Up @@ -10028,13 +9978,6 @@ pkg-dir@^3.0.0:
dependencies:
find-up "^3.0.0"

pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==
dependencies:
find-up "^4.0.0"

please-upgrade-node@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942"
Expand Down Expand Up @@ -11716,11 +11659,6 @@ semver-greatest-satisfied-range@^1.1.0:
dependencies:
sver-compat "^1.5.0"

semver-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-2.0.0.tgz#a93c2c5844539a770233379107b38c7b4ac9d338"
integrity sha512-mUdIBBvdn0PLOeP3TEkMH7HHeUP3GjsXCwKarjv/kGmUFOYg1VqEemKhoQpWMu6X2I8kHeuVdGibLGkVK+/5Qw==

"semver@2 || 3 || 4 || 5", "semver@2.x || 3.x || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0, semver@^5.7.0, semver@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
Expand Down Expand Up @@ -11911,11 +11849,6 @@ slash@^2.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==

slash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

slice-ansi@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636"
Expand Down

0 comments on commit c8e3747

Please sign in to comment.