Add gluafixer workflow (#2614)

* Add glualint workflow

* Manual workflow

Don't think I'll be able to do what I want with the automatic workflow.

* Tweak some settings

Syntax errors should be reported now that E2 extensions are preprocessed.

Removed shadowing.
Removed redundant if statements.

Both of those were mostly caused by the code automatically generated by the preprocessor, so they will be disabled until the preprocessor generates better code.

* Delete luacheck

* Smaller trim

Don't need the char edge case

* Test only linting changed files

* Use changed-files workflow

* Used wrong variable

* Run the preprocessor anyway

Shouldn't take too much time anyway and I can't be bothered with this workflow not working properly.
This commit is contained in:
Vurv 2023-06-20 19:03:36 -07:00 committed by GitHub
parent b20a7f005f
commit 4338d17dac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 162 additions and 3873 deletions

34
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Lint
on:
pull_request:
paths:
- "lua/**"
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"
- name: Get any changed files
id: changed-files
uses: tj-actions/changed-files@v36
- name: Run E2 Extension Preprocessor
run: |
lua .github/workflows/preprocess.lua
- name: Download GluaFixer
run: |
curl -o glualint.zip -L https://github.com/FPtje/GLuaFixer/releases/download/1.24.6/glualint-1.24.6-x86_64-linux.zip
unzip glualint.zip
- name: Lint Code
run: |
./glualint ${{ steps.changed-files.outputs.all_changed_files }}

79
.github/workflows/preprocess.lua vendored Normal file
View File

@ -0,0 +1,79 @@
-- Before linting E2 Files, need to preprocess that e2function syntax away.
-- Hackily polyfill gmod-globals and run the preprocesor outside of gmod in the linter workflow.
-- Polyfills
AddCSLuaFile = function() end
_G.E2Lib = {}
_G.wire_expression_types = {
VECTOR = {"v"}, VECTOR2 = {"xv2"},
VECTOR4 = {"xv4"}, STRING = {"s"},
NORMAL = {"n"}, ANGLE = {"a"},
ARRAY = {"r"}, TABLE = {"t"},
ENTITY = {"e"}, WIRELINK = {"xwl"},
BONE = {"b"}, QUATERNION = {"q"},
COMPLEX = {"c"}, GTABLE = {"xgt"},
MATRIX = {"m"}, MATRIX2 = {"xm2"},
MATRIX4 = {"xm4"}, RANGER = {"xrd"},
EFFECT = {"xef"}
}
if not unpack then unpack = table.unpack end
function istable(t) return type(t) == "table" end
function string.Trim(s)
return string.match( s, "^%s*(.-)%s*$" ) or s
end
function string.Split(str, separator)
local ret, current_pos = {}, 1
for i = 1, #str do
local start_pos, end_pos = string.find(str, separator, current_pos)
if not start_pos then break end
ret[ i ] = string.sub( str, current_pos, start_pos - 1 )
current_pos = end_pos + 1
end
ret[ #ret + 1 ] = string.sub( str, current_pos )
return ret
end
-- Polyfills
require("lua.entities.gmod_wire_expression2.core.extpp")
E2Lib.ExtPP.Init()
local path_sep = package.config:sub(1, 1)
local traverse_cmd = path_sep == "\\" and "dir /b " or "ls "
---@param path string
---@param callback fun(filename: string, path: string)
local function iterFiles(path, callback)
path = string.gsub(path, "/", path_sep)
local dir = io.popen(traverse_cmd .. path)
for file in dir:lines() do
callback(file, path .. "/" .. file)
end
dir:close()
end
---@param filename string
---@param path string
local function handle(filename, path)
if filename:sub(1, 3) ~= "cl_" and filename:sub(-4) == ".lua" then
local handle = io.open(path, "rb")
local content = handle:read("*a")
handle:close()
E2Lib.ExtPP.Pass1(content)
local preprocessed = E2Lib.ExtPP.Pass2(content)
if preprocessed then
local handle = io.open(path, "wb")
handle:write(preprocessed)
handle:close()
end
end
end
iterFiles("lua/entities/gmod_wire_expression2/core", handle)
iterFiles("lua/entities/gmod_wire_expression2/core/custom", handle)

47
.glualint.json Normal file
View File

@ -0,0 +1,47 @@
{
"lint_maxScopeDepth": 9,
"lint_syntaxErrors": true,
"lint_syntaxInconsistencies": true,
"lint_deprecated": true,
"lint_trailingWhitespace": true,
"lint_whitespaceStyle": false,
"lint_beginnerMistakes": false,
"lint_emptyBlocks": true,
"lint_shadowing": false,
"lint_gotos": true,
"lint_goto_identifier": true,
"lint_doubleNegations": true,
"lint_redundantIfStatements": false,
"lint_redundantParentheses": true,
"lint_duplicateTableKeys": true,
"lint_profanity": true,
"lint_unusedVars": true,
"lint_unusedParameters": false,
"lint_unusedLoopVars": false,
"lint_inconsistentVariableStyle": false,
"lint_spaceBetweenParens": false,
"lint_spaceBetweenBrackets": false,
"lint_spaceBetweenBraces": false,
"lint_ignoreFiles": [],
"lint_spaceBeforeComma": false,
"lint_spaceAfterComma": false,
"lint_maxLineLength": 0,
"prettyprint_spaceBetweenParens": false,
"prettyprint_spaceBetweenBrackets": false,
"prettyprint_spaceBetweenBraces": false,
"prettyprint_spaceEmptyParens": false,
"prettyprint_spaceEmptyBraces": false,
"prettyprint_spaceAfterLabel": false,
"prettyprint_spaceBeforeComma": false,
"prettyprint_spaceAfterComma": true,
"prettyprint_semicolons": false,
"prettyprint_cStyle": false,
"prettyprint_removeRedundantParens": true,
"prettyprint_minimizeParens": false,
"prettyprint_assumeOperatorAssociativity": true,
"prettyprint_rejectInvalidCode": false,
"prettyprint_indentation": " ",
"log_format": "auto"
}

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,8 @@
"*.xcf",
".git*",
"*.md",
".luacheckrc",
".travis.yml",
"generate-luacheck.sh",
".glualint.json",
".github",
"git-hooks-pre-commit",
"gitrid.sh",
"LICENSE",

View File

@ -1,122 +0,0 @@
#!/bin/sh
set -e
base_url='http://wiki.garrysmod.com'
detag() {
printf '%s' "${1##*>}"
}
wget -o /dev/null -O - "$base_url"/navbar/ |
sed -r '
# Split up before each closing tag
s#</#\n\0#g
' |
sed -r '
# Remove navbarlink tags
s/<a class='\''navbarlink'\'' .*>//g
# Remove everything before the last tag
s/.*</</
' |
{
section=
while read -r line; do
detagged="$(detag "$line")"
case "$line" in
'<h2'*' &raquo;')
# Parse menu headers
detagged="${detagged% &raquo;}"
if printf '%s' "$detagged" | grep -v -q '^[[:alpha:]_][[:alnum:]_]*$'; then continue; fi
case "$section" in
Hooks|Libraries|Classes|Panels)
printf ' "%s",\n' "$detagged"
;;
Structures|Shaders|'Lua Reference'|'Lua Tutorials'|Global|Enumerations)
:
;;
*)
echo >&2 "unknown section '$section' for '$detagged'"
;;
esac
;;
'<a'*)
# Parse menu entries
case "$section" in
Global)
printf ' "%s",\n' "$detagged"
;;
Enumerations)
echo >&2 "Retrieving enum data for $detagged"
url="$base_url/page/Enums/$detagged" # TODO: use URL from the <a> tag
output="$(wget "$url" -o /dev/null -O -)"
if ! printf '%s' "$output" | grep -q "These enumerations do not exist in the game"; then
printf '\n --- %s\n' "$detagged"
printf '%s' "$output" | sed -rn 's/^<td> ('"$detagged"'_[^[:space:]]+|[A-Z][A-Z0-9_]{2,})$/ "\1",/p'
fi
;;
Structures|Shaders|'Lua Reference'|'Lua Tutorials'|Hooks|Libraries|Classes|Panels)
:
;;
*)
echo >&2 "unknown section '$section' for '$detagged'"
;;
esac
;;
'<h1>'*)
section="$detagged"
case "$section" in
Reference)
:
;;
*)
echo >&2 "Parsing section $section"
printf '\n -- %s\n' "$section"
;;
esac
;;
'<h2>'*)
section="$detagged"
case "$section" in
Enumerations)
echo >&2 "Parsing section $section"
printf '\n -- %s' "$section" # No newline after this, to avoid double newlines
;;
esac
;;
'</'*|'<ul'*)
# Ignore closing tags and <ul> tags
:
;;
*)
echo >&2 "Warning: Unhandled line '$line'"
esac
done
printf '\n'
} |
sed -ri '
0,/BEGIN_GENERATED_CODE/ {
/BEGIN_GENERATED_CODE/ {
r /dev/stdin
}
b
}
/END_GENERATED_CODE/,$ b
d
' .luacheckrc