Skip to content

Commit eb2ec2c

Browse files
committed
lint fixes
1 parent 8e37c33 commit eb2ec2c

7 files changed

+86
-67
lines changed

.luacheckrc

+1-1
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/text_editor_control.lua

+44-26
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

+8-8
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)

src/hotkey_script_palettes.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ function configure_palette(palette_number, index_num)
518518
end
519519
end)
520520
add_item:AddHandleCommand(function() -- ADD PALETTE or SCRIPT
521-
local new_name, new_script, hotkey
522-
local new_element, ok = {}
521+
local new_name, new_script, hotkey, ok
522+
local new_element = {}
523523
if is_macro then
524524
new_element = { name = "", key = "?" }
525525
ok, new_name, hotkey = user_enters_text(new_element, "Create New Palette")
@@ -627,8 +627,8 @@ function main()
627627
end
628628
configuration.get_user_settings(script_name, config, true)
629629
palettes = cjson.decode(config.palettes)
630-
local finished, ok = false
631-
local palette_number, item_number
630+
local finished = false
631+
local palette_number, item_number, ok
632632

633633
while not finished do -- keep circling until user makes a choice or cancels
634634
ok, palette_number = choose_palette(0) -- main palette

src/library/note_entry.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Calculates the handle offset for an expression with "Left of Primary Notehead" h
174174
@ entry (FCNoteEntry) the entry to calculate from
175175
: (number) offset from left side of primary notehead rectangle
176176
]]
177-
function note_entry.calc_left_of_primary_notehead()
177+
function note_entry.calc_left_of_primary_notehead(_entry)
178178
return 0
179179
end
180180

src/lyrics_baseline_spacing.lua

+23-22
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ function lyrics_spacing(title)
5757
end
5858
--
5959

60-
local function add_ctrl(dialog, ctrl_type, text, x, y, h, w) -- luacheck: ignore dialog
60+
local function add_ctrl(dialog, ctrl_type, text, x, y, h, w) -- luacheck: ignore dialog
6161
str.LuaString = tostring(text)
62-
local ctrl = ""
62+
local ctrl
6363
if ctrl_type == "checkbox" then
6464
ctrl = dialog:CreateCheckbox(x, y)
6565
elseif ctrl_type == "edit" then
@@ -68,7 +68,7 @@ function lyrics_spacing(title)
6868
ctrl = dialog:CreateStatic(x, y)
6969
end
7070
if ctrl_type == "edit" then
71-
ctrl:SetHeight(h-2)
71+
ctrl:SetHeight(h - 2)
7272
ctrl:SetWidth(w - col_gap)
7373
else
7474
ctrl:SetHeight(h)
@@ -77,24 +77,25 @@ function lyrics_spacing(title)
7777
ctrl:SetText(str)
7878
return ctrl
7979
end
80+
8081

8182
-- local control = add_ctrl(dialog, "static", "TESTING!", col[1], row[2], row_h, col_w, 0, 0)
82-
local verse_static = add_ctrl(dialog, "static", "All Lyrics", col[3], row[1], row_h, col_w, 0, 0)
83-
local chorus_static = add_ctrl(dialog, "static", "", col[4], row[1], row_h, col_w, 0, 0)
84-
local section_static = add_ctrl(dialog, "static", "", col[5], row[1], row_h, col_w, 0, 0)
83+
local verse_static = add_ctrl(dialog, "static", "All Lyrics", col[3], row[1], row_h, col_w)
84+
local chorus_static = add_ctrl(dialog, "static", "", col[4], row[1], row_h, col_w)
85+
local section_static = add_ctrl(dialog, "static", "", col[5], row[1], row_h, col_w)
8586
--
86-
add_ctrl(dialog, "static", "Lyric 1 baseline:", col[1] + 31, row[2], row_h, col_w * 2, 0, 0)
87-
local verse1_edit = add_ctrl(dialog, "edit", verse1_start, col[3], row[2], row_h, col_w, 0, 0)
88-
local chorus1_edit = add_ctrl(dialog, "edit", chorus1_start, col[4], row[2], row_h, col_w, 0, 0)
89-
local section1_edit = add_ctrl(dialog, "edit", section1_start, col[5], row[2], row_h, col_w, 0, 0)
87+
add_ctrl(dialog, "static", "Lyric 1 baseline:", col[1] + 31, row[2], row_h, col_w * 2)
88+
local verse1_edit = add_ctrl(dialog, "edit", verse1_start, col[3], row[2], row_h, col_w)
89+
local chorus1_edit = add_ctrl(dialog, "edit", chorus1_start, col[4], row[2], row_h, col_w)
90+
local section1_edit = add_ctrl(dialog, "edit", section1_start, col[5], row[2], row_h, col_w)
9091
--
91-
add_ctrl(dialog, "static", "Gap:", col[2] + 29, row[3], row_h, col_w, 0, 0)
92-
local verse_gap_edit = add_ctrl(dialog, "edit", verse_gap, col[3], row[3], row_h, col_w, 0, 0)
93-
local chorus_gap_edit = add_ctrl(dialog, "edit", chorus_gap, col[4], row[3], row_h, col_w, 0, 0)
94-
local section_gap_edit = add_ctrl(dialog, "edit", section_gap, col[5], row[3], row_h, col_w, 0, 0)
92+
add_ctrl(dialog, "static", "Gap:", col[2] + 29, row[3], row_h, col_w)
93+
local verse_gap_edit = add_ctrl(dialog, "edit", verse_gap, col[3], row[3], row_h, col_w)
94+
local chorus_gap_edit = add_ctrl(dialog, "edit", chorus_gap, col[4], row[3], row_h, col_w)
95+
local section_gap_edit = add_ctrl(dialog, "edit", section_gap, col[5], row[3], row_h, col_w)
9596
--
96-
add_ctrl(dialog, "static", "Edit all:", col[2] + 14, row[4], row_h, col_w, 0, 0)
97-
local all_lyrics_check = add_ctrl(dialog, "checkbox", "", col[3], row[4], row_h, col_w * 2, 0, 0)
97+
add_ctrl(dialog, "static", "Edit all:", col[2] + 14, row[4], row_h, col_w)
98+
local all_lyrics_check = add_ctrl(dialog, "checkbox", "", col[3], row[4], row_h, col_w * 2)
9899

99100
dialog:CreateOkButton()
100101
dialog:CreateCancelButton()
@@ -111,18 +112,18 @@ function lyrics_spacing(title)
111112
end
112113

113114
verse1_edit:GetText(str)
114-
verse1_start = tonumber(str.LuaString)
115+
verse1_start = tonumber(str.LuaString) or 0
115116
chorus1_edit:GetText(str)
116-
chorus1_start = tonumber(str.LuaString)
117+
chorus1_start = tonumber(str.LuaString) or 0
117118
section1_edit:GetText(str)
118-
section1_start = tonumber(str.LuaString)
119+
section1_start = tonumber(str.LuaString) or 0
119120
--
120121
verse_gap_edit:GetText(str)
121-
verse_gap = tonumber(str.LuaString)
122+
verse_gap = tonumber(str.LuaString) or 0
122123
chorus_gap_edit:GetText(str)
123-
chorus_gap = tonumber(str.LuaString)
124+
chorus_gap = tonumber(str.LuaString) or 0
124125
section_gap_edit:GetText(str)
125-
section_gap = tonumber(str.LuaString)
126+
section_gap = tonumber(str.LuaString) or 0
126127
--
127128
for i = 1, 100, 1 do
128129
baseline_verse:LoadDefaultForLyricNumber(finale.BASELINEMODE_LYRICSVERSE,i)

0 commit comments

Comments
 (0)