Convert Figma logo to code with AI

mpeterv logoluacheck

A tool for linting and static analysis of Lua code.

1,908
316
1,908
44

Top Related Projects

12,589

A Ruby static code analyzer and formatter, based on the community Ruby style guide.

5,236

It's not just a linter that annoys you!

24,850

Find and fix problems in your JavaScript code.

ShellCheck, a static analysis tool for shell scripts

🦙 MegaLinter analyzes 50 languages, 22 formats, 21 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.

Quick Overview

Luacheck is a static analyzer and linter for Lua. It detects various issues in Lua code, including runtime errors, unused variables, and stylistic inconsistencies. Luacheck is designed to be fast, customizable, and easy to integrate into development workflows.

Pros

  • Fast and efficient analysis of Lua code
  • Highly customizable with support for configuration files
  • Can be integrated into various editors and CI/CD pipelines
  • Supports multiple Lua versions and implementations

Cons

  • May produce false positives in some cases
  • Limited ability to detect certain types of logical errors
  • Learning curve for advanced configuration options
  • Some features may require additional setup or plugins

Code Examples

  1. Basic usage:
-- example.lua
local unused_var = 5
print("Hello, World!")

Running Luacheck:

luacheck example.lua

Output:

Checking example.lua                            1 warning

    example.lua:1:7: unused variable unused_var

Total: 1 warning
  1. Using inline comments to control Luacheck:
local unused_var = 5 -- luacheck: ignore
print("Hello, World!")
  1. Configuring Luacheck with a .luacheckrc file:
-- .luacheckrc
ignore = {"611"}
globals = {"my_global_function"}

Getting Started

  1. Install Luacheck:

    luarocks install luacheck
    
  2. Run Luacheck on a Lua file:

    luacheck path/to/your/lua/file.lua
    
  3. Create a .luacheckrc file in your project root for custom configuration:

    -- .luacheckrc
    ignore = {"611", "612"}
    globals = {"my_global_function"}
    
  4. Integrate Luacheck with your editor or CI/CD pipeline for automated checks.

Competitor Comparisons

12,589

A Ruby static code analyzer and formatter, based on the community Ruby style guide.

Pros of RuboCop

  • More comprehensive linting and style checking for Ruby
  • Larger community and more frequent updates
  • Extensive configuration options and customizable rules

Cons of RuboCop

  • Slower performance, especially on large codebases
  • Steeper learning curve due to numerous rules and options

Code Comparison

LuaCheck example:

local function foo()
  local unused_var = 5
  return 42
end

RuboCop example:

def foo
  unused_var = 5
  42
end

Both tools would likely flag the unused variable, but RuboCop might also suggest using implicit return in Ruby.

Additional Notes

LuaCheck is specifically designed for Lua, while RuboCop focuses on Ruby. This makes each tool more tailored to its respective language's idioms and best practices. RuboCop offers a wider range of features, including auto-correction and integration with various text editors and IDEs. LuaCheck, being lighter-weight, may be easier to set up and use for smaller projects or quick checks.

Both tools are valuable for maintaining code quality and consistency in their respective ecosystems, with RuboCop being more feature-rich but potentially more complex to use, and LuaCheck offering a simpler, more focused approach for Lua development.

5,236

It's not just a linter that annoys you!

Pros of Pylint

  • More comprehensive analysis with a wider range of checks and features
  • Highly configurable with extensive options for customization
  • Integrates well with various IDEs and development environments

Cons of Pylint

  • Can be slower to run, especially on larger codebases
  • May produce more false positives, requiring fine-tuning of configuration
  • Steeper learning curve due to its extensive feature set

Code Comparison

Pylint configuration example:

[MASTER]
ignore=CVS
ignore-patterns=
persistent=yes
load-plugins=
jobs=1
unsafe-load-any-extension=no

Luacheck configuration example:

cache = true
codes = true
formatter = "plain"
quiet = 1
color = true

Both tools offer configuration options, but Pylint's configuration is typically more extensive and detailed, reflecting its broader feature set. Luacheck's configuration is generally simpler and more straightforward, focusing on core linting functionality for Lua code.

While Pylint is a powerful tool for Python development with a wide range of features, Luacheck provides a more focused and lightweight linting experience for Lua projects. The choice between the two depends on the specific language and project requirements.

24,850

Find and fix problems in your JavaScript code.

Pros of ESLint

  • Larger ecosystem with extensive plugin support and customizable rules
  • Supports modern JavaScript features and frameworks
  • Integrates well with popular development tools and IDEs

Cons of ESLint

  • Slower performance on large codebases compared to Luacheck
  • More complex configuration and setup process
  • Limited to JavaScript and related languages

Code Comparison

Luacheck configuration:

std = {
  globals = {"love"},
  read_globals = {"math"}
}

ESLint configuration:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": "eslint:recommended",
  "rules": {
    "indent": ["error", 2],
    "linebreak-style": ["error", "unix"]
  }
}

Both Luacheck and ESLint are static analysis tools for their respective languages. Luacheck is focused on Lua, while ESLint targets JavaScript and related languages. ESLint offers more extensive customization options and a larger ecosystem of plugins, making it highly adaptable to various project needs. However, this comes at the cost of increased complexity and potentially slower performance on large codebases. Luacheck, being more specialized, provides faster analysis for Lua projects with a simpler configuration process. The choice between the two depends on the primary language used in the project and the desired level of customization and ecosystem support.

ShellCheck, a static analysis tool for shell scripts

Pros of ShellCheck

  • Wider language support: Analyzes Bash, Dash, Ksh, and POSIX shell scripts
  • More comprehensive checks: Covers a broader range of potential issues and best practices
  • Integrates with many popular editors and CI systems out-of-the-box

Cons of ShellCheck

  • Slower performance on large codebases compared to LuaCheck
  • Less customizable: Fewer options for ignoring specific warnings or adjusting severity levels

Code Comparison

ShellCheck example:

#!/bin/bash
echo $1

ShellCheck output:

Line 2:
echo $1
     ^-- SC2086: Double quote to prevent globbing and word splitting.

LuaCheck example:

local function greet(name)
  print("Hello, " .. name)
end

LuaCheck output:

No warnings

Both tools provide static analysis for their respective languages, but ShellCheck offers more detailed explanations and suggestions for improvements in shell scripts, while LuaCheck focuses on Lua-specific issues and performance optimizations.

🦙 MegaLinter analyzes 50 languages, 22 formats, 21 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.

Pros of MegaLinter

  • Supports multiple languages and linters, not just Lua
  • Provides a comprehensive suite of tools for code quality and security
  • Offers easy integration with CI/CD pipelines and customizable configurations

Cons of MegaLinter

  • May be overkill for projects focused solely on Lua
  • Potentially longer setup and configuration time
  • Higher resource usage due to its comprehensive nature

Code Comparison

LuaCheck example:

-- LuaCheck configuration
std = "lua51+lua52+lua53"
max_line_length = 120

MegaLinter example:

# MegaLinter configuration
ENABLE_LINTERS:
  - LUA_LUACHECK
  - MARKDOWN_MARKDOWNLINT
  - YAML_YAMLLINT
LUA_LUACHECK_CONFIG_FILE: .luacheckrc

Summary

LuaCheck is a dedicated Lua static analyzer, offering focused and efficient Lua code checking. MegaLinter, on the other hand, is a comprehensive linting solution supporting multiple languages and tools, including LuaCheck for Lua files. While MegaLinter provides broader coverage and easier integration with various development workflows, it may be excessive for projects exclusively using Lua. LuaCheck offers a more streamlined approach for Lua-centric projects, with potentially quicker setup and lower resource requirements.

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.

Pros of Checkstyle

  • More comprehensive and customizable with a wide range of checks for Java code
  • Supports integration with various build tools and IDEs
  • Has a larger community and more frequent updates

Cons of Checkstyle

  • Limited to Java language, while Luacheck supports Lua
  • More complex configuration and setup process
  • Heavier resource usage due to its extensive feature set

Code Comparison

Checkstyle configuration (XML):

<module name="Checker">
  <module name="TreeWalker">
    <module name="MethodLength">
      <property name="max" value="50"/>
    </module>
  </module>
</module>

Luacheck configuration (Lua):

return {
  max_line_length = 120,
  max_code_line_length = 100,
}

Both tools allow for customization of coding standards, but Checkstyle's XML-based configuration is more verbose compared to Luacheck's simpler Lua-based approach.

Checkstyle is a powerful tool for Java projects with extensive customization options, while Luacheck offers a lightweight and focused solution for Lua codebases. The choice between the two depends on the primary programming language used in the project and the desired level of complexity in code style enforcement.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Luacheck

Join the chat at https://gitter.im/luacheck/Lobby

Build Status Windows build status codecov License

Contents

Overview

Luacheck is a static analyzer and a linter for Lua. Luacheck detects various issues such as usage of undefined global variables, unused variables and values, accessing uninitialized variables, unreachable code and more. Most aspects of checking are configurable: there are options for defining custom project-related globals, for selecting set of standard globals (version of Lua standard library), for filtering warnings by type and name of related variable, etc. The options can be used on the command line, put into a config or directly into checked files as Lua comments.

Luacheck supports checking Lua files using syntax of Lua 5.1, Lua 5.2, Lua 5.3 and LuaJIT. Luacheck itself is written in Lua and runs on all of mentioned Lua versions.

Installation

Using LuaRocks

From your command line run the following command (using sudo if necessary):

luarocks install luacheck

For parallel checking Luacheck additionally requires LuaLanes, which can be installed using LuaRocks as well (luarocks install lanes).

Windows binary download

For Windows there is single-file 64-bit binary distribution, bundling Lua 5.3.4, Luacheck, LuaFileSystem, and LuaLanes using LuaStatic: download.

Basic usage

After Luacheck is installed, run luacheck program from the command line. Pass a list of files, rockspecs or directories (requires LuaFileSystem) to be checked:

luacheck src extra_file.lua another_file.lua
Checking src/good_code.lua               OK
Checking src/bad_code.lua                3 warnings

    src/bad_code.lua:3:23: unused variable length argument
    src/bad_code.lua:7:10: setting non-standard global variable embrace
    src/bad_code.lua:8:10: variable opt was previously defined as an argument on line 7

Checking src/python_code.lua             1 error

    src/python_code.lua:1:6: expected '=' near '__future__'

Checking extra_file.lua                  5 warnings

    extra_file.lua:3:18: unused argument baz
    extra_file.lua:4:8: unused loop variable i
    extra_file.lua:13:7: accessing uninitialized variable a
    extra_file.lua:14:1: value assigned to variable x is unused
    extra_file.lua:21:7: variable z is never accessed

Checking another_file.lua                2 warnings

    another_file.lua:2:7: unused variable height
    another_file.lua:3:7: accessing undefined variable heigth

Total: 10 warnings / 1 error in 5 files

For more info, see documentation.

Related projects

Editor support

There are a few plugins which allow using Luacheck directly inside an editor, showing warnings inline:

If you are a plugin developer, see recommended way of using Luacheck in a plugin.

Other projects

Documentation

Documentation is available online. If Luacheck has been installed using LuaRocks, it can be browsed offline using luarocks doc luacheck command.

Documentation can be built using Sphinx: sphinx-build docsrc doc, the files will be found inside doc/.

Development

Luacheck is currently in development. The latest released version is 0.23.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.

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 and luautf8 installed and run busted.

License

The MIT License (MIT)

Copyright (c) 2014 - 2018 Peter Melnichenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.