From eb2d617ed84419c64245f08360e59de39a8e788d Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 28 Apr 2021 21:24:27 +0100 Subject: [PATCH] Add a pre commit hook to lint code This uses pre-commit [1] to check patches are well formed and run several linters on them. We currently do some boring things (check files are syntactically valid) as well as some project-specific ones: - Run illuaminate on the Lua files - Run checkstyle on Java [1]: https://pre-commit.com/ --- .editorconfig | 3 -- .github/workflows/main-ci.yml | 30 +++++++----- CONTRIBUTING.md | 8 ++-- LICENSE | 14 +++--- config/idea/codeInspectionSettings.xml | 2 +- config/idea/codeStyleSettings.xml | 2 +- config/pre-commit/config.yml | 48 +++++++++++++++++++ config/pre-commit/illuaminate-lint.sh | 9 ++++ doc/events/key.md | 2 +- .../computercraft/lua/rom/apis/colours.lua | 2 +- .../computercraft/lua/rom/autorun/.ignoreme | 2 +- tools/check-lines.py | 45 ----------------- 12 files changed, 90 insertions(+), 77 deletions(-) create mode 100644 config/pre-commit/config.yml create mode 100755 config/pre-commit/illuaminate-lint.sh delete mode 100644 tools/check-lines.py diff --git a/.editorconfig b/.editorconfig index f5f23d8d4..dadfafa5b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,6 +16,3 @@ indent_size = 2 [*.yml] indent_size = 2 - -[*.properties] -insert_final_newline = false diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 64b5a89c0..646f3123c 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -23,10 +23,15 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- + - name: Disable Gradle daemon + run: | + mkdir -p ~/.gradle + echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties + - name: Build with Gradle run: | - ./gradlew assemble --no-daemon || ./gradlew assemble --no-daemon - ./gradlew downloadAssets --no-daemon || ./gradlew downloadAssets --no-daemon + ./gradlew assemble || ./gradlew assemble + ./gradlew downloadAssets || ./gradlew downloadAssets ./gradlew build - name: Upload Jar @@ -39,15 +44,14 @@ jobs: run: bash <(curl -s https://codecov.io/bash) continue-on-error: true - - name: Generate Java documentation stubs - run: ./gradlew luaJavadoc --no-daemon - - - name: Lint Lua code + - name: Cache pre-commit + uses: actions/cache@v2 + with: + path: ~/.cache/pre-commit + key: ${{ runner.os }}-pre-commit-${{ hashFiles('config/pre-commit/config.yml') }} + restore-keys: | + ${{ runner.os }}-pre-commit- + - name: Run linters run: | - test -d bin || mkdir bin - test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/linux-x86-64/illuaminate - chmod +x bin/illuaminate - bin/illuaminate lint - - - name: Check whitespace - run: python3 tools/check-lines.py + pip install pre-commit + pre-commit run --config config/pre-commit/config.yml --show-diff-on-failure --all --color=always diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24b3ce1ca..7c250e89c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ #### Building documentation #### Writing documentation illuaminate's documentation system is not currently documented (somewhat ironic), but is _largely_ the same as -[ldoc][ldoc]. Documentation comments are written in Markdown, +[ldoc][ldoc]. Documentation comments are written in Markdown, Our markdown engine does _not_ support GitHub flavoured markdown, and so does not support all the features one might expect (such as tables). It is very much recommended that you build and preview the docs locally first. @@ -77,18 +77,18 @@ ### Testing Before we get into writing tests, it's worth mentioning the various test suites that CC: Tweaked has: - "Core" Java (`./src/test/java`): These test core bits of the mod which don't require any Minecraft interaction. This includes the `@LuaFunction` system, file system code, etc... - + These tests are run by `./gradlew test`. - CraftOS (`./src/test/resources/test-rom/`): These tests are written in Lua, and ensure the Lua environment, libraries and programs work as expected. These are (generally) written to be able to be run on emulators too, to provide some sort of compliance test. - + These tests are run by the '"Core" Java' test suite, and so are also run with `./gradlew test`. - In-game (`./src/test/java/dan200/computercraft/ingame/`): These tests are run on an actual Minecraft server, using [the same system Mojang do][mc-test]. The aim of these is to test in-game behaviour of blocks and peripherals. - + These are run by `./gradlew testInGame`. ## CraftOS tests diff --git a/LICENSE b/LICENSE index 65a70f5ae..cf30d77a6 100644 --- a/LICENSE +++ b/LICENSE @@ -19,14 +19,14 @@ Mod: The mod code designated by the present license, in source form, binary form, as obtained standalone, as part of a wider distribution or resulting from the compilation of the original or modified sources. -Dependency: Code required for the mod to work properly. This includes +Dependency: Code required for the mod to work properly. This includes dependencies required to compile the code as well as any file or modification that is explicitly or implicitly required for the mod to be working. 1. Scope -------- -The present license is granted to any user of the mod. As a prerequisite, +The present license is granted to any user of the mod. As a prerequisite, a user must own a legally acquired copy of Minecraft 2. Liability @@ -41,13 +41,13 @@ or misuse of this mod fall on the user. 3. Play rights -------------- -The user is allowed to install this mod on a Minecraft client or server and to play +The user is allowed to install this mod on a Minecraft client or server and to play without restriction. 4. Modification rights ---------------------- -The user has the right to decompile the source code, look at either the +The user has the right to decompile the source code, look at either the decompiled version or the original source code, and to modify it. 5. Distribution of original or modified copy rights @@ -61,10 +61,10 @@ include: - patch to its source or binary files - any copy of a portion of its binary source files -The user is allowed to redistribute this mod partially, in totality, or +The user is allowed to redistribute this mod partially, in totality, or included in a distribution. -When distributing binary files, the user must provide means to obtain its +When distributing binary files, the user must provide means to obtain its entire set of sources or modified sources at no cost. All distributions of this mod must remain licensed under the CCPL. @@ -92,7 +92,7 @@ must be made available at no cost and remain licensed under the CCPL. --------------- If you choose to contribute code or assets to be included in this mod, you -agree that, if added to to the main repository at +agree that, if added to to the main repository at https://github.com/dan200/ComputerCraft, your contributions will be covered by this license, and that Daniel Ratcliffe will retain the right to re-license the mod, including your contributions, in part or in whole, under other licenses. diff --git a/config/idea/codeInspectionSettings.xml b/config/idea/codeInspectionSettings.xml index 2862d72b4..57b8ed0d7 100644 --- a/config/idea/codeInspectionSettings.xml +++ b/config/idea/codeInspectionSettings.xml @@ -2488,4 +2488,4 @@ - \ No newline at end of file + diff --git a/config/idea/codeStyleSettings.xml b/config/idea/codeStyleSettings.xml index b4c9573fd..9a1e0f1d4 100644 --- a/config/idea/codeStyleSettings.xml +++ b/config/idea/codeStyleSettings.xml @@ -58,4 +58,4 @@