From 271f689a2fe728aab2f18f425d240fa809926c0c Mon Sep 17 00:00:00 2001 From: taku0 Date: Sat, 21 Jan 2023 11:33:16 +0900 Subject: [PATCH 1/4] Add linter --- .dir-locals.el | 7 +++++++ Cask | 3 ++- Makefile | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .dir-locals.el diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..ffd8cc1 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,7 @@ +((emacs-lisp-mode . ((package-lint-main-file . "kotlin-mode.el") + (eval . (checkdoc-minor-mode)) + (indent-tabs-mode . nil) + (fill-column . 80) + (tab-width . 8) + (sentence-end-double-space . t) + (emacs-lisp-docstring-fill-column . 75)))) diff --git a/Cask b/Cask index 2755da6..e2f4405 100644 --- a/Cask +++ b/Cask @@ -6,4 +6,5 @@ (development (depends-on "ecukes") (depends-on "ert-expectations") - (depends-on "ert-runner")) + (depends-on "ert-runner") + (depends-on "elisp-lint")) diff --git a/Makefile b/Makefile index aa17634..16a590d 100644 --- a/Makefile +++ b/Makefile @@ -54,3 +54,15 @@ test: -f batch-byte-compile \ *.el cask exec ert-runner -L . -L test + +lint: +## Run linters. + rm -f *.elc + rm -f kotlin-mode-autoloads.el + $(CASK) exec $(EMACS) --batch -Q \ + -l elisp-lint.el \ + --eval '(setq elisp-lint--debug t)' \ + -f elisp-lint-files-batch \ + *.el + rm -f *.elc + rm -f kotlin-mode-autoloads.el From 4e9da8b4095d481d3505a157aab3fc5ed81c8c9c Mon Sep 17 00:00:00 2001 From: taku0 Date: Sat, 21 Jan 2023 13:03:12 +0900 Subject: [PATCH 2/4] Address linter warnings. --- .dir-locals.el | 3 ++- kotlin-mode-indent.el | 4 ---- kotlin-mode-lexer.el | 2 -- kotlin-mode.el | 12 +++++++++++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.dir-locals.el b/.dir-locals.el index ffd8cc1..b3fb854 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -4,4 +4,5 @@ (fill-column . 80) (tab-width . 8) (sentence-end-double-space . t) - (emacs-lisp-docstring-fill-column . 75)))) + (emacs-lisp-docstring-fill-column . 75) + (elisp-lint-indent-specs . ((kotlin-mode--save-mark-and-excursion . 0)))))) diff --git a/kotlin-mode-indent.el b/kotlin-mode-indent.el index 0ca7802..9501ebd 100644 --- a/kotlin-mode-indent.el +++ b/kotlin-mode-indent.el @@ -3,10 +3,6 @@ ;; Copyright (C) 2019 taku0 ;; Authors: taku0 (http://github.com/taku0) -;; Keywords: languages -;; Package-Requires: ((emacs "24.3")) -;; Version: 0.0.1 -;; URL: https://github.com/Emacs-Kotlin-Mode-Maintainers/kotlin-mode ;; This file is not part of GNU Emacs. diff --git a/kotlin-mode-lexer.el b/kotlin-mode-lexer.el index c19e999..cf1b56d 100644 --- a/kotlin-mode-lexer.el +++ b/kotlin-mode-lexer.el @@ -5,8 +5,6 @@ ;; Author: Shodai Yokoyama (quantumcars@gmail.com) ;; taku0 (http://github.com/taku0) -;; Keywords: languages -;; Package-Requires: ((emacs "24.3")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by diff --git a/kotlin-mode.el b/kotlin-mode.el index eedbb35..cdaec8a 100644 --- a/kotlin-mode.el +++ b/kotlin-mode.el @@ -93,10 +93,20 @@ START and END define region within current buffer." (interactive) (kotlin-do-and-repl-focus 'kotlin-send-buffer)) +(defmacro kotlin-mode--save-mark-and-excursion (&rest body) + "Polyfill of `save-mark-and-excursion' for <25.1. + +For argument BODY, see `save-mark-and-excursion'." + (declare (indent 0) (debug t)) + (let ((save-mark-and-excursion (if (fboundp 'save-mark-and-excursion) + #'save-mark-and-excursion + #'save-excursion))) + (cons save-mark-and-excursion body))) + (defun kotlin-send-block () "Send block to Kotlin interpreter." (interactive) - (save-mark-and-excursion + (kotlin-mode--save-mark-and-excursion (mark-paragraph) (kotlin-send-region (region-beginning) (region-end)))) From c504b569aab3d8188619a17b61b4cca899b94df8 Mon Sep 17 00:00:00 2001 From: taku0 Date: Sun, 22 Jan 2023 16:45:59 +0900 Subject: [PATCH 3/4] Add scripts to run tests and linters in Docker --- Makefile | 25 ++++++++++--------------- scripts/invoke_cask.sh | 18 ++++++++++++++++++ scripts/run_linter.sh | 19 +++++++++++++++++++ scripts/run_linter_in_docker.sh | 21 +++++++++++++++++++++ scripts/run_test.sh | 16 ++++++++++++++++ scripts/run_test_in_docker.sh | 23 +++++++++++++++++++++++ 6 files changed, 107 insertions(+), 15 deletions(-) create mode 100755 scripts/invoke_cask.sh create mode 100755 scripts/run_linter.sh create mode 100755 scripts/run_linter_in_docker.sh create mode 100755 scripts/run_test.sh create mode 100755 scripts/run_test_in_docker.sh diff --git a/Makefile b/Makefile index 16a590d..ab982e7 100644 --- a/Makefile +++ b/Makefile @@ -48,21 +48,16 @@ clean: test: ## Tests the package. - $(CASK) exec $(EMACS) --batch -q \ - --eval "(add-to-list 'load-path \""$(shell readlink -f .)"\")" \ - --eval "(add-to-list 'load-path \""$(shell readlink -f .)"/test\")" \ - -f batch-byte-compile \ - *.el - cask exec ert-runner -L . -L test + CASK="${CASK}" EMACS="${EMACS}" scripts/run_test.sh + +test_in_docker: +## Tests the package in Docker. + CASK="${CASK}" EMACS="${EMACS}" scripts/run_test_in_docker.sh lint: ## Run linters. - rm -f *.elc - rm -f kotlin-mode-autoloads.el - $(CASK) exec $(EMACS) --batch -Q \ - -l elisp-lint.el \ - --eval '(setq elisp-lint--debug t)' \ - -f elisp-lint-files-batch \ - *.el - rm -f *.elc - rm -f kotlin-mode-autoloads.el + CASK="${CASK}" EMACS="${EMACS}" scripts/run_linter.sh + +lint_in_docker: +## Run linters in Docker. + CASK="${CASK}" EMACS="${EMACS}" scripts/run_linter_in_docker.sh diff --git a/scripts/invoke_cask.sh b/scripts/invoke_cask.sh new file mode 100755 index 0000000..23b24db --- /dev/null +++ b/scripts/invoke_cask.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# A little wrapper for Cask. Used in Makefile. +# If ${CASK} is executable, use it. +# Otherwise, download the Cask to .cask/cask if not exists, then execute it. + +if command -v "${CASK}" > /dev/null +then + "${CASK}" "$@" +elif command -v .cask/cask/bin/cask > /dev/null +then + .cask/cask/bin/cask "$@" +else + mkdir -p .cask || exit 1 + git clone --depth 1 https://github.com/cask/cask.git .cask/cask || exit 1 + chmod a+x .cask/cask/bin/cask || exit 1 + .cask/cask/bin/cask "$@" +fi diff --git a/scripts/run_linter.sh b/scripts/run_linter.sh new file mode 100755 index 0000000..61e55b2 --- /dev/null +++ b/scripts/run_linter.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Run linter. Used in Makefile. + +if ! [ -d ".cask/$(./scripts/invoke_cask.sh eval '(princ emacs-version)')/elpa/elisp-lint-"* ] +then + ./scripts/invoke_cask.sh install || exit 1 +fi + +./scripts/invoke_cask.sh emacs --version || exit 1 +rm -f *.elc test/*.elc || exit 1 +rm -f *-autoloads.el || exit 1 +./scripts/invoke_cask.sh emacs --batch -Q \ + -l elisp-lint.el \ + --eval '(setq elisp-lint--debug t)' \ + -f elisp-lint-files-batch \ + *.el || exit 1 +rm -f *.elc test/*.elc || exit 1 +rm -f *-autoloads.el || exit 1 diff --git a/scripts/run_linter_in_docker.sh b/scripts/run_linter_in_docker.sh new file mode 100755 index 0000000..44ebf6b --- /dev/null +++ b/scripts/run_linter_in_docker.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Run linter in Docker. Used in Makefile. + +# Cask does't support Emacs 24. +for version in 28 27 26 25 # 24 +do + docker \ + run \ + --rm \ + --volume="$(pwd)":/src \ + --user="$(id -u):$(id -g)" \ + --workdir="/src" \ + --env=ELDEV_DIR=/src/.eldev \ + --env=HOME=/tmp \ + silex/emacs:${version} \ + bash -c "/src/scripts/run_linter.sh" \ + || exit 1 +done + +echo "done" diff --git a/scripts/run_test.sh b/scripts/run_test.sh new file mode 100755 index 0000000..cc38930 --- /dev/null +++ b/scripts/run_test.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Run tests. Used in Makefile. + +if ! [ -d ".cask/$(./scripts/invoke_cask.sh eval '(princ emacs-version)')/elpa/ert-runner-"* ] +then + ./scripts/invoke_cask.sh install || exit 1 +fi + +./scripts/invoke_cask.sh emacs --version || exit 1 +./scripts/invoke_cask.sh emacs --batch -q \ + --eval "(add-to-list 'load-path \"$(readlink -f .)\")" \ + --eval "(add-to-list 'load-path \"$(readlink -f .)/test\")" \ + -f batch-byte-compile \ + *.el test/*.el || exit 1 +./scripts/invoke_cask.sh exec ert-runner -L . -L test diff --git a/scripts/run_test_in_docker.sh b/scripts/run_test_in_docker.sh new file mode 100755 index 0000000..2e3dc69 --- /dev/null +++ b/scripts/run_test_in_docker.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# Run tests in Docker. Used in Makefile. + +# Cask does't support Emacs 24. +for version in 28 27 26 25 # 24 +do + rm -f *.elc test/*.elc + rm -f *-autoloads.el + docker \ + run \ + --rm \ + --volume="$(pwd)":/src \ + --user="$(id -u):$(id -g)" \ + --workdir="/src" \ + --env=ELDEV_DIR=/src/.eldev \ + --env=HOME=/tmp \ + silex/emacs:${version} \ + bash -c "/src/scripts/run_test.sh" \ + || exit 1 +done + +echo "done" From 8fbc1a9d745fadba8cc73b49a425dbc283311a33 Mon Sep 17 00:00:00 2001 From: taku0 Date: Sun, 22 Jan 2023 16:52:10 +0900 Subject: [PATCH 4/4] Add GitHub Actions for tests and linters --- .github/workflows/run-test.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/run-test.yml diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml new file mode 100644 index 0000000..7a1a818 --- /dev/null +++ b/.github/workflows/run-test.yml @@ -0,0 +1,27 @@ +name: Run Tests + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + build: + runs-on: ubuntu-latest + continue-on-error: ${{matrix.version == 'snapshot'}} + + strategy: + matrix: + # Cask does't support Emacs 24. + version: ['25.1', '25.2', '25.3', '26.1', '26.2', '26.3', '27.1', '27.2', '28.1', '28.2', 'snapshot'] + + steps: + - uses: actions/checkout@v3 + - uses: purcell/setup-emacs@master + with: + version: ${{ matrix.version }} + - name: Run linters + run: ./scripts/run_linter.sh + - name: Run tests + run: ./scripts/run_test.sh