From 5df8db3fd675a4524f483ad462755345a4040446 Mon Sep 17 00:00:00 2001 From: Chris Araman Date: Sun, 28 Mar 2021 17:16:37 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Separate=20format=20from=20lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftformat | 2 ++ CONTRIBUTING.md | 2 +- docs/style.md | 1 + script/format | 35 +++++++++++++++++++++++++++++++++++ script/lint | 16 ++++++++++------ 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 script/format diff --git a/.swiftformat b/.swiftformat index 10bf263..bb06579 100644 --- a/.swiftformat +++ b/.swiftformat @@ -9,6 +9,8 @@ # Disabled rules --disable blankLinesAroundMark +--disable consecutiveSpaces +--disable indent # Enabled rules (disabled by default) --enable trailingClosures diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a9d52cc..367d941 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,7 +23,7 @@ We love pull requests from everyone. By participating in this project, you agree `git checkout -b awesome-feature master` - Please avoid working [directly on the master branch](https://softwareengineering.stackexchange.com/questions/223400/when-should-i-stop-committing-to-master-on-new-projects). - Make commits of logical units. -- Run script/lint before committing your changes. Fix anything that isn't automatically fixed by the linters. +- Run script/format before committing your changes. Fix anything that isn't automatically fixed by the linters. - Push your topic branch to your fork and [submit a pull request](https://github.com/mas-cli/mas/compare/master...your-username:topic-branch). Some things that will increase the chance that your pull request is accepted: diff --git a/docs/style.md b/docs/style.md index 2432d71..6de3332 100644 --- a/docs/style.md +++ b/docs/style.md @@ -1,5 +1,6 @@ # All Files +- Use `script/format` to automatically fix a number of style violations. - Remove unnecessary whitespace from the end of lines. - Use `script/lint` to look for these before committing. - Note that [two trailing spaces](https://gist.github.com/shaunlebron/746476e6e7a4d698b373) diff --git a/script/format b/script/format new file mode 100755 index 0000000..0d36606 --- /dev/null +++ b/script/format @@ -0,0 +1,35 @@ +#!/bin/bash -e +# +# script/format +# mas +# +# Linting checks for development and CI. +# +# Automatically formats and fixes style violations using various tools. +# Additionally runs `lint` to report any remaining style violations. +# +# Please keep in sync with script/lint. +# + +echo "==> 🚨 Formatting mas" + +for LINTER in shfmt swift-format swiftformat swiftlint; do + if [[ ! -x "$(command -v ${LINTER})" ]]; then + echo "error: ${LINTER} is not installed. Run script/bootstrap." + exit 1 + fi +done + +echo +echo "--> 🕊️ Swift" +swiftformat . +for SOURCE in mas MasKit MasKitTests; do + swift-format format --in-place --configuration .swift-format --recursive ${SOURCE} +done +swiftlint lint --fix --strict + +echo +echo "--> 📜 Bash" +shfmt -i 2 -l -w contrib/ script/ + +script/lint diff --git a/script/lint b/script/lint index bb8ed5b..354c06a 100755 --- a/script/lint +++ b/script/lint @@ -5,12 +5,16 @@ # # Linting checks for development and CI. # +# Reports style violations without making any modifications to the code. +# +# Please keep in sync with script/format. +# echo "==> 🚨 Linting mas" -for LINTER in swift-format swiftformat swiftlint; do +for LINTER in git swift-format swiftformat swiftlint; do if [[ ! -x "$(command -v ${LINTER})" ]]; then - echo "warning: ${LINTER} is not installed: script/bootstrap" + echo "error: ${LINTER} is not installed. Run script/bootstrap." exit 1 fi done @@ -20,12 +24,12 @@ git diff --check echo echo "--> 🕊️ Swift" -swiftformat . +swiftformat --lint . for SOURCE in mas MasKit MasKitTests; do - swift-format format --in-place --configuration .swift-format --recursive ${SOURCE} + swift-format lint --configuration .swift-format --recursive ${SOURCE} done -swiftlint lint --fix --strict +swiftlint lint --strict echo echo "--> 📜 Bash" -shfmt -i 2 -l -w contrib/ script/ +shfmt -d -i 2 -l -w contrib/ script/