Git Product home page Git Product logo

gluafixer's Issues

Wrong error location with iterative for loop variables

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

Something in these files causes the linter/pretty printer to break

Description of the bug

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

How to make the bug happen

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).

Errors

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

Wrong inconsistent ' "

a = '\n'
b = "anus"

Shouldn't throw a warning, but does, because '\n' is two characters.

Pretty print without unnecessary parentheses

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.

Incorrect 'double if statement' warning

image
I'm not sure if there's any debug information I could provide you, but it seems that the linter does not check for the scenario of
if > loop > if
In which case you cannot combine the if blocks, because you're probably also checking information from within that loop.

Error installing dependencies when compiling | Ubuntu

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

glualint sublime plugin: errors are placed in the wrong position


The style error in question is referring to the second concatenation operator not having a space after it. The plugin however highlights the word "GENERIC" for some reason.
With this case it is easy to detect, but with more advanced cases it becomes harder to find the actual error location.

Errors appear on the line above of the actual error

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 =

screenshot


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

screenshot

OSX build

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.

Linux Version Broken

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.

Pass code via stdin

I'm creating a linter plugin for VSCode and this would be nicer option over using a temp file.

Issue compiling glualint with Haskell 8.0.2 on macOS

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.

Suggestion: Add Option lint_combineifstatements

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!

Hello :):):):)))))

If you add local • = "sex" somewhere in code linter will stop working until you remove it
:):):)

How can i pretty print a file with cli ?

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.

--help please

Could you please add a brief --help switch to show some infos?

Your MD doesn't really explain the --pretty-print switch

Update

Update please so I can compile. I'm using GHC 8.0.1

'Inconsistent use of tabs and spaces' warning has the wrong position

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

screenshot

Control-flow changing double if statement warning

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).

local function shadowing problem

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

Incorrect unused variable warning

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.

Non glua version?

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.

Pretty Print Tables

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?

Incorrect shadowing warning

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 commented empty blocks breaks control flow

Description of the bug

Pretty printing what are essentially empty blocks, except for a single line comment, will break the control flow.

How to make the bug happen

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).

Lua errors

[ERROR] gamemodes/cityrp/schema/sh_commands.lua:358: unexpected symbol near '}'
  1. unknown - gamemodes/cityrp/schema/sh_commands.lua:0

False positive with exponentiation

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

Separate option for warning on trailing whitespace

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?

Glualint doesn't seem to handle unicode input

Description of the bug

Unless I have done something particularly stupid, it seems to strip all unicode text and replace it with question marks.

How to make the bug happen

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).

Combine condition of if statement with while loop incorrect

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.

Bad pretty print behaviour with comments

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

Improve Don't use self in a non-metafunction filter

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

Trouble with making the settings work

Hello there, I'm having some trouble to make the .glualint.json settings file work...

What I've tried

  • I tried putting the file into C:\Users\username\<right here>
  • I tried adding a folder to my PATH and putting glualint.exe and the .glualint.json in there
  • I tried to put the .glualint.json in my project folder
  • I tried changing the name from .glualint.json to glualint.json and tried all the directories mentioned above
  • I tried adding --config "D:\Documents\Executables\.glualint.json parameter in the settings (in atom)
  • I tried running 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

  • I am using Atom and I installed the linter-glualint package.
  • I have 2 disk in play, I have my documents on a 3TB drive with the letter D and my main drive (which is an SSD, if that matters) and it's obviously C.

Thanks for the support, if you need any other information I will be happy to give it.
Cheers!

Improve Empty if/elseif statement filter

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.

Wrong "don't use self in non-meta function"

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

(Discussion) Deprecated function warnings are emitted even when the function is not called

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.

Odd shifting of comment locations

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).

ULX Support and table option

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.