From 07ef06eff8ba5a88c9f821f77c53a7ce89795a24 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 18 Dec 2023 22:56:08 +0100 Subject: [PATCH] chore: Add editorconfig-checker check --- .ecrc | 5 +++++ .editorconfig | 12 ++++++++++++ .github/workflows/main.yml | 9 ++++++++- .gitignore | 1 + Makefile | 13 ++++++++++++- assets/scripts/install-local-bin.sh | 6 +++--- assets/scripts/install.sh | 6 +++--- internal/cmds/generate-install.sh/install.sh.tmpl | 6 +++--- 8 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 .ecrc diff --git a/.ecrc b/.ecrc new file mode 100644 index 00000000000..936853682ef --- /dev/null +++ b/.ecrc @@ -0,0 +1,5 @@ +{ + "Exclude": [ + "^completions/" + ] +} diff --git a/.editorconfig b/.editorconfig index 145b9f869b0..914c2ea683f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,15 @@ charset = utf-8 end_of_line = crlf insert_final_newline = true trim_trailing_whitespace = true + +[*.py] +indent_size = 4 +indent_style = space + +[*.sh] +indent_size = 1 +indent_style = tab + +[{*.yaml,*.yml}] +indent_size = 2 +indent_style = space diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d73ec51deba..e943182262a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,7 @@ env: ACTIONLINT_VERSION: 1.6.26 AGE_VERSION: 1.1.1 CHOCOLATEY_VERSION: 2.2.2 + EDITORCONFIG_CHECKER_VERSION: 2.7.2 GO_VERSION: 1.21.5 GOFUMPT_VERSION: 0.5.0 GOLANGCI_LINT_VERSION: 1.55.2 @@ -319,6 +320,12 @@ jobs: - uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 with: ignore_paths: completions + - name: editorconfig-checker + run: | + GOOS="$(go env GOOS)" + GOARCH="$(go env GOARCH)" + curl -sSfL "https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${EDITORCONFIG_CHECKER_VERSION}/ec-${GOOS}-${GOARCH}.tar.gz" | tar -xzf - + "bin/ec-${GOOS}-${GOARCH}" - name: lint-whitespace run: | go run ./internal/cmds/lint-whitespace @@ -334,7 +341,7 @@ jobs: run: | go run ./internal/cmds/lint-commit-messages HEAD~1..HEAD - name: lint-commit-messages - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' && github.event.pull_request.draft == false run: | go run ./internal/cmds/lint-commit-messages ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}..${{ github.event.pull_request.head.sha }} lint: diff --git a/.gitignore b/.gitignore index b8916ac068a..15197d1b2ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /COMMIT /bin/actionlint /bin/chezmoi +/bin/editorconfig-checker /bin/find-typos /bin/gofumpt /bin/golines diff --git a/Makefile b/Makefile index 4c8681fbcda..ec0984a7e38 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ GO?=go +GOOS=$(shell ${GO} env GOOS) +GOARCH=$(shell ${GO} env GOARCH) ACTIONLINT_VERSION=$(shell awk '/ACTIONLINT_VERSION:/ { print $$2 }' .github/workflows/main.yml) +EDITORCONFIG_CHECKER_VERSION=$(shell awk '/EDITORCONFIG_CHECKER_VERSION:/ { print $$2 }' .github/workflows/main.yml) FIND_TYPOS_VERSION=$(shell awk '/FIND_TYPOS_VERSION:/ { print $$2 }' .github/workflows/main.yml) GOFUMPT_VERSION=$(shell awk '/GOFUMPT_VERSION:/ { print $$2 }' .github/workflows/main.yml) GOLANGCI_LINT_VERSION=$(shell awk '/GOLANGCI_LINT_VERSION:/ { print $$2 }' .github/workflows/main.yml) @@ -110,8 +113,9 @@ generate: ${GO} generate .PHONY: lint -lint: ensure-actionlint ensure-find-typos ensure-golangci-lint +lint: ensure-actionlint ensure-editorconfig-checker ensure-find-typos ensure-golangci-lint ./bin/actionlint + ./bin/editorconfig-checker ./bin/golangci-lint run ${GO} run ./internal/cmds/lint-whitespace find . -name \*.txtar | xargs ${GO} run ./internal/cmds/lint-txtar @@ -142,6 +146,13 @@ ensure-actionlint: GOBIN=$(shell pwd)/bin ${GO} install "github.com/rhysd/actionlint/cmd/actionlint@v${ACTIONLINT_VERSION}" ; \ fi +.PHONY: ensure-editorconfig-checker +ensure-editorconfig-checker: + if [ ! -x bin/editorconfig-checker ] || ( ./bin/editorconfig-checker --version | grep -Fqv "v${EDITORCONFIG_CHECKER_VERSION}" ) ; then \ + curl -sSfL "https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${EDITORCONFIG_CHECKER_VERSION}/ec-${GOOS}-${GOARCH}.tar.gz" | tar -xzf - ; \ + mv "bin/ec-${GOOS}-${GOARCH}" bin/editorconfig-checker ; \ + fi + .PHONY: ensure-find-typos ensure-find-typos: if [ ! -x bin/find-typos ] ; then \ diff --git a/assets/scripts/install-local-bin.sh b/assets/scripts/install-local-bin.sh index a59ef0e4201..f517e9c5067 100644 --- a/assets/scripts/install-local-bin.sh +++ b/assets/scripts/install-local-bin.sh @@ -24,9 +24,9 @@ usage() { ${this}: download chezmoi and optionally run chezmoi Usage: ${this} [-b bindir] [-d] [-t tag] [chezmoi-args] - -b sets the installation directory, default is ${BINDIR}. - -d enables debug logging. - -t sets the tag, default is ${TAG}. + -b sets the installation directory, default is ${BINDIR}. + -d enables debug logging. + -t sets the tag, default is ${TAG}. If chezmoi-args are given, after install chezmoi is executed with chezmoi-args. EOF exit 2 diff --git a/assets/scripts/install.sh b/assets/scripts/install.sh index 5ac467eb9dc..da139dfd5c2 100644 --- a/assets/scripts/install.sh +++ b/assets/scripts/install.sh @@ -24,9 +24,9 @@ usage() { ${this}: download chezmoi and optionally run chezmoi Usage: ${this} [-b bindir] [-d] [-t tag] [chezmoi-args] - -b sets the installation directory, default is ${BINDIR}. - -d enables debug logging. - -t sets the tag, default is ${TAG}. + -b sets the installation directory, default is ${BINDIR}. + -d enables debug logging. + -t sets the tag, default is ${TAG}. If chezmoi-args are given, after install chezmoi is executed with chezmoi-args. EOF exit 2 diff --git a/internal/cmds/generate-install.sh/install.sh.tmpl b/internal/cmds/generate-install.sh/install.sh.tmpl index 8051871f4c4..3bca012550b 100644 --- a/internal/cmds/generate-install.sh/install.sh.tmpl +++ b/internal/cmds/generate-install.sh/install.sh.tmpl @@ -24,9 +24,9 @@ usage() { ${this}: download chezmoi and optionally run chezmoi Usage: ${this} [-b bindir] [-d] [-t tag] [chezmoi-args] - -b sets the installation directory, default is ${BINDIR}. - -d enables debug logging. - -t sets the tag, default is ${TAG}. + -b sets the installation directory, default is ${BINDIR}. + -d enables debug logging. + -t sets the tag, default is ${TAG}. If chezmoi-args are given, after install chezmoi is executed with chezmoi-args. EOF exit 2