Skip to content

Commit 522ea52

Browse files
timvwtustvold
andauthored
Issue 2321: Add code formatting instructions to CONTRIBUTING (#2444)
* ehance documentation on how to format/check your code * Update dev/format-code.sh Co-authored-by: Raphael Taylor-Davies <[email protected]> * Update dev/format-code.sh Co-authored-by: Raphael Taylor-Davies <[email protected]> * attempt to share lint infra * corrected invalid / * mention scripts in formatting instructions Co-authored-by: Raphael Taylor-Davies <[email protected]>
1 parent 3f67f16 commit 522ea52

File tree

6 files changed

+106
-4
lines changed

6 files changed

+106
-4
lines changed

.github/workflows/rust.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ jobs:
307307
rustup default stable
308308
rustup component add rustfmt
309309
- name: Run
310-
run: cargo fmt --all -- --check
310+
run: ci/scripts/rust_fmt.sh
311+
env:
312+
CARGO_HOME: "/github/home/.cargo"
313+
CARGO_TARGET_DIR: "/github/home/target"
311314

312315
clippy:
313316
name: Clippy
@@ -347,8 +350,7 @@ jobs:
347350
run: |
348351
rustup component add clippy
349352
- name: Run clippy
350-
run: |
351-
cargo clippy --all-targets --workspace -- -D warnings
353+
run: ci/scripts/rust_clippy.sh
352354
env:
353355
CARGO_HOME: "/github/home/.cargo"
354356
CARGO_TARGET_DIR: "/github/home/target"
@@ -479,7 +481,7 @@ jobs:
479481
# check which Cargo.toml introduces formatting violation
480482
#
481483
# ignore ./Cargo.toml because putting workspaces in multi-line lists make it easy to read
482-
find . -mindepth 2 -name 'Cargo.toml' -exec cargo tomlfmt -p {} \;
484+
ci/scripts/rust_toml_fmt.sh
483485
git diff --exit-code
484486
env:
485487
CARGO_HOME: "/github/home/.cargo"

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ Testing setup:
5353
- `git submodule init`
5454
- `git submodule update`
5555

56+
Formatting instructions:
57+
58+
- [ci/scripts/rust_fmt.sh](ci/scripts/rust_fmt.sh)
59+
- [ci/scripts/rust_clippy.sh](ci/scripts/rust_clippy.sh)
60+
- [ci/scripts/rust_toml_fmt.sh](ci/scripts/rust_toml_fmt.sh)
61+
62+
or run them all at once:
63+
64+
- [dev/rust_lint.sh](dev/rust_lint.sh)
65+
5666
## Test Organization
5767

5868
DataFusion has several levels of tests in its [Test

ci/scripts/rust_clippy.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -ex
21+
cargo clippy --all-targets --workspace -- -D warnings

ci/scripts/rust_fmt.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -ex
21+
cargo fmt --all -- --check

ci/scripts/rust_toml_fmt.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -ex
21+
find . -mindepth 2 -name 'Cargo.toml' -exec cargo tomlfmt -p {} \;

dev/rust_lint.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
set -e
20+
if ! command -v cargo-tomlfmt &> /dev/null; then
21+
echo "Installing cargo-tomlfmt using cargo"
22+
cargo install cargo-tomlfmt
23+
fi
24+
25+
ci/scripts/rust_fmt.sh
26+
ci/scripts/rust_clippy.sh
27+
ci/scripts/rust_toml_fmt.sh

0 commit comments

Comments
 (0)