Skip to content

bhsd-harry/luacheck-browserify

 
 

Repository files navigation

Luacheck-browserify

npm version 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), etc. Luacheck itself is written in Lua and runs on different Lua versions.

Luacheck-browserify is a fork of Luacheck that has been modified to work in browser environments. The Lua code is executed using Wasmoon. Luacheck-browserify can also be specifically configured to check Lua modules in MediaWiki sites.

Installation

Using CDN

As a NPM package, Luacheck-browserify can be included in a project using a CDN. Add the following script tag to the HTML file:

<script src="https://cdn.jsdelivr.net/npm/luacheck-browserify"></script>

or

<script src="https://unpkg.com/luacheck-browserify"></script>

Basic usage

After Luacheck-browserify is installed, a global async function luacheck is available. The luacheck function takes a required string argument to specify the standard globals similar to the --std CLI option, and its return value is resolved with a class instance with an async queue method that can be called with a string of Lua code to check. The queue method returns a promise that is resolved with an array of warnings.

const Luacheck = await luacheck('max');
console.log(await Luacheck.queue('local a, b, c = nil'));

The warnings are objects with the following properties:

interface {
	line: number;
	column: number;
	end_column: number;
	msg: string;
	/** 0: info, 1: warning, 2: error */
	severity: 0 | 1 | 2;
}

For more info about the warnings, see Luacheck documentation.

Related projects

Editor support

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

Documentation

Luacheck Documentation is available online.

About

A browser tool for linting and static analysis of Lua code.

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • Lua 96.4%
  • Python 1.3%
  • Shell 0.8%
  • TypeScript 0.8%
  • Makefile 0.4%
  • JavaScript 0.3%