martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.27k stars 264 forks source link

luacheck: accessing undefined variable attr, in `lua/vis.lua` #1215

Open aimixsaka opened 2 weeks ago

aimixsaka commented 2 weeks ago

Problem

I'm building vis from source, following https://github.com/martanne/vis/wiki/Developer-Overview#luacheck, got:

...
Checking lua/vis-std.lua                          OK
Checking lua/vis.lua                              1 warning

    lua/vis.lua:291:35: accessing undefined variable attr

Checking lua/visrc.lua                            OK
...

lua/vis.lua:291

...
if style.attr then
        s = string.format("%s,%s", s, attr)
elseif style.fore then
        s = string.format("%s,fore:%s", s, style.fore)
...

Is this a mistake ?

Steps to reproduce

No response

vis version (vis -v)

vis c0d083f +curses +lua +tre +acl

Terminal name/version

No response

$TERM environment variable

No response

fischerling commented 2 weeks ago

This is definitely an error. Checking style.attr in line 290 but using the global attr in line 291 is wrong.

However, there is not a single style in the code base of vis defining a style as table. All style definitions use the string representation directly. Therefore, this mistake was probably never noticed except a user defines a style as a table. Which is unlikely because all examples are strings but possible.

Using something like in a custom user theme

lexers.STYLE_CLASS = {fore=colors.yellow, attr='bold'}

does not render the class tokens bold.