From 52f9778a3db55f007eb0ff91bbb17ced12fe31e7 Mon Sep 17 00:00:00 2001 From: Didier Malenfant Date: Thu, 2 Jun 2022 18:28:28 +0200 Subject: [PATCH 01/46] feat: Add builtin std option for the Playdate SDK --- luacheck-dev-1.rockspec | 1 + src/luacheck/builtin_standards/init.lua | 3 + src/luacheck/builtin_standards/playdate.lua | 421 ++++++++++++++++++++ src/luacheck/main.lua | 1 + 4 files changed, 426 insertions(+) create mode 100644 src/luacheck/builtin_standards/playdate.lua diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index 1749c610..bfb0805c 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -24,6 +24,7 @@ build = { luacheck = "src/luacheck/init.lua", ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", ["luacheck.cache"] = "src/luacheck/cache.lua", ["luacheck.check"] = "src/luacheck/check.lua", diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index f8839169..b032df10 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -1,4 +1,5 @@ local love = require "luacheck.builtin_standards.love" +local playdate = require "luacheck.builtin_standards.playdate" local ngx = require "luacheck.builtin_standards.ngx" local standards = require "luacheck.standards" @@ -295,6 +296,8 @@ builtin_standards.busted = { builtin_standards.love = love +builtin_standards.playdate = playdate + builtin_standards.rockspec = { globals = { "rockspec_format", "package", "version", "description", "dependencies", "supported_platforms", diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua new file mode 100644 index 00000000..48c92861 --- /dev/null +++ b/src/luacheck/builtin_standards/playdate.lua @@ -0,0 +1,421 @@ +local standards = require "luacheck.standards" + +local empty = {} +local read_write = {read_only = false} + +-- import statement used by the playdate SDK +local import = { + fields = {} +} + +-- Table additions +local table = standards.def_fields("indexOfElement", "getsize", "create", "shallowcopy", "deepcopy") + +-- Debugging +local printTable = { + fields = {} +} + +local where = { + fields = {} +} + +-- Profiling +local sample = { + fields = {} +} + +-- JSON +local json = standards.def_fields("decode", "decodeFile", "encode", "encodePretty", "encodeToFile") + +-- Text Alignement +local kTextAlignment = standards.def_fields("left", "center", "right") + +-- Playdate SDK +local playdate = { + fields = { + -- System and Game Metadata + apiVersion = empty, + metadata = standards.def_fields("bundleID", "version", "buildNumber", "imagePath", "card.png", + "card-highlighted", "animation.txt", "loopCount", "frames", "introFrames", "card-pressed.png", + "launchImage.png", "launchImages", "wrapping-pattern.png", "launchSoundPath", "contentWarning", + "contentWarning2"), + + -- Game flow + update = read_write, + wait = empty, + stop = empty, + start = empty, + + -- Game lifecycle + gameWillTerminate = read_write, + deviceWillSleep = read_write, + deviceWillLock = read_write, + deviceDidUnlock = read_write, + gameWillPause = read_write, + gameWillResume = read_write, + + -- Interacting with the System Menu + getSystemMenu = empty, + setMenuImage = empty, + + -- Localization + getSystemLanguage = empty, + + -- Accessibility + getReduceFlashing = empty, + getFlipped = empty, + + -- Accelerometer + startAccelerometer = empty, + stopAccelerometer = empty, + readAccelerometer = empty, + accelerometerIsRunning = empty, + + -- Buttons + buttonIsPressed = empty, + buttonJustPressed = empty, + buttonJustRelease = empty, + getButtonState = empty, + AButtonDown = read_write, + AButtonHeld = read_write, + AButtonUp = read_write, + BButtonDown = read_write, + BButtonHeld = read_write, + BButtonUp = read_write, + downButtonDown = read_write, + downButtonUp = read_write, + leftButtonDown = read_write, + leftButtonUp = read_write, + rightButtonDown = read_write, + rightButtonUp = read_write, + upButtonDown = read_write, + upButtonUp = read_write, + + -- Crank + isCrankDocked = empty, + getCrankPosition = empty, + getCrankChange = empty, + cranked = read_write, + crankDocked = read_write, + crankUndocked = read_write, + setCrankSoundsDisabled = empty, + + -- Input Handlers + inputHandlers = standards.def_fields("push", "pop"), + + -- Device Auto Lock + setAutoLockDisabled = empty, + + -- Date & Time + getCurrentTimeMilliseconds = empty, + resetElapsedTime = empty, + getElapsedTime = empty, + getSecondsSinceEpoch = empty, + getTime = empty, + getGMTTime = empty, + epochFromTime = empty, + epochFromGMTTime = empty, + timeFromEpoch = empty, + GMTTimeFromEpoch = empty, + + -- Debugging + argv = empty, + setNewlinePrinted = empty, + drawFPS = empty, + + -- Profiling + getStats = empty, + setStatsInterval = empty, + + -- Display + display = standards.def_fields("setRefreshRate", "getRefreshRate", "flush", "getHeight", "getWidth", + "getSize", "getRect", "setScale", "getScale", "setInverted", "getInverted", "setMosaic", + "getMosaic", "setOffset", "getOffset", "setFlipped", "loadImage"), + + -- Easing Functions + easingFunctions = standards.def_fields("linear", "inQuad", "outQuad", "inOutQuad", "outInQuad", "inCubic", + "outCubic", "inOutCubic", "outInCubic", "inQuart", "outQuart", "inOutQuart", "outInQuart", "inQuint", + "outQuint", "inOutQuint", "outInQuint", "inSine", "outSine", "inOutSine", "outInSine", "inExpo", + "outExpo", "inOutExpo", "outInExpo", "inCirc", "outCirc", "inOutCirc", "outInCirc", "inElastic", + "outElastic", "inOutElastic", "outInElastic", "inBack", "outBack", "inOutBack", "outInBack", + "outBounce", "inBounce", "inOutBounce", "outInBounce"), + + -- Files + datastore = standards.def_fields("write", "read", "delete", "writeImage", "readImage"), + file = standards.def_fields("open", "kFileRead", "kFileWrite", "kFileAppend", "listFiles", "exists", + "isdir", "mkdir", "delete", "getSize", "getType", "modtime", "rename", "load", "run"), + + -- Geometry + geometry = { + fields = { + affineTransform = standards.def_fields("new"), + arc = standards.def_fields("new"), + lineSegment = standards.def_fields("new"), + point = standards.def_fields("new"), + polygon = standards.def_fields("new"), + rect = standards.def_fields("new", "fast_intersection", "fast_union"), + kUnflipped = empty, + kFlippedX = empty, + kFlippedY = empty, + kFlippedXY = empty, + size = standards.def_fields("new"), + squaredDistanceToPoint = empty, + distanceToPoint = empty, + vector2D = standards.def_fields("new"), + } + }, + + -- Graphics + graphics = { + fields = { + pushContext = empty, + popContext = empty, + clear = empty, + image = standards.def_fields("new"), + imageSizeAtPath = empty, + kImageUnflipped = empty, + kImageFlippedX = empty, + kImageFlippedY = empty, + kImageFlippedXY = empty, + kDitherTypeNone = empty, + kDitherTypeDiagonalLine = empty, + kDitherTypeVerticalLine = empty, + kDitherTypeHorizontalLine = empty, + kDitherTypeScreen = empty, + kDitherTypeBayer2x2 = empty, + kDitherTypeBayer4x4 = empty, + kDitherTypeBayer8x8 = empty, + kDitherTypeFloydSteinberg = empty, + kDitherTypeBurkes = empty, + kDitherTypeAtkinson = empty, + checkAlphaCollision = empty, + setColor = empty, + kColorBlack = empty, + kColorWhite = empty, + kColorClear = empty, + kColorXOR = empty, + getColor = empty, + getBackgroundColor = empty, + setPattern = empty, + setDitherPattern = empty, + drawLine = empty, + setLineCapStyle = empty, + kLineCapStyleButt = empty, + kLineCapStyleRound = empty, + kLineCapStyleSquare = empty, + drawPixel = empty, + drawRect = empty, + fillRect = empty, + drawRoundRect = empty, + fillRoundRect = empty, + drawArc = empty, + drawCircleAtPoint = empty, + drawCircleInRect = empty, + fillCircleAtPoint = empty, + fillCircleInRect = empty, + drawEllipseInRect = empty, + fillEllipseInRect = empty, + drawPolygon = empty, + fillPolygon = empty, + setPolygonFillRule = empty, + kPolygonFillNonZero = empty, + kPolygonFillEvenOdd = empty, + drawTriangle = empty, + fillTriangle = empty, + nineSlice = standards.def_fields("new"), + perlin = empty, + perlinArray = empty, + generateQRCode = empty, + drawSineWave = empty, + setClipRect = empty, + getClipRect = empty, + setScreenClipRect = empty, + getScreenClipRect = empty, + clearClipRect = empty, + setStencilImage = empty, + setStencilPattern = empty, + clearStencil = empty, + clearStencilImage = empty, + setImageDrawMode = empty, + kDrawModeCopy = empty, + kDrawModeWhiteTransparent = empty, + kDrawModeBlackTransparent = empty, + kDrawModeFillWhite = empty, + kDrawModeFillBlack = empty, + kDrawModeXOR = empty, + kDrawModeNXOR = empty, + kDrawModeInverted = empty, + getImageDrawMode = empty, + setLineWidth = empty, + getLineWidth = empty, + setStrokeLocation = empty, + kStrokeCentered = empty, + kStrokeOutside = empty, + kStrokeInside = empty, + getStrokeLocation = empty, + lockFocus = empty, + unlockFocus = empty, + animation = { + fields = { + loop = standards.def_fields("new"), + blinker = standards.def_fields("new", "updateAll", "stopAll"), + } + }, + animator = standards.def_fields("new"), + setDrawOffset = empty, + getDrawOffset = empty, + getDisplayImage = empty, + getWorkingImage = empty, + imagetable = standards.def_fields("new"), + tilemap = standards.def_fields("new"), + sprite = standards.def_fields("new", "update", "addSprite", "removeSprite", "setBackgroundDrawingCallback", + "redrawBackground", "setClipRectsInRange", "setAlwaysRedraw", "getAlwaysRedraw", "addDirtyRect", + "getAllSprites", "performOnAllSprites", "spriteCount", "removeAll", "removeSprites", + "allOverlappingSprites", "kCollisionTypeSlide", "kCollisionTypeFreeze", "kCollisionTypeOverlap", + "kCollisionTypeBounce", "querySpritesAtPoint", "querySpritesInRect", "querySpritesAlongLine", + "querySpriteInfoAlongLine", "addEmptyCollisionSprite", "addWallSprites"), + setFont = empty, + getFont = empty, + setFontFamily = empty, + font = standards.def_fields("new", "newFamily", "kVariantNormal", "kVariantBold", "kVariantItalic", + "kLanguageEnglish", "kLanguageJapanese"), + setFontTracking = empty, + getFontTracking = empty, + getSystemFont = empty, + drawText = empty, + drawLocalizedText = empty, + getLocalizedText = empty, + getTextSize = empty, + drawTextInRect = empty, + drawLocalizedTextAligned = empty, + drawLocalizedTextInRect = empty, + getTextSizeForMaxWidth = empty, + video = standards.def_fields("new"), + } + }, + + -- Keyboard + keyboard = { + fields = { + show = empty, + hide = empty, + text = read_write, + setCapitalizationBehavior = empty, + left = empty, + width = empty, + isVisible = empty, + keyboardDidShowCallback = read_write, + keyboardDidHideCallback = read_write, + keyboardWillHideCallback = read_write, + keyboardAnimatingCallback = read_write, + textChangedCallback = read_write, + } + }, + + -- Math + math = standards.def_fields("lerp"), + + -- Pathfinding + pathfinder = standards.def_fields("new", "new2DGrid"), + + -- Power + getPowerStatus = empty, + getBatteryPercentage = empty, + getBatteryVoltage = empty, + + -- Simulator only + isSimulator = empty, + simulator = standards.def_fields("writeToFile", "exit", "getURL"), + clearConsole = empty, + setDebugDrawColor = empty, + keyPressed = read_write, + keyReleased = read_write, + debugDraw = read_write, + + -- Sound + sound = { + fields = { + getSampleRate = empty, + sampleplayer = standards.def_fields("new"), + fileplayer = standards.def_fields("new"), + sample = standards.def_fields("new"), + kFormat8bitMono = empty, + kFormat8bitStereo = empty, + kFormat16bitMono = empty, + kFormat16bitStereo = empty, + channel = standards.def_fields("new"), + playingSources = empty, + synth = standards.def_fields("new"), + kWaveSine = empty, + kWaveSquare = empty, + kWaveSawtooth = empty, + kWaveTriangle = empty, + kWaveNoise = empty, + kWavePOPhase = empty, + kWavePODigital = empty, + kWavePOVosim = empty, + lfo = standards.def_fields("new"), + kLFOSquare = empty, + kLFOSawtoothUp = empty, + kLFOSawtoothDown = empty, + kLFOTriangle = empty, + kLFOSine = empty, + kLFOSampleAndHold = empty, + envelope = standards.def_fields("new"), + addEffect = empty, + removeEffect = empty, + bitcrusher = standards.def_fields("new"), + ringmod = standards.def_fields("new"), + onepolefilter = standards.def_fields("new"), + twopolefilter = standards.def_fields("new"), + kFilterLowPass = empty, + kFilterHighPass = empty, + kFilterBandPass = empty, + kFilterNotch = empty, + kFilterPEQ = empty, + kFilterLowShelf = empty, + kFilterHighShelf = empty, + overdrive = standards.def_fields("new"), + delayline = standards.def_fields("new"), + sequence = standards.def_fields("new"), + track = standards.def_fields("new"), + controlsignal = standards.def_fields("new"), + micinput = standards.def_fields("recordToSample", "stopRecording", "startListening", "stopListening", + "getLevel", "getSource"), + getHeadphoneState = empty, + setOutputsActive = empty, + getCurrentTime = empty, + resetTime = empty, + } + }, + + -- Strings + string = standards.def_fields("UUID", "trimWhitespace", "trimLeadingWhitespace", "trimTrailingWhitespace"), + + -- Timers + timer = standards.def_fields("updateTimers", "new", "performAfterDelay", "keyRepeatTimer", + "keyRepeatTimerWithDelay", "allTimers"), + + -- Frame timers + frameTimer = standards.def_fields("updateTimers", "new", "performAfterDelay", "allTimers"), + + -- UI components + ui = { + fields = { + crankIndicator = standards.def_fields("start", "update", "clockwise"), + gridview = standards.def_fields("new"), + } + }, + + -- Garbage collection + setCollectsGarbage = empty, + setMinimumGCTime = empty, + setGCScaling = empty, + } +} + +return { + read_globals = {import = import, playdate = playdate, table = table, printTable = printTable, + where = where, sample = sample, json = json, kTextAlignment = kTextAlignment} +} diff --git a/src/luacheck/main.lua b/src/luacheck/main.lua index 9b8d035c..e141f471 100644 --- a/src/luacheck/main.lua +++ b/src/luacheck/main.lua @@ -86,6 +86,7 @@ Links: " luajit - globals of LuaJIT 2.x;\n" .. " ngx_lua - globals of Openresty lua-nginx-module 0.10.10, including standard LuaJIT 2.x globals;\n" .. " love - globals added by LÖVE;\n" .. + " playdate - globals added by the Playdate SDK;\n" .. " busted - globals added by Busted 2.0, by default added for files ending with _spec.lua within spec, " .. "test, and tests subdirectories;\n" .. " rockspec - globals allowed in rockspecs, by default added for files ending with .rockspec;\n" .. From d7cf99fe4ad3339ec59d86b3ad96d0fa2d6dd438 Mon Sep 17 00:00:00 2001 From: Didier Malenfant Date: Fri, 3 Jun 2022 13:27:26 +0200 Subject: [PATCH 02/46] chore: Tweak definitions for playdate builtins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These were found by running luacheck against the SDK’s sample code. --- src/luacheck/builtin_standards/playdate.lua | 54 +++++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua index 48c92861..5a6ffedb 100644 --- a/src/luacheck/builtin_standards/playdate.lua +++ b/src/luacheck/builtin_standards/playdate.lua @@ -8,6 +8,13 @@ local import = { fields = {} } +-- Object oriented programming support +local class = standards.def_fields("extends") + +local Object = { + fields = {} +} + -- Table additions local table = standards.def_fields("indexOfElement", "getsize", "create", "shallowcopy", "deepcopy") @@ -74,6 +81,12 @@ local playdate = { -- Buttons buttonIsPressed = empty, + kButtonA = empty, + kButtonB = empty, + kButtonUp = empty, + kButtonDown = empty, + kButtonLeft = empty, + kButtonRight = empty, buttonJustPressed = empty, buttonJustRelease = empty, getButtonState = empty, @@ -172,23 +185,14 @@ local playdate = { pushContext = empty, popContext = empty, clear = empty, - image = standards.def_fields("new"), + image = standards.def_fields("new", "kDitherTypeNone", "kDitherTypeDiagonalLine", "kDitherTypeVerticalLine", + "kDitherTypeHorizontalLine", "kDitherTypeScreen", "kDitherTypeBayer2x2", "kDitherTypeBayer4x4", + "kDitherTypeBayer8x8", "kDitherTypeFloydSteinberg", "kDitherTypeBurkes", "kDitherTypeAtkinson"), imageSizeAtPath = empty, kImageUnflipped = empty, kImageFlippedX = empty, kImageFlippedY = empty, kImageFlippedXY = empty, - kDitherTypeNone = empty, - kDitherTypeDiagonalLine = empty, - kDitherTypeVerticalLine = empty, - kDitherTypeHorizontalLine = empty, - kDitherTypeScreen = empty, - kDitherTypeBayer2x2 = empty, - kDitherTypeBayer4x4 = empty, - kDitherTypeBayer8x8 = empty, - kDitherTypeFloydSteinberg = empty, - kDitherTypeBurkes = empty, - kDitherTypeAtkinson = empty, checkAlphaCollision = empty, setColor = empty, kColorBlack = empty, @@ -196,6 +200,7 @@ local playdate = { kColorClear = empty, kColorXOR = empty, getColor = empty, + setBackgroundColor = empty, getBackgroundColor = empty, setPattern = empty, setDitherPattern = empty, @@ -287,6 +292,7 @@ local playdate = { drawLocalizedText = empty, getLocalizedText = empty, getTextSize = empty, + drawTextAligned = empty, drawTextInRect = empty, drawLocalizedTextAligned = empty, drawLocalizedTextInRect = empty, @@ -317,7 +323,11 @@ local playdate = { math = standards.def_fields("lerp"), -- Pathfinding - pathfinder = standards.def_fields("new", "new2DGrid"), + pathfinder = { + fields = { + graph = standards.def_fields("new", "new2DGrid") + } + }, -- Power getPowerStatus = empty, @@ -380,6 +390,7 @@ local playdate = { delayline = standards.def_fields("new"), sequence = standards.def_fields("new"), track = standards.def_fields("new"), + instrument = standards.def_fields("new"), controlsignal = standards.def_fields("new"), micinput = standards.def_fields("recordToSample", "stopRecording", "startListening", "stopListening", "getLevel", "getSource"), @@ -415,7 +426,20 @@ local playdate = { } } +-- vector3d (This isn't part of the playdate namespace so may be beta or unsupported) +local vector3d = standards.def_fields("new") + +-- face3d (This isn't part of the playdate namespace so may be beta or unsupported) +local face3d = standards.def_fields("new") + +-- shape3d (This isn't part of the playdate namespace so may be beta or unsupported) +local shape3d = standards.def_fields("new") + +-- scene3d (This isn't part of the playdate namespace so may be beta or unsupported) +local scene3d = standards.def_fields("new") + return { - read_globals = {import = import, playdate = playdate, table = table, printTable = printTable, - where = where, sample = sample, json = json, kTextAlignment = kTextAlignment} + read_globals = {class = class, import = import, Object = Object, playdate = playdate, table = table, + printTable = printTable, where = where, sample = sample, json = json, kTextAlignment = kTextAlignment, + vector3d = vector3d, face3d = face3d, shape3d = shape3d, scene3d = scene3d} } From f911d293cd03a4bd4d0ebbe4e373e7ceffe8d02f Mon Sep 17 00:00:00 2001 From: Didier Malenfant Date: Fri, 10 Jun 2022 10:34:30 +0200 Subject: [PATCH 03/46] chore: Fix the list of metadata properties for playdate --- src/luacheck/builtin_standards/playdate.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua index 5a6ffedb..ec1888a6 100644 --- a/src/luacheck/builtin_standards/playdate.lua +++ b/src/luacheck/builtin_standards/playdate.lua @@ -43,10 +43,8 @@ local playdate = { fields = { -- System and Game Metadata apiVersion = empty, - metadata = standards.def_fields("bundleID", "version", "buildNumber", "imagePath", "card.png", - "card-highlighted", "animation.txt", "loopCount", "frames", "introFrames", "card-pressed.png", - "launchImage.png", "launchImages", "wrapping-pattern.png", "launchSoundPath", "contentWarning", - "contentWarning2"), + metadata = standards.def_fields("name", "description", "bundleID", "version", "buildNumber", "imagePath", + "launchSoundPath", "contentWarning", "contentWarning2"), -- Game flow update = read_write, From 9631698afdd370279797347bc12d18bac309c3bc Mon Sep 17 00:00:00 2001 From: Didier Malenfant Date: Fri, 17 Jun 2022 09:38:12 +0200 Subject: [PATCH 04/46] chore: Added changes from the playdate 1.12.0 SDK --- src/luacheck/builtin_standards/playdate.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua index ec1888a6..b43529df 100644 --- a/src/luacheck/builtin_standards/playdate.lua +++ b/src/luacheck/builtin_standards/playdate.lua @@ -162,7 +162,7 @@ local playdate = { fields = { affineTransform = standards.def_fields("new"), arc = standards.def_fields("new"), - lineSegment = standards.def_fields("new"), + lineSegment = standards.def_fields("new", "fast_intersection"), point = standards.def_fields("new"), polygon = standards.def_fields("new"), rect = standards.def_fields("new", "fast_intersection", "fast_union"), From da91ca2210c963e4ef9769588fbbf31629ae1c63 Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Mon, 9 May 2022 22:21:09 -0400 Subject: [PATCH 05/46] feat: Implement support for compound operators --- README.md | 2 +- docsrc/cli.rst | 1 + docsrc/config.rst | 1 + luacheck-dev-1.rockspec | 1 + spec/cli_spec.lua | 41 +++++++++++++++++-- .../compound_operators_config.luacheckrc | 1 + spec/samples/compound_operators.lua | 6 +++ src/luacheck/builtin_standards/init.lua | 2 +- src/luacheck/filter.lua | 9 ++++ src/luacheck/main.lua | 6 +++ src/luacheck/options.lua | 26 +++++++++++- src/luacheck/parser.lua | 38 +++++++++++++++-- src/luacheck/serializer.lua | 2 +- .../stages/detect_compound_operators.lua | 34 +++++++++++++++ src/luacheck/stages/init.lua | 1 + src/luacheck/stages/linearize.lua | 33 +++++++++++++++ src/luacheck/stages/parse_inline_options.lua | 2 +- 17 files changed, 193 insertions(+), 13 deletions(-) create mode 100644 spec/configs/compound_operators_config.luacheckrc create mode 100644 spec/samples/compound_operators.lua create mode 100644 src/luacheck/stages/detect_compound_operators.lua diff --git a/README.md b/README.md index 16ae41d4..2eb27eba 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Use the Luacheck issue tracker on GitHub to submit bugs, suggestions and questio ## Building and testing -After the Luacheck repo is cloned and changes are made, run `luarocks make` (using `sudo` if necessary) from its root directory to install dev version of Luacheck. To run Luacheck using sources in current directory without installing it, run `lua -e 'package.path="./src/?.lua;./src/?/init.lua;"..package.path' bin/luacheck.lua ...`. To test Luacheck, ensure that you have [busted](http://olivinelabs.com/busted/) and [luautf8](/~https://github.com/starwing/luautf8) installed and run `busted`. +After the Luacheck repo is cloned and changes are made, run `luarocks make` (using `sudo` if necessary) from its root directory to install dev version of Luacheck. To run Luacheck using sources in current directory without installing it, run `lua -e 'package.path="./src/?.lua;./src/?/init.lua;"..package.path' bin/luacheck.lua ...`. To test Luacheck, ensure that you have [busted](http://olivinelabs.com/busted/), [luautf8](/~https://github.com/starwing/luautf8), and [luasocket](/~https://github.com/lunarmodules/luasocket) installed and run `busted`. ## Docker diff --git a/docsrc/cli.rst b/docsrc/cli.rst index af98b7b0..f7e56c02 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -117,6 +117,7 @@ Option Meaning ``--ignore | -i [] ...`` Filter out warnings matching patterns. ``--enable | -e [] ...`` Do not filter out warnings matching patterns. ``--only | -o [] ...`` Filter out warnings not matching patterns. +``--operators [] ...`` Allow compound operators matching patterns. ``--config `` Path to custom configuration file (default: ``.luacheckrc``). ``--no-config`` Do not look up custom configuration file. ``--default-config `` Default path to custom configuration file, to be used if ``--[no-]config`` is not used and ``.luacheckrc`` is not found. diff --git a/docsrc/config.rst b/docsrc/config.rst index a2de43a3..5ccca92c 100644 --- a/docsrc/config.rst +++ b/docsrc/config.rst @@ -42,6 +42,7 @@ Option Type Default v ``read_globals`` Array of strings or field definition map ``{}`` ``new_read_globals`` Array of strings or field definition map (Do not overwrite) ``not_globals`` Array of strings ``{}`` +``operators`` Array of strings ``{}`` ``compat`` Boolean ``false`` ``allow_defined`` Boolean ``false`` ``allow_defined_top`` Boolean ``false`` diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index 1749c610..a0f7af62 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -46,6 +46,7 @@ build = { ["luacheck.serializer"] = "src/luacheck/serializer.lua", ["luacheck.stages"] = "src/luacheck/stages/init.lua", ["luacheck.stages.detect_bad_whitespace"] = "src/luacheck/stages/detect_bad_whitespace.lua", + ["luacheck.stages.detect_compound_operators"] = "src/luacheck/stages/detect_compound_operators.lua", ["luacheck.stages.detect_cyclomatic_complexity"] = "src/luacheck/stages/detect_cyclomatic_complexity.lua", ["luacheck.stages.detect_empty_blocks"] = "src/luacheck/stages/detect_empty_blocks.lua", ["luacheck.stages.detect_empty_statements"] = "src/luacheck/stages/detect_empty_statements.lua", diff --git a/spec/cli_spec.lua b/spec/cli_spec.lua index 9b6cab28..d8d9761e 100644 --- a/spec/cli_spec.lua +++ b/spec/cli_spec.lua @@ -295,6 +295,36 @@ Total: 5 warnings / 0 errors in 1 file ]], get_output "--std lua51+lua52+lua53 spec/samples/bad_code.lua --no-config") end) + it("raises critical errors on config without additional operators", function() + assert.equal([[Checking spec/samples/compound_operators.lua 4 warnings + + spec/samples/compound_operators.lua:2:1: assignment uses compound operator += + spec/samples/compound_operators.lua:3:1: assignment uses compound operator -= + spec/samples/compound_operators.lua:4:1: assignment uses compound operator *= + spec/samples/compound_operators.lua:5:1: assignment uses compound operator /= + +Total: 4 warnings / 0 errors in 1 file +]], get_output "spec/samples/compound_operators.lua --no-config") + end) + + it("raises critical errors for unfiltered additional operators", function() + assert.equal([[Checking spec/samples/compound_operators.lua 3 warnings + + spec/samples/compound_operators.lua:3:1: assignment uses compound operator -= + spec/samples/compound_operators.lua:4:1: assignment uses compound operator *= + spec/samples/compound_operators.lua:5:1: assignment uses compound operator /= + +Total: 3 warnings / 0 errors in 1 file +]], get_output "spec/samples/compound_operators.lua --no-config --operators +=") + end) + + it("allows to define allowed compound operators", function() + assert.equal([[Checking spec/samples/compound_operators.lua OK + +Total: 0 warnings / 0 errors in 1 file +]], get_output "spec/samples/compound_operators.lua --config=spec/configs/compound_operators_config.luacheckrc") + end) + it("allows to ignore some variables", function() assert.equal([[ Checking spec/samples/bad_code.lua 3 warnings @@ -993,7 +1023,7 @@ spec/samples/python_code.lua:1:6: (E011) expected '=' near '__future__' end) it("expands folders", function() - assert.matches("^Total: %d+ warnings / %d+ errors in 26 files\n$", get_output "spec/samples -qqq --no-config --exclude-files spec/samples/global_fields.lua") + assert.matches("^Total: %d+ warnings / %d+ errors in 27 files\n$", get_output "spec/samples -qqq --no-config --exclude-files spec/samples/global_fields.lua") end) it("uses --include-files when expanding folders", function() @@ -1205,6 +1235,7 @@ Codes: true assert.equal(([[ Checking spec/samples/argparse-0.2.0.lua 9 warnings Checking spec/samples/compat.lua 4 warnings +Checking spec/samples/compound_operators.lua 4 warnings Checking spec/samples/custom_std_inline_options.lua 3 warnings / 1 error Checking spec/samples/global_inline_options.lua 3 warnings Checking spec/samples/globals.lua 2 warnings @@ -1221,7 +1252,7 @@ Checking spec/samples/unused_secondaries.lua 4 warnings Checking spec/samples/utf8.lua 4 warnings Checking spec/samples/utf8_error.lua 1 error -Total: 73 warnings / 5 errors in 19 files +Total: 77 warnings / 5 errors in 20 files ]]):gsub("(spec/samples)/", "%1"..package.config:sub(1, 1)), get_output "spec/samples --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files spec/samples/global_fields.lua") end) @@ -1230,6 +1261,7 @@ Total: 73 warnings / 5 errors in 19 files assert.equal([[ Checking argparse-0.2.0.lua 9 warnings Checking compat.lua 4 warnings +Checking compound_operators.lua 4 warnings Checking custom_std_inline_options.lua 3 warnings / 1 error Checking global_inline_options.lua 3 warnings Checking globals.lua 2 warnings @@ -1246,7 +1278,7 @@ Checking unused_secondaries.lua 4 warnings Checking utf8.lua 4 warnings Checking utf8_error.lua 1 error -Total: 73 warnings / 5 errors in 19 files +Total: 77 warnings / 5 errors in 20 files ]], get_output(". --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files global_fields.lua", "spec/samples/")) end) @@ -1254,6 +1286,7 @@ Total: 73 warnings / 5 errors in 19 files assert.equal([[ Checking argparse-0.2.0.lua 9 warnings Checking compat.lua 4 warnings +Checking compound_operators.lua 4 warnings Checking custom_std_inline_options.lua 3 warnings / 1 error Checking global_inline_options.lua 3 warnings Checking globals.lua 2 warnings @@ -1268,7 +1301,7 @@ Checking unused_secondaries.lua 4 warnings Checking utf8.lua 4 warnings Checking utf8_error.lua 1 error -Total: 65 warnings / 5 errors in 17 files +Total: 69 warnings / 5 errors in 18 files ]], get_output(". --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files global_fields.lua --exclude-files " .. quote("./read*"), "spec/samples/")) end) diff --git a/spec/configs/compound_operators_config.luacheckrc b/spec/configs/compound_operators_config.luacheckrc new file mode 100644 index 00000000..3d845bf9 --- /dev/null +++ b/spec/configs/compound_operators_config.luacheckrc @@ -0,0 +1 @@ +operators = {"+=", "-=", "*=", "/="} diff --git a/spec/samples/compound_operators.lua b/spec/samples/compound_operators.lua new file mode 100644 index 00000000..42e6dedc --- /dev/null +++ b/spec/samples/compound_operators.lua @@ -0,0 +1,6 @@ +local i = 0 +i += 10 +i -= 5 +i *= 2 +i /= 5 +return i diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index f8839169..ffd34814 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -308,7 +308,7 @@ builtin_standards.luacheckrc = { "allow_defined_top", "module", "globals", "read_globals", "new_globals", "new_read_globals", "not_globals", "ignore", "enable", "only", "std", "max_line_length", "max_code_line_length", "max_string_line_length", "max_comment_line_length", "max_cyclomatic_complexity", "quiet", "color", "codes", "ranges", "formatter", - "cache", "jobs", "files", "stds", "exclude_files", "include_files" + "cache", "jobs", "files", "stds", "exclude_files", "include_files", "operators" } } diff --git a/src/luacheck/filter.lua b/src/luacheck/filter.lua index 5ef8fd1b..bd6d3838 100644 --- a/src/luacheck/filter.lua +++ b/src/luacheck/filter.lua @@ -163,6 +163,15 @@ local function passes_filter(normalized_options, warning) end warning.max_complexity = max_complexity + elseif warning.code == "533" then + local operators = normalized_options.operators or {} + for _, op in ipairs(operators) do + if warning.operator == op then + return false + end + end + + return true elseif warning.code:find("^[234]") and warning.name == "_" and not warning.useless then return false elseif warning.code:find("^1[14]") then diff --git a/src/luacheck/main.lua b/src/luacheck/main.lua index 9b8d035c..eb9fe194 100644 --- a/src/luacheck/main.lua +++ b/src/luacheck/main.lua @@ -65,6 +65,12 @@ Links: :action "concat" :init(nil), parser:option("--only -o", "Filter out warnings not matching these patterns.") + :args "+" + :count "*" + :argname "" + :action "concat" + :init(nil), + parser:option("--operators", "Allow compound operators matching patterns") :args "+" :count "*" :argname "" diff --git a/src/luacheck/options.lua b/src/luacheck/options.lua index 991eb7e3..1cf9f34c 100644 --- a/src/luacheck/options.lua +++ b/src/luacheck/options.lua @@ -70,7 +70,7 @@ options.variadic_inline_options = { not_globals = array_of_strings, ignore = array_of_strings, enable = array_of_strings, - only = array_of_strings + only = array_of_strings, } options.all_options = { @@ -79,7 +79,8 @@ options.all_options = { max_code_line_length = number_or_false, max_string_line_length = number_or_false, max_comment_line_length = number_or_false, - max_cyclomatic_complexity = number_or_false + max_cyclomatic_complexity = number_or_false, + operators = array_of_strings } utils.update(options.all_options, options.nullary_inline_options) @@ -385,6 +386,26 @@ local function normalize_patterns(rules) return res end +local function get_operators(opts_stack) + local operators, operatorsMap = nil, nil + + for _, opts in ipairs(opts_stack) do + if opts.operators then + operators = operators or {} + operatorsMap = operatorsMap or {} + + for _, op in ipairs(opts.operators) do + if not operatorsMap[op] then + table.insert(operators, op) + operatorsMap[op] = true + end + end + end + end + + return operators +end + local scalar_options = { unused_secondaries = true, self = true, @@ -404,6 +425,7 @@ function options.normalize(opts_stack, stds) local res = {} stds = stds or builtin_standards res.std = get_final_std(opts_stack, stds) + res.operators = get_operators(opts_stack) for option, default in pairs(scalar_options) do res[option] = get_scalar_opt(opts_stack, option, default) diff --git a/src/luacheck/parser.lua b/src/luacheck/parser.lua index 040bd50e..870a3de0 100644 --- a/src/luacheck/parser.lua +++ b/src/luacheck/parser.lua @@ -572,6 +572,16 @@ local binary_operators = { ["and"] = "and", ["or"] = "or" } +local compound_operators = { + ["+"] = "add", ["-"] = "sub", + ["*"] = "mul", ["%"] = "mod", + ["^"] = "pow", + ["/"] = "div", ["//"] = "idiv", + ["&"] = "band", ["|"] = "bor", ["~"] = "bxor", + ["<<"] = "shl", [">>"] = "shr", + [".."] = "concat" +} + local left_priorities = { add = 10, sub = 10, mul = 11, mod = 11, @@ -903,9 +913,31 @@ local function parse_expression_statement(state) lhs[#lhs + 1] = primary_expression until not test_and_skip_token(state, ",") - check_and_skip_token(state, "=") - local rhs = parse_expression_list(state) - return new_inner_node(start_range, rhs[#rhs], "Set", {lhs, rhs}) + local compound_operator = compound_operators[state.token] + if compound_operator then + -- This is an assignment in the form `lhs op= rhs`. + + if #lhs ~= 1 then + -- Multiple lhs values are not valid + parse_error(state, "compound assignment not allowed on tuples near " .. compound_operator .. "=") + end + + -- Skip operator. + skip_token(state) + check_and_skip_token(state, "=") + + local rhs = parse_expression_list(state) + if #rhs ~= 1 then + parse_error(state, "compound assignment not allowed on tuples near " .. compound_operator .. "=") + end + + return new_inner_node(start_range, rhs[1], "OpSet", {compound_operator, lhs[1], rhs[1]}) + else + -- This is an assignment in the form `lhs = rhs`. + check_and_skip_token(state, "=") + local rhs = parse_expression_list(state) + return new_inner_node(start_range, rhs[#rhs], "Set", {lhs, rhs}) + end end local function parse_statement(state) diff --git a/src/luacheck/serializer.lua b/src/luacheck/serializer.lua index 03e50142..bce7c015 100644 --- a/src/luacheck/serializer.lua +++ b/src/luacheck/serializer.lua @@ -9,7 +9,7 @@ local option_fields = { "unused_secondaries", "allow_defined", "allow_defined_top", "module", "read_globals", "new_globals", "new_read_globals", "enable", "only", "not_globals", "max_line_length", "max_code_line_length", "max_string_line_length", "max_comment_line_length", - "max_cyclomatic_complexity" + "max_cyclomatic_complexity", "operators" } local function compress_table(t, fields) diff --git a/src/luacheck/stages/detect_compound_operators.lua b/src/luacheck/stages/detect_compound_operators.lua new file mode 100644 index 00000000..b09ea7f3 --- /dev/null +++ b/src/luacheck/stages/detect_compound_operators.lua @@ -0,0 +1,34 @@ +local core_utils = require "luacheck.core_utils" + +local stage = {} + +stage.warnings = { + ["533"] = {message_format = "assignment uses compound operator {operator}", fields = {"operator"}}, +} + +local reverse_compound_operators = { + add = "+=", + sub = "-=", + mul = "*=", + mod = "%=", + pow = "^=", + div = "/=", + idiv = "//=", + band = "&=", + bor = "|=", + bxor = "~=", + shl = "<<=", + shr = ">>=", + concat = "..=" +} + +local function check_node(chstate, node) + local operator = reverse_compound_operators[node[1]] + chstate:warn_range("533", node, {operator = operator}) +end + +function stage.run(chstate) + core_utils.each_statement(chstate, { "OpSet" }, check_node) +end + +return stage diff --git a/src/luacheck/stages/init.lua b/src/luacheck/stages/init.lua index c70cf239..d8588785 100644 --- a/src/luacheck/stages/init.lua +++ b/src/luacheck/stages/init.lua @@ -16,6 +16,7 @@ stages.names = { "name_functions", "resolve_locals", "detect_bad_whitespace", + "detect_compound_operators", "detect_cyclomatic_complexity", "detect_empty_blocks", "detect_empty_statements", diff --git a/src/luacheck/stages/linearize.lua b/src/luacheck/stages/linearize.lua index f7838862..350ed88e 100644 --- a/src/luacheck/stages/linearize.lua +++ b/src/luacheck/stages/linearize.lua @@ -199,6 +199,19 @@ local function new_set_item(node) } end +local function new_opset_item(node) + return { + tag = "OpSet", + node = node, + lhs = node[2], + rhs = node[3], + accesses = {}, + mutations = {}, + used_values = {}, + lines = {} + } +end + local function is_unpacking(node) return node.tag == "Dots" or node.tag == "Call" or node.tag == "Invoke" end @@ -515,6 +528,24 @@ function LinState:emit_stmt_Set(node) self:emit(item) end +function LinState:emit_stmt_OpSet(node) + local item = new_opset_item(node) + self:scan_expr(item, node[3]) + + local lhs = node[2] + if lhs.tag == "Id" then + local var = self:check_var(lhs) + + if var then + self:register_upvalue_action(item, var, "set_upvalues") + end + else + assert(lhs.tag == "Index") + self:scan_lhs_index(item, lhs) + end + + self:emit(item) +end function LinState:scan_expr(item, node) local scanner = self["scan_expr_" .. node.tag] @@ -611,6 +642,8 @@ function LinState:scan_expr_Op(item, node) end end +LinState.scan_expr_OpSet = LinState.scan_expr_Op + -- Puts tables {var = value} into field `set_variables` of items in line which set values. -- Registers set values in field `values` of variables. function LinState:register_set_variables() diff --git a/src/luacheck/stages/parse_inline_options.lua b/src/luacheck/stages/parse_inline_options.lua index b8f7e5db..cab07b48 100644 --- a/src/luacheck/stages/parse_inline_options.lua +++ b/src/luacheck/stages/parse_inline_options.lua @@ -193,7 +193,7 @@ end -- Adds a table with `line`, `column`, and `options` fields to given array. -- For each function a table with `options` set to "push" for the function start --- and a talbe with `options` set to "pop" for the function end are added. +-- and a table with `options` set to "pop" for the function end are added. local function add_function_boundaries(inline_options_and_boundaries, chstate) for _, line in ipairs(chstate.top_line.lines) do local fn_node = line.node From cd8928111a259424951e803353db1297d5935a05 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Mon, 4 Jul 2022 20:00:18 +0200 Subject: [PATCH 06/46] feat(buildtin_standards): ldoc globals --- src/luacheck/builtin_standards/init.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index b032df10..fd652c1a 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -315,6 +315,25 @@ builtin_standards.luacheckrc = { } } +builtin_standards.ldoc = { + globals = { + -- Fields from cli parameters + "file", "project", "title", "package", "all", "format", "output", "dir", "colon", "boilerplate", "ext", "one", + "style", "template", "merge", "icon", + -- `config.ld` additional fields + "description", "full_description", "examples", "readme", "topics", "pretty", "prettify_files", "charset", "sort", + "no_return_or_parms", "no_lua_ref", "backtick_references", "plain", "wrap", "manual_url", "no_summary", + "custom_tags", "custom_see_handler", "custom_display_name_handler", "not_luadoc", "no_space_before_args", + "template_escape", "user_keywords", "postprocess_html", + -- Available functions + "alias", "add_language_extension", "add_section", "new_type", "tparam_alias", "custom_see_handler", + -- "Undocumented" fields + "kind_names", "topics", "unqualified", "dont_escape_underscore", "custom_css", "version", "no_args_infer", + "parse_extra", "output", "dir", "charset", "ignore", "module_file", "vars", "wrap", "not_luadoc", + "merge_error_groups", "sort_modules", "use_markdown_titles", "custom_references", "global_lookup", "convert_opt" + } +} + builtin_standards.none = {} return builtin_standards From ca4ff793df6a65692d2276621cdd70a065aea46a Mon Sep 17 00:00:00 2001 From: Aire-One Date: Tue, 5 Jul 2022 00:15:51 +0200 Subject: [PATCH 07/46] doc(cli): document ldoc builtin standards option --- docsrc/cli.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index af98b7b0..ece68c5e 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -86,6 +86,7 @@ Option Meaning * ``busted`` - globals added by Busted 2.0, by default added for files ending with ``_spec.lua`` within ``spec``, ``test``, and ``tests`` subdirectories; * ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``; * ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``; + * ``ldoc`` - globals allowed in LDoc config; * ``none`` - no standard globals. See :ref:`stds` From 488e870d1fb8b9224e963f5d9707f7184affedeb Mon Sep 17 00:00:00 2001 From: Aire-One Date: Tue, 5 Jul 2022 00:17:00 +0200 Subject: [PATCH 08/46] feat(config): set_default_std for ldoc --- docsrc/cli.rst | 2 +- docsrc/config.rst | 1 + src/luacheck/config.lua | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index ece68c5e..c94da6f3 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -86,7 +86,7 @@ Option Meaning * ``busted`` - globals added by Busted 2.0, by default added for files ending with ``_spec.lua`` within ``spec``, ``test``, and ``tests`` subdirectories; * ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``; * ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``; - * ``ldoc`` - globals allowed in LDoc config; + * ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``; * ``none`` - no standard globals. See :ref:`stds` diff --git a/docsrc/config.rst b/docsrc/config.rst index a2de43a3..9efcb861 100644 --- a/docsrc/config.rst +++ b/docsrc/config.rst @@ -191,5 +191,6 @@ Default per-path std overrides files["**/tests/**/*_spec.lua"].std = "+busted" files["**/*.rockspec"].std = "+rockspec" files["**/*.luacheckrc"].std = "+luacheckrc" + files["**/config.ld"].std = "+ldoc" Each of these can be overriden by setting a different ``std`` value for the corresponding key in ``files``. diff --git a/src/luacheck/config.lua b/src/luacheck/config.lua index d31143ce..86fef13b 100644 --- a/src/luacheck/config.lua +++ b/src/luacheck/config.lua @@ -228,6 +228,7 @@ local function add_default_path_options(opts) set_default_std(files, "**/tests/**/*_spec.lua", "+busted") set_default_std(files, "**/*.rockspec", "+rockspec") set_default_std(files, "**/*.luacheckrc", "+luacheckrc") + set_default_std(files, "**/config.ld", "+ldoc") end local fallback_config = {options = {}, anchor_dir = ""} From 44f7086ec14587b66cf4dc6c5202c9d5c2c6c823 Mon Sep 17 00:00:00 2001 From: Didier Malenfant <98774335+DidierMalenfant@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:14:50 +0300 Subject: [PATCH 09/46] chore: Add missing Playdate SDK functions and fix a typo (#73) --- src/luacheck/builtin_standards/playdate.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua index b43529df..e2da05ba 100644 --- a/src/luacheck/builtin_standards/playdate.lua +++ b/src/luacheck/builtin_standards/playdate.lua @@ -86,7 +86,7 @@ local playdate = { kButtonLeft = empty, kButtonRight = empty, buttonJustPressed = empty, - buttonJustRelease = empty, + buttonJustReleased = empty, getButtonState = empty, AButtonDown = read_write, AButtonHeld = read_write, @@ -107,6 +107,7 @@ local playdate = { isCrankDocked = empty, getCrankPosition = empty, getCrankChange = empty, + getCrankTicks = empty, cranked = read_write, crankDocked = read_write, crankUndocked = read_write, @@ -134,6 +135,7 @@ local playdate = { argv = empty, setNewlinePrinted = empty, drawFPS = empty, + exit = empty, -- Profiling getStats = empty, From 88d127d134b34d87011405eb5726b5618793bb18 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Thu, 4 Aug 2022 08:48:09 -0700 Subject: [PATCH 10/46] feat(cache): Store cached luacheck values per-version in case of changes --- spec/config_spec.lua | 6 ++++-- src/luacheck/config.lua | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 0a555c28..f678dc4a 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -1,10 +1,12 @@ local lfs = require "lfs" +local luacheck = require "luacheck" local config = require "luacheck.config" local fs = require "luacheck.fs" local cur_dir = lfs.currentdir() local P = fs.normalize local function AP(p) return P(fs.join(cur_dir, p)) end +local function cache_dir(p) return P(fs.join(cur_dir, p, luacheck._VERSION)) end local function nest(dir, func) local backed = false @@ -172,7 +174,7 @@ describe("config", function() formatter = "helper.fmt", formatter_anchor_dir = P(cur_dir), jobs = false, - cache = AP("something.luacheckcache"), + cache = cache_dir("something.luacheckcache"), include_files = { AP("foo"), AP("bar") @@ -197,7 +199,7 @@ describe("config", function() formatter = "helper.fmt2", formatter_anchor_dir = P(cur_dir), jobs = false, - cache = AP("something.luacheckcache"), + cache = cache_dir("something.luacheckcache"), include_files = { AP("foo"), AP("bar"), diff --git a/src/luacheck/config.lua b/src/luacheck/config.lua index d31143ce..e81e2120 100644 --- a/src/luacheck/config.lua +++ b/src/luacheck/config.lua @@ -5,6 +5,7 @@ local fs = require "luacheck.fs" local globbing = require "luacheck.globbing" local standards = require "luacheck.standards" local utils = require "luacheck.utils" +local luacheck = require "luacheck" local config = {} @@ -475,12 +476,16 @@ function ConfigStack:get_top_options() if conf.options.cache ~= nil then if conf.options.cache == true then if not res.cache then - res.cache = fs.normalize(fs.join(last_anchor_dir or current_dir, cache.get_default_dir())) + res.cache = fs.normalize(fs.join( + last_anchor_dir or current_dir, + cache.get_default_dir(), + luacheck._VERSION + )) end elseif conf.options.cache == false then res.cache = false else - res.cache = fs.normalize(fs.join(anchor_dir, conf.options.cache)) + res.cache = fs.normalize(fs.join(anchor_dir, conf.options.cache, luacheck._VERSION)) end end end From a25ae051fb5af29747bcd17bd2215e2eb6c9a473 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Thu, 18 Aug 2022 02:15:35 -0700 Subject: [PATCH 11/46] fix(tests): Drops flaky openresty-luajit test (#76) Co-authored-by: Caleb Maclennan --- .github/workflows/busted.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/busted.yml b/.github/workflows/busted.yml index d7d4c3e4..af0f8610 100644 --- a/.github/workflows/busted.yml +++ b/.github/workflows/busted.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ] + luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit" ] # "luajit-openresty" runs-on: ubuntu-20.04 steps: - name: Checkout From 8c58f1bee0a5673c56a3a6233c0190286b1b636c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 20 Aug 2022 22:19:02 +0300 Subject: [PATCH 12/46] style(ci): Bump container version of GH Action workflows --- .github/workflows/busted.yml | 11 ++++++++--- .github/workflows/docker.yml | 2 +- .github/workflows/luacheck.yml | 9 +++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/busted.yml b/.github/workflows/busted.yml index af0f8610..db140b50 100644 --- a/.github/workflows/busted.yml +++ b/.github/workflows/busted.yml @@ -8,17 +8,20 @@ jobs: strategy: fail-fast: false matrix: - luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit" ] # "luajit-openresty" - runs-on: ubuntu-20.04 + luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit" ] # , "luajit-openresty" + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 + - name: Setup ‘lua’ uses: leafo/gh-actions-lua@v9 with: luaVersion: ${{ matrix.luaVersion }} + - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 + - name: Setup dependencies run: | luarocks install --deps-only luacheck-dev-1.rockspec @@ -27,8 +30,10 @@ jobs: luarocks install luautf8 # required for decoder unit test luarocks install luasocket # required for profiler unit test luarocks install luacov-coveralls - - name: Run busted test suite + + - name: Run regression tests run: busted -c -v + - name: Report test coverage if: success() continue-on-error: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 099be840..4159058b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,7 +16,7 @@ on: jobs: docker: name: Build image and push to GHRC - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml index 076041a9..00c73754 100644 --- a/.github/workflows/luacheck.yml +++ b/.github/workflows/luacheck.yml @@ -21,21 +21,26 @@ jobs: strategy: fail-fast: false matrix: - luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ] - runs-on: ubuntu-20.04 + luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit" ] # , "luajit-openresty" + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 + - name: Setup ‘lua’ uses: leafo/gh-actions-lua@v9 with: luaVersion: ${{ matrix.luaVersion }} + - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 + - name: Setup dependencies run: | luarocks install --deps-only luacheck-dev-1.rockspec + - name: Build ‘luacheck’ (bootstrap) run: luarocks make + - name: Run ‘luacheck’ (dogfood) run: luacheck . From 3069d5f2db1b076c6faeeae02e58235500ccf627 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 20 Aug 2022 22:46:49 +0300 Subject: [PATCH 13/46] chore(ci): Switch to reusable workflow from org repo for docker deploy --- .github/workflows/deploy.yml | 2 +- .github/workflows/docker.yml | 37 ------------------------------------ 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2c68a84c..cfc705df 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -39,7 +39,7 @@ jobs: github.repository == 'lunarmodules/luacheck' && ( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) }} - uses: ./.github/workflows/docker.yml + uses: lunarmodules/.github/.github/workflows/docker_ghcr_deploy.yml@main with: username: ${{ github.actor }} tag: ${{ github.ref_name }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 4159058b..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Docker - -on: - workflow_call: - inputs: - tag: - required: true - type: string - username: - required: true - type: string - secrets: - token: - required: true - -jobs: - docker: - name: Build image and push to GHRC - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ inputs.username }} - password: ${{ secrets.token }} - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - push: ${{ github.ref == 'refs/heads/master' }} - tags: | - ghcr.io/lunarmodules/luacheck:${{ inputs.tag }} From d0e5d9da653d3c6c172cbecbe32a54884d31bbc4 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 20 Aug 2022 22:51:49 +0300 Subject: [PATCH 14/46] feat(docker): Overhaul docker container to run on Lua 5.4 --- Dockerfile | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 01bd74db..0bf8e782 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,20 @@ #syntax=docker/dockerfile:1.2 -FROM alpine:edge AS luacheck +FROM akorn/luarocks:lua5.4-alpine AS builder + +RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ + dumb-init gcc libc-dev + +COPY ./ /src +WORKDIR /src + +RUN luarocks --tree /pkgdir/usr/local make +RUN find /pkgdir -type f -exec sed -i -e 's!/pkgdir!!g' {} \; + +FROM akorn/lua:5.4-alpine AS final + +RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ + dumb-init LABEL org.opencontainers.image.title="Luacheck" LABEL org.opencontainers.image.description="A containerized version of Luacheck, a tool for linting and static analysis of Lua code" @@ -9,10 +23,8 @@ LABEL org.opencontainers.image.licenses="MIT" LABEL org.opencontainers.image.url="/~https://github.com/lunarmodules/luacheck/pkgs/container/luacheck" LABEL org.opencontainers.image.source="/~https://github.com/lunarmodules/luacheck" -RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing dumb-init lua lua-argparse lua-filesystem lua-lanes - -COPY "src/luacheck/" "/usr/share/lua/5.1/luacheck/" -COPY "bin/luacheck.lua" "/usr/bin/luacheck" +COPY --from=builder /pkgdir / +RUN luacheck --version WORKDIR /data From 2d1a531ead540142298df250d62d995cf4e6c2ef Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 24 Aug 2022 11:37:44 +0300 Subject: [PATCH 15/46] docs!: Follow semver guidelines, next release will be v1.x.y BREAKING CHANGE: According to the SemVer spec the v0.x.y release scheme signals that we do not consider the public facing API and usage stable. That isn't true at all for this project, it is quite stable. Any changes we do make are carefully considered not to break existing usage. Additional warnings may be added, but the way it is implemented and used is expected to remain the same. I probably should have done this bump earlier and there is nothing magic about this release. This is only an announcement that things are considered stable and that we'll bump version numbers in future releases roughly corresponding to SemVer spec. From e8ba0a037432f6f4b68ad3ab448494a1587e3b60 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 24 Aug 2022 12:03:25 +0300 Subject: [PATCH 16/46] chore(tooling): Add git-cliff config --- cliff.toml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cliff.toml diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000..f861d380 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,19 @@ +[git] +commit_parsers = [ + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Bug Fixes" }, + { message = "^doc.*!:", group = "Documentation", skip = false }, + { message = "^doc", group = "Documentation", skip = true }, + { message = "^perf", group = "Performance" }, + { message = "^refactor.*!:", group = "Refactor", skip = false }, + { message = "^refactor", group = "Refactor", skip = true }, + { message = "^style", group = "Styling", skip = true }, + { message = "^test", group = "Testing", skip = true }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore.*!:", group = "Miscellaneous Tasks", skip = false }, + { message = "^chore", group = "Miscellaneous Tasks", skip = true }, + { body = ".*security", group = "Security"}, +] +filter_commits = true +tag_pattern = "v[0-9]*" +sort_commits = "newest" From 1d42a2af12f2274cac20717c753197e9f86139e3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 24 Aug 2022 11:55:24 +0300 Subject: [PATCH 17/46] refactor(build): Tweak dev rockspec with format 3 features Also normalize a bit with some niceties from other lunarmodules projects that make it a little easier to cut releases without missing things. --- luacheck-dev-1.rockspec | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index bfb0805c..e653c2fd 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -1,23 +1,44 @@ -package = "luacheck" -version = "dev-1" +local package_name = "luacheck" +local package_version = "dev" +local rockspec_revision = "1" +local github_account_name = "lunarmodules" +local github_repo_name = package_name + +rockspec_format = "3.0" +package = package_name +version = package_version .. "-" .. rockspec_revision + source = { - url = "git+/~https://github.com/lunarmodules/luacheck.git" + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" } + +if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end + description = { summary = "A static analyzer and a linter for Lua", detailed = [[ -Luacheck is a command-line tool for linting and static analysis of Lua code. -It is able to spot usage of undefined global variables, unused local variables and -a few other typical problems within Lua programs. -]], + Luacheck is a command-line tool for linting and static analysis of Lua + code. It is able to spot usage of undefined global variables, unused + local variables and a few other typical problems within Lua programs. + ]], homepage = "/~https://github.com/lunarmodules/luacheck", license = "MIT" } + dependencies = { "lua >= 5.1", "argparse >= 0.6.0", "luafilesystem >= 1.6.3" } + +test_dependencies = { + "busted", +} + +test = { + type = "busted", +} + build = { type = "builtin", modules = { From 4d2979930245415e556a7c9f47b63ea038afcfee Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 24 Aug 2022 12:40:02 +0300 Subject: [PATCH 18/46] chore: Release v1.0.0 --- CHANGELOG.md | 14 +++++ README.md | 4 +- action.yml | 2 +- docsrc/conf.py | 4 +- luacheck-dev-1.rockspec | 6 +- rockspecs/luacheck-1.0.0-1.rockspec | 94 +++++++++++++++++++++++++++++ src/luacheck/init.lua | 2 +- 7 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 rockspecs/luacheck-1.0.0-1.rockspec diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c6438a..599ddc96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. +## v1.0.0 (2022-08-24) + +### Documentation + +- [**breaking**] Follow semver guidelines, next release will be v1.x.y + +### Features + +- Overhaul docker container to run on Lua 5.4 +- Store cached luacheck values per-version in case of changes +- Set_default_std for ldoc +- Add builtin std option for Ldoc globals +- Add builtin std option for the Playdate SDK + ## v0.26.1 (2022-04-23) ### Bug Fixes diff --git a/README.md b/README.md index 16ae41d4..57374079 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ For parallel checking Luacheck additionally requires [LuaLanes](https://github.c ### Windows binary download For Windows there is single-file 64-bit binary distribution, bundling Lua 5.4.4, Luacheck, LuaFileSystem, and LuaLanes using [LuaStatic](/~https://github.com/ers35/luastatic): -[download](/~https://github.com/lunarmodules/luacheck/releases/download/0.26.1/luacheck.exe). +[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.0.0/luacheck.exe). ## Basic usage @@ -109,7 +109,7 @@ Documentation can be built using [Sphinx](http://sphinx-doc.org/): `sphinx-build ## Development -Luacheck is currently in development. The latest released version is 0.26.1. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. +Luacheck is currently in development. The latest released version is v1.0.0. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. Use the Luacheck issue tracker on GitHub to submit bugs, suggestions and questions. Any pull requests are welcome, too. diff --git a/action.yml b/action.yml index e2c213c5..0587825b 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: "." runs: using: docker - image: docker://ghcr.io/lunarmodules/luacheck:v0.26.1 + image: docker://ghcr.io/lunarmodules/luacheck:v1.0.0 entrypoint: sh args: - -c diff --git a/docsrc/conf.py b/docsrc/conf.py index 1c894e1d..f1aef94c 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = '0.26.1' +version = '1.0.0' # The full version, including alpha/beta/rc tags. -release = '0.26.1' +release = '1.0.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index e653c2fd..5bf43437 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -9,7 +9,7 @@ package = package_name version = package_version .. "-" .. rockspec_revision source = { - url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" } if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end @@ -32,11 +32,11 @@ dependencies = { } test_dependencies = { - "busted", + "busted", } test = { - type = "busted", + type = "busted", } build = { diff --git a/rockspecs/luacheck-1.0.0-1.rockspec b/rockspecs/luacheck-1.0.0-1.rockspec new file mode 100644 index 00000000..4fbfb2c5 --- /dev/null +++ b/rockspecs/luacheck-1.0.0-1.rockspec @@ -0,0 +1,94 @@ +local package_name = "luacheck" +local package_version = "1.0.0" +local rockspec_revision = "1" +local github_account_name = "lunarmodules" +local github_repo_name = package_name + +package = package_name +version = package_version .. "-" .. rockspec_revision + +source = { + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" +} + +if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end + +description = { + summary = "A static analyzer and a linter for Lua", + detailed = [[ + Luacheck is a command-line tool for linting and static analysis of Lua + code. It is able to spot usage of undefined global variables, unused + local variables and a few other typical problems within Lua programs. + ]], + homepage = "/~https://github.com/lunarmodules/luacheck", + license = "MIT" +} + +dependencies = { + "lua >= 5.1", + "argparse >= 0.6.0", + "luafilesystem >= 1.6.3" +} +build = { + type = "builtin", + modules = { + luacheck = "src/luacheck/init.lua", + ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", + ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", + ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", + ["luacheck.cache"] = "src/luacheck/cache.lua", + ["luacheck.check"] = "src/luacheck/check.lua", + ["luacheck.check_state"] = "src/luacheck/check_state.lua", + ["luacheck.config"] = "src/luacheck/config.lua", + ["luacheck.core_utils"] = "src/luacheck/core_utils.lua", + ["luacheck.decoder"] = "src/luacheck/decoder.lua", + ["luacheck.expand_rockspec"] = "src/luacheck/expand_rockspec.lua", + ["luacheck.filter"] = "src/luacheck/filter.lua", + ["luacheck.format"] = "src/luacheck/format.lua", + ["luacheck.fs"] = "src/luacheck/fs.lua", + ["luacheck.globbing"] = "src/luacheck/globbing.lua", + ["luacheck.lexer"] = "src/luacheck/lexer.lua", + ["luacheck.main"] = "src/luacheck/main.lua", + ["luacheck.multithreading"] = "src/luacheck/multithreading.lua", + ["luacheck.options"] = "src/luacheck/options.lua", + ["luacheck.parser"] = "src/luacheck/parser.lua", + ["luacheck.profiler"] = "src/luacheck/profiler.lua", + ["luacheck.runner"] = "src/luacheck/runner.lua", + ["luacheck.serializer"] = "src/luacheck/serializer.lua", + ["luacheck.stages"] = "src/luacheck/stages/init.lua", + ["luacheck.stages.detect_bad_whitespace"] = "src/luacheck/stages/detect_bad_whitespace.lua", + ["luacheck.stages.detect_cyclomatic_complexity"] = "src/luacheck/stages/detect_cyclomatic_complexity.lua", + ["luacheck.stages.detect_empty_blocks"] = "src/luacheck/stages/detect_empty_blocks.lua", + ["luacheck.stages.detect_empty_statements"] = "src/luacheck/stages/detect_empty_statements.lua", + ["luacheck.stages.detect_globals"] = "src/luacheck/stages/detect_globals.lua", + ["luacheck.stages.detect_reversed_fornum_loops"] = "src/luacheck/stages/detect_reversed_fornum_loops.lua", + ["luacheck.stages.detect_unbalanced_assignments"] = "src/luacheck/stages/detect_unbalanced_assignments.lua", + ["luacheck.stages.detect_uninit_accesses"] = "src/luacheck/stages/detect_uninit_accesses.lua", + ["luacheck.stages.detect_unreachable_code"] = "src/luacheck/stages/detect_unreachable_code.lua", + ["luacheck.stages.detect_unused_fields"] = "src/luacheck/stages/detect_unused_fields.lua", + ["luacheck.stages.detect_unused_locals"] = "src/luacheck/stages/detect_unused_locals.lua", + ["luacheck.stages.linearize"] = "src/luacheck/stages/linearize.lua", + ["luacheck.stages.name_functions"] = "src/luacheck/stages/name_functions.lua", + ["luacheck.stages.parse"] = "src/luacheck/stages/parse.lua", + ["luacheck.stages.parse_inline_options"] = "src/luacheck/stages/parse_inline_options.lua", + ["luacheck.stages.resolve_locals"] = "src/luacheck/stages/resolve_locals.lua", + ["luacheck.stages.unwrap_parens"] = "src/luacheck/stages/unwrap_parens.lua", + ["luacheck.standards"] = "src/luacheck/standards.lua", + ["luacheck.unicode"] = "src/luacheck/unicode.lua", + ["luacheck.unicode_printability_boundaries"] = "src/luacheck/unicode_printability_boundaries.lua", + ["luacheck.utils"] = "src/luacheck/utils.lua", + ["luacheck.vendor.sha1"] = "src/luacheck/vendor/sha1/init.lua", + ["luacheck.vendor.sha1.bit32_ops"] = "src/luacheck/vendor/sha1/bit32_ops.lua", + ["luacheck.vendor.sha1.bit_ops"] = "src/luacheck/vendor/sha1/bit_ops.lua", + ["luacheck.vendor.sha1.common"] = "src/luacheck/vendor/sha1/common.lua", + ["luacheck.vendor.sha1.lua53_ops"] = "src/luacheck/vendor/sha1/lua53_ops.lua", + ["luacheck.vendor.sha1.pure_lua_ops"] = "src/luacheck/vendor/sha1/pure_lua_ops.lua", + ["luacheck.version"] = "src/luacheck/version.lua" + }, + install = { + bin = { + luacheck = "bin/luacheck.lua" + } + } +} diff --git a/src/luacheck/init.lua b/src/luacheck/init.lua index 427255c4..41359b98 100644 --- a/src/luacheck/init.lua +++ b/src/luacheck/init.lua @@ -5,7 +5,7 @@ local format = require "luacheck.format" local utils = require "luacheck.utils" local luacheck = { - _VERSION = "0.26.1" + _VERSION = "1.0.0" } local function raw_validate_options(fname, opts, stds, context) From 456b20be76466e7ededad52292bd994f5d6ffcde Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 24 Aug 2022 14:40:14 +0300 Subject: [PATCH 19/46] chore(tooling): Add generated artifacts to ignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 879d268b..b83b56b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ luacov.stats.out luacov.report.out doc +*.rock !build/ build/* !build/Makefile From 81bb2f2e70a07a14cb369852dcd12716fae75877 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 12 Sep 2022 09:17:35 +0300 Subject: [PATCH 20/46] feat: Add builtin rule set for SILE globals (#79) --- docsrc/cli.rst | 1 + src/luacheck/builtin_standards/init.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index c94da6f3..23ad9a23 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -87,6 +87,7 @@ Option Meaning * ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``; * ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``; * ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``; + * ``sile`` - globals allowed in The SILE Typesetter and its package ecosystem; * ``none`` - no standard globals. See :ref:`stds` diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index fd652c1a..783114d2 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -334,6 +334,12 @@ builtin_standards.ldoc = { } } +builtin_standards.sile = { + globals = { + "SILE", "SU", "luautf8", "pl", "fluent", "CASILE" + } +} + builtin_standards.none = {} return builtin_standards From 54b19b297e83af6948c79ec1f0294923d8fa43a0 Mon Sep 17 00:00:00 2001 From: Muescha <184316+muescha@users.noreply.github.com> Date: Tue, 29 Nov 2022 07:22:19 +0100 Subject: [PATCH 21/46] Update (and use variable for) version number in docs index (#82) Co-authored-by: Alex Richard --- docsrc/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docsrc/index.rst b/docsrc/index.rst index fe3d558f..dee34aef 100644 --- a/docsrc/index.rst +++ b/docsrc/index.rst @@ -11,4 +11,4 @@ Contents: inline module -This is documentation for 0.26.0 version of `Luacheck `_, a linter for `Lua `_. +This is documentation for version |version| of `Luacheck `_, a linter for `Lua `_. From c899b7263c6124d279941c543ed09224c6d96427 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Sat, 17 Dec 2022 15:14:06 -0800 Subject: [PATCH 22/46] Fix circular reference detection to notice that OpSet passes around lhs/rhs as a single var, not multiple --- docsrc/cli.rst | 2 +- src/luacheck/stages/resolve_locals.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index f7e56c02..9b383925 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -117,7 +117,7 @@ Option Meaning ``--ignore | -i [] ...`` Filter out warnings matching patterns. ``--enable | -e [] ...`` Do not filter out warnings matching patterns. ``--only | -o [] ...`` Filter out warnings not matching patterns. -``--operators [] ...`` Allow compound operators matching patterns. +``--operators [] ...`` Allow compound operators matching patterns. (Multiple assignment not supported, as this is specifically for the Playdate SDK.) ``--config `` Path to custom configuration file (default: ``.luacheckrc``). ``--no-config`` Do not look up custom configuration file. ``--default-config `` Default path to custom configuration file, to be used if ``--[no-]config`` is not used and ``.luacheckrc`` is not found. diff --git a/src/luacheck/stages/resolve_locals.lua b/src/luacheck/stages/resolve_locals.lua index 174e88f4..b5623da9 100644 --- a/src/luacheck/stages/resolve_locals.lua +++ b/src/luacheck/stages/resolve_locals.lua @@ -96,18 +96,18 @@ end local function is_circular_reference(item, var) -- No support for matching multiple assignment to the specific assignment - if not item.lhs or #item.lhs ~= 1 or not item.rhs or #item.rhs ~= 1 then + if not (item.tag == "Set" or item.tag == "Local" or item.tag == "OpSet") then return false end -- Case t[t.function()] = t.func() -- Functions can have side-effects, so this isn't purely circular - local right_assignment = item.rhs[1] + local right_assignment = item.tag == "OpSet" and item.rhs or item.rhs[1] if contains_call(right_assignment) then return false end - local left_assignment = item.lhs[1] + local left_assignment = item.tag == "OpSet" and item.lhs or item.lhs[1] if contains_call(left_assignment) then return false end From ea2b33628c6abe65e279a68247adba50431b5caa Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Sat, 17 Dec 2022 15:19:53 -0800 Subject: [PATCH 23/46] Update warning code --- docsrc/warnings.rst | 1 + src/luacheck/filter.lua | 2 +- src/luacheck/stages/detect_compound_operators.lua | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docsrc/warnings.rst b/docsrc/warnings.rst index 28378c35..5b0a79d5 100644 --- a/docsrc/warnings.rst +++ b/docsrc/warnings.rst @@ -10,6 +10,7 @@ Code Description 021 An invalid inline option. 022 An unpaired inline push directive. 023 An unpaired inline pop directive. +033 Invalid use of a compound operator. (Lua doesn't support compound operator by default; if using an extension that does, please set the operators option.) 111 Setting an undefined global variable. 112 Mutating an undefined global variable. 113 Accessing an undefined global variable. diff --git a/src/luacheck/filter.lua b/src/luacheck/filter.lua index bd6d3838..ad5be732 100644 --- a/src/luacheck/filter.lua +++ b/src/luacheck/filter.lua @@ -163,7 +163,7 @@ local function passes_filter(normalized_options, warning) end warning.max_complexity = max_complexity - elseif warning.code == "533" then + elseif warning.code == "033" then local operators = normalized_options.operators or {} for _, op in ipairs(operators) do if warning.operator == op then diff --git a/src/luacheck/stages/detect_compound_operators.lua b/src/luacheck/stages/detect_compound_operators.lua index b09ea7f3..460306d0 100644 --- a/src/luacheck/stages/detect_compound_operators.lua +++ b/src/luacheck/stages/detect_compound_operators.lua @@ -3,7 +3,7 @@ local core_utils = require "luacheck.core_utils" local stage = {} stage.warnings = { - ["533"] = {message_format = "assignment uses compound operator {operator}", fields = {"operator"}}, + ["033"] = {message_format = "assignment uses compound operator {operator}", fields = {"operator"}}, } local reverse_compound_operators = { @@ -24,7 +24,7 @@ local reverse_compound_operators = { local function check_node(chstate, node) local operator = reverse_compound_operators[node[1]] - chstate:warn_range("533", node, {operator = operator}) + chstate:warn_range("033", node, {operator = operator}) end function stage.run(chstate) From e6fd44f8bd388709183e196f136c548826619872 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Sat, 17 Dec 2022 16:49:52 -0800 Subject: [PATCH 24/46] Fix tests --- spec/cli_spec.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/cli_spec.lua b/spec/cli_spec.lua index d8d9761e..9f47635e 100644 --- a/spec/cli_spec.lua +++ b/spec/cli_spec.lua @@ -296,25 +296,25 @@ Total: 5 warnings / 0 errors in 1 file end) it("raises critical errors on config without additional operators", function() - assert.equal([[Checking spec/samples/compound_operators.lua 4 warnings + assert.equal([[Checking spec/samples/compound_operators.lua 4 errors spec/samples/compound_operators.lua:2:1: assignment uses compound operator += spec/samples/compound_operators.lua:3:1: assignment uses compound operator -= spec/samples/compound_operators.lua:4:1: assignment uses compound operator *= spec/samples/compound_operators.lua:5:1: assignment uses compound operator /= -Total: 4 warnings / 0 errors in 1 file +Total: 0 warnings / 4 errors in 1 file ]], get_output "spec/samples/compound_operators.lua --no-config") end) it("raises critical errors for unfiltered additional operators", function() - assert.equal([[Checking spec/samples/compound_operators.lua 3 warnings + assert.equal([[Checking spec/samples/compound_operators.lua 3 errors spec/samples/compound_operators.lua:3:1: assignment uses compound operator -= spec/samples/compound_operators.lua:4:1: assignment uses compound operator *= spec/samples/compound_operators.lua:5:1: assignment uses compound operator /= -Total: 3 warnings / 0 errors in 1 file +Total: 0 warnings / 3 errors in 1 file ]], get_output "spec/samples/compound_operators.lua --no-config --operators +=") end) @@ -1235,7 +1235,7 @@ Codes: true assert.equal(([[ Checking spec/samples/argparse-0.2.0.lua 9 warnings Checking spec/samples/compat.lua 4 warnings -Checking spec/samples/compound_operators.lua 4 warnings +Checking spec/samples/compound_operators.lua 4 errors Checking spec/samples/custom_std_inline_options.lua 3 warnings / 1 error Checking spec/samples/global_inline_options.lua 3 warnings Checking spec/samples/globals.lua 2 warnings @@ -1252,7 +1252,7 @@ Checking spec/samples/unused_secondaries.lua 4 warnings Checking spec/samples/utf8.lua 4 warnings Checking spec/samples/utf8_error.lua 1 error -Total: 77 warnings / 5 errors in 20 files +Total: 73 warnings / 9 errors in 20 files ]]):gsub("(spec/samples)/", "%1"..package.config:sub(1, 1)), get_output "spec/samples --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files spec/samples/global_fields.lua") end) @@ -1261,7 +1261,7 @@ Total: 77 warnings / 5 errors in 20 files assert.equal([[ Checking argparse-0.2.0.lua 9 warnings Checking compat.lua 4 warnings -Checking compound_operators.lua 4 warnings +Checking compound_operators.lua 4 errors Checking custom_std_inline_options.lua 3 warnings / 1 error Checking global_inline_options.lua 3 warnings Checking globals.lua 2 warnings @@ -1278,7 +1278,7 @@ Checking unused_secondaries.lua 4 warnings Checking utf8.lua 4 warnings Checking utf8_error.lua 1 error -Total: 77 warnings / 5 errors in 20 files +Total: 73 warnings / 9 errors in 20 files ]], get_output(". --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files global_fields.lua", "spec/samples/")) end) @@ -1286,7 +1286,7 @@ Total: 77 warnings / 5 errors in 20 files assert.equal([[ Checking argparse-0.2.0.lua 9 warnings Checking compat.lua 4 warnings -Checking compound_operators.lua 4 warnings +Checking compound_operators.lua 4 errors Checking custom_std_inline_options.lua 3 warnings / 1 error Checking global_inline_options.lua 3 warnings Checking globals.lua 2 warnings @@ -1301,7 +1301,7 @@ Checking unused_secondaries.lua 4 warnings Checking utf8.lua 4 warnings Checking utf8_error.lua 1 error -Total: 69 warnings / 5 errors in 18 files +Total: 65 warnings / 9 errors in 18 files ]], get_output(". --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files global_fields.lua --exclude-files " .. quote("./read*"), "spec/samples/")) end) From ba6d58de220b8d29c7d00eddd760decf9cf4cde5 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 19 Dec 2022 17:38:14 +0300 Subject: [PATCH 25/46] docs: Update shields.io badges for GH Actions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index efe086d2..8bb28163 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![Join the chat at https://gitter.im/luacheck/Lobby](https://badges.gitter.im/luacheck/Lobby.svg)](https://gitter.im/luacheck/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Luacheck](https://img.shields.io/github/workflow/status/lunarmodules/luacheck/Luacheck?label=Luacheck&logo=Lua)](/~https://github.com/lunarmodules/luacheck/actions?workflow=Luacheck) -[![Busted](https://img.shields.io/github/workflow/status/lunarmodules/luacheck/Busted?label=Busted&logo=Lua)](/~https://github.com/lunarmodules/luacheck/actions?workflow=Busted) +[![Luacheck](https://img.shields.io/github/actions/workflow/status/lunarmodules/luacheck/luacheck.yml?branch=master&label=Luacheck&logo=Lua)](/~https://github.com/lunarmodules/luacheck/actions?workflow=Luacheck) +[![Busted](https://img.shields.io/github/actions/workflow/status/lunarmodules/luacheck/busted.yml?branch=master&label=Busted&logo=Lua)](/~https://github.com/lunarmodules/luacheck/actions?workflow=Busted) [![Coverage Status](https://img.shields.io/coveralls/github/lunarmodules/luacheck?label=Coveralls&logo=Coveralls)](https://coveralls.io/github/lunarmodules/luacheck?branch=master) [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/lunarmodules/luacheck?label=Tag&logo=GitHub)](/~https://github.com/lunarmodules/luacheck/releases) [![Luarocks](https://img.shields.io/luarocks/v/lunarmodules/luacheck?label=Luarocks&logo=Lua)](https://luarocks.org/modules/lunarmodules/luacheck) From 629c262853eeaa34213cec9116f1beb11eac7dc0 Mon Sep 17 00:00:00 2001 From: Didier Malenfant <07_debiteur_blogueur@icloud.com> Date: Mon, 19 Dec 2022 16:59:26 +0200 Subject: [PATCH 26/46] chore: Removed unnecessary symbol from Playdate std (#84) --- src/luacheck/builtin_standards/playdate.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua index e2da05ba..bb4b6475 100644 --- a/src/luacheck/builtin_standards/playdate.lua +++ b/src/luacheck/builtin_standards/playdate.lua @@ -135,7 +135,6 @@ local playdate = { argv = empty, setNewlinePrinted = empty, drawFPS = empty, - exit = empty, -- Profiling getStats = empty, From 01e635c1750fccc56fe99199720752e2e74ad260 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 19 Dec 2022 20:16:47 +0300 Subject: [PATCH 27/46] docs: Backfill contributer information to changelog --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 599ddc96..e65b68ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,11 @@ All notable changes to this project will be documented in this file. ### Features -- Overhaul docker container to run on Lua 5.4 -- Store cached luacheck values per-version in case of changes -- Set_default_std for ldoc -- Add builtin std option for Ldoc globals -- Add builtin std option for the Playdate SDK +- Overhaul docker container to run on Lua 5.4 — @alerque +- Store cached luacheck values per-version in case of changes — @arichard4 +- Set_default_std for ldoc — @Aire-One +- Add builtin std option for Ldoc globals — @Aire-One +- Add builtin std option for the Playdate SDK — @DidierMalenfant ## v0.26.1 (2022-04-23) From fcbdeacad00e643e0d78c56b9ba6d8b3c7fa584f Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 19 Dec 2022 20:44:23 +0300 Subject: [PATCH 28/46] chore: Release v1.1.0 --- CHANGELOG.md | 12 ++++ README.md | 4 +- action.yml | 2 +- docsrc/conf.py | 4 +- rockspecs/luacheck-1.1.0-1.rockspec | 95 +++++++++++++++++++++++++++++ src/luacheck/init.lua | 2 +- 6 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 rockspecs/luacheck-1.1.0-1.rockspec diff --git a/CHANGELOG.md b/CHANGELOG.md index e65b68ec..b87b7215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. +## [1.1.0] - 2022-12-19 + +### Features + +- Add builtin rule set for SILE globals (#79) — @alerque +- Implement support for compound operators (#66) — @a2 & @arichard4 + +### Bug Fixes + +- Correct circular reference detection visavis OpSet — @arichard4 +- Remove unnecessary symbol from Playdate std (#84) — @DidierMalenfant + ## v1.0.0 (2022-08-24) ### Documentation diff --git a/README.md b/README.md index 8bb28163..c9a903b3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ For parallel checking Luacheck additionally requires [LuaLanes](https://github.c ### Windows binary download For Windows there is single-file 64-bit binary distribution, bundling Lua 5.4.4, Luacheck, LuaFileSystem, and LuaLanes using [LuaStatic](/~https://github.com/ers35/luastatic): -[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.0.0/luacheck.exe). +[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.1.0/luacheck.exe). ## Basic usage @@ -109,7 +109,7 @@ Documentation can be built using [Sphinx](http://sphinx-doc.org/): `sphinx-build ## Development -Luacheck is currently in development. The latest released version is v1.0.0. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. +Luacheck is currently in development. The latest released version is v1.1.0. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. Use the Luacheck issue tracker on GitHub to submit bugs, suggestions and questions. Any pull requests are welcome, too. diff --git a/action.yml b/action.yml index 0587825b..ffb9b504 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: "." runs: using: docker - image: docker://ghcr.io/lunarmodules/luacheck:v1.0.0 + image: docker://ghcr.io/lunarmodules/luacheck:v1.1.0 entrypoint: sh args: - -c diff --git a/docsrc/conf.py b/docsrc/conf.py index f1aef94c..cb5f508e 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = '1.0.0' +version = '1.1.0' # The full version, including alpha/beta/rc tags. -release = '1.0.0' +release = '1.1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rockspecs/luacheck-1.1.0-1.rockspec b/rockspecs/luacheck-1.1.0-1.rockspec new file mode 100644 index 00000000..423a4ac4 --- /dev/null +++ b/rockspecs/luacheck-1.1.0-1.rockspec @@ -0,0 +1,95 @@ +local package_name = "luacheck" +local package_version = "1.1.0" +local rockspec_revision = "1" +local github_account_name = "lunarmodules" +local github_repo_name = package_name + +package = package_name +version = package_version .. "-" .. rockspec_revision + +source = { + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" +} + +if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end + +description = { + summary = "A static analyzer and a linter for Lua", + detailed = [[ + Luacheck is a command-line tool for linting and static analysis of Lua + code. It is able to spot usage of undefined global variables, unused + local variables and a few other typical problems within Lua programs. + ]], + homepage = "/~https://github.com/lunarmodules/luacheck", + license = "MIT" +} + +dependencies = { + "lua >= 5.1", + "argparse >= 0.6.0", + "luafilesystem >= 1.6.3" +} +build = { + type = "builtin", + modules = { + luacheck = "src/luacheck/init.lua", + ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", + ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", + ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", + ["luacheck.cache"] = "src/luacheck/cache.lua", + ["luacheck.check"] = "src/luacheck/check.lua", + ["luacheck.check_state"] = "src/luacheck/check_state.lua", + ["luacheck.config"] = "src/luacheck/config.lua", + ["luacheck.core_utils"] = "src/luacheck/core_utils.lua", + ["luacheck.decoder"] = "src/luacheck/decoder.lua", + ["luacheck.expand_rockspec"] = "src/luacheck/expand_rockspec.lua", + ["luacheck.filter"] = "src/luacheck/filter.lua", + ["luacheck.format"] = "src/luacheck/format.lua", + ["luacheck.fs"] = "src/luacheck/fs.lua", + ["luacheck.globbing"] = "src/luacheck/globbing.lua", + ["luacheck.lexer"] = "src/luacheck/lexer.lua", + ["luacheck.main"] = "src/luacheck/main.lua", + ["luacheck.multithreading"] = "src/luacheck/multithreading.lua", + ["luacheck.options"] = "src/luacheck/options.lua", + ["luacheck.parser"] = "src/luacheck/parser.lua", + ["luacheck.profiler"] = "src/luacheck/profiler.lua", + ["luacheck.runner"] = "src/luacheck/runner.lua", + ["luacheck.serializer"] = "src/luacheck/serializer.lua", + ["luacheck.stages"] = "src/luacheck/stages/init.lua", + ["luacheck.stages.detect_bad_whitespace"] = "src/luacheck/stages/detect_bad_whitespace.lua", + ["luacheck.stages.detect_compound_operators"] = "src/luacheck/stages/detect_compound_operators.lua", + ["luacheck.stages.detect_cyclomatic_complexity"] = "src/luacheck/stages/detect_cyclomatic_complexity.lua", + ["luacheck.stages.detect_empty_blocks"] = "src/luacheck/stages/detect_empty_blocks.lua", + ["luacheck.stages.detect_empty_statements"] = "src/luacheck/stages/detect_empty_statements.lua", + ["luacheck.stages.detect_globals"] = "src/luacheck/stages/detect_globals.lua", + ["luacheck.stages.detect_reversed_fornum_loops"] = "src/luacheck/stages/detect_reversed_fornum_loops.lua", + ["luacheck.stages.detect_unbalanced_assignments"] = "src/luacheck/stages/detect_unbalanced_assignments.lua", + ["luacheck.stages.detect_uninit_accesses"] = "src/luacheck/stages/detect_uninit_accesses.lua", + ["luacheck.stages.detect_unreachable_code"] = "src/luacheck/stages/detect_unreachable_code.lua", + ["luacheck.stages.detect_unused_fields"] = "src/luacheck/stages/detect_unused_fields.lua", + ["luacheck.stages.detect_unused_locals"] = "src/luacheck/stages/detect_unused_locals.lua", + ["luacheck.stages.linearize"] = "src/luacheck/stages/linearize.lua", + ["luacheck.stages.name_functions"] = "src/luacheck/stages/name_functions.lua", + ["luacheck.stages.parse"] = "src/luacheck/stages/parse.lua", + ["luacheck.stages.parse_inline_options"] = "src/luacheck/stages/parse_inline_options.lua", + ["luacheck.stages.resolve_locals"] = "src/luacheck/stages/resolve_locals.lua", + ["luacheck.stages.unwrap_parens"] = "src/luacheck/stages/unwrap_parens.lua", + ["luacheck.standards"] = "src/luacheck/standards.lua", + ["luacheck.unicode"] = "src/luacheck/unicode.lua", + ["luacheck.unicode_printability_boundaries"] = "src/luacheck/unicode_printability_boundaries.lua", + ["luacheck.utils"] = "src/luacheck/utils.lua", + ["luacheck.vendor.sha1"] = "src/luacheck/vendor/sha1/init.lua", + ["luacheck.vendor.sha1.bit32_ops"] = "src/luacheck/vendor/sha1/bit32_ops.lua", + ["luacheck.vendor.sha1.bit_ops"] = "src/luacheck/vendor/sha1/bit_ops.lua", + ["luacheck.vendor.sha1.common"] = "src/luacheck/vendor/sha1/common.lua", + ["luacheck.vendor.sha1.lua53_ops"] = "src/luacheck/vendor/sha1/lua53_ops.lua", + ["luacheck.vendor.sha1.pure_lua_ops"] = "src/luacheck/vendor/sha1/pure_lua_ops.lua", + ["luacheck.version"] = "src/luacheck/version.lua" + }, + install = { + bin = { + luacheck = "bin/luacheck.lua" + } + } +} diff --git a/src/luacheck/init.lua b/src/luacheck/init.lua index 41359b98..d08cfee1 100644 --- a/src/luacheck/init.lua +++ b/src/luacheck/init.lua @@ -5,7 +5,7 @@ local format = require "luacheck.format" local utils = require "luacheck.utils" local luacheck = { - _VERSION = "1.0.0" + _VERSION = "1.1.0" } local function raw_validate_options(fname, opts, stds, context) From 0cef17da7ae2a39d3b6d384f7fb517a6b0859931 Mon Sep 17 00:00:00 2001 From: Russell Cloran Date: Wed, 12 Apr 2023 01:09:12 -0700 Subject: [PATCH 29/46] docs: Update GitHub Action examples in README for v1 (#89) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9a903b3..3d452382 100644 --- a/README.md +++ b/README.md @@ -172,14 +172,14 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Luacheck linter - uses: lunarmodules/luacheck@v0 + uses: lunarmodules/luacheck@v1 ``` By default the GH Action is configured to run `luacheck .`, but you can also pass it your own `args` to replace the default input of `.`. ```yaml - name: Luacheck linter - uses: lunarmodules/luacheck@v0 + uses: lunarmodules/luacheck@v1 with: args: myfile.lua ``` From 606d9615ea23e4ce8b1acbecca0d6bb0f1659a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Such=C3=A1nek?= Date: Thu, 4 May 2023 20:01:06 +0200 Subject: [PATCH 30/46] docs: Clarify how default overrides interact with std (#92) --- docsrc/config.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docsrc/config.rst b/docsrc/config.rst index 6f2a43b7..dbbafbe9 100644 --- a/docsrc/config.rst +++ b/docsrc/config.rst @@ -194,4 +194,6 @@ Default per-path std overrides files["**/*.luacheckrc"].std = "+luacheckrc" files["**/config.ld"].std = "+ldoc" +These are added to the global ``std`` specified in the config file. Each of these can be overriden by setting a different ``std`` value for the corresponding key in ``files``. +Setting ``std`` on the commandline removes these default overrides. From 14fbbc0c56820fb2b53ff84858c8b21125f3b670 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sun, 21 May 2023 11:51:12 +0200 Subject: [PATCH 31/46] Fix warning 582 (error prone negation) not applying to subexpressions --- spec/check_spec.lua | 32 ++++++++++++++++++++++----- src/luacheck/stages/unwrap_parens.lua | 13 +++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/spec/check_spec.lua b/spec/check_spec.lua index d49a6c87..9eedb594 100644 --- a/spec/check_spec.lua +++ b/spec/check_spec.lua @@ -331,12 +331,34 @@ end ]]) end) - it("warns about error-prone negations", function() - assert.same({ - {code = "582", line = 1, column = 13, end_column = 21} - }, check[[ - if not 5 > 5 then return end + describe("error-prone negations", function() + it("as sole conditions", function() + assert.same({ + {code = "582", line = 1, column = 16, end_column = 24} + }, check[[ + if not 5 > 5 then return end +]]) + end) + + it("as subexpressions", function() + assert.same({ + {code = "582", line = 1, column = 25, end_column = 34} + }, check[[ + if not 5 or not 5 == 5 then return end +]]) + end) + + it("doesn't warn if properly parenthesized", function() + assert.same({}, check[[ + if (not 5) == 5 then return end +]]) + end) + + it("doesn't warn for a literal 'not'", function() + assert.same({}, check[[ + if 5 == "not" then return end ]]) + end) end) it("doesn't warn on similarly named variables", function() diff --git a/src/luacheck/stages/unwrap_parens.lua b/src/luacheck/stages/unwrap_parens.lua index 6d9a82bd..d17aeb49 100644 --- a/src/luacheck/stages/unwrap_parens.lua +++ b/src/luacheck/stages/unwrap_parens.lua @@ -54,14 +54,13 @@ local function handle_nodes(chstate, nodes, list_start) handle_nodes(chstate, node[1]) handle_nodes(chstate, node[2], 1) else - -- warn that not x == y means (not x) == y - if tag ~= "Paren" - and node[1] - and node[1].tag == "Op" - and relational_operators[node[1][1]] - and node[1][2][1] == "not" + -- warn that not x y means (not x) y + if tag == "Op" + and relational_operators[node[1]] + and node[2].tag == "Op" + and node[2][1] == "not" then - chstate:warn_range("582", node[1]) + chstate:warn_range("582", node) end handle_nodes(chstate, node) From 9b9764d6290e900c7df4e09b1d6721d7c6da9d03 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Mon, 5 Jun 2023 10:06:07 -0700 Subject: [PATCH 32/46] Bugfixes for the compound operators: (1) makes (almost) everywhere that checks against Set also check against OpSet, (2) makes OpSet have the same format (lhs and rhs are tables of assignments, same over node order with the operator on the end) as Set so that it's usable where Set is used --- src/luacheck/parser.lua | 2 +- .../stages/detect_compound_operators.lua | 2 +- src/luacheck/stages/detect_globals.lua | 2 +- src/luacheck/stages/linearize.lua | 29 +++++++++++-------- src/luacheck/stages/unwrap_parens.lua | 4 +-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/luacheck/parser.lua b/src/luacheck/parser.lua index 870a3de0..45271e13 100644 --- a/src/luacheck/parser.lua +++ b/src/luacheck/parser.lua @@ -931,7 +931,7 @@ local function parse_expression_statement(state) parse_error(state, "compound assignment not allowed on tuples near " .. compound_operator .. "=") end - return new_inner_node(start_range, rhs[1], "OpSet", {compound_operator, lhs[1], rhs[1]}) + return new_inner_node(start_range, rhs[1], "OpSet", {lhs, rhs, compound_operator}) else -- This is an assignment in the form `lhs = rhs`. check_and_skip_token(state, "=") diff --git a/src/luacheck/stages/detect_compound_operators.lua b/src/luacheck/stages/detect_compound_operators.lua index 460306d0..279f6651 100644 --- a/src/luacheck/stages/detect_compound_operators.lua +++ b/src/luacheck/stages/detect_compound_operators.lua @@ -23,7 +23,7 @@ local reverse_compound_operators = { } local function check_node(chstate, node) - local operator = reverse_compound_operators[node[1]] + local operator = reverse_compound_operators[node[3]] chstate:warn_range("033", node, {operator = operator}) end diff --git a/src/luacheck/stages/detect_globals.lua b/src/luacheck/stages/detect_globals.lua index 59ed41b0..b8b3d164 100644 --- a/src/luacheck/stages/detect_globals.lua +++ b/src/luacheck/stages/detect_globals.lua @@ -234,7 +234,7 @@ local function detect_globals_in_line(chstate, line) if item.rhs then detect_in_nodes(chstate, item, item.rhs, is_top_line) end - elseif item.tag == "Set" then + elseif item.tag == "Set" or item.tag == "OpSet" then detect_in_nodes(chstate, item, item.lhs, is_top_line, true) detect_in_nodes(chstate, item, item.rhs, is_top_line) end diff --git a/src/luacheck/stages/linearize.lua b/src/luacheck/stages/linearize.lua index 350ed88e..9d4511f9 100644 --- a/src/luacheck/stages/linearize.lua +++ b/src/luacheck/stages/linearize.lua @@ -203,8 +203,8 @@ local function new_opset_item(node) return { tag = "OpSet", node = node, - lhs = node[2], - rhs = node[3], + lhs = node[1], + rhs = node[2], accesses = {}, mutations = {}, used_values = {}, @@ -530,18 +530,19 @@ end function LinState:emit_stmt_OpSet(node) local item = new_opset_item(node) - self:scan_expr(item, node[3]) + self:scan_exprs(item, node[2]) - local lhs = node[2] - if lhs.tag == "Id" then - local var = self:check_var(lhs) + for _, expr in ipairs(node[1]) do + if expr.tag == "Id" then + local var = self:check_var(expr) - if var then - self:register_upvalue_action(item, var, "set_upvalues") + if var then + self:register_upvalue_action(item, var, "set_upvalues") + end + else + assert(expr.tag == "Index") + self:scan_lhs_index(item, expr) end - else - assert(lhs.tag == "Index") - self:scan_lhs_index(item, lhs) end self:emit(item) @@ -650,7 +651,7 @@ function LinState:register_set_variables() local line = self.lines.top for _, item in ipairs(line.items) do - if item.tag == "Local" or item.tag == "Set" then + if item.tag == "Local" or item.tag == "Set" or item.tag == "OpSet" then item.set_variables = {} local is_init = item.tag == "Local" @@ -674,6 +675,10 @@ function LinState:register_set_variables() local value if node.var then + -- OpSet also accesses + if item.tag == "OpSet" then + self:mark_access(item, node) + end value = new_value(node, item.rhs and item.rhs[i] or unpacking_item, item, is_init) item.set_variables[node.var] = value table.insert(node.var.values, value) diff --git a/src/luacheck/stages/unwrap_parens.lua b/src/luacheck/stages/unwrap_parens.lua index d17aeb49..2df055d7 100644 --- a/src/luacheck/stages/unwrap_parens.lua +++ b/src/luacheck/stages/unwrap_parens.lua @@ -50,7 +50,7 @@ local function handle_nodes(chstate, nodes, list_start) if node[2] then handle_nodes(chstate, node[2]) end - elseif tag == "Set" then + elseif tag == "Set" or tag == "OpSet" then handle_nodes(chstate, node[1]) handle_nodes(chstate, node[2], 1) else @@ -67,7 +67,7 @@ local function handle_nodes(chstate, nodes, list_start) -- warn that not (x == y) can become x ~= y if tag == "Op" and node[1] == "not" and node[2].tag == "Op" and relational_operators[node[2][1]] then - chstate:warn_range("581", node, { + chstate:warn_range("581", node, { operator = relational_operators[node[2][1]], replacement_operator = replacements[node[2][1]] }) From bb9e7f64df507c175a18f4cfc43197f1795027a9 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Mon, 5 Jun 2023 10:09:45 -0700 Subject: [PATCH 33/46] Fix circular reference detection to note that all OpSets are circular references --- src/luacheck/stages/resolve_locals.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/luacheck/stages/resolve_locals.lua b/src/luacheck/stages/resolve_locals.lua index b5623da9..b47f0f93 100644 --- a/src/luacheck/stages/resolve_locals.lua +++ b/src/luacheck/stages/resolve_locals.lua @@ -95,19 +95,24 @@ local function contains_call(node) end local function is_circular_reference(item, var) + -- OpSet is circular by definition + if not (item.tag == "Set" or item.tag == "Local") then + return false + end + -- No support for matching multiple assignment to the specific assignment - if not (item.tag == "Set" or item.tag == "Local" or item.tag == "OpSet") then + if not item.lhs or #item.lhs ~= 1 or not item.rhs or #item.rhs ~= 1 then return false end -- Case t[t.function()] = t.func() -- Functions can have side-effects, so this isn't purely circular - local right_assignment = item.tag == "OpSet" and item.rhs or item.rhs[1] + local right_assignment = item.rhs[1] if contains_call(right_assignment) then return false end - local left_assignment = item.tag == "OpSet" and item.lhs or item.lhs[1] + local left_assignment = item.lhs[1] if contains_call(left_assignment) then return false end From a8de4bcdc182afcfacf7c5b6a3b85d959c93df76 Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Mon, 5 Jun 2023 10:45:07 -0700 Subject: [PATCH 34/46] Adds testing for the function upvalue case --- spec/cli_spec.lua | 8 ++++---- spec/samples/compound_operators.lua | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/spec/cli_spec.lua b/spec/cli_spec.lua index 9f47635e..40879e58 100644 --- a/spec/cli_spec.lua +++ b/spec/cli_spec.lua @@ -300,8 +300,8 @@ Total: 5 warnings / 0 errors in 1 file spec/samples/compound_operators.lua:2:1: assignment uses compound operator += spec/samples/compound_operators.lua:3:1: assignment uses compound operator -= - spec/samples/compound_operators.lua:4:1: assignment uses compound operator *= - spec/samples/compound_operators.lua:5:1: assignment uses compound operator /= + spec/samples/compound_operators.lua:5:2: assignment uses compound operator /= + spec/samples/compound_operators.lua:10:1: assignment uses compound operator *= Total: 0 warnings / 4 errors in 1 file ]], get_output "spec/samples/compound_operators.lua --no-config") @@ -311,8 +311,8 @@ Total: 0 warnings / 4 errors in 1 file assert.equal([[Checking spec/samples/compound_operators.lua 3 errors spec/samples/compound_operators.lua:3:1: assignment uses compound operator -= - spec/samples/compound_operators.lua:4:1: assignment uses compound operator *= - spec/samples/compound_operators.lua:5:1: assignment uses compound operator /= + spec/samples/compound_operators.lua:5:2: assignment uses compound operator /= + spec/samples/compound_operators.lua:10:1: assignment uses compound operator *= Total: 0 warnings / 3 errors in 1 file ]], get_output "spec/samples/compound_operators.lua --no-config --operators +=") diff --git a/spec/samples/compound_operators.lua b/spec/samples/compound_operators.lua index 42e6dedc..84753e45 100644 --- a/spec/samples/compound_operators.lua +++ b/spec/samples/compound_operators.lua @@ -1,6 +1,11 @@ local i = 0 i += 10 i -= 5 -i *= 2 -i /= 5 -return i +local function func() + i /= 5 +end +func() +local t = {} +t.a = i +t.a *= 2 +return t From 501cf5768d08a3a00c35a002365b7b236ae504b4 Mon Sep 17 00:00:00 2001 From: RunningDroid Date: Tue, 6 Jun 2023 03:51:40 -0400 Subject: [PATCH 35/46] =?UTF-8?q?feat:=20Update=20L=C3=B6ve=20standard=20t?= =?UTF-8?q?o=2011.4=20(#95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/luacheck/builtin_standards/love.lua | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/luacheck/builtin_standards/love.lua b/src/luacheck/builtin_standards/love.lua index aa173dc5..04f495ba 100644 --- a/src/luacheck/builtin_standards/love.lua +++ b/src/luacheck/builtin_standards/love.lua @@ -8,6 +8,7 @@ local love = { getVersion = empty, conf = read_write, directorydropped = read_write, + displayrotated = read_write, draw = read_write, errhand = read_write, errorhandler = read_write, @@ -18,6 +19,7 @@ local love = { gamepadreleased = read_write, handlers = read_write, hasDeprecationOutput = empty, + isVersionCompatible = read_write, joystickadded = read_write, joystickaxis = read_write, joystickhat = read_write, @@ -87,17 +89,17 @@ local love = { "getDPIScale","getPixelDimensions","getPixelHeight","getPixelWidth","isActive","getDefaultMipmapFilter", "setDefaultMipmapFilter"), - image = standards.def_fields("isCompressed","newCompressedData","newImageData","newCubeFaces"), + image = standards.def_fields("isCompressed","newCompressedData","newImageData"), - joystick = standards.def_fields("getJoystickCount","getJoysticks","loadGamepadMappings", - "saveGamepadMappings","setGamepadMapping"), + joystick = standards.def_fields("getGamepadMappingString","getJoystickCount","getJoysticks", + "loadGamepadMappings","saveGamepadMappings","setGamepadMapping"), keyboard = standards.def_fields("getKeyFromScancode","getScancodeFromKey","hasKeyRepeat","hasTextInput", "isDown","isScancodeDown","setKeyRepeat","setTextInput","hasScreenKeyboard"), - math = standards.def_fields("compress","decompress","gammaToLinear","getRandomSeed","getRandomState", - "isConvex","linearToGamma","newBezierCurve","newRandomGenerator","noise","random", - "randomNormal","setRandomSeed","setRandomState","triangulate","newTransform"), + math = standards.def_fields("colorFromBytes","colorToBytes","compress","decompress","gammaToLinear", + "getRandomSeed","getRandomState","isConvex","linearToGamma","newBezierCurve","newRandomGenerator","noise", + "random","randomNormal","setRandomSeed","setRandomState","triangulate","newTransform"), mouse = standards.def_fields("getCursor","getPosition","getRelativeMode","getSystemCursor","getX", "getY","hasCursor","isDown","isGrabbed","isVisible","newCursor","setCursor","setGrabbed", @@ -122,12 +124,12 @@ local love = { video = standards.def_fields("newVideoStream"), - window = standards.def_fields("close","fromPixels","getDisplayName","getFullscreen", - "getFullscreenModes","getIcon","getMode","getPixelScale","getPosition","getTitle", - "hasFocus","hasMouseFocus","isDisplaySleepEnabled","isMaximized","isOpen","isVisible", - "maximize","minimize","requestAttention","setDisplaySleepEnabled","setFullscreen", - "setIcon","setMode","setPosition","setTitle","showMessageBox","toPixels", - "updateMode","isMinimized","restore","getDPIScale") + window = standards.def_fields("close","fromPixels","getDesktopDimensions","getDisplayCount","getDisplayName", + "getDisplayOrientation","getFullscreen","getFullscreenModes","getIcon","getMode","getPosition","getSafeArea", + "getTitle","getVSync","hasFocus","hasMouseFocus","isDisplaySleepEnabled","isMaximized","isOpen","isVisible", + "maximize","minimize","requestAttention","setDisplaySleepEnabled","setFullscreen","setIcon","setMode", + "setPosition","setTitle","setVSync","showMessageBox","toPixels","updateMode","isMinimized","restore", + "getDPIScale") } } From ababb6d403d634eb74d2c541035e9ede966e710d Mon Sep 17 00:00:00 2001 From: Alex Richard Date: Sat, 10 Jun 2023 01:27:25 -0700 Subject: [PATCH 36/46] chore: Release 1.1.1 (#97) --- CHANGELOG.md | 12 ++++ README.md | 4 +- action.yml | 2 +- docsrc/conf.py | 4 +- rockspecs/luacheck-1.1.1-1.rockspec | 95 +++++++++++++++++++++++++++++ src/luacheck/init.lua | 2 +- 6 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 rockspecs/luacheck-1.1.1-1.rockspec diff --git a/CHANGELOG.md b/CHANGELOG.md index b87b7215..8b0df74b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. +## [1.1.1] - 2023-06-09 + +### Features + +- Update Löve standard to 11.4 (#95) - @RunningDroid +- Documentation improvements (#92 and #89) - @rcloran and @hamrach + +### Bug Fixes + +- Correct compound operators to not crash on modifying upvalues (#96) - @arichard4 +- Fix warning 582 (error prone negation) not applying to subexpressions (#94) - @appgurueu + ## [1.1.0] - 2022-12-19 ### Features diff --git a/README.md b/README.md index 3d452382..a6dbeafa 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ For parallel checking Luacheck additionally requires [LuaLanes](https://github.c ### Windows binary download For Windows there is single-file 64-bit binary distribution, bundling Lua 5.4.4, Luacheck, LuaFileSystem, and LuaLanes using [LuaStatic](/~https://github.com/ers35/luastatic): -[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.1.0/luacheck.exe). +[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.1.1/luacheck.exe). ## Basic usage @@ -109,7 +109,7 @@ Documentation can be built using [Sphinx](http://sphinx-doc.org/): `sphinx-build ## Development -Luacheck is currently in development. The latest released version is v1.1.0. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. +Luacheck is currently in development. The latest released version is v1.1.1. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. Use the Luacheck issue tracker on GitHub to submit bugs, suggestions and questions. Any pull requests are welcome, too. diff --git a/action.yml b/action.yml index ffb9b504..e9f5ce79 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: "." runs: using: docker - image: docker://ghcr.io/lunarmodules/luacheck:v1.1.0 + image: docker://ghcr.io/lunarmodules/luacheck:v1.1.1 entrypoint: sh args: - -c diff --git a/docsrc/conf.py b/docsrc/conf.py index cb5f508e..764336c8 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = '1.1.0' +version = '1.1.1' # The full version, including alpha/beta/rc tags. -release = '1.1.0' +release = '1.1.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rockspecs/luacheck-1.1.1-1.rockspec b/rockspecs/luacheck-1.1.1-1.rockspec new file mode 100644 index 00000000..28ff8264 --- /dev/null +++ b/rockspecs/luacheck-1.1.1-1.rockspec @@ -0,0 +1,95 @@ +local package_name = "luacheck" +local package_version = "1.1.1" +local rockspec_revision = "1" +local github_account_name = "lunarmodules" +local github_repo_name = package_name + +package = package_name +version = package_version .. "-" .. rockspec_revision + +source = { + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" +} + +if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end + +description = { + summary = "A static analyzer and a linter for Lua", + detailed = [[ + Luacheck is a command-line tool for linting and static analysis of Lua + code. It is able to spot usage of undefined global variables, unused + local variables and a few other typical problems within Lua programs. + ]], + homepage = "/~https://github.com/lunarmodules/luacheck", + license = "MIT" +} + +dependencies = { + "lua >= 5.1", + "argparse >= 0.6.0", + "luafilesystem >= 1.6.3" +} +build = { + type = "builtin", + modules = { + luacheck = "src/luacheck/init.lua", + ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", + ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", + ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", + ["luacheck.cache"] = "src/luacheck/cache.lua", + ["luacheck.check"] = "src/luacheck/check.lua", + ["luacheck.check_state"] = "src/luacheck/check_state.lua", + ["luacheck.config"] = "src/luacheck/config.lua", + ["luacheck.core_utils"] = "src/luacheck/core_utils.lua", + ["luacheck.decoder"] = "src/luacheck/decoder.lua", + ["luacheck.expand_rockspec"] = "src/luacheck/expand_rockspec.lua", + ["luacheck.filter"] = "src/luacheck/filter.lua", + ["luacheck.format"] = "src/luacheck/format.lua", + ["luacheck.fs"] = "src/luacheck/fs.lua", + ["luacheck.globbing"] = "src/luacheck/globbing.lua", + ["luacheck.lexer"] = "src/luacheck/lexer.lua", + ["luacheck.main"] = "src/luacheck/main.lua", + ["luacheck.multithreading"] = "src/luacheck/multithreading.lua", + ["luacheck.options"] = "src/luacheck/options.lua", + ["luacheck.parser"] = "src/luacheck/parser.lua", + ["luacheck.profiler"] = "src/luacheck/profiler.lua", + ["luacheck.runner"] = "src/luacheck/runner.lua", + ["luacheck.serializer"] = "src/luacheck/serializer.lua", + ["luacheck.stages"] = "src/luacheck/stages/init.lua", + ["luacheck.stages.detect_bad_whitespace"] = "src/luacheck/stages/detect_bad_whitespace.lua", + ["luacheck.stages.detect_compound_operators"] = "src/luacheck/stages/detect_compound_operators.lua", + ["luacheck.stages.detect_cyclomatic_complexity"] = "src/luacheck/stages/detect_cyclomatic_complexity.lua", + ["luacheck.stages.detect_empty_blocks"] = "src/luacheck/stages/detect_empty_blocks.lua", + ["luacheck.stages.detect_empty_statements"] = "src/luacheck/stages/detect_empty_statements.lua", + ["luacheck.stages.detect_globals"] = "src/luacheck/stages/detect_globals.lua", + ["luacheck.stages.detect_reversed_fornum_loops"] = "src/luacheck/stages/detect_reversed_fornum_loops.lua", + ["luacheck.stages.detect_unbalanced_assignments"] = "src/luacheck/stages/detect_unbalanced_assignments.lua", + ["luacheck.stages.detect_uninit_accesses"] = "src/luacheck/stages/detect_uninit_accesses.lua", + ["luacheck.stages.detect_unreachable_code"] = "src/luacheck/stages/detect_unreachable_code.lua", + ["luacheck.stages.detect_unused_fields"] = "src/luacheck/stages/detect_unused_fields.lua", + ["luacheck.stages.detect_unused_locals"] = "src/luacheck/stages/detect_unused_locals.lua", + ["luacheck.stages.linearize"] = "src/luacheck/stages/linearize.lua", + ["luacheck.stages.name_functions"] = "src/luacheck/stages/name_functions.lua", + ["luacheck.stages.parse"] = "src/luacheck/stages/parse.lua", + ["luacheck.stages.parse_inline_options"] = "src/luacheck/stages/parse_inline_options.lua", + ["luacheck.stages.resolve_locals"] = "src/luacheck/stages/resolve_locals.lua", + ["luacheck.stages.unwrap_parens"] = "src/luacheck/stages/unwrap_parens.lua", + ["luacheck.standards"] = "src/luacheck/standards.lua", + ["luacheck.unicode"] = "src/luacheck/unicode.lua", + ["luacheck.unicode_printability_boundaries"] = "src/luacheck/unicode_printability_boundaries.lua", + ["luacheck.utils"] = "src/luacheck/utils.lua", + ["luacheck.vendor.sha1"] = "src/luacheck/vendor/sha1/init.lua", + ["luacheck.vendor.sha1.bit32_ops"] = "src/luacheck/vendor/sha1/bit32_ops.lua", + ["luacheck.vendor.sha1.bit_ops"] = "src/luacheck/vendor/sha1/bit_ops.lua", + ["luacheck.vendor.sha1.common"] = "src/luacheck/vendor/sha1/common.lua", + ["luacheck.vendor.sha1.lua53_ops"] = "src/luacheck/vendor/sha1/lua53_ops.lua", + ["luacheck.vendor.sha1.pure_lua_ops"] = "src/luacheck/vendor/sha1/pure_lua_ops.lua", + ["luacheck.version"] = "src/luacheck/version.lua" + }, + install = { + bin = { + luacheck = "bin/luacheck.lua" + } + } +} diff --git a/src/luacheck/init.lua b/src/luacheck/init.lua index d08cfee1..7ba56bc3 100644 --- a/src/luacheck/init.lua +++ b/src/luacheck/init.lua @@ -5,7 +5,7 @@ local format = require "luacheck.format" local utils = require "luacheck.utils" local luacheck = { - _VERSION = "1.1.0" + _VERSION = "1.1.1" } local function raw_validate_options(fname, opts, stds, context) From 24747f51e16bffee482d5ff3690820d158339aec Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 10 Jun 2023 11:33:27 +0300 Subject: [PATCH 37/46] docs: Fix contributor moniker and normalize formatting --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b0df74b..3a5c8be0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,13 @@ All notable changes to this project will be documented in this file. ### Features -- Update Löve standard to 11.4 (#95) - @RunningDroid -- Documentation improvements (#92 and #89) - @rcloran and @hamrach +- Update Löve standard to 11.4 (#95) — @RunningDroid +- Documentation improvements (#92 and #89) — @rcloran and @hramrach ### Bug Fixes -- Correct compound operators to not crash on modifying upvalues (#96) - @arichard4 -- Fix warning 582 (error prone negation) not applying to subexpressions (#94) - @appgurueu +- Correct compound operators to not crash on modifying upvalues (#96) — @arichard4 +- Fix warning 582 (error prone negation) not applying to subexpressions (#94) — @appgurueu ## [1.1.0] - 2022-12-19 From 494c8a90a584e7b268919ebc90e320ee4b03b74c Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Tue, 24 Oct 2023 22:18:04 +0300 Subject: [PATCH 38/46] chore: Fix typos in comments and documentation strings (#101) --- src/luacheck/builtin_standards/playdate.lua | 2 +- src/luacheck/format.lua | 2 +- src/luacheck/parser.lua | 2 +- src/luacheck/runner.lua | 2 +- src/luacheck/serializer.lua | 2 +- src/luacheck/stages/detect_uninit_accesses.lua | 2 +- src/luacheck/stages/linearize.lua | 4 ++-- src/luacheck/stages/parse_inline_options.lua | 2 +- src/luacheck/vendor/sha1/init.lua | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/luacheck/builtin_standards/playdate.lua b/src/luacheck/builtin_standards/playdate.lua index bb4b6475..7496d9da 100644 --- a/src/luacheck/builtin_standards/playdate.lua +++ b/src/luacheck/builtin_standards/playdate.lua @@ -35,7 +35,7 @@ local sample = { -- JSON local json = standards.def_fields("decode", "decodeFile", "encode", "encodePretty", "encodeToFile") --- Text Alignement +-- Text Alignment local kTextAlignment = standards.def_fields("left", "center", "right") -- Playdate SDK diff --git a/src/luacheck/format.lua b/src/luacheck/format.lua index 96f39a5f..a9d23c3f 100644 --- a/src/luacheck/format.lua +++ b/src/luacheck/format.lua @@ -6,7 +6,7 @@ local format = {} local color_support = not utils.is_windows or os.getenv("ANSICON") local function get_message_format(warning) - local message_format = assert(stages.warnings[warning.code], "Unkown warning code " .. warning.code).message_format + local message_format = assert(stages.warnings[warning.code], "Unknown warning code " .. warning.code).message_format if type(message_format) == "function" then return message_format(warning) diff --git a/src/luacheck/parser.lua b/src/luacheck/parser.lua index 45271e13..7637e68a 100644 --- a/src/luacheck/parser.lua +++ b/src/luacheck/parser.lua @@ -900,7 +900,7 @@ local function parse_expression_statement(state) if primary_expression.tag == "Call" or primary_expression.tag == "Invoke" then if lhs then - -- The is an assingment, and a call is not valid in lhs. + -- The is an assignment, and a call is not valid in lhs. parse_error(state, "expected call or indexing") else -- This is a call. diff --git a/src/luacheck/runner.lua b/src/luacheck/runner.lua index ce46221d..373fdaf1 100644 --- a/src/luacheck/runner.lua +++ b/src/luacheck/runner.lua @@ -104,7 +104,7 @@ end -- Normalizes inputs and filters inputs using `exclude_files` and `include_files` options. -- Returns an array of prepared input tables. --- Differences between normal and prepated inputs: +-- Differences between normal and prepared inputs: -- * Prepared inputs can't have `rockspec_path` field. -- * Prepared inputs can't have `path` pointing to a directory (unless it has an error). -- * Prepared inputs have `filename` field if possible (copied from `path` if not given). diff --git a/src/luacheck/serializer.lua b/src/luacheck/serializer.lua index bce7c015..91f02be9 100644 --- a/src/luacheck/serializer.lua +++ b/src/luacheck/serializer.lua @@ -110,7 +110,7 @@ local function max_n(t) end -- Serializes a value into buffer. --- `strings` is a table mapping string values to where they first occured or to name of local +-- `strings` is a table mapping string values to where they first occurred or to name of local -- variable used to represent it. -- Array part contains representations of values saved into locals. local function add_value(buffer, strings, value, level) diff --git a/src/luacheck/stages/detect_uninit_accesses.lua b/src/luacheck/stages/detect_uninit_accesses.lua index 3afe8d2a..66c719c4 100644 --- a/src/luacheck/stages/detect_uninit_accesses.lua +++ b/src/luacheck/stages/detect_uninit_accesses.lua @@ -15,7 +15,7 @@ local function detect_uninit_access_in_line(chstate, line) for var, accessing_nodes in pairs(item_var_map) do -- If there are no values at all reaching this access, not even the empty one, -- this item (or a closure containing it) is not reachable from variable definition. - -- It will be reported as unreachable code, no need to report uninitalized accesses in it. + -- It will be reported as unreachable code, no need to report uninitialized accesses in it. if item.used_values[var] then -- If this variable is has only one, empty value then it's already reported as never set, -- no need to report each access. diff --git a/src/luacheck/stages/linearize.lua b/src/luacheck/stages/linearize.lua index 9d4511f9..a3ab5475 100644 --- a/src/luacheck/stages/linearize.lua +++ b/src/luacheck/stages/linearize.lua @@ -57,7 +57,7 @@ function Line:__init(node, parent, value) self.accessed_upvalues = {} -- Maps variables to arrays of mutating items. self.mutated_upvalues = {} - -- Maps variables to arays of setting items. + -- Maps variables to arrays of setting items. self.set_upvalues = {} self.lines = {} self.node = node @@ -729,7 +729,7 @@ function LinState:scan_expr_Function(item, node) end -- Builds linear representation (line) of AST and assigns it as `chstate.top_line`. --- Assings an array of all lines as `chstate.lines`. +-- Assigns an array of all lines as `chstate.lines`. -- Adds warnings for redefined/shadowed locals and unused labels. function stage.run(chstate) local linstate = LinState(chstate) diff --git a/src/luacheck/stages/parse_inline_options.lua b/src/luacheck/stages/parse_inline_options.lua index cab07b48..1da56679 100644 --- a/src/luacheck/stages/parse_inline_options.lua +++ b/src/luacheck/stages/parse_inline_options.lua @@ -239,7 +239,7 @@ local function options_and_boundaries_comparator(t1, t2) end end --- Applies bounadaries withing `inline_options_and_boundaries` to replace them with pop count +-- Applies boundaries within `inline_options_and_boundaries` to replace them with pop count -- instructions in the resulting array. -- Comments on lines with code are popped at the end of line. -- Warns about unpaired push and pop directives. diff --git a/src/luacheck/vendor/sha1/init.lua b/src/luacheck/vendor/sha1/init.lua index 49f95bee..d85db689 100644 --- a/src/luacheck/vendor/sha1/init.lua +++ b/src/luacheck/vendor/sha1/init.lua @@ -8,7 +8,7 @@ local sha1 = { SHA-1 secure hash and HMAC-SHA1 signature computation in Lua, using bit and bit32 modules and Lua 5.3 operators when available and falling back to a pure Lua implementation on Lua 5.1. -Based on code orignally by Jeffrey Friedl and modified by +Based on code originally by Jeffrey Friedl and modified by Eike Decker and Enrique García Cota.]], _LICENSE = [[ MIT LICENSE From 031db72f1d6ca6dcbd99ea9d5144fece7dcfbbcd Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Tue, 24 Oct 2023 22:31:26 +0300 Subject: [PATCH 39/46] feat: Support NO_COLOR environment variable (#102) --- src/luacheck/format.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/luacheck/format.lua b/src/luacheck/format.lua index a9d23c3f..18f95c83 100644 --- a/src/luacheck/format.lua +++ b/src/luacheck/format.lua @@ -4,6 +4,8 @@ local utils = require "luacheck.utils" local format = {} local color_support = not utils.is_windows or os.getenv("ANSICON") +-- Disable colors when NO_COLOR is set, see https://no-color.org/. +color_support = color_support and not os.getenv("NO_COLOR") local function get_message_format(warning) local message_format = assert(stages.warnings[warning.code], "Unknown warning code " .. warning.code).message_format From 7370b522bfa26b6e50f9c1accf29f983ef4545c3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 8 Dec 2023 15:31:34 +0300 Subject: [PATCH 40/46] fix: Update SILE builtin with more allowed variables --- src/luacheck/builtin_standards/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 2fb021ca..f35c2d75 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -336,7 +336,8 @@ builtin_standards.ldoc = { builtin_standards.sile = { globals = { - "SILE", "SU", "luautf8", "pl", "fluent", "CASILE" + package = { fields = { "searchpath" } }, + "SILE", "SU", "luautf8", "pl", "fluent", "executablePath", "extendSilePath", "CASILE" } } From 418f48976c73be697fe64b0eba9ea9821ac9bca8 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 8 Dec 2023 15:41:57 +0300 Subject: [PATCH 41/46] chore: Release 1.1.2 --- CHANGELOG.md | 10 +++ README.md | 4 +- action.yml | 2 +- docsrc/conf.py | 4 +- rockspecs/luacheck-1.1.2-1.rockspec | 95 +++++++++++++++++++++++++++++ src/luacheck/init.lua | 2 +- 6 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 rockspecs/luacheck-1.1.2-1.rockspec diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a5c8be0..dbef09b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. +## [1.1.2] - 2023-12-08 + +### Features + +- Support NO_COLOR environment variable (#102) — @ligurio + +### Bug Fixes + +- Update SILE builtin with more allowed variables — @alerque + ## [1.1.1] - 2023-06-09 ### Features diff --git a/README.md b/README.md index a6dbeafa..c3ef7211 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ For parallel checking Luacheck additionally requires [LuaLanes](https://github.c ### Windows binary download For Windows there is single-file 64-bit binary distribution, bundling Lua 5.4.4, Luacheck, LuaFileSystem, and LuaLanes using [LuaStatic](/~https://github.com/ers35/luastatic): -[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.1.1/luacheck.exe). +[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.1.2/luacheck.exe). ## Basic usage @@ -109,7 +109,7 @@ Documentation can be built using [Sphinx](http://sphinx-doc.org/): `sphinx-build ## Development -Luacheck is currently in development. The latest released version is v1.1.1. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. +Luacheck is currently in development. The latest released version is v1.1.2. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. Use the Luacheck issue tracker on GitHub to submit bugs, suggestions and questions. Any pull requests are welcome, too. diff --git a/action.yml b/action.yml index e9f5ce79..0e52683e 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: "." runs: using: docker - image: docker://ghcr.io/lunarmodules/luacheck:v1.1.1 + image: docker://ghcr.io/lunarmodules/luacheck:v1.1.2 entrypoint: sh args: - -c diff --git a/docsrc/conf.py b/docsrc/conf.py index 764336c8..f2569bb9 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = '1.1.1' +version = '1.1.2' # The full version, including alpha/beta/rc tags. -release = '1.1.1' +release = '1.1.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rockspecs/luacheck-1.1.2-1.rockspec b/rockspecs/luacheck-1.1.2-1.rockspec new file mode 100644 index 00000000..99a5c0d4 --- /dev/null +++ b/rockspecs/luacheck-1.1.2-1.rockspec @@ -0,0 +1,95 @@ +local package_name = "luacheck" +local package_version = "1.1.2" +local rockspec_revision = "1" +local github_account_name = "lunarmodules" +local github_repo_name = package_name + +package = package_name +version = package_version .. "-" .. rockspec_revision + +source = { + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" +} + +if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end + +description = { + summary = "A static analyzer and a linter for Lua", + detailed = [[ + Luacheck is a command-line tool for linting and static analysis of Lua + code. It is able to spot usage of undefined global variables, unused + local variables and a few other typical problems within Lua programs. + ]], + homepage = "/~https://github.com/lunarmodules/luacheck", + license = "MIT" +} + +dependencies = { + "lua >= 5.1", + "argparse >= 0.6.0", + "luafilesystem >= 1.6.3" +} +build = { + type = "builtin", + modules = { + luacheck = "src/luacheck/init.lua", + ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", + ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", + ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", + ["luacheck.cache"] = "src/luacheck/cache.lua", + ["luacheck.check"] = "src/luacheck/check.lua", + ["luacheck.check_state"] = "src/luacheck/check_state.lua", + ["luacheck.config"] = "src/luacheck/config.lua", + ["luacheck.core_utils"] = "src/luacheck/core_utils.lua", + ["luacheck.decoder"] = "src/luacheck/decoder.lua", + ["luacheck.expand_rockspec"] = "src/luacheck/expand_rockspec.lua", + ["luacheck.filter"] = "src/luacheck/filter.lua", + ["luacheck.format"] = "src/luacheck/format.lua", + ["luacheck.fs"] = "src/luacheck/fs.lua", + ["luacheck.globbing"] = "src/luacheck/globbing.lua", + ["luacheck.lexer"] = "src/luacheck/lexer.lua", + ["luacheck.main"] = "src/luacheck/main.lua", + ["luacheck.multithreading"] = "src/luacheck/multithreading.lua", + ["luacheck.options"] = "src/luacheck/options.lua", + ["luacheck.parser"] = "src/luacheck/parser.lua", + ["luacheck.profiler"] = "src/luacheck/profiler.lua", + ["luacheck.runner"] = "src/luacheck/runner.lua", + ["luacheck.serializer"] = "src/luacheck/serializer.lua", + ["luacheck.stages"] = "src/luacheck/stages/init.lua", + ["luacheck.stages.detect_bad_whitespace"] = "src/luacheck/stages/detect_bad_whitespace.lua", + ["luacheck.stages.detect_compound_operators"] = "src/luacheck/stages/detect_compound_operators.lua", + ["luacheck.stages.detect_cyclomatic_complexity"] = "src/luacheck/stages/detect_cyclomatic_complexity.lua", + ["luacheck.stages.detect_empty_blocks"] = "src/luacheck/stages/detect_empty_blocks.lua", + ["luacheck.stages.detect_empty_statements"] = "src/luacheck/stages/detect_empty_statements.lua", + ["luacheck.stages.detect_globals"] = "src/luacheck/stages/detect_globals.lua", + ["luacheck.stages.detect_reversed_fornum_loops"] = "src/luacheck/stages/detect_reversed_fornum_loops.lua", + ["luacheck.stages.detect_unbalanced_assignments"] = "src/luacheck/stages/detect_unbalanced_assignments.lua", + ["luacheck.stages.detect_uninit_accesses"] = "src/luacheck/stages/detect_uninit_accesses.lua", + ["luacheck.stages.detect_unreachable_code"] = "src/luacheck/stages/detect_unreachable_code.lua", + ["luacheck.stages.detect_unused_fields"] = "src/luacheck/stages/detect_unused_fields.lua", + ["luacheck.stages.detect_unused_locals"] = "src/luacheck/stages/detect_unused_locals.lua", + ["luacheck.stages.linearize"] = "src/luacheck/stages/linearize.lua", + ["luacheck.stages.name_functions"] = "src/luacheck/stages/name_functions.lua", + ["luacheck.stages.parse"] = "src/luacheck/stages/parse.lua", + ["luacheck.stages.parse_inline_options"] = "src/luacheck/stages/parse_inline_options.lua", + ["luacheck.stages.resolve_locals"] = "src/luacheck/stages/resolve_locals.lua", + ["luacheck.stages.unwrap_parens"] = "src/luacheck/stages/unwrap_parens.lua", + ["luacheck.standards"] = "src/luacheck/standards.lua", + ["luacheck.unicode"] = "src/luacheck/unicode.lua", + ["luacheck.unicode_printability_boundaries"] = "src/luacheck/unicode_printability_boundaries.lua", + ["luacheck.utils"] = "src/luacheck/utils.lua", + ["luacheck.vendor.sha1"] = "src/luacheck/vendor/sha1/init.lua", + ["luacheck.vendor.sha1.bit32_ops"] = "src/luacheck/vendor/sha1/bit32_ops.lua", + ["luacheck.vendor.sha1.bit_ops"] = "src/luacheck/vendor/sha1/bit_ops.lua", + ["luacheck.vendor.sha1.common"] = "src/luacheck/vendor/sha1/common.lua", + ["luacheck.vendor.sha1.lua53_ops"] = "src/luacheck/vendor/sha1/lua53_ops.lua", + ["luacheck.vendor.sha1.pure_lua_ops"] = "src/luacheck/vendor/sha1/pure_lua_ops.lua", + ["luacheck.version"] = "src/luacheck/version.lua" + }, + install = { + bin = { + luacheck = "bin/luacheck.lua" + } + } +} diff --git a/src/luacheck/init.lua b/src/luacheck/init.lua index 7ba56bc3..cbc2aadf 100644 --- a/src/luacheck/init.lua +++ b/src/luacheck/init.lua @@ -5,7 +5,7 @@ local format = require "luacheck.format" local utils = require "luacheck.utils" local luacheck = { - _VERSION = "1.1.1" + _VERSION = "1.1.2" } local function raw_validate_options(fname, opts, stds, context) From 94ae28561ab9cd9427183552122cd8446e45d2c2 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Thu, 8 Feb 2024 13:12:29 +0100 Subject: [PATCH 42/46] feat: Add builtin standards for `minetest` --- luacheck-dev-1.rockspec | 1 + src/luacheck/builtin_standards/init.lua | 3 + src/luacheck/builtin_standards/minetest.lua | 445 ++++++++++++++++++++ src/luacheck/main.lua | 1 + 4 files changed, 450 insertions(+) create mode 100644 src/luacheck/builtin_standards/minetest.lua diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index cc549540..0389dd14 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -45,6 +45,7 @@ build = { luacheck = "src/luacheck/init.lua", ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.minetest"] = "src/luacheck/builtin_standards/minetest.lua", ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", ["luacheck.cache"] = "src/luacheck/cache.lua", diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index f35c2d75..097fee2d 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -1,4 +1,5 @@ local love = require "luacheck.builtin_standards.love" +local minetest = require "luacheck.builtin_standards.minetest" local playdate = require "luacheck.builtin_standards.playdate" local ngx = require "luacheck.builtin_standards.ngx" local standards = require "luacheck.standards" @@ -296,6 +297,8 @@ builtin_standards.busted = { builtin_standards.love = love +builtin_standards.minetest = minetest + builtin_standards.playdate = playdate builtin_standards.rockspec = { diff --git a/src/luacheck/builtin_standards/minetest.lua b/src/luacheck/builtin_standards/minetest.lua new file mode 100644 index 00000000..95c56857 --- /dev/null +++ b/src/luacheck/builtin_standards/minetest.lua @@ -0,0 +1,445 @@ +-- minetest lua api standard +-- lua-api reference: /~https://github.com/minetest/minetest/blob/master/doc/lua_api.md +local standards = require "luacheck.standards" + +local empty = {} +local read_write = {read_only = false} +local open_table = {read_only = false, other_fields = true} + +-- main namespace +local minetest = { + fields = { + -- Utilities + get_current_modname = empty, + get_modpath = empty, + get_modnames = empty, + get_game_info = empty, + get_worldpath = empty, + is_singleplayer = empty, + features = open_table, + has_feature = empty, + get_player_information = empty, + get_player_window_information = empty, + mkdir = empty, + rmdir = empty, + cpdir = empty, + mvdir = empty, + get_dir_list = empty, + safe_file_write = empty, + get_version = empty, + sha1 = empty, + colorspec_to_colorstring = empty, + colorspec_to_bytes = empty, + encode_png = empty, + urlencode = empty, + + -- Logging + debug = empty, + log = empty, + + -- Environment + register_node = empty, + register_craftitem = empty, + register_tool = empty, + override_item = empty, + unregister_item = empty, + register_entity = empty, + register_abm = empty, + register_lbm = empty, + register_alias = empty, + register_alias_force = empty, + register_ore = empty, + register_biome = empty, + unregister_biome = empty, + register_decoration = empty, + register_schematic = empty, + clear_registered_biomes = empty, + clear_registered_decorations = empty, + clear_registered_ores = empty, + clear_registered_schematics = empty, + + -- Gameplay + register_craft = empty, + clear_craft = empty, + register_chatcommand = empty, + override_chatcommand = empty, + unregister_chatcommand = empty, + register_privilege = empty, + register_authentication_handler = empty, + + -- Global callback registration functions + register_globalstep = empty, + register_on_mods_loaded = empty, + register_on_shutdown = empty, + register_on_placenode = empty, + register_on_dignode = empty, + register_on_punchnode = empty, + register_on_generated = empty, + register_on_newplayer = empty, + register_on_punchplayer = empty, + register_on_rightclickplayer = empty, + register_on_player_hpchange = empty, + register_on_dieplayer = empty, + register_on_respawnplayer = empty, + register_on_prejoinplayer = empty, + register_on_joinplayer = empty, + register_on_leaveplayer = empty, + register_on_authplayer = empty, + register_on_auth_fail = empty, + register_on_cheat = empty, + register_on_chat_message = empty, + register_on_chatcommand = empty, + register_on_player_receive_fields = empty, + register_on_craft = empty, + register_craft_predict = empty, + register_allow_player_inventory_action = empty, + register_on_player_inventory_action = empty, + register_on_protection_violation = empty, + register_on_item_eat = empty, + register_on_item_pickup = empty, + register_on_priv_grant = empty, + register_on_priv_revoke = empty, + register_can_bypass_userlimit = empty, + register_on_modchannel_message = empty, + register_on_liquid_transformed = empty, + register_on_mapblocks_changed = empty, + + -- Setting-related + settings = standards.def_fields("get", "get_bool", "get_np_group", "get_flags", "set", "set_bool", + "set_np_group", "remove", "get_names", "has", "write", "to_table"), + setting_get_pos = empty, + + -- Authentication + string_to_privs = empty, + privs_to_string = empty, + get_player_privs = empty, + check_player_privs = empty, + check_password_entry = empty, + get_password_hash = empty, + get_player_ip = empty, + get_auth_handler = empty, + notify_authentication_modified = empty, + set_player_password = empty, + set_player_privs = empty, + change_player_privs = empty, + auth_reload = empty, + + -- Chat + chat_send_all = empty, + chat_send_player = empty, + format_chat_message = empty, + + -- Environment access + set_node = empty, + add_node = empty, + bulk_set_node = empty, + swap_node = empty, + remove_node = empty, + get_node = empty, + get_node_or_nil = empty, + get_node_light = empty, + get_natural_light = empty, + get_artificial_light = empty, + place_node = empty, + dig_node = empty, + punch_node = empty, + spawn_falling_node = empty, + find_nodes_with_meta = empty, + get_meta = empty, + get_node_timer = empty, + add_entity = empty, + add_item = empty, + get_player_by_name = empty, + get_objects_inside_radius = empty, + get_objects_in_area = empty, + set_timeofday = empty, + get_timeofday = empty, + get_gametime = empty, + get_day_count = empty, + find_node_near = empty, + find_nodes_in_area = empty, + find_nodes_in_area_under_air = empty, + get_perlin = empty, + get_voxel_manip = empty, + set_gen_notify = empty, + get_gen_notify = empty, + get_decoration_id = empty, + get_mapgen_object = empty, + get_heat = empty, + get_humidity = empty, + get_biome_data = empty, + get_biome_id = empty, + get_biome_name = empty, + get_mapgen_params = empty, + set_mapgen_params = empty, + get_mapgen_edges = empty, + get_mapgen_setting = empty, + get_mapgen_setting_noiseparams = empty, + set_mapgen_setting = empty, + set_mapgen_setting_noiseparams = empty, + set_noiseparams = empty, + get_noiseparams = empty, + generate_ores = empty, + generate_decorations = empty, + clear_objects = empty, + load_area = empty, + emerge_area = empty, + delete_area = empty, + line_of_sight = empty, + raycast = empty, + find_path = empty, + spawn_tree = empty, + transforming_liquid_add = empty, + get_node_max_level = empty, + get_node_level = empty, + set_node_level = empty, + add_node_level = empty, + get_node_boxes = empty, + fix_light = empty, + check_single_for_falling = empty, + check_for_falling = empty, + get_spawn_level = empty, + + -- Mod channels + mod_channel_join = empty, + + -- Inventory + get_inventory = empty, + create_detached_inventory = empty, + remove_detached_inventory = empty, + do_item_eat = empty, + + -- Formspec + show_formspec = empty, + close_formspec = empty, + formspec_escape = empty, + explode_table_event = empty, + explode_textlist_event = empty, + explode_scrollbar_event = empty, + + -- Item handling + inventorycube = empty, + get_pointed_thing_position = empty, + dir_to_facedir = empty, + facedir_to_dir = empty, + dir_to_fourdir = empty, + fourdir_to_dir = empty, + dir_to_wallmounted = empty, + wallmounted_to_dir = empty, + dir_to_yaw = empty, + yaw_to_dir = empty, + is_colored_paramtype = empty, + strip_param2_color = empty, + get_node_drops = empty, + get_craft_result = empty, + get_craft_recipe = empty, + get_all_craft_recipes = empty, + handle_node_drops = empty, + itemstring_with_palette = empty, + itemstring_with_color = empty, + + -- Rollback + rollback_get_node_actions = empty, + rollback_revert_actions_by = empty, + + -- Defaults for the on_place and on_drop item definition functions + item_place_node = empty, + item_place_object = empty, + item_place = empty, + item_pickup = empty, + item_drop = empty, + item_eat = empty, + + -- Defaults for the on_punch and on_dig node definition callbacks + node_punch = empty, + node_dig = empty, + + -- Sounds + sound_play = empty, + sound_stop = empty, + sound_fade = empty, + + -- Timing + after = empty, + + -- Async environment + handle_async = empty, + register_async_dofile = empty, + + -- Server + request_shutdown = empty, + cancel_shutdown_requests = empty, + get_server_status = empty, + get_server_uptime = empty, + get_server_max_lag = empty, + remove_player = empty, + remove_player_auth = empty, + dynamic_add_media = empty, + + -- Bans + get_ban_list = empty, + get_ban_description = empty, + ban_player = empty, + unban_player_or_ip = empty, + kick_player = empty, + disconnect_player = empty, + + -- Particles + add_particle = empty, + add_particlespawner = empty, + delete_particlespawner = empty, + + -- Schematics + create_schematic = empty, + place_schematic = empty, + place_schematic_on_vmanip = empty, + serialize_schematic = empty, + read_schematic = empty, + + -- HTTP Requests + request_http_api = empty, + + -- Storage API + get_mod_storage = empty, + + -- Misc + get_connected_players = empty, + is_player = empty, + player_exists = empty, + hud_replace_builtin = empty, + parse_relative_number = empty, + send_join_message = empty, + send_leave_message = empty, + hash_node_position = empty, + get_position_from_hash = empty, + get_item_group = empty, + get_node_group = empty, + raillike_group = empty, + get_content_id = empty, + get_name_from_content_id = empty, + parse_json = empty, + write_json = empty, + serialize = empty, + deserialize = empty, + compress = empty, + decompress = empty, + rgba = empty, + encode_base64 = empty, + decode_base64 = empty, + is_protected = read_write, + record_protection_violation = empty, + is_creative_enabled = empty, + is_area_protected = empty, + rotate_and_place = empty, + rotate_node = empty, + calculate_knockback = empty, + forceload_block = empty, + forceload_free_block = empty, + compare_block_status = empty, + request_insecure_environment = empty, + global_exists = empty, + + -- Error Handling + error_handler = read_write, + + -- Helper functions + wrap_text = empty, + pos_to_string = empty, + string_to_pos = empty, + string_to_area = empty, + is_yes = empty, + is_nan = empty, + get_us_time = empty, + pointed_thing_to_face_pos = empty, + get_tool_wear_after_use = empty, + get_dig_params = empty, + get_hit_params = empty, + colorize = empty, + + -- Translations + get_translator = empty, + get_translated_string = empty, + translate = empty, + + -- Global tables + registered_items = open_table, + registered_nodes = open_table, + registered_craftitems = open_table, + registered_tools = open_table, + registered_entities = open_table, + object_refs = open_table, + luaentities = open_table, + registered_abms = open_table, + registered_lbms = open_table, + registered_aliases = open_table, + registered_ores = open_table, + registered_biomes = open_table, + registered_decorations = open_table, + registered_schematics = open_table, + registered_chatcommands = open_table, + registered_privileges = open_table, + + -- Constants (see: /~https://github.com/minetest/minetest/blob/master/builtin/game/constants.lua) + CONTENT_UNKNOWN = empty, + CONTENT_AIR = empty, + CONTENT_IGNORE = empty, + EMERGE_CANCELLED = empty, + EMERGE_ERRORED = empty, + EMERGE_FROM_MEMORY = empty, + EMERGE_FROM_DISK = empty, + EMERGE_GENERATED = empty, + MAP_BLOCKSIZE = empty, + PLAYER_MAX_HP_DEFAULT = empty, + PLAYER_MAX_BREATH_DEFAULT = empty, + LIGHT_MAX = empty + } +} + +-- Table additions +local table = standards.def_fields("copy", "indexof", "insert_all", "key_value_swap", "shuffle") + +-- String additions +local string = standards.def_fields("split", "trim") + +-- Math additions +local math = standards.def_fields("hypot", "sign", "factorial", "round") + +-- Bit library +local bit = standards.def_fields("tobit","tohex","bnot","band","bor","bxor","lshift","rshift","arshift","rol","ror", + "bswap") + +-- vector util +local vector = standards.def_fields("new", "zero", "copy", "from_string", "to_string", "direction", "distance", + "length", "normalize", "floor", "round", "apply", "combine", "equals", "sort", "angle", "dot", "cross", "offset", + "check", "in_area", "add", "subtract", "multiply", "divide", "rotate", "rotate_around_axis", "dir_to_rotation") + +return { + read_globals = { + -- main namespace + minetest = minetest, + + -- extensions + table = table, + math = math, + bit = bit, + string = string, + + -- Helper functions + vector = vector, + dump = empty, + dump2 = empty, + + -- classes + AreaStore = empty, + ItemStack = empty, + PerlinNoise = empty, + PerlinNoiseMap = empty, + PseudoRandom = empty, + PcgRandom = empty, + SecureRandom = empty, + VoxelArea = open_table, + VoxelManip = empty, + Raycast = empty, + Settings = empty, + } +} diff --git a/src/luacheck/main.lua b/src/luacheck/main.lua index 730bd118..bb94eb67 100644 --- a/src/luacheck/main.lua +++ b/src/luacheck/main.lua @@ -92,6 +92,7 @@ Links: " luajit - globals of LuaJIT 2.x;\n" .. " ngx_lua - globals of Openresty lua-nginx-module 0.10.10, including standard LuaJIT 2.x globals;\n" .. " love - globals added by LÖVE;\n" .. + " minetest - globals added by minetest;\n" .. " playdate - globals added by the Playdate SDK;\n" .. " busted - globals added by Busted 2.0, by default added for files ending with _spec.lua within spec, " .. "test, and tests subdirectories;\n" .. From 52d809e4b5c03d823847c113ccde9ebdaa8a740d Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 10 Feb 2024 12:43:33 +0300 Subject: [PATCH 43/46] test: Confirm builtin minetest std is taking effect --- spec/cli_spec.lua | 22 ++++++++++++++++++---- spec/samples/minetest.lua | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 spec/samples/minetest.lua diff --git a/spec/cli_spec.lua b/spec/cli_spec.lua index 40879e58..4ebb90aa 100644 --- a/spec/cli_spec.lua +++ b/spec/cli_spec.lua @@ -1023,7 +1023,7 @@ spec/samples/python_code.lua:1:6: (E011) expected '=' near '__future__' end) it("expands folders", function() - assert.matches("^Total: %d+ warnings / %d+ errors in 27 files\n$", get_output "spec/samples -qqq --no-config --exclude-files spec/samples/global_fields.lua") + assert.matches("^Total: %d+ warnings / %d+ errors in 28 files\n$", get_output "spec/samples -qqq --no-config --exclude-files spec/samples/global_fields.lua") end) it("uses --include-files when expanding folders", function() @@ -1242,6 +1242,7 @@ Checking spec/samples/globals.lua 2 warnings Checking spec/samples/indirect_globals.lua 3 warnings Checking spec/samples/inline_options.lua 7 warnings / 2 errors Checking spec/samples/line_length.lua 8 warnings +Checking spec/samples/minetest.lua 2 warnings Checking spec/samples/python_code.lua 1 error Checking spec/samples/read_globals.lua 5 warnings Checking spec/samples/read_globals_inline_options.lua 3 warnings @@ -1252,7 +1253,7 @@ Checking spec/samples/unused_secondaries.lua 4 warnings Checking spec/samples/utf8.lua 4 warnings Checking spec/samples/utf8_error.lua 1 error -Total: 73 warnings / 9 errors in 20 files +Total: 75 warnings / 9 errors in 21 files ]]):gsub("(spec/samples)/", "%1"..package.config:sub(1, 1)), get_output "spec/samples --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files spec/samples/global_fields.lua") end) @@ -1268,6 +1269,7 @@ Checking globals.lua 2 warnings Checking indirect_globals.lua 3 warnings Checking inline_options.lua 7 warnings / 2 errors Checking line_length.lua 8 warnings +Checking minetest.lua 2 warnings Checking python_code.lua 1 error Checking read_globals.lua 5 warnings Checking read_globals_inline_options.lua 3 warnings @@ -1278,7 +1280,7 @@ Checking unused_secondaries.lua 4 warnings Checking utf8.lua 4 warnings Checking utf8_error.lua 1 error -Total: 73 warnings / 9 errors in 20 files +Total: 75 warnings / 9 errors in 21 files ]], get_output(". --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files global_fields.lua", "spec/samples/")) end) @@ -1293,6 +1295,7 @@ Checking globals.lua 2 warnings Checking indirect_globals.lua 3 warnings Checking inline_options.lua 7 warnings / 2 errors Checking line_length.lua 8 warnings +Checking minetest.lua 2 warnings Checking python_code.lua 1 error Checking redefined.lua 7 warnings Checking reversed_fornum.lua 1 warning @@ -1301,7 +1304,7 @@ Checking unused_secondaries.lua 4 warnings Checking utf8.lua 4 warnings Checking utf8_error.lua 1 error -Total: 65 warnings / 9 errors in 18 files +Total: 67 warnings / 9 errors in 19 files ]], get_output(". --config=spec/configs/exclude_files_config.luacheckrc -qq --exclude-files global_fields.lua --exclude-files " .. quote("./read*"), "spec/samples/")) end) @@ -1351,6 +1354,17 @@ Total: 1 warning / 0 errors in 1 file ]], get_output "spec/samples/globals.lua --config=spec/configs/import_config.luacheckrc") end) + describe("responds to builtin std preset", function() + it("minetest", function() + -- make sure minetest sample has something that normally throws a lint error + assert.equal(1, get_exitcode "spec/samples/minetest.lua --no-config") + -- turning on minetest std should pass all lints + assert.equal(0, get_exitcode "spec/samples/minetest.lua --no-config --std minetest") + -- confirm minetest std set isn't just blindly allowing anything + assert.equal(1, get_exitcode "spec/samples/sample.rockspec --no-config --std minetest") + end) + end) + describe("global path", function() setup(function() os.rename(".luacheckrc", ".luacheckrc.bak") diff --git a/spec/samples/minetest.lua b/spec/samples/minetest.lua new file mode 100644 index 00000000..b7206937 --- /dev/null +++ b/spec/samples/minetest.lua @@ -0,0 +1,2 @@ +local _ = minetest +local _ = minetest.get_current_modname() From 494b0f1333bcf0ed5cbff913c989cfdcc0089e12 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 15 Feb 2024 19:33:26 +0100 Subject: [PATCH 44/46] chore: Add registered callback tables to minetest builtin --- src/luacheck/builtin_standards/minetest.lua | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/luacheck/builtin_standards/minetest.lua b/src/luacheck/builtin_standards/minetest.lua index 95c56857..ef06a42c 100644 --- a/src/luacheck/builtin_standards/minetest.lua +++ b/src/luacheck/builtin_standards/minetest.lua @@ -103,6 +103,40 @@ local minetest = { register_on_modchannel_message = empty, register_on_liquid_transformed = empty, register_on_mapblocks_changed = empty, + -- ... and corresponding callback tables + registered_on_chat_messages = open_table, + registered_on_chatcommands = open_table, + registered_globalsteps = open_table, + registered_on_mods_loaded = open_table, + registered_on_shutdown = open_table, + registered_on_punchnodes = open_table, + registered_on_placenodes = open_table, + registered_on_dignodes = open_table, + registered_on_generateds = open_table, + registered_on_newplayers = open_table, + registered_on_dieplayers = open_table, + registered_on_respawnplayers = open_table, + registered_on_prejoinplayers = open_table, + registered_on_joinplayers = open_table, + registered_on_leaveplayers = open_table, + registered_on_player_receive_fields = open_table, + registered_on_cheats = open_table, + registered_on_crafts = open_table, + registered_craft_predicts = open_table, + registered_on_protection_violation = open_table, + registered_on_item_eats = open_table, + registered_on_item_pickups = open_table, + registered_on_punchplayers = open_table, + registered_on_priv_grant = open_table, + registered_on_priv_revoke = open_table, + registered_on_authplayers = open_table, + registered_can_bypass_userlimit = open_table, + registered_on_modchannel_message = open_table, + registered_on_player_inventory_actions = open_table, + registered_allow_player_inventory_actions = open_table, + registered_on_rightclickplayers = open_table, + registered_on_liquid_transformed = open_table, + registered_on_mapblocks_changed = open_table, -- Setting-related settings = standards.def_fields("get", "get_bool", "get_np_group", "get_flags", "set", "set_bool", From b39bbd00881a3265486bff3003a2aed72730af08 Mon Sep 17 00:00:00 2001 From: Tom Lau Date: Fri, 24 May 2024 15:24:58 +0800 Subject: [PATCH 45/46] perf: Optimize `contains_call()` by adding memoization (#105) --- src/luacheck/stages/resolve_locals.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/luacheck/stages/resolve_locals.lua b/src/luacheck/stages/resolve_locals.lua index b47f0f93..be81c69f 100644 --- a/src/luacheck/stages/resolve_locals.lua +++ b/src/luacheck/stages/resolve_locals.lua @@ -79,18 +79,26 @@ local function in_scope(var, index) end local function contains_call(node) + if node._contains_call ~= nil then + -- return cached result + return node._contains_call + end + if node.tag == "Call" or node.tag == "Invoke" then + node._contains_call = true return true end if node.tag ~= "Function" then for _, sub_node in ipairs(node) do if type(sub_node) == 'table' and contains_call(sub_node) then + node._contains_call = true return true end end end + node._contains_call = false return false end From cc089e3f65acdd1ef8716cc73a3eca24a6b845e4 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 24 May 2024 11:32:29 +0300 Subject: [PATCH 46/46] chore: Release 1.2.0 --- CHANGELOG.md | 10 +++ README.md | 4 +- action.yml | 2 +- docsrc/conf.py | 4 +- rockspecs/luacheck-1.2.0-1.rockspec | 96 +++++++++++++++++++++++++++++ src/luacheck/init.lua | 2 +- 6 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 rockspecs/luacheck-1.2.0-1.rockspec diff --git a/CHANGELOG.md b/CHANGELOG.md index dbef09b9..cbc61d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. +## [1.2.0] - 2024-05-24 + +### Features + +- Add builtin standards support for minetest (#108) — @BuckarooBanzay and @appgurueu + +### Performance + +- Memoize results to addresses speed refression from new feature in v0.26 (#105) — @tomlau10 + ## [1.1.2] - 2023-12-08 ### Features diff --git a/README.md b/README.md index c3ef7211..efb7dbd3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ For parallel checking Luacheck additionally requires [LuaLanes](https://github.c ### Windows binary download For Windows there is single-file 64-bit binary distribution, bundling Lua 5.4.4, Luacheck, LuaFileSystem, and LuaLanes using [LuaStatic](/~https://github.com/ers35/luastatic): -[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.1.2/luacheck.exe). +[download](/~https://github.com/lunarmodules/luacheck/releases/download/v1.2.0/luacheck.exe). ## Basic usage @@ -109,7 +109,7 @@ Documentation can be built using [Sphinx](http://sphinx-doc.org/): `sphinx-build ## Development -Luacheck is currently in development. The latest released version is v1.1.2. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. +Luacheck is currently in development. The latest released version is v1.2.0. The interface of the `luacheck` module may change between minor releases. The command line interface is fairly stable. Use the Luacheck issue tracker on GitHub to submit bugs, suggestions and questions. Any pull requests are welcome, too. diff --git a/action.yml b/action.yml index 0e52683e..4b257241 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: default: "." runs: using: docker - image: docker://ghcr.io/lunarmodules/luacheck:v1.1.2 + image: docker://ghcr.io/lunarmodules/luacheck:v1.2.0 entrypoint: sh args: - -c diff --git a/docsrc/conf.py b/docsrc/conf.py index f2569bb9..5a2cf7c9 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = '1.1.2' +version = '1.2.0' # The full version, including alpha/beta/rc tags. -release = '1.1.2' +release = '1.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rockspecs/luacheck-1.2.0-1.rockspec b/rockspecs/luacheck-1.2.0-1.rockspec new file mode 100644 index 00000000..9046931b --- /dev/null +++ b/rockspecs/luacheck-1.2.0-1.rockspec @@ -0,0 +1,96 @@ +local package_name = "luacheck" +local package_version = "1.2.0" +local rockspec_revision = "1" +local github_account_name = "lunarmodules" +local github_repo_name = package_name + +package = package_name +version = package_version .. "-" .. rockspec_revision + +source = { + url = "git+/~https://github.com/" .. github_account_name .. "/" .. github_repo_name .. ".git" +} + +if package_version == "dev" then source.branch = "master" else source.tag = "v" .. package_version end + +description = { + summary = "A static analyzer and a linter for Lua", + detailed = [[ + Luacheck is a command-line tool for linting and static analysis of Lua + code. It is able to spot usage of undefined global variables, unused + local variables and a few other typical problems within Lua programs. + ]], + homepage = "/~https://github.com/lunarmodules/luacheck", + license = "MIT" +} + +dependencies = { + "lua >= 5.1", + "argparse >= 0.6.0", + "luafilesystem >= 1.6.3" +} +build = { + type = "builtin", + modules = { + luacheck = "src/luacheck/init.lua", + ["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua", + ["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua", + ["luacheck.builtin_standards.minetest"] = "src/luacheck/builtin_standards/minetest.lua", + ["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua", + ["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua", + ["luacheck.cache"] = "src/luacheck/cache.lua", + ["luacheck.check"] = "src/luacheck/check.lua", + ["luacheck.check_state"] = "src/luacheck/check_state.lua", + ["luacheck.config"] = "src/luacheck/config.lua", + ["luacheck.core_utils"] = "src/luacheck/core_utils.lua", + ["luacheck.decoder"] = "src/luacheck/decoder.lua", + ["luacheck.expand_rockspec"] = "src/luacheck/expand_rockspec.lua", + ["luacheck.filter"] = "src/luacheck/filter.lua", + ["luacheck.format"] = "src/luacheck/format.lua", + ["luacheck.fs"] = "src/luacheck/fs.lua", + ["luacheck.globbing"] = "src/luacheck/globbing.lua", + ["luacheck.lexer"] = "src/luacheck/lexer.lua", + ["luacheck.main"] = "src/luacheck/main.lua", + ["luacheck.multithreading"] = "src/luacheck/multithreading.lua", + ["luacheck.options"] = "src/luacheck/options.lua", + ["luacheck.parser"] = "src/luacheck/parser.lua", + ["luacheck.profiler"] = "src/luacheck/profiler.lua", + ["luacheck.runner"] = "src/luacheck/runner.lua", + ["luacheck.serializer"] = "src/luacheck/serializer.lua", + ["luacheck.stages"] = "src/luacheck/stages/init.lua", + ["luacheck.stages.detect_bad_whitespace"] = "src/luacheck/stages/detect_bad_whitespace.lua", + ["luacheck.stages.detect_compound_operators"] = "src/luacheck/stages/detect_compound_operators.lua", + ["luacheck.stages.detect_cyclomatic_complexity"] = "src/luacheck/stages/detect_cyclomatic_complexity.lua", + ["luacheck.stages.detect_empty_blocks"] = "src/luacheck/stages/detect_empty_blocks.lua", + ["luacheck.stages.detect_empty_statements"] = "src/luacheck/stages/detect_empty_statements.lua", + ["luacheck.stages.detect_globals"] = "src/luacheck/stages/detect_globals.lua", + ["luacheck.stages.detect_reversed_fornum_loops"] = "src/luacheck/stages/detect_reversed_fornum_loops.lua", + ["luacheck.stages.detect_unbalanced_assignments"] = "src/luacheck/stages/detect_unbalanced_assignments.lua", + ["luacheck.stages.detect_uninit_accesses"] = "src/luacheck/stages/detect_uninit_accesses.lua", + ["luacheck.stages.detect_unreachable_code"] = "src/luacheck/stages/detect_unreachable_code.lua", + ["luacheck.stages.detect_unused_fields"] = "src/luacheck/stages/detect_unused_fields.lua", + ["luacheck.stages.detect_unused_locals"] = "src/luacheck/stages/detect_unused_locals.lua", + ["luacheck.stages.linearize"] = "src/luacheck/stages/linearize.lua", + ["luacheck.stages.name_functions"] = "src/luacheck/stages/name_functions.lua", + ["luacheck.stages.parse"] = "src/luacheck/stages/parse.lua", + ["luacheck.stages.parse_inline_options"] = "src/luacheck/stages/parse_inline_options.lua", + ["luacheck.stages.resolve_locals"] = "src/luacheck/stages/resolve_locals.lua", + ["luacheck.stages.unwrap_parens"] = "src/luacheck/stages/unwrap_parens.lua", + ["luacheck.standards"] = "src/luacheck/standards.lua", + ["luacheck.unicode"] = "src/luacheck/unicode.lua", + ["luacheck.unicode_printability_boundaries"] = "src/luacheck/unicode_printability_boundaries.lua", + ["luacheck.utils"] = "src/luacheck/utils.lua", + ["luacheck.vendor.sha1"] = "src/luacheck/vendor/sha1/init.lua", + ["luacheck.vendor.sha1.bit32_ops"] = "src/luacheck/vendor/sha1/bit32_ops.lua", + ["luacheck.vendor.sha1.bit_ops"] = "src/luacheck/vendor/sha1/bit_ops.lua", + ["luacheck.vendor.sha1.common"] = "src/luacheck/vendor/sha1/common.lua", + ["luacheck.vendor.sha1.lua53_ops"] = "src/luacheck/vendor/sha1/lua53_ops.lua", + ["luacheck.vendor.sha1.pure_lua_ops"] = "src/luacheck/vendor/sha1/pure_lua_ops.lua", + ["luacheck.version"] = "src/luacheck/version.lua" + }, + install = { + bin = { + luacheck = "bin/luacheck.lua" + } + } +} diff --git a/src/luacheck/init.lua b/src/luacheck/init.lua index cbc2aadf..eb6e172e 100644 --- a/src/luacheck/init.lua +++ b/src/luacheck/init.lua @@ -5,7 +5,7 @@ local format = require "luacheck.format" local utils = require "luacheck.utils" local luacheck = { - _VERSION = "1.1.2" + _VERSION = "1.2.0" } local function raw_validate_options(fname, opts, stds, context)