Linting
- 4 minutes read - 723 wordsEarlier, I asked if anyone knew of any resources about code linting. A couple of people (hi, @jonveal and @iouwon) asked what I meant and what I was up to.
I thought I’d provide some background to what I’m trying to do. If you’re interested in the technical detail, it’s in here. If not, then just feel free to follow along and watch while a very small and silly idea spins wildly out of control.
So, I’ve been doing a fair bit of messing around with games lately. This got me thinking that a game could be another way to tell a story, or to show someone a small scene in an interesting way. And so I decided that I’d look into how to do that, and eventually I stumbled across a thing called Twine, which is an open-source graphical tool to build basic games. As long as what you’re trying to build is a simple text-based HTML game, this is probably the best tool to use.
And so I set about messing about with Twine games. After a while, I realised I wanted to learn how to use the tool, so I set about trying to convert a random adventure book I found online called “Escape from Tenopia” into this format. Because, why not, eh?
Quickly I realised that trying to do this with a GUI tool was madness. I’m so much better with a text editor and command-line tooling. So I searched some more and stumbled across a tool called twee2. Just the job, and after a brief digression fixing why it installed on one of my machines but not the other (conflict with something Homebrew installed that was a dependency of something else that was a dependency of something I wanted), I got it working.
So now I can write source code in tw2 format, and use twee2 to convert from the source code into the finished HTML representation. All good. The games are basically a set of passages and links between the passages. The basic idea is remiscent of those old adventure books that had you flipping between pages with text like “If you fight the dragon, turn to page 42. If you flee, turn to page 86.”.
Except that twee2 does not emit error messages apart from basic mechanical problems. So, if you ask it to convert a file that doesn’t exist, it complains. But it will happily convert files with all kinds of different problems, such as syntax errors, unclosed strings, mismatched brackets, and so on. It will even, unhelpfully, use lamentably inconsistent rules about when line breaks are significant and when they’re not, meaning that your finished game can look quite wonky. (Basically, in text passages, line breaks are echoed in the final game, unless you wrap the paragraph in curly brackets, in which case line breaks are ignored, unless inside double square brackets, which signifies a link, in which case they’re are passed through again. Argh!) You also get run-time diagnostics for broken links, messed up macro formatting and so on. For someone brought up on relatively helpful compiler errors, this isn’t a great experience.
And so, I decided to attack this problem. I first managed to build a little bit of code that would map the passages and links with Graphviz, the idea being that I could look at the graph and see what was going on. This worked, except that I ended up with a diagram that was something like two meters by one and a half. I’ve got rather a lot of passages. Still, it’s nice to know that Graphviz can handle anything I throw at it. Looking at that proved rather unhelpful.
So I decided I’d move on to looking at the graph output to identify nodes that aren’t reachable from the start, nodes that don’t have any valid exits, nodes referred to only once, and so on. And there are certain things that the documentation warns you about not doing that I wanted to check for. And then I wanted to look for quote marks that are out of place, and so on. This is where I got bogged down and asked for help.
So, that’s where I’ve got to — does anyone have any ideas? If so, feel free to comment below, or ping me on Twitter. Many thanks.