Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3399031
D6310.id21085.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6310.id21085.diff
View Options
diff --git a/.lintstagedrc.js b/.lintstagedrc.js
--- a/.lintstagedrc.js
+++ b/.lintstagedrc.js
@@ -1,5 +1,6 @@
const { CLIEngine } = require('eslint');
const { getClangPaths } = require('./scripts/get_clang_paths');
+const { findRustProjectPath } = require('./scripts/get_cargo_path');
const cli = new CLIEngine({});
@@ -58,8 +59,9 @@
});
return 'clang-format -i ' + files.join(' ');
},
- 'services/commtest/**/*.rs': function rustFormat(files) {
- return 'yarn rust-pre-commit';
+ '*.rs': function rustFormat(files) {
+ const paths = new Set(files.map(findRustProjectPath).filter(Boolean));
+ return `yarn rust-pre-commit ${Array.from(paths).join(' ')}`;
},
'services/terraform/*.tf': function checkTerraform(files) {
return 'yarn terraform-pre-commit';
diff --git a/scripts/get_cargo_path.js b/scripts/get_cargo_path.js
new file mode 100644
--- /dev/null
+++ b/scripts/get_cargo_path.js
@@ -0,0 +1,12 @@
+// @flow
+
+const findUp = require('find-up');
+
+// finds the path to the parent directory containing a Cargo.toml file for the
+// given path. Returns null if no Cargo.toml file is found.
+function findRustProjectPath(path) {
+ const cargoTomlPath = findUp.sync('Cargo.toml', { cwd: path });
+ return cargoTomlPath ? cargoTomlPath.replace('/Cargo.toml', '') : null;
+}
+
+module.exports = { findRustProjectPath };
diff --git a/scripts/rust_pre_commit.sh b/scripts/rust_pre_commit.sh
--- a/scripts/rust_pre_commit.sh
+++ b/scripts/rust_pre_commit.sh
@@ -5,17 +5,23 @@
# shellcheck source=/dev/null
[[ -r "$HOME"/.cargo/env ]] && source "$HOME"/.cargo/env
-PATHS="services/commtest"
+# list of cargo project paths
+PATHS="$*"
+
+if [[ -z "$PATHS" ]]; then
+ echo "no paths provided"
+ exit 1
+fi
command -v cargo > /dev/null
for directory in $PATHS; do
- pushd "$directory"
+ pushd "$directory" > /dev/null
echo "formatting ${directory}..."
cargo fmt --all -- --check
echo "checking ${directory}..."
cargo check
- popd # $directory
+ popd > /dev/null # $directory
done
echo "done formatting"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 1:31 AM (20 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609660
Default Alt Text
D6310.id21085.diff (2 KB)
Attached To
Mode
D6310: Lint all Rust projects in pre-commit
Attached
Detach File
Event Timeline
Log In to Comment