From 5038020500d9c71c1ba02ed05ea85384b99d8bd7 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 8 Apr 2023 16:24:47 -0400 Subject: [PATCH 1/3] Add compatibility with Bash 3.0 This is the default bash installed on MacOS. Before this change, the script would only check files in subdirectories, not top-level files. --- ci/check_line_lengths.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/check_line_lengths.sh b/ci/check_line_lengths.sh index 31cda5c65..45046cfa6 100755 --- a/ci/check_line_lengths.sh +++ b/ci/check_line_lengths.sh @@ -10,8 +10,7 @@ if [ "$MAX_LINE_LENGTH" == "" ]; then fi if [ "$1" == "" ]; then - shopt -s globstar - files=( src/**/*.md ) + files=( src/*.md src/*/*.md src/*/*/*.md ) else files=( "$@" ) fi From 012113be82d2e94196e713e5f2323ba07607afb2 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 8 Apr 2023 16:25:20 -0400 Subject: [PATCH 2/3] Make line length errors easier to read This also makes them clickable in VSCode. Before: ``` ; ci/check_line_lengths.sh Checking line lengths in all source files <= 100 chars... Offending files and lines: src/SUMMARY.md src/about-this-guide.md src/asm.md src/ast-validation.md src/borrow_check.md src/bug-fix-procedure.md src/cli.md src/closure.md src/compiler-debugging.md src/compiler-src.md src/compiler-team.md src/const-eval.md src/constants.md src/contributing.md src/conventions.md src/crates-io.md src/debugging-support-in-rustc.md src/diagnostics.md src/early-late-bound.md src/external-repos.md src/feature-gate-ck.md src/feature-gates.md src/fuzzing.md src/generic_arguments.md src/generics.md src/getting-started.md 26 : Zulip - you can ask questions in `#wg-rustup` [on Discord][rust-discord]. See [the Community page][community] on 88 : Not all important or beginner work has issue labels. See below for how to find work that isn't labelled. 95 : Some work is too large to be done by a single person. In this case, it's commmon to have "Tracking issues" to co-ordinate the work between contributors. 96 : Here are some example tracking issues where it's easy to pick up a work without a large time commitment: 106 : The [Clippy] project has spent a long time making its contribution process as friendly to newcomers as possible. src/git.md src/hir-debugging.md src/hir.md src/identifiers.md src/implementing_new_features.md src/incrcomp-debugging.md src/lang-items.md src/licenses.md src/llvm-coverage-instrumentation.md src/lowering.md src/macro-expansion.md src/memory.md src/method-lookup.md src/name-resolution.md src/opaque-types-impl-trait-inference.md src/opaque-types-type-alias-impl-trait.md src/overview.md src/panic-implementation.md src/parallel-rustc.md src/param_env.md src/part-2-intro.md src/part-3-intro.md src/part-4-intro.md src/part-5-intro.md src/pat-exhaustive-checking.md src/profile-guided-optimization.md src/profiling.md src/query.md src/rustbot.md src/rustc-driver-getting-diagnostics.md src/rustc-driver-interacting-with-the-ast.md src/rustc-driver.md src/rustdoc-internals.md src/rustdoc.md src/salsa.md src/sanitizers.md src/serialization.md src/stability.md src/stabilization_guide.md src/syntax-intro.md src/test-implementation.md src/the-parser.md src/thir.md src/tracing.md src/ty-fold.md src/ty.md src/type-checking.md src/type-inference.md src/variance.md src/walkthrough.md src/appendix/background.md src/appendix/bibliography.md src/appendix/code-index.md src/appendix/compiler-lecture.md src/appendix/glossary.md src/appendix/humorust.md src/backend/backend-agnostic.md src/backend/codegen.md src/backend/debugging.md src/backend/implicit-caller-location.md src/backend/inline-asm.md src/backend/libs-and-metadata.md src/backend/lowering-mir.md src/backend/monomorph.md src/backend/updating-llvm.md src/borrow_check/moves_and_initialization.md src/borrow_check/region_inference.md src/borrow_check/two_phase_borrows.md src/borrow_check/type_check.md src/building/bootstrapping.md src/building/build-install-distribution-artifacts.md src/building/compiler-documenting.md src/building/how-to-build-and-run.md src/building/new-target.md src/building/prerequisites.md src/building/suggested.md src/const-eval/interpret.md src/diagnostics/diagnostic-items.md src/diagnostics/diagnostic-structs.md src/diagnostics/error-codes.md src/diagnostics/error-guaranteed.md src/diagnostics/lintstore.md src/diagnostics/translation.md src/mir/construction.md src/mir/dataflow.md src/mir/debugging.md src/mir/drop-elaboration.md src/mir/index.md src/mir/optimizations.md src/mir/passes.md src/mir/visitor.md src/notification-groups/about.md src/notification-groups/arm.md src/notification-groups/cleanup-crew.md src/notification-groups/llvm.md src/notification-groups/risc-v.md src/notification-groups/windows.md src/profiling/with_perf.md src/profiling/wpa_profiling.md src/queries/incremental-compilation-in-detail.md src/queries/incremental-compilation.md src/queries/query-evaluation-model-in-detail.md src/solve/canonicalization.md src/solve/coinduction.md src/solve/the-solver.md src/solve/trait-solving.md src/tests/adding.md src/tests/ci.md src/tests/compiletest.md src/tests/crater.md src/tests/docker.md src/tests/headers.md src/tests/intro.md src/tests/perf.md src/tests/running.md src/tests/ui.md src/traits/caching.md src/traits/canonical-queries.md src/traits/chalk.md src/traits/goals-and-clauses.md src/traits/hrtb.md src/traits/lowering-to-logic.md src/traits/resolution.md src/traits/specialization.md src/borrow_check/moves_and_initialization/move_paths.md src/borrow_check/region_inference/closure_constraints.md src/borrow_check/region_inference/constraint_propagation.md src/borrow_check/region_inference/error_reporting.md src/borrow_check/region_inference/lifetime_parameters.md src/borrow_check/region_inference/member_constraints.md src/borrow_check/region_inference/placeholders_and_universes.md 5 offending lines found. ``` After: ``` ; ci/check_line_lengths.sh Checking line lengths in all source files <= 100 chars... Offending files and lines: src/getting-started.md:26 : Zulip - you can ask questions in `#wg-rustup` [on Discord][rust-discord]. See [the Community page][community] on src/getting-started.md:88 : Not all important or beginner work has issue labels. See below for how to find work that isn't labelled. src/getting-started.md:95 : Some work is too large to be done by a single person. In this case, it's commmon to have "Tracking issues" to co-ordinate the work between contributors. src/getting-started.md:96 : Here are some example tracking issues where it's easy to pick up a work without a large time commitment: src/getting-started.md:106 : The [Clippy] project has spent a long time making its contribution process as friendly to newcomers as possible. 5 offending lines found. ``` ``` --- ci/check_line_lengths.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/check_line_lengths.sh b/ci/check_line_lengths.sh index 45046cfa6..78c3b89e9 100755 --- a/ci/check_line_lengths.sh +++ b/ci/check_line_lengths.sh @@ -21,7 +21,6 @@ echo "Offending files and lines:" (( bad_lines = 0 )) (( inside_block = 0 )) for file in "${files[@]}"; do - echo "$file" (( line_no = 0 )) while IFS="" read -r line || [[ -n "$line" ]] ; do (( line_no++ )) @@ -33,7 +32,7 @@ for file in "${files[@]}"; do && ! [[ "$line" =~ " | "|"-|-"|"://"|"]:"|\[\^[^\ ]+\]: ]] \ && (( "${#line}" > $MAX_LINE_LENGTH )) ; then (( bad_lines++ )) - echo -e "\t$line_no : $line" + echo -e "\t$file:$line_no : $line" fi done < "$file" done From 50666f8ab012379ad9d0e44aedd3ab179b8ad724 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 8 Apr 2023 16:31:20 -0400 Subject: [PATCH 3/3] Rename `check_line_lengths.sh` to `lengthcheck.sh` This allows using tab completion to run the script. Before, `ci/check` would stop because of the ambiguity between `check-in.sh` and `check_line_lengths.sh`. This also takes the liberty of fixing up the powershell example to work without changes. --- .github/workflows/ci.yml | 2 +- README.md | 6 +++--- ci/{check_line_lengths.sh => lengthcheck.sh} | 2 ++ src/contributing.md | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename ci/{check_line_lengths.sh => lengthcheck.sh} (95%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2346698d4..bb0493bf7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: if: github.event_name != 'push' run: | shopt -s globstar - MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md + MAX_LINE_LENGTH=100 bash ci/lengthcheck.sh src/**/*.md - name: Install latest nightly Rust toolchain if: steps.mdbook-cache.outputs.cache-hit != 'true' diff --git a/README.md b/README.md index b2b538ffb..fdf6c5050 100644 --- a/README.md +++ b/README.md @@ -67,20 +67,20 @@ including the `` marker at the place where you want the TOC. ### Pre-commit script We also test that line lengths are less than 100 columns. To test this locally, -you can run `ci/check_line_lengths.sh`. +you can run `ci/lengthcheck.sh`. You can also set this to run automatically. On Linux: ```bash -ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit +ln -s ../../ci/lengthcheck.sh .git/hooks/pre-commit ``` On Windows: ```powershell -New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value +New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value $(Resolve-Path ci/lengthcheck.sh) ``` ## How to fix toolstate failures diff --git a/ci/check_line_lengths.sh b/ci/lengthcheck.sh similarity index 95% rename from ci/check_line_lengths.sh rename to ci/lengthcheck.sh index 78c3b89e9..76d677be7 100755 --- a/ci/check_line_lengths.sh +++ b/ci/lengthcheck.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# Check files for lines that are too long. + if [ "$1" == "--help" ]; then echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]" exit 1 diff --git a/src/contributing.md b/src/contributing.md index 549c18cc4..8f4f498b1 100644 --- a/src/contributing.md +++ b/src/contributing.md @@ -311,7 +311,7 @@ There are issues for beginners and advanced compiler devs alike! Just a few things to keep in mind: - Please limit line length to 100 characters. This is enforced by CI, and you can run the checks - locally with `ci/check_line_lengths.sh`. + locally with `ci/lengthcheck.sh`. - When contributing text to the guide, please contextualize the information with some time period and/or a reason so that the reader knows how much to trust or mistrust the information.