fptje / gluafixer Goto Github PK
View Code? Open in Web Editor NEWLinter for Garry's mod Lua.
Home Page: https://fptje.github.io/glualint-web/
License: GNU Lesser General Public License v2.1
Linter for Garry's mod Lua.
Home Page: https://fptje.github.io/glualint-web/
License: GNU Lesser General Public License v2.1
Note the line in which the error occurs in the image. It should occur on line 12.
Test code:
local names = {
"martha",
"bob",
"eduardo" -- diversity is important
}
local othernames = {
"abe",
"lincoln"
}
for _, name in pairs(name) do
something(name)
end
for _, name in pairs(othernames) do
something_else(name)
end
Super descriptive and helpful title, I know. I haven't been able to try debugging glualint yet to actually figure out where in the file it breaks.
I was trying to lint and pretty print a gamemode schema. Which mostly went fine, except for #45 and some unicode issue.
However, these two files appear to break it somewhere and cause it to quit.
moneyprinter_samsung/cl_init.lua
: cl_init.lua
plugins/cityrphud.lua
: cityrphud.lua
Pretty print either of the two files I linked above. Other than that, not sure right now. Haven't dug too much.
Tested against v1.9.6 on Windows (pre-compiled release).
This is what my powershell script prints when looping the gamemode:
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\entities\entities\moneyprinter_lg\shared.lua
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\entities\entities\moneyprinter_samsung\cl_init.lua
glualint.exe: <<loop>>
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\entities\entities\moneyprinter_samsung\init.lua
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\entities\entities\moneyprinter_samsung\shared.lua
...
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\plugins\3d2ddoors.lua
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\plugins\cityrphud.lua
glualint.exe: <<loop>>
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\plugins\effects.lua
Linting file: C:\Users\Omar\CityRP\gamemodes\cityrp\plugins\flashlight2.lua
As the title suggests.
Thanks.
a = '\n'
b = "anus"
Shouldn't throw a warning, but does, because '\n' is two characters.
Take the GMod draw.lua library for example.
Just a feature request. As far as I can tell, there is an option to lint unnecessary parentheses. However, there doesn't appear to be an option to beautify the code to not have them.
Hi,
I am trying to compile glualint, but when I am installing dependencies, it keeps throwing off the same error. I saw something about the UUAGC error in Compiling.md, however I have a fresh install of Ubuntu that I installed not even an hour ago. I installed GHC and Cabal through the Haskell Platform. I downloaded and installed the core generic version of Haskell Platform for Linux.
Here is the end of the dependency installation: https://pastebin.com/yddgiYUP
If you prettify:
local w, h = surface.GetTextSize("blabla")
it will turn it into
local w, h = surface.GetTextSize("blabla"), nil
which is wrong.
reproduce:
a = 1*1/2*3
I've just installed this for Sublime and this seems to be happening pretty consistently for me. Here is some test code:
function Hello(world)
print("The following line has a syntax error, but it's displayed on this line")
error("message", errorLevel = 1)
end
4 lines total, and line 3 contains an error. However, GLuaLint declares that the error is on line 2:
C:\Users\neatn\Documents>glualint throwaway_lint.lua
throwaway_lint.lua: [Error] line 2, column 32 - line 2, column 32: unexpected =
This issue is not present with most warnings I've tested - the exception is #29.
function Hello(world)
local unusedvar1
local unusedvar2
-- comment 1
// comment 2
local some_vec = Vector(0, 0+2, 0)
some_vec.x = some_vec.x +1
end
C:\Users\neatn\Documents>glualint throwaway_lint.lua
throwaway_lint.lua: [Warning] line 2, column 11 - line 2, column 21: Unused variable: unusedvar1
throwaway_lint.lua: [Warning] line 3, column 11 - line 3, column 21: Unused variable: unusedvar2
throwaway_lint.lua: [Warning] line 5, column 5 - line 5, column 17: Inconsistent use of '//' and '--'
throwaway_lint.lua: [Warning] line 5, column 17 - line 5, column 20: Inconsistent use of tabs and spaces for indentation
throwaway_lint.lua: [Warning] line 7, column 29 - line 7, column 31: Style: Please put some whitespace before the operator
throwaway_lint.lua: [Warning] line 8, column 26 - line 8, column 28: Style: Please put some whitespace after the operator
You probably don't want to build for OSX yourself but it would be nice to supply a build anyways, I just spend 1h to create a build myself and would gladly forward it to you if you are interested.
I tried to use the Lua linter in combination with Sublime text and I can't seem to get the Linux binary working. Version 1.9.3 works just fine though.
I'm creating a linter plugin for VSCode and this would be nicer option over using a temp file.
Following the directions in https://github.com/FPtje/GLuaFixer/blob/master/Compiling.md leads to a build error following cabal build glualint
.
Preprocessing library glualint-lib-0.1.0.0...
cabal: can't find source for GLua/AG/AST in src, dist/build/autogen
Poked around at it for a bit, running cabal sdist
gives:
cabal: can't find source for GLua/AG/AST in src,
dist/src/sdist.-51698/glualint-lib-0.1.0.0/dist/build/autogen
glualint.cabal has hs-source-dirs: src
set.
Going to try rolling back Haskell version.
My suggestion is to add a option that toggles the warning about combining if-statements.
An example of what I am talking about: Double if statement. Please combine the condition of this if statement with that of the outer if statement using and
Thank you!
If you add local • = "sex"
somewhere in code linter will stop working until you remove it
:):):)
Hi,
I spent more time that i'm willing to admit maybe to do that,i'm on Windows.
I can do glualint filename.lua and it will output me errors/warnings,but it doesn't work if i do glua lint --pretty-print filename.lua
Thanks.
Could you please add a brief --help switch to show some infos?
Your MD doesn't really explain the --pretty-print switch
Update please so I can compile. I'm using GHC 8.0.1
Splitting this off from #28 which is probably unrelated.
The position of the 'Inconsistent use of tabs and spaces' warning is kind of bad. When it finds a new line with indentation that is inconsistent with previous indentation, it highlights the last previous line with content (i.e. non-whitespace characters), starting at the column after the last column on that line and ending n columns after that, where n is the number of whitespace/newline characters between that and the first non-whitespace character of the line with the bad indent.
That explanation was a bit convoluted, but a demonstration makes it quite simple.
Example/Recreation:
function Hello(world)
print("a") -- one tab
print("b") -- four spaces
end
Output:
C:\Users\neatn\Documents>glualint throwaway_lint.lua
throwaway_lint.lua: [Warning] line 2, column 23 - line 2, column 29: Inconsistent use of tabs and spaces for indentation
I got a warning for this code
if act == "spin" then
if not self.Spinning and self:TakeBet(ply) then
self.SpinPlayer = ply
self:Spin()
end
else
BaseClass.OnAct(self, ply, act)
end
Merging the if conditions would change the behavior of the outer if statement (this being good code is another question).
Pretty Print seems to convert all tabs into whitespaces, even my preference is set to tabs.
Can you add an option to change this behaviour?
function cena()
local function benus()
end
benus()
end
function dundundundun()
local benus = 3
end
the local benus = 3
is seen as shadowing the other benus
I downloaded the unstripped version and still could not get it to work. 1.9.3 works just fine.
local canMerge = false;
local neDiffX = math.abs(self.neCorner.x - adj.neCorner.x)
local swDiffX = math.abs(self.swCorner.x - adj.swCorner.x)
if ((neDiffX < mergeTolerance) and (swDiffX < mergeTolerance)) then
canMerge = true
end
canMerge is the 'unused' variable.
Not exactly an issue but, seeing that this is the only actual linter available for any Lua, would be mind creating a vanilla Lua version?
I'd love to use that linter for non garrysmod projects.
in pretty printing
Whenever writing tables and pretty printing the file, sometimes I find it cleaner to leave a table on only one line. However, I can't really figure out an option that stops the PP from turning this
local hstmd = xlib.makecheckbox { label = "ttt_haste", repconvar = "rep_ttt_haste", parent = rsrllst }
into this:
local hstmd = xlib.makecheckbox {
label = "ttt_haste",
repconvar = "rep_ttt_haste",
parent = rsrllst
}
Any way to configure the printer not to expand tables like this?
function DarkRP.storeTeamDoorOwnability(ent)
local map = string.lower(game.GetMap())
end
if job then
e:addKeysDoorTeam(job)
else
print(("can't find job %s for door %d, removing from database"):format(row.job, row.idx))
MySQLite.query(("DELETE FROM darkrp_doorjobs WHERE idx = %d AND map = %s AND job = %s;"):format(row.idx, MySQLite.SQLStr(map), MySQLite.SQLStr(row.job)))
end
function DarkRP.storeDoorGroup(ent, group)
local map = MySQLite.SQLStr(string.lower(game.GetMap()))
end
the second map
is said to shadow the first. Probably those damn elses.
Pretty printing what are essentially empty blocks, except for a single line comment, will break the control flow.
If you write something like the code below, pretty printing will mangle it by commenting out a necessary end token.
Before:
if (amount and isnumber(amount) and amount > 0 and char) then
if (char:hasReserve(amount)) then
-- Fee 10%
end
else
client:notify(L("provideValidNumber", client))
end
After:
if (amount and isnumber(amount) and amount > 0 and char) then
if (char:hasReserve(amount)) then -- Fee 10% end
else
client:notify(L("provideValidNumber", client))
end
Tested against v1.9.6 on Windows (pre-compiled release).
[ERROR] gamemodes/cityrp/schema/sh_commands.lua:358: unexpected symbol near '}'
1. unknown - gamemodes/cityrp/schema/sh_commands.lua:0
GLuaLint will detect an exponent operator (^) followed by any unary operator(#, -, not) as an error. For example, it will detect the following as errors, even though they are fine.
5^-1
tbl={1,2}
5^#tbl
5^not 1
Currently the only way to disable the warning for trailing whitespace is with lint_whitespaceStyle, but this also disables warning for things like a==b
(prefers a == b
). These are very different things, and I have Sublime configured to remove all trailing whitespace on save with "trim_trailing_white_space_on_save": true
anyway so any warning about that is 100% useless. However I want to keep the warnings about whitespace surrounding opreators.
Can this setting be separated?
Unless I have done something particularly stupid, it seems to strip all unicode text and replace it with question marks.
Here's CityRP's Korean translation to text against: sh_korean.lua
This is my powershell script: lint-all.ps1
When debugging it against sh_korean.lua
, powershell outputs the expected Korean text - E.g.,:
microwave = "전자렌지",
However, after glualint is done with it and it gets piped back out, it looks a little something like this:
microwave = "????",
Tested against v1.9.6 on Windows (pre-compiled release).
local nextupdate = 0
local tickrate = 0.015
local clock = os.clock
while true do
if clock() >= nextupdate then
nextupdate = clock() + tickrate
drawBuffer()
clearScreen()
end
end
Will say
Uneccessary if statement. Please combine the condition of this if statement with that of the while loop
and
.
However, if that was done the code wouldn't have the same meaning and would not work.
Never tell your password to anyone.
Python1320: if true then
return false end -- a
Python1320: this breaks glualint, but only if newline between
(FPtje) Falco: you mean pretty print
if true then
return false end -- a
Most of the time I see this warning, the actual context of the use of self is perfectly fine. It triggers when its being used in a local function whose parent function has a meta object the local function needs to access. Example code below.
function GM:Initialize()
local function someThing()
local foo = bar;
self:Log( "just logging stuff with a gm wrapper " .. tostring( foo ) );
end
otherThing();
end
Hello there, I'm having some trouble to make the .glualint.json
settings file work...
What I've tried
C:\Users\username\<right here>
glualint.exe
and the .glualint.json
in there.glualint.json
in my project folder.glualint.json
to glualint.json
and tried all the directories mentioned above--config "D:\Documents\Executables\.glualint.json
parameter in the settings (in atom)glualint.exe
in the console both in the new folder added to the PATH and the System32
directory, worked both times.What I'm using
linter-glualint
package.Thanks for the support, if you need any other information I will be happy to give it.
Cheers!
Would be great if this filter didn't trigger when comments are within the statement, often time's I see or have commented out code in conditionals for debugging or marking areas I need to implement something later. In a large project where these TODOs exist, it can plug up the lint log with lots of non-issues.
a = -.5
Wrong syntax error in parser
Add support for functions not called anywhere.
function ENT:Use(activator,caller)
if not self.CanUse then return false end
self.CanUse = false
self.drug_user = activator
if activator.maxDrugs and activator.maxDrugs >= GAMEMODE.Config.maxdrugs then
DarkRP.notify(activator, 1, 3, DarkRP.getPhrase("limit", string.lower(DarkRP.getPhrase("drugs"))))
timer.Simple(0.5, function() self.CanUse = true end)
else
local productioncost = math.random(math.Round(self:Getprice() / 8), math.Round(self:Getprice() / 4))
if not activator:canAfford(productioncost) then
DarkRP.notify(activator, 1, 4, DarkRP.getPhrase("cant_afford", string.lower(DarkRP.getPhrase("drugs"))))
timer.Simple(0.5, function() self.CanUse = true end)
return false
end
activator:addMoney(-productioncost)
DarkRP.notify(activator, 0, 4, DarkRP.getPhrase("you_bought", string.lower(DarkRP.getPhrase("drugs")), DarkRP.formatMoney(productioncost), ""))
self.sparking = true
timer.Create(self:EntIndex() .. "drug", 1, 1, function() self:createDrug() end)
end
end
error in timer anonymous func
Really annoying that this isn't supported
GetConVarString = nil
emits the warning Deprecated: Use ConVar objects instead
This may be a tricky issue because this might no longer warn:
local qwerty = GetConVarString
qwerty()
An idea might be to check for the deprecated function being assigned to some other value, and if that is the case, do not raise the warning. In all other cases, still emit the warning.
I fucking thought it did.
glualint
warns me CEffectData:SetAttachment
is deprecated, even though it isn't.
https://wiki.garrysmod.com/page/CEffectData/SetAttachment
On the other hand, Entity:SetAttachment
is actually deprecated.
https://wiki.garrysmod.com/page/Entity/SetAttachment
using Atom.
Unsure if this is an unintended side-effect of: 1d7a43c
Not sure what can really be done about it. But, you can see what I'm on about below.
Before:
for num,ply in pairs(player.GetAll()) do --If the buddies are in the server then add them serverside
for num,ply in pairs(player.GetAll()) do --If the buddies are in the server then add them serverside
if ply:SteamID() == v.steamid then
-- update the name
sql.Query("UPDATE FPP_Buddies SET name = " .. sql.SQLStr(ply:Nick()) .. " WHERE steamid = " .. sql.SQLStr(v.steamid) .. ";")
FPP.Buddies[v.steamid].name = ply:Nick()
RunConsoleCommand("FPP_SetBuddy", ply:UserID(), v.physgun, v.gravgun, v.toolgun, v.playeruse, v.entitydamage)
end
end
After
end
--If the buddies are in the server then add them serverside
end
for num, ply in pairs(player.GetAll()) do
if ply:SteamID() == v.steamid then
-- update the name
sql.Query("UPDATE FPP_Buddies SET name = " .. sql.SQLStr(ply:Nick()) .. " WHERE steamid = " .. sql.SQLStr(v.steamid) .. ";")
FPP.Buddies[v.steamid].name = ply:Nick()
RunConsoleCommand("FPP_SetBuddy", ply:UserID(), v.physgun, v.gravgun, v.toolgun, v.playeruse, v.entitydamage)
end
end
--If the buddies are in the server then add them serverside
end
I figure it's probably better to try and move that kind of comment above the start of the control flow segment rather than after it. It gets a little confusing when it moves a comment from something like:
if v:SteamID() == SteamID then -- If the person you're adding is in the server then add him serverside
to below the end statement (which might be the beginning of another if statement or something).
Was wondeirng if you could prevent it from formatting the ulx tables on new lines. Also an optioin in the .json to have tables on one line or to break them or every new value in the table.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.