[Guide] Linting lua and json files to spot missed errors

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

[Guide] Linting lua and json files to spot missed errors

Post by aubergine18 »

I've been looking through the sources of several mods to get a feel for how the modding system works and what can be done with it... I had "linting" tools installed on my text editor which highlighted numerous issues. Seems most modders aren't linting their code. *sad face*

Here's how I get my files linted, using ST3:

1. Install SublimeText 3

It has unlimited free demo (but buy it if you think it's awesome to help support the devs): ST3 Beta (currently in beta, but already better than v2)

2. Install Package Control

A free package manager addon for SublimeText: Package Control

3. Install Sublime Linter

This is an open source generic linting framework for Sublime Text - it provides a consistent UI for multiple linting tools (eg. for Javascript, Lua, JSON, Ruby, etc). Get it here.

4. Install Lua
5. Install linters
  • Lua: requires `luacheck`= read install instructions!!
  • JSON
6. Stop it moaning about inbuilt globals

The linter doesn't know about the globals that Factorio defines, but you can teach it with an inline comment at the start of your lua script file. For example to tell it about `defines`, `game`, `global` and `script`, use:

Code: Select all

--luacheck: globals defines game global script
Depending on which file you're editing, you might want to add other globals such as `data` or `recipes` etc.

Don't add custom globals though, you should be defining them as locals (actually improves performance in some cases, and just good practice to get in to). Yes, even functions `local function foo() ...`.

That's it - when you start editing you'll see errors quickly reported as you type :)

Useful ST3 packages
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Helfima
Fast Inserter
Fast Inserter
Posts: 200
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: [Guide] Linting lua and json files to spot missed errors

Post by Helfima »

I prefere Eclipse IDE

1) download eclipse
https://eclipse.org/downloads/eclipse-packages/ choose "Eclipse IDE for Java EE Developers"

2) install plugin lua
launch eclipse
open Help/Install new software
add Work with http://download.eclipse.org/ldt/releases/milestones/
select lua developement tools and lua developement tools SDK
use next and accept if necessary

3) Make a project
File/New/Lua project

4) Use comment
With comment Eclipse can build Outline with fonction name and args
It s very nice to check fonction argument and find it quickly

5) add mod in factorio
Open CMD Dos in folder factorio MOD
Make a junction with your MOD

Code: Select all

mklink /J helmod_0.2.11 C:\Users\Helfima\workspace\helmod\src
scrren eclipse
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [Guide] Linting lua and json files to spot missed errors

Post by aubergine18 »

Another alternative is the free open source ZeroBrane IDE for Lua - it has inbuilt static analysis of some kind which should provide similar linting functionality to luacheck:

https://studio.zerobrane.com/features
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [Guide] Linting lua and json files to spot missed errors

Post by aubergine18 »

bumping, still seeing lots of people not using proper editors and running in to basic syntax errors as a result.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
apriori
Filter Inserter
Filter Inserter
Posts: 277
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Re: [Guide] Linting lua and json files to spot missed errors

Post by apriori »

aubergine18 wrote:bumping, still seeing lots of people not using proper editors and running in to basic syntax errors as a result.
Hmm... I just use npp... If there's any editor/IDE that can help me in looking through "classes" (fields and methods) - tell me please.
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.
Post Reply

Return to “Modding discussion”