Skip to content

Apache DataFusion SQL Query Engine

Issue 2321: Add code formatting instructions to CONTRIBUTING (#2444)

Tim Van Wassenhove522ea52fcd61
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 8646f8058e..056e83df0c 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -307,7 +307,10 @@ jobs:
rustup default stable
rustup component add rustfmt
- name: Run
- run: cargo fmt --all -- --check
+ run: ci/scripts/rust_fmt.sh
+ env:
+ CARGO_HOME: "/github/home/.cargo"
+ CARGO_TARGET_DIR: "/github/home/target"
clippy:
name: Clippy
@@ -347,8 +350,7 @@ jobs:
run: |
rustup component add clippy
- name: Run clippy
- run: |
- cargo clippy --all-targets --workspace -- -D warnings
+ run: ci/scripts/rust_clippy.sh
env:
CARGO_HOME: "/github/home/.cargo"
CARGO_TARGET_DIR: "/github/home/target"
@@ -479,7 +481,7 @@ jobs:
# check which Cargo.toml introduces formatting violation
#
# ignore ./Cargo.toml because putting workspaces in multi-line lists make it easy to read
- find . -mindepth 2 -name 'Cargo.toml' -exec cargo tomlfmt -p {} \;
+ ci/scripts/rust_toml_fmt.sh
git diff --exit-code
env:
CARGO_HOME: "/github/home/.cargo"
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4f0fe71636..24fdbb90b1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,16 @@ Testing setup:
- `git submodule init`
- `git submodule update`
+Formatting instructions:
+
+- [ci/scripts/rust_fmt.sh](ci/scripts/rust_fmt.sh)
+- [ci/scripts/rust_clippy.sh](ci/scripts/rust_clippy.sh)
+- [ci/scripts/rust_toml_fmt.sh](ci/scripts/rust_toml_fmt.sh)
+
+or run them all at once:
+
+- [dev/rust_lint.sh](dev/rust_lint.sh)
+
## Test Organization
DataFusion has several levels of tests in its [Test
diff --git a/ci/scripts/rust_clippy.sh b/ci/scripts/rust_clippy.sh
new file mode 100755
index 0000000000..ee505fea9a
--- /dev/null
+++ b/ci/scripts/rust_clippy.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+cargo clippy --all-targets --workspace -- -D warnings
diff --git a/ci/scripts/rust_fmt.sh b/ci/scripts/rust_fmt.sh
new file mode 100755
index 0000000000..9d8325877a
--- /dev/null
+++ b/ci/scripts/rust_fmt.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+cargo fmt --all -- --check
diff --git a/ci/scripts/rust_toml_fmt.sh b/ci/scripts/rust_toml_fmt.sh
new file mode 100755
index 0000000000..e297ef0015
--- /dev/null
+++ b/ci/scripts/rust_toml_fmt.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+find . -mindepth 2 -name 'Cargo.toml' -exec cargo tomlfmt -p {} \;
diff --git a/dev/rust_lint.sh b/dev/rust_lint.sh
new file mode 100755
index 0000000000..f634266010
--- /dev/null
+++ b/dev/rust_lint.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+set -e
+if ! command -v cargo-tomlfmt &> /dev/null; then
+ echo "Installing cargo-tomlfmt using cargo"
+ cargo install cargo-tomlfmt
+fi
+
+ci/scripts/rust_fmt.sh
+ci/scripts/rust_clippy.sh
+ci/scripts/rust_toml_fmt.sh
\ No newline at end of file