Skip to content

Commit 7b6bbc1

Browse files
authored
Merge pull request finale-lua#673 from rpatters1/RGP-more-lint
lint fixes
2 parents 8e37c33 + faf40c3 commit 7b6bbc1

9 files changed

+107
-88
lines changed

.luacheckrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- luacheck: ignore 131
2-
include_files = { "src/**/*.lua"}
2+
include_files = { "src/**/*.lua", "samples/**/*.lua"}
33
exclude_files = {
44
"mobdebug.lua",
55
"src/lunajson/**/*.lua",

samples/data_list_control.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ x_inc = 70
9090
local toggle_row_colors = dlg:CreateButton(x, y)
9191
toggle_row_colors:SetText(finale.FCString("row colors"))
9292
toggle_row_colors:SetWidth(x_inc - x_sep)
93-
dlg:RegisterHandleControlEvent(toggle_row_colors, function(control)
93+
dlg:RegisterHandleControlEvent(toggle_row_colors, function(_control)
9494
data_list.AlternatingBackgroundRowColors = not data_list.AlternatingBackgroundRowColors
9595
data_list:SetKeyboardFocus()
9696
end)
9797
x = x + x_inc
9898
local select_row_random = dlg:CreateButton(x, y)
9999
select_row_random:SetText(finale.FCString("random row"))
100100
select_row_random:SetWidth(x_inc - x_sep)
101-
dlg:RegisterHandleControlEvent(select_row_random, function(control)
101+
dlg:RegisterHandleControlEvent(select_row_random, function(_control)
102102
local random_row_index = math.floor(math.random() * numrows)
103103
data_list:SelectLine(random_row_index)
104104
data_list:SetKeyboardFocus()
@@ -107,10 +107,10 @@ x = x + x_inc
107107
local unsel_first = dlg:CreateButton(x, y)
108108
unsel_first:SetText(finale.FCString("unsel 1st"))
109109
unsel_first:SetWidth(x_inc - x_sep)
110-
dlg:RegisterHandleControlEvent(unsel_first, function(control)
111-
for x = 0, data_list:GetCount() - 1 do
112-
if data_list:IsLineSelected(x) then
113-
data_list:UnselectLine(x)
110+
dlg:RegisterHandleControlEvent(unsel_first, function(_control)
111+
for rowx = 0, data_list:GetCount() - 1 do
112+
if data_list:IsLineSelected(rowx) then
113+
data_list:UnselectLine(rowx)
114114
break
115115
end
116116
end
@@ -120,12 +120,12 @@ x = x + x_inc
120120
local unsel_all = dlg:CreateButton(x, y)
121121
unsel_all:SetText(finale.FCString("unsel all"))
122122
unsel_all:SetWidth(x_inc - x_sep)
123-
dlg:RegisterHandleControlEvent(unsel_all, function(control)
123+
dlg:RegisterHandleControlEvent(unsel_all, function(_control)
124124
data_list:UnselectAll()
125125
data_list:SetKeyboardFocus()
126126
end)
127-
x = x + x_inc
128-
y = y + y_inc
127+
x = x + x_inc -- luacheck: ignore
128+
y = y + y_inc -- luacheck: ignore
129129
-- registrations
130130
local function on_item_selected()
131131
local index = data_list:GetSelectedLine()
@@ -139,23 +139,23 @@ local function on_item_selected()
139139
end
140140
end
141141
end
142-
dlg:RegisterHandleListDoubleClick(function(control)
142+
dlg:RegisterHandleListDoubleClick(function(_control)
143143
on_item_selected()
144144
end)
145-
dlg:RegisterHandleListEnterKey(function(control)
145+
dlg:RegisterHandleListEnterKey(function(_control)
146146
on_item_selected()
147147
return true
148148
end)
149-
dlg:RegisterHandleKeyboardCommand(function(control, character)
149+
dlg:RegisterHandleKeyboardCommand(function(_control, character)
150150
local charstr = utf8.char(character)
151151
show_kbd_command:SetText(finale.FCString(charstr))
152152
return charstr == "N" or charstr == "W" -- eat "N" and "W"
153153
end)
154-
dlg:RegisterHandleDataListSelect(function(control, line_index)
154+
dlg:RegisterHandleDataListSelect(function(_control, line_index)
155155
show_selection:SetText(finale.FCString("selected " .. line_index .. "(" .. data_list:GetSelectedLine() .. ")"))
156156
end)
157157
if usecheckboxes then
158-
dlg:RegisterHandleDataListCheck(function(control, line_index, state)
158+
dlg:RegisterHandleDataListCheck(function(_control, line_index, state)
159159
local state_str = state and "checked " or "unchecked "
160160
show_checkbox:SetText(finale.FCString(state_str .. line_index))
161161
end)
@@ -171,19 +171,19 @@ dlg:ExecuteModal(nil)
171171

172172
local checked_str = ""
173173
local selected_str = ""
174-
for x = 0, data_list:GetCount() - 1 do
175-
if data_list:IsLineSelected(x) then
174+
for rowx = 0, data_list:GetCount() - 1 do
175+
if data_list:IsLineSelected(rowx) then
176176
if #selected_str > 0 then
177177
selected_str = selected_str .. ", "
178178
end
179-
selected_str = selected_str .. x
179+
selected_str = selected_str .. rowx
180180
end
181-
local row = data_list:GetItemAt(x)
181+
local row = data_list:GetItemAt(rowx)
182182
if row.Check then
183183
if #checked_str > 0 then
184184
checked_str = checked_str .. ", "
185185
end
186-
checked_str = checked_str .. x
186+
checked_str = checked_str .. rowx
187187
end
188188
end
189189
if finenv.ConsoleIsAvailable then

samples/modeless_dialog.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ local function create_dialog()
6565
end)
6666

6767
dlg:RegisterHandleControlEvent(do_something,
68-
function(control)
68+
function(_control)
6969
local grp1 = global_dialog:GetControl("radio1")
7070
print("radio group 1 selected item: " .. grp1:GetSelectedItem())
7171
local grp2 = global_dialog:GetControl("radio2")
@@ -128,7 +128,7 @@ local function create_dialog()
128128
)
129129

130130
dlg:RegisterOSMenuCommandExecuted(function(menucmd, cmdtype)
131-
local cmdstr = ""
131+
local cmdstr
132132
if finenv.UI():IsOnMac() then
133133
cmdstr = string.char(
134134
bit32.extract(menucmd, 24, 8),

samples/text_editor_control.lua

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function plugindef()
22
finaleplugin.RequireDocument = true -- Load Text Metrics crashes Finale (and doesn't work) if no document is open
3-
finaleplugin.MinJWLuaVersion = 0.68
3+
finaleplugin.MinJWLuaVersion = 0.71
44
return "0--text_editor_control.lua"
55
end
66

@@ -41,7 +41,7 @@ print(edit_text:GetControlID())
4141
local tabstop_width = calc_tab_width(edit_font, 4)
4242
edit_text:SetTabstopWidth(tabstop_width)
4343
edit_text:SetAutomaticEditing(true)
44-
dlg:RegisterHandleControlEvent(edit_text, function(control)
44+
dlg:RegisterHandleControlEvent(edit_text, function(_control)
4545
-- local finale.FCString = control:CreateEnigmaString()
4646
-- print("Got Enigma String: "..finale.FCString.LuaString)
4747
end)
@@ -53,7 +53,7 @@ local non_bmp_text = [[𝒜𝓈 𝒸𝒽
5353
𝓊𝓃𝓈𝑒
5454
𝓉𝓈 𝒾𝓃 𝓉𝒽𝑒 𝓋𝒶𝓈𝓉 𝒾𝓃𝓉𝓸 𝓉𝒽𝑒 𝓊𝓃𝓀𝓃𝑜𝓌𝓃
5555
𝒾𝓈 𝒶 𝒷𝑒𝒶𝓊𝓉𝒾𝒻𝓊𝓁 𝓂𝒶𝑔𝒾𝒸 𝑜𝒻 𝒸𝒽𝒶𝓇𝒶𝒸𝓉𝑒𝓇𝓈.]]
56-
local long_line_text = "This is a test. Now is the time for a very long string to come to the aid and comfort of their friends and enemies to create a very, very long string."
56+
local long_line_text = "This is a test. Now is the time for a very long string to come to the aid and comfort of their friends and enemies to create a very, very long string." -- luacheck: ignore
5757
local rtf_text = [[{\rtf1\ansi
5858
This is some {\b bold} text.
5959
This is some {\i italic} text.
@@ -80,40 +80,41 @@ dlg:RegisterHandleControlEvent(enabler, function(control)
8080
end)
8181
local visifier = dlg:CreateButton(90, 200)
8282
visifier:SetText(finale.FCString("Visible"))
83-
dlg:RegisterHandleControlEvent(visifier, function(control)
83+
dlg:RegisterHandleControlEvent(visifier, function(_control)
8484
edit_text:SetVisible(not edit_text:GetVisible())
8585
enabler:SetVisible(not enabler:GetVisible())
8686
edit_text:SetKeyboardFocus()
8787
end)
8888
local readonly = dlg:CreateButton(170, 200)
8989
readonly:SetText(finale.FCString("Readonly"))
90-
dlg:RegisterHandleControlEvent(readonly, function(control)
90+
dlg:RegisterHandleControlEvent(readonly, function(_control)
9191
edit_text:SetReadOnly(not edit_text:GetReadOnly())
9292
edit_text:SetKeyboardFocus()
9393
end)
9494
local sizer = dlg:CreateButton(250, 200)
9595
sizer:SetText(finale.FCString("Size"))
96-
dlg:RegisterHandleControlEvent(sizer, function(control)
97-
if not glob_size then glob_size = 10 end
98-
glob_size = glob_size * 1.25
99-
edit_text:SetFontSizeForSelection(glob_size)
96+
local size_incrementer
97+
dlg:RegisterHandleControlEvent(sizer, function(_control)
98+
if not size_incrementer then size_incrementer = 10 end
99+
size_incrementer = size_incrementer * 1.25
100+
edit_text:SetFontSizeForSelection(size_incrementer)
100101
end)
101102
local copier = dlg:CreateButton(330, 200)
102103
copier:SetText(finale.FCString("Copy"))
103-
dlg:RegisterHandleControlEvent(copier, function(control)
104+
dlg:RegisterHandleControlEvent(copier, function(_control)
104105
edit_text:TextToClipboard()
105106
end)
106107
local replacer = dlg:CreateButton(10, 225)
107108
replacer:SetText(finale.FCString("Replace"))
108-
dlg:RegisterHandleControlEvent(replacer, function(control)
109+
dlg:RegisterHandleControlEvent(replacer, function(_control)
109110
if not edit_text:ReplaceSelectedText(finale.FCString("*** replaced\ntext ***")) then
110111
print("ReplaceSelectedText failed because no selected text.")
111112
end
112113
edit_text:SetKeyboardFocus()
113114
end)
114115
local restorer = dlg:CreateButton(90, 225)
115116
restorer:SetText(finale.FCString("Restore"))
116-
dlg:RegisterHandleControlEvent(restorer, function(control)
117+
dlg:RegisterHandleControlEvent(restorer, function(_control)
117118
-- local vers1 = finale.FCVerseLyricsText()
118119
-- if not vers1:Load(1) then print("lyrics load failed") end
119120
-- local versstr = vers1:CreateString()
@@ -125,21 +126,21 @@ dlg:RegisterHandleControlEvent(restorer, function(control)
125126
end)
126127
local inserter = dlg:CreateButton(170, 225)
127128
inserter:SetText(finale.FCString("Insert"))
128-
dlg:RegisterHandleControlEvent(inserter, function(control)
129+
dlg:RegisterHandleControlEvent(inserter, function(_control)
129130
edit_text:InsertTextAtCursor(finale.FCString("*** inserted text ***"))
130131
edit_text:SetKeyboardFocus()
131132
end)
132133
local selectall = dlg:CreateButton(250, 225)
133134
selectall:SetText(finale.FCString("SelAll"))
134-
dlg:RegisterHandleControlEvent(selectall, function(control)
135+
dlg:RegisterHandleControlEvent(selectall, function(_control)
135136
local range = finale.FCRange()
136137
edit_text:GetTotalTextRange(range)
137138
edit_text:SetSelection(range)
138139
edit_text:SetKeyboardFocus()
139140
end)
140141
local tabber = dlg:CreateButton(10, 250)
141142
tabber:SetText(finale.FCString("Tabs"))
142-
dlg:RegisterHandleControlEvent(tabber, function(control)
143+
dlg:RegisterHandleControlEvent(tabber, function(_control)
143144
tabstop_width = tabstop_width - 12
144145
if tabstop_width < 12 then
145146
tabstop_width = 12
@@ -171,7 +172,7 @@ dlg:RegisterHandleControlEvent(italicer, function(control)
171172
local locinfo = dlg:CreateButton(330, 250)
172173
locinfo:SetText(finale.FCString("Loc."))
173174
locinfo:SetWidth(70)
174-
dlg:RegisterHandleControlEvent(locinfo, function(control)
175+
dlg:RegisterHandleControlEvent(locinfo, function(_control)
175176
local selrange = finale.FCRange()
176177
edit_text:GetSelection(selrange)
177178
local posrange = finale.FCRange()
@@ -195,7 +196,7 @@ wordonly:SetWidth(70)
195196
local igncase = dlg:CreateCheckbox(250, 275)
196197
igncase:SetText(finale.FCString("Ign Case"))
197198
igncase:SetWidth(70)
198-
dlg:RegisterHandleControlEvent(finder, function(control)
199+
dlg:RegisterHandleControlEvent(finder, function(_control)
199200
local str = finale.FCString()
200201
findtext:GetText(str)
201202
local options = 0
@@ -223,26 +224,44 @@ dlg:RegisterHandleControlEvent(finder, function(control)
223224
local dumper = dlg:CreateButton(330, 275)
224225
dumper:SetText(finale.FCString("DumpText"))
225226
dumper:SetWidth(70)
226-
dlg:RegisterHandleControlEvent(dumper, function(control)
227+
dlg:RegisterHandleControlEvent(dumper, function(_control)
227228
local range = finale.FCRange()
228-
if not edit_text:GetSelection(range) then
229+
edit_text:GetSelection(range)
230+
if range.Length == 0 then
229231
edit_text:GetTotalTextRange(range)
230232
end
233+
local raw_string = finale.FCString()
234+
edit_text:GetTextInRange(raw_string, range)
235+
print("Got Raw String: " .. raw_string.LuaString)
236+
local utf16_string = finale.FCString()
237+
local i = range.Start
238+
while (i < range.End) do
239+
local next_char = edit_text:CreateCharacterAtIndex(i)
240+
if not next_char then
241+
print("GetCharacterAtIndex failed")
242+
break
243+
end
244+
utf16_string:AppendString(next_char)
245+
i = i + next_char.Length
246+
end
247+
if utf16_string.Length > 0 then
248+
print("Got Utf16 String: " .. utf16_string.LuaString)
249+
end
231250
local fcstr = edit_text:CreateEnigmaString(range)
232251
print("Got Enigma String: "..fcstr.LuaString)
233252
end)
234253
local colorizer = dlg:CreateButton(10, 300)
235254
colorizer:SetText(finale.FCString("Sel2Red"))
236255
colorizer:SetWidth(90)
237-
dlg:RegisterHandleControlEvent(colorizer, function(control)
256+
dlg:RegisterHandleControlEvent(colorizer, function(_control)
238257
local range = finale.FCRange()
239258
edit_text:GetSelection(range)
240259
edit_text:SetTextColorInRange(247, 0, 0, range)
241260
end)
242261
local find2color = dlg:CreateButton(110, 300)
243262
find2color:SetText(finale.FCString("Find2Green"))
244263
find2color:SetWidth(90)
245-
dlg:RegisterHandleControlEvent(find2color, function(control)
264+
dlg:RegisterHandleControlEvent(find2color, function(_control)
246265
local str = finale.FCString()
247266
findtext:GetText(str)
248267
local options = 0
@@ -264,7 +283,7 @@ dlg:RegisterHandleControlEvent(find2color, function(control)
264283
local colorreporter = dlg:CreateButton(210, 300)
265284
colorreporter:SetText(finale.FCString("Color Starts"))
266285
colorreporter:SetWidth(90)
267-
dlg:RegisterHandleControlEvent(colorreporter, function(control)
286+
dlg:RegisterHandleControlEvent(colorreporter, function(_control)
268287
local ranges = edit_text:CreateTextColorChanges()
269288
if not ranges then
270289
print("No colors returned.")
@@ -281,7 +300,7 @@ dlg:RegisterHandleControlEvent(colorreporter, function(control)
281300
end)
282301
local colorreverter = dlg:CreateButton(310, 300)
283302
colorreverter:SetText(finale.FCString("Default"))
284-
dlg:RegisterHandleControlEvent(colorreverter, function(control)
303+
dlg:RegisterHandleControlEvent(colorreverter, function(_control)
285304
edit_text:SetFont(finale.FCFontInfo("Arial", 12))
286305
--local range = finale.FCRange()
287306
--edit_text:GetTotalTextRange(range)
@@ -296,11 +315,10 @@ curr_sel:SetWidth(200)
296315
dlg:RegisterTextSelectionChanged(function(control)
297316
local fstr = finale.FCString()
298317
control:GetSelectedText(fstr) -- if no selection, fstr is unchanged and empty
299-
local seltext = fstr.LuaString
300-
--print("Selected Text: "..seltext)
318+
--print("Selected Text: "..fstr.LuaString)
301319
curr_sel:SetText(fstr)
302320
end)
303-
local ok = dlg:CreateOkButton()
321+
dlg:CreateOkButton()
304322
dlg:RegisterInitWindow(function()
305323
if init_with_rtf then
306324
edit_text:SetFont(finale.FCFontInfo("Arial", 12))

src/hairpin_creator.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ local function extend_region_by_EDU(region, add_duration)
132132
end
133133

134134
local function duration_gap(measureA, positionA, measureB, positionB)
135-
local diff, duration = 0
135+
local diff = 0
136136
if measureA == measureB then -- simple EDU offset
137137
diff = positionB - positionA
138138
elseif measureB < measureA then
139-
duration = - positionB
139+
local duration = - positionB
140140
while measureB < measureA do -- add up measures until they meet
141141
duration = duration + measure_width(measureB)
142142
measureB = measureB + 1
143143
end
144144
diff = - duration - positionA
145145
elseif measureA < measureB then
146-
duration = - positionA
146+
local duration = - positionA
147147
while measureA < measureB do
148148
duration = duration + measure_width(measureA)
149149
measureA = measureA + 1
@@ -245,15 +245,15 @@ end
245245

246246
local function lowest_note_element(rgn)
247247
local lowest_vert = -13 * 12 -- at least to bottom of staff
248-
local current_measure, top_of_staff, bottom_pos = 0, 0
248+
local current_measure, top_of_staff = 0, 0
249249

250250
for entry in eachentry(rgn) do
251251
if entry:IsNote() then
252252
if current_measure ~= entry.Measure then -- new measure, new top of staff vertical
253253
current_measure = entry.Measure
254254
top_of_staff = calc_top_of_staff(current_measure, entry.Staff)
255255
end
256-
bottom_pos = (entry:CalcLowestStaffPosition() * 12) - config.below_note_cushion
256+
local bottom_pos = (entry:CalcLowestStaffPosition() * 12) - config.below_note_cushion
257257
if entry:CalcStemUp() then -- stem up
258258
if lowest_vert > bottom_pos then
259259
lowest_vert = bottom_pos
@@ -548,13 +548,13 @@ function create_dialog_box()
548548
}
549549

550550
local dialog = mixin.FCXCustomLuaWindow():SetTitle("Hairpin Creator Configuration")
551-
local y_step, y_current = 20
551+
local y_step = 20
552552
local max_text_width = 385
553553
local x_offset = {0, 130, 155, 190}
554554
local mac_offset = finenv.UI():IsOnMac() and 3 or 0 -- horizontal offset for Mac Edit boxes
555555

556556
for i, v in ipairs(dialog_options) do -- run through config parameters
557-
y_current = y_step * i
557+
local y_current = y_step * i
558558
local msg = string.gsub(v[1], "_", " ")
559559
if boolean_options[v[1]] then -- checkboxes
560560
dialog:CreateCheckbox(x_offset[1], y_current, v[1]):SetText(msg):SetWidth(x_offset[3]):SetCheck(config[v[1]] and 1 or 0)
@@ -573,7 +573,7 @@ function create_dialog_box()
573573
end
574574

575575
-- measurement unit options
576-
y_current = (#dialog_options + 1.6) * y_step
576+
local y_current = (#dialog_options + 1.6) * y_step
577577
dialog:CreateStatic(x_offset[2] - 40, y_current):SetText("Units:")
578578
dialog:SetMeasurementUnit(config.measurement_unit)
579579
dialog:CreateMeasurementUnitPopup(x_offset[2], y_current)

0 commit comments

Comments
 (0)