From 686a0e68bb43bb1da689f0f72e8ee8bc0e2d004b Mon Sep 17 00:00:00 2001 From: Tyler VanZanten Date: Fri, 25 Oct 2024 14:15:15 -0400 Subject: [PATCH] Add MegaLinter workflow, update editorconfig for consistent code formatting --- .editorconfig | 25 ++++++++- .github/workflows/cmake.yml | 61 +++++++++++++++++++--- .github/workflows/mega-linter.yml | 79 +++++++++++++++++++++++++++++ .github/workflows/node.js.yml | 4 +- .markdownlint.yml | 43 ++++++++++++++++ .mega-linter.yml | 34 +++++++++++++ .yamllint.yml | 21 ++++++++ CMakeLists.txt | 14 ++--- README.md | 3 +- proto/config.proto | 18 +++---- proto/enums.proto | 18 +++---- src/drivers/xboxog/xid/xid.c | 18 +++---- src/drivers/xboxog/xid/xid_driver.c | 2 +- www/.eslintrc.yml | 1 + 14 files changed, 295 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/mega-linter.yml create mode 100644 .markdownlint.yml create mode 100755 .mega-linter.yml create mode 100644 .yamllint.yml diff --git a/.editorconfig b/.editorconfig index e4cb7988b..9dae1a731 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,13 +11,36 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.md, *.yml] +[*.{md,yml}] indent_style = space indent_size = 2 trim_trailing_whitespace = false +[configs/**CMakeLists.txt] +insert_final_newline = false + [*.scss] end_of_line = lf [*.{js,jsx,ts,tsx}] quote_type = single + +[{package-lock.json,CMakeLists.txt,www/public/manifest.json}] +indent_style = space +indent_size = 2 + +[src/**.c] +indent_style = space +indent_size = 4 + +[pico_sdk_import.cmake] +indent_style = space +indent_size = 4 + +[modules/**.cmake] +indent_style = space +insert_final_newline = false + +[proto/**.proto] +indent_style = space +indent_size = 4 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index abbd1a63c..9549b4b5b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,12 +1,11 @@ +--- name: CMake on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] -# pull_request_target: -# branches: [ "main" ] + branches: ["main"] workflow_dispatch: env: @@ -23,10 +22,56 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - GP2040_BOARDCONFIG: [ARCController, Blank, Pico, PicoW, BentoBox, ergoSHIFTRev2, FightboardV3, FightboardV3Mirrored, FlatboxRev4, FlatboxRev5, FlatboxRev5RGB, FlatboxRev5USBPassthrough, FlatboxRev5Southpaw, Granola, KB2040, KeyboardConverter, Haute42COSMOX, Liatris, MavercadeRev1, MavercadeRev2, MiSTercadeV2, OpenCore0, OpenCore0WASD, OSUMGP-RP2040, PicoAnn, PicoFightingBoard, PXPGamepad, RanaTadpole, ReflexCtrlGenesis6, ReflexCtrlNES, ReflexCtrlSaturn, ReflexCtrlSNES, ReflexCtrlVB, ReflexEncodeV1.2, ReflexEncodeV2.0, RP2040AdvancedBreakoutBoard, RP2040AdvancedBreakoutBoardUSBPassthrough, RP2040MiniBreakoutBoard, SparkFunProMicro, WaveshareZero, Stress, SGFDevices, ZeroRhythm] + GP2040_BOARDCONFIG: + [ + ARCController, + Blank, + Pico, + PicoW, + BentoBox, + ergoSHIFTRev2, + FightboardV3, + FightboardV3Mirrored, + FlatboxRev4, + FlatboxRev5, + FlatboxRev5RGB, + FlatboxRev5USBPassthrough, + FlatboxRev5Southpaw, + Granola, + KB2040, + KeyboardConverter, + Haute42COSMOX, + Liatris, + MavercadeRev1, + MavercadeRev2, + MiSTercadeV2, + OpenCore0, + OpenCore0WASD, + OSUMGP-RP2040, + PicoAnn, + PicoFightingBoard, + PXPGamepad, + RanaTadpole, + ReflexCtrlGenesis6, + ReflexCtrlNES, + ReflexCtrlSaturn, + ReflexCtrlSNES, + ReflexCtrlVB, + ReflexEncodeV1.2, + ReflexEncodeV2.0, + RP2040AdvancedBreakoutBoard, + RP2040AdvancedBreakoutBoardUSBPassthrough, + RP2040MiniBreakoutBoard, + SparkFunProMicro, + WaveshareZero, + Stress, + SGFDevices, + ZeroRhythm, + ] steps: - #Global Setup + # Global Setup + # yamllint disable-line rule:indentation - name: Checkout GP2040-CE uses: actions/checkout@v4.1.1 with: @@ -44,8 +89,8 @@ jobs: - name: Get core count id: core_count - run : cat /proc/cpuinfo | grep processor | wc -l - #End Global Setup + run: cat /proc/cpuinfo | grep processor | wc -l + # End Global Setup - name: Pico Build Configure CMake shell: bash diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 000000000..ec19d749e --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,79 @@ +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +--- +name: MegaLinter + +# Trigger mega-linter at every push. +# Action will also be visible from Pull Requests to main +on: + push: + branches-ignore: + - main + pull_request: + branches: + - main + +# Commentted out env block because we do not want to apply fixes +# env: +# # Apply linter fixes configuration +# # +# # When active, APPLY_FIXES must also be defined as environment variable +# # (in github/workflows/mega-linter.yml or other CI tool) +# APPLY_FIXES: all + +# # Decide which event triggers application of fixes in a commit or a PR +# # (pull_request, push, all) +# APPLY_FIXES_EVENT: pull_request + +# # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) +# # or posted in a PR (pull_request) +# APPLY_FIXES_MODE: commit + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to + # improve performance + fetch-depth: 0 + + # MegaLinter + - name: MegaLinter + # You can override MegaLinter flavor used to have faster performances + # More info at https://megalinter.io/flavors/ + uses: oxsecurity/megalinter@v7 + id: ml + + # All available variables are described in documentation + # https://megalinter.io/configuration/ + env: + # Validates all source when push on main, else just the git diff with + # main. Override with true if you always want to lint all sources + VALIDATE_ALL_CODEBASE: >- + ${{ + github.event_name == 'push' && + contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) + }} + + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Upload MegaLinter artifacts + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index a117ec288..6f865ddf2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,3 +1,4 @@ +--- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs @@ -10,8 +11,9 @@ on: jobs: build: runs-on: ubuntu-latest - + steps: + # yamllint disable-line rule:indentation - uses: actions/checkout@v4.1.1 - name: Use Node.js diff --git a/.markdownlint.yml b/.markdownlint.yml new file mode 100644 index 000000000..81068de41 --- /dev/null +++ b/.markdownlint.yml @@ -0,0 +1,43 @@ +--- +########################### +########################### +## Markdown Linter rules ## +########################### +########################### + +# Linter rules doc: +# - https://github.com/DavidAnson/markdownlint +# +# Note: +# To comment out a single error: +# +# any violations you want +# +# + +############### +# Rules by id # +############### +MD004: false # Unordered list style +MD007: + indent: 2 # Unordered list indentation +MD009: false # Trailing spaces +MD013: + line_length: 500 # Line length 80 is far to short +MD026: + punctuation: ".,;:!。,;" # List of not allowed +MD029: false # Ordered list item prefix +MD030: + ul_single: 1 + ol_single: 1 + ul_multi: 1 + ol_multi: 1 +MD033: false # Allow inline HTML +MD036: false # Emphasis used instead of a heading +MD041: false # First line in a file should be a top-level heading +MD045: false # Images without alt text + +################# +# Rules by tags # +################# +blank_lines: false # Error on blank lines diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100755 index 000000000..9f53f6570 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,34 @@ +--- +# Configuration file for MegaLinter +# See all available variables at https://oxsecurity.github.io/megalinter/configuration/ and in linters documentation + +# If you use ENABLE_LINTERS variable, all other linters will be disabled by default +ENABLE_LINTERS: + [ + ACTION_ACTIONLINT, + EDITORCONFIG_EDITORCONFIG_CHECKER, + JSON_JSONLINT, + JSON_V8R, + MARKDOWN_MARKDOWNLINT, + REPOSITORY_DUSTILOCK, + REPOSITORY_GIT_DIFF, + REPOSITORY_GRYPE, + REPOSITORY_SECRETLINT, + REPOSITORY_SYFT, + REPOSITORY_TRIVY_SBOM, + REPOSITORY_TRUFFLEHOG, + YAML_V8R, + YAML_YAMLLINT, + ] +DISABLE: + - COPYPASTE # Disable checks of excessive copy-pastes + - SPELL # Disable checks of spelling mistakes + +DISABLE_ERRORS_LINTERS: [ACTION_ACTIONLINT, REPOSITORY_GRYPE, REPOSITORY_TRIVY, REPOSITORY_TRUFFLEHOG] +SHOW_ELAPSED_TIME: false +FILEIO_REPORTER: false +# DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass +# Exclude certain files from linting +FILTER_REGEX_EXCLUDE: "(lib/.*)" +# If we enable ESLint in the future, use our ESLint rules file +TSX_ESLINT_CONFIG_FILE: www/.eslintrc.yml diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 000000000..36945235c --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,21 @@ +--- +########################################### +# These are the rules used for # +# linting all the yaml files in the stack # +# NOTE: # +# You can disable line with: # +# # yamllint disable-line # +########################################### +extends: default +rules: + braces: + max-spaces-inside: 1 + new-lines: + level: warning + type: unix + line-length: + max: 500 + comments: + min-spaces-from-content: 1 # Used to follow prettier standard: https://github.com/prettier/prettier/pull/10926 + trailing-spaces: disable + truthy: disable diff --git a/CMakeLists.txt b/CMakeLists.txt index 54f6e70be..3ef951618 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,13 @@ endif() # set the version for webconfig, etc. based on git find_package(Git) execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_REPO_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REPO_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --abbrev=7 - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_REPO_BUILD_ID - OUTPUT_STRIP_TRAILING_WHITESPACE) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REPO_BUILD_ID + OUTPUT_STRIP_TRAILING_WHITESPACE) string(REGEX REPLACE "v([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" CMAKE_GIT_REPO_VERSION ${GIT_REPO_VERSION}) string(REGEX REPLACE "^(.......-.*)|(.......)$" "0.0.0" CMAKE_GIT_REPO_VERSION ${CMAKE_GIT_REPO_VERSION}) # fix if all we have is the git SHA configure_file("headers/version.h.in" "headers/version.h") @@ -307,5 +307,5 @@ install(FILES if (NOT (DEFINED ENV(CI)) AND (EXISTS ${CMAKE_SOURCE_DIR}/modules/Custom.cmake)) message(STATUS "Found custom script.") - include(${CMAKE_SOURCE_DIR}/modules/Custom.cmake) + include(${CMAKE_SOURCE_DIR}/modules/Custom.cmake) endif() diff --git a/README.md b/README.md index f1c7dcbdd..67325bb7d 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,8 @@ Visit the [GP2040-CE Usage](https://gp2040-ce.info/usage) page for more details. ## Performance -Input latency is tested using the methodology outlined at [WydD's inputlag.science website](https://inputlag.science/controller/methodology), using the default 1000 Hz (1 ms) polling rate in the firmware. You can read more about the setup we use to conduct latency testing [HERE](https://github.com/OpenStickCommunity/Site/blob/main/latency_testing/README.md) if you are interested in testing for yourself or would just like to know more about the devices used to do the testing. +Input latency is tested using the methodology outlined at [WydD's inputlag.science website](https://inputlag.science/controller/methodology), using the default 1000 Hz (1 ms) polling rate in the firmware. +You can read more about the setup we use to conduct latency testing [HERE](https://github.com/OpenStickCommunity/Site/blob/main/latency_testing/README.md) if you are interested in testing for yourself or would just like to know more about the devices used to do the testing. | Version | Mode | Poll Rate | Min | Max | Avg | Stdev | % on time | %1f skip | %2f skip | | ------- | ------- | --------- | ------- | ------- | ------- | ------- | --------- | -------- | -------- | diff --git a/proto/config.proto b/proto/config.proto index 44593ec4d..3a696d261 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -223,7 +223,7 @@ message ProfileOptions message DisplayOptions { optional bool enabled = 1; - + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; @@ -438,7 +438,7 @@ message ReverseOptions message AnalogADS1219Options { optional bool enabled = 1; - + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; @@ -764,14 +764,14 @@ message PCF8575Options message DRV8833RumbleOptions { - optional bool enabled = 1; + optional bool enabled = 1; - optional int32 leftMotorPin = 2; - optional int32 rightMotorPin = 3; - optional int32 motorSleepPin = 4; - optional uint32 pwmFrequency = 5; - optional float dutyMin = 6; - optional float dutyMax = 7; + optional int32 leftMotorPin = 2; + optional int32 rightMotorPin = 3; + optional int32 motorSleepPin = 4; + optional uint32 pwmFrequency = 5; + optional float dutyMin = 6; + optional float dutyMax = 7; } message ReactiveLEDInfo diff --git a/proto/enums.proto b/proto/enums.proto index db76de54b..e33af7986 100644 --- a/proto/enums.proto +++ b/proto/enums.proto @@ -332,20 +332,20 @@ enum ForcedSetupMode { option (nanopb_enumopt).long_names = false; - FORCED_SETUP_MODE_OFF = 0; - FORCED_SETUP_MODE_LOCK_MODE_SWITCH = 1; - FORCED_SETUP_MODE_LOCK_WEB_CONFIG = 2; - FORCED_SETUP_MODE_LOCK_BOTH = 3; + FORCED_SETUP_MODE_OFF = 0; + FORCED_SETUP_MODE_LOCK_MODE_SWITCH = 1; + FORCED_SETUP_MODE_LOCK_WEB_CONFIG = 2; + FORCED_SETUP_MODE_LOCK_BOTH = 3; }; enum DualDirectionalCombinationMode { - option (nanopb_enumopt).long_names = false; + option (nanopb_enumopt).long_names = false; - MIXED_MODE = 0; - GAMEPAD_MODE = 1; - DUAL_MODE = 2; - NONE_MODE = 3; + MIXED_MODE = 0; + GAMEPAD_MODE = 1; + DUAL_MODE = 2; + NONE_MODE = 3; } enum PS4ControllerType diff --git a/src/drivers/xboxog/xid/xid.c b/src/drivers/xboxog/xid/xid.c index 86312ff77..83ec2792b 100644 --- a/src/drivers/xboxog/xid/xid.c +++ b/src/drivers/xboxog/xid/xid.c @@ -17,8 +17,8 @@ static inline int8_t get_index_by_itfnum(uint8_t itf_num) //Xremote has two interfaces. Handle is separately. if (_xid_itf[i].type == XID_TYPE_XREMOTE) { - if (itf_num == _xid_itf[i].itf_num + 1) - return i; + if (itf_num == _xid_itf[i].itf_num + 1) + return i; } } return -1; @@ -55,8 +55,8 @@ static void xid_init(void) for (uint8_t i = 0; i < MAX_XIDS; i++) { _xid_itf[i].type = (i < (XID_DUKE)) ? XID_TYPE_GAMECONTROLLER : - (i < (XID_DUKE + XID_STEELBATTALION)) ? XID_TYPE_STEELBATTALION : - (i < (XID_DUKE + XID_STEELBATTALION + XID_XREMOTE)) ? XID_TYPE_XREMOTE : 0xFF; + (i < (XID_DUKE + XID_STEELBATTALION)) ? XID_TYPE_STEELBATTALION : + (i < (XID_DUKE + XID_STEELBATTALION + XID_XREMOTE)) ? XID_TYPE_XREMOTE : 0xFF; } } @@ -74,8 +74,8 @@ static uint16_t xid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, TU_ASSERT(p_xid != NULL, 0); uint16_t const drv_len = (p_xid->type == XID_TYPE_GAMECONTROLLER) ? TUD_XID_DUKE_DESC_LEN : - (p_xid->type == XID_TYPE_STEELBATTALION) ? TUD_XID_SB_DESC_LEN : - (p_xid->type == XID_TYPE_XREMOTE) ? TUD_XID_XREMOTE_DESC_LEN : 0; + (p_xid->type == XID_TYPE_STEELBATTALION) ? TUD_XID_SB_DESC_LEN : + (p_xid->type == XID_TYPE_XREMOTE) ? TUD_XID_XREMOTE_DESC_LEN : 0; TU_ASSERT(max_len >= drv_len, 0); p_xid->itf_num = itf_desc->bInterfaceNumber; @@ -86,7 +86,7 @@ static uint16_t xid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, { usbd_edpt_open(rhport, ep_desc); (ep_desc->bEndpointAddress & 0x80) ? (p_xid->ep_in = ep_desc->bEndpointAddress) : - (p_xid->ep_out = ep_desc->bEndpointAddress); + (p_xid->ep_out = ep_desc->bEndpointAddress); } TU_VERIFY(itf_desc->bNumEndpoints >= 2, drv_len); @@ -95,7 +95,7 @@ static uint16_t xid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, { usbd_edpt_open(rhport, ep_desc); (ep_desc->bEndpointAddress & 0x80) ? (p_xid->ep_in = ep_desc->bEndpointAddress) : - (p_xid->ep_out = ep_desc->bEndpointAddress); + (p_xid->ep_out = ep_desc->bEndpointAddress); } return drv_len; @@ -182,7 +182,7 @@ bool xid_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t c bool ret = false; - //Get HID Report + //Get HID Report if (request->bmRequestType == 0xA1 && request->bRequest == 0x01 && request->wValue == 0x0100) { if (stage == CONTROL_STAGE_SETUP) diff --git a/src/drivers/xboxog/xid/xid_driver.c b/src/drivers/xboxog/xid/xid_driver.c index 3d4531e95..cb36df488 100644 --- a/src/drivers/xboxog/xid/xid_driver.c +++ b/src/drivers/xboxog/xid/xid_driver.c @@ -3,4 +3,4 @@ uint8_t *xremote_get_rom() { return NULL; -} \ No newline at end of file +} diff --git a/www/.eslintrc.yml b/www/.eslintrc.yml index 0fe7bc7fd..fcb4e7cd2 100644 --- a/www/.eslintrc.yml +++ b/www/.eslintrc.yml @@ -1,3 +1,4 @@ +--- env: node: true browser: true