From 13ab8fb2b22f8d0412ffb92c7847706eaddd8792 Mon Sep 17 00:00:00 2001 From: aooohan Date: Sat, 12 Sep 2026 14:56:09 +0800 Subject: [PATCH] style: provide a Lua 5.1 formatting baseline for plugins Add a StyLua configuration, format template Lua files without changing their behavior, and document local checks and opt-in shared CI formatting. Shared format checks become active after the corresponding common-tool release is published. Fixes #2 --- Injection.lua | 1 - README.md | 16 ++++++++++++++++ hooks/available.lua | 8 ++++---- hooks/env_keys.lua | 12 +++++------- hooks/parse_legacy_file.lua | 4 ++-- hooks/post_install.lua | 4 ++-- hooks/pre_install.lua | 6 +++--- hooks/pre_uninstall.lua | 3 +-- hooks/pre_use.lua | 4 ++-- lib/util.lua | 3 +-- metadata.lua | 7 ++----- stylua.toml | 11 +++++++++++ 12 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 stylua.toml diff --git a/Injection.lua b/Injection.lua index a18c044..4d7b595 100644 --- a/Injection.lua +++ b/Injection.lua @@ -14,4 +14,3 @@ RUNTIME = { --- Plugin directory pluginDirPath = "", } - diff --git a/README.md b/README.md index e031afa..9abef33 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,22 @@ Keep runtime resources under `lib/`. Shared checks validate metadata, required h files and Lua syntax and build the same package used for publishing. They do not run lifecycle hooks or install SDKs. See the [package contract](https://github.com/version-fox/plugin-manifest-action#插件包与检查范围). +## Lua checks and formatting + +Use [StyLua 2.5.2](https://github.com/JohnnyMorganz/StyLua/releases/tag/v2.5.2) +with the included `stylua.toml` configuration: + +```shell +stylua . +stylua --check . +``` + +The shared PR check validates metadata, required hooks and Lua 5.1 syntax. +Repositories with `stylua.toml` also receive a read-only format check after the +shared tool release containing that check is published. Existing plugins can opt +in by adding this configuration and formatting their Lua files together. +Plugin behavior tests remain separate from syntax and style checks. + ## Publish a plugin Merge your changes into the default branch, then open **Actions → Plugin → Run diff --git a/hooks/available.lua b/hooks/available.lua index a5e6e3b..cc474a0 100644 --- a/hooks/available.lua +++ b/hooks/available.lua @@ -13,8 +13,8 @@ function PLUGIN:Available(ctx) { name = "npm", version = "8.8.8", - } - } - } + }, + }, + }, } -end \ No newline at end of file +end diff --git a/hooks/env_keys.lua b/hooks/env_keys.lua index aa80ad2..f2115e3 100644 --- a/hooks/env_keys.lua +++ b/hooks/env_keys.lua @@ -10,24 +10,22 @@ function PLUGIN:EnvKeys(ctx) local mpath = mainSdkInfo.path local mversion = mainSdkInfo.version local mname = mainSdkInfo.name - local sdkInfo = ctx.sdkInfo['sdk-name'] + local sdkInfo = ctx.sdkInfo["sdk-name"] local path = sdkInfo.path local version = sdkInfo.version local name = sdkInfo.name return { { key = "JAVA_HOME", - value = mainPath + value = mainPath, }, { key = "PATH", - value = mainPath .. "/bin" + value = mainPath .. "/bin", }, { key = "PATH", - value = mainPath .. "/bin2" + value = mainPath .. "/bin2", }, - } - -end \ No newline at end of file +end diff --git a/hooks/parse_legacy_file.lua b/hooks/parse_legacy_file.lua index df56b0d..d352159 100644 --- a/hooks/parse_legacy_file.lua +++ b/hooks/parse_legacy_file.lua @@ -7,6 +7,6 @@ function PLUGIN:ParseLegacyFile(ctx) local versions = ctx:getInstalledVersions() return { - version = "xxx" + version = "xxx", } -end \ No newline at end of file +end diff --git a/hooks/post_install.lua b/hooks/post_install.lua index 4bf262a..65d0aa6 100644 --- a/hooks/post_install.lua +++ b/hooks/post_install.lua @@ -4,9 +4,9 @@ function PLUGIN:PostInstall(ctx) --- ctx.rootPath SDK installation directory local rootPath = ctx.rootPath - local sdkInfo = ctx.sdkInfo['sdk-name'] + local sdkInfo = ctx.sdkInfo["sdk-name"] local path = sdkInfo.path local version = sdkInfo.version local name = sdkInfo.name local note = sdkInfo.note -end \ No newline at end of file +end diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 1a9c34c..a9d2f4d 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -33,7 +33,7 @@ function PLUGIN:PreInstall(ctx) sha1 = "xxx", --- sha512 checksum [optional] sha512 = "xx", - } - } + }, + }, } -end \ No newline at end of file +end diff --git a/hooks/pre_uninstall.lua b/hooks/pre_uninstall.lua index f78866f..b316986 100644 --- a/hooks/pre_uninstall.lua +++ b/hooks/pre_uninstall.lua @@ -1,4 +1,3 @@ - --- This is called before the SDK is uninstalled. --- @param ctx table Context information function PLUGIN:PreUninstall(ctx) @@ -6,4 +5,4 @@ function PLUGIN:PreUninstall(ctx) local mpath = mainSdkInfo.path local mversion = mainSdkInfo.version local mname = mainSdkInfo.name -end \ No newline at end of file +end diff --git a/hooks/pre_use.lua b/hooks/pre_use.lua index daf6d36..1366c5a 100644 --- a/hooks/pre_use.lua +++ b/hooks/pre_use.lua @@ -8,7 +8,7 @@ function PLUGIN:PreUse(ctx) local previousVersion = ctx.previousVersion --- installed sdks - local sdkInfo = ctx.installedSdks['version'] + local sdkInfo = ctx.installedSdks["version"] local path = sdkInfo.path local name = sdkInfo.name local version = sdkInfo.version @@ -24,4 +24,4 @@ function PLUGIN:PreUse(ctx) return { version = version, } -end \ No newline at end of file +end diff --git a/lib/util.lua b/lib/util.lua index 7a7f8d9..d2b30f3 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -1,8 +1,7 @@ - local util = {} function util:DoSomeThing() print("Do some thing") end -return util \ No newline at end of file +return util diff --git a/metadata.lua b/metadata.lua index 549bf95..c62e8f9 100644 --- a/metadata.lua +++ b/metadata.lua @@ -13,7 +13,6 @@ PLUGIN.license = "Apache 2.0" --- Plugin description PLUGIN.description = "your plugin description" - --- !!! OPTIONAL !!! --[[ NOTE: @@ -35,10 +34,8 @@ NOTE: --]] PLUGIN.manifestUrl = "https://github.com/version-fox/vfox-plugin-template/releases/download/manifest/manifest.json" -- Some things that need user to be attention! -PLUGIN.notes = { -} +PLUGIN.notes = {} --- List legacy configuration filenames for determining the specified version of the tool. --- such as ".node-version", ".nvmrc", etc. -PLUGIN.legacyFilenames = { -} +PLUGIN.legacyFilenames = {} diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..42c6c5b --- /dev/null +++ b/stylua.toml @@ -0,0 +1,11 @@ +syntax = "Lua51" +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 4 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "Never" + +[sort_requires] +enabled = false