Skip to content

Commit

Permalink
Check formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanplusplus committed Dec 18, 2023
1 parent ce6fbb9 commit d0df6d9
Show file tree
Hide file tree
Showing 195 changed files with 1,067 additions and 1,552 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check Formatting

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- uses: leafo/gh-actions-lua@35bcb06abec04ec87df82e08caa84d545348536e
with:
luaVersion: 5.4

- uses: leafo/gh-actions-luarocks@e65774a6386cb4f24e293dca7fc4ff89165b64c5

- name: install
run: |
luarocks install busted
luarocks install --server=https://luarocks.org/dev luaformatter
- name: check-formatting
run: |
bin/check-formatting
git diff-index --quiet HEAD
12 changes: 6 additions & 6 deletions .lua-format
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
column_limit: 80
column_limit: 120
indent_width: 2
use_tab: false
tab_width: 4
continuation_indent_width: 4
tab_width: 2
continuation_indent_width: 2
spaces_before_call: 1
keep_simple_control_block_one_line: true
keep_simple_control_block_one_line: false
keep_simple_function_one_line: false
align_args: true
break_after_functioncall_lp: false
break_before_functioncall_rp: false
spaces_inside_functioncall_parens: false
spaces_inside_functiondef_parens: false
align_parameter: true
chop_down_parameter: false
chop_down_parameter: true
break_after_functiondef_lp: false
break_before_functiondef_rp: false
align_table_field: true
break_after_table_lb: true
break_before_table_rb: true
chop_down_table: false
chop_down_table: true
chop_down_kv_table: true
table_sep: ","
column_table_limit: 0
Expand Down
3 changes: 3 additions & 0 deletions bin/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

find exercises -iname '*.lua' -print0 | xargs --null lua-format -i
1 change: 0 additions & 1 deletion exercises/practice/accumulate/accumulate.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
return function(xs, f)

end
4 changes: 3 additions & 1 deletion exercises/practice/accumulate/accumulate_spec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
local accumulate = require('accumulate')

describe('accumulate', function()
local function square(x) return x * x end
local function square(x)
return x * x
end

it('should accumulate over an empty array', function()
assert.are.same({}, accumulate({}, square))
Expand Down
1 change: 0 additions & 1 deletion exercises/practice/acronym/acronym.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
return function(s)

end
1 change: 0 additions & 1 deletion exercises/practice/all-your-base/all-your-base.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local all_your_base = {}

all_your_base.convert = function(from_digits, from_base)

end

return all_your_base
4 changes: 2 additions & 2 deletions exercises/practice/all-your-base/all-your-base_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ describe('all-your-base', function()
end)

it('should convert no digits to 0', function()
assert.are.same({ 0 }, all_your_base.convert({ }, 2).to(10))
assert.are.same({ 0 }, all_your_base.convert({}, 2).to(10))
end)

it('should convert no digits to 0', function()
assert.are.same({ 0 }, all_your_base.convert({ }, 10).to(2))
assert.are.same({ 0 }, all_your_base.convert({}, 10).to(2))
end)

it('should convert multiple 0 digits to 0', function()
Expand Down
20 changes: 5 additions & 15 deletions exercises/practice/allergies/.meta/example.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
local allergens = {
'eggs',
'peanuts',
'shellfish',
'strawberries',
'tomatoes',
'chocolate',
'pollen',
'cats'
}
local allergens = { 'eggs', 'peanuts', 'shellfish', 'strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats' }

local function list(score)
local results = {}
Expand All @@ -21,12 +12,11 @@ end

local function allergic_to(score, which)
for _, allergen in ipairs(list(score)) do
if allergen == which then return true end
if allergen == which then
return true
end
end
return false
end

return {
list = list,
allergic_to = allergic_to
}
return { list = list, allergic_to = allergic_to }
7 changes: 1 addition & 6 deletions exercises/practice/allergies/allergies.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
local function list(score)

end

local function allergic_to(score, which)

end

return {
list = list,
allergic_to = allergic_to
}
return { list = list, allergic_to = allergic_to }
12 changes: 2 additions & 10 deletions exercises/practice/allergies/allergies_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,8 @@ describe('allergies', function()
end)

it('should be able to list all allergies', function()
assert.same({
'eggs',
'peanuts',
'shellfish',
'strawberries',
'tomatoes',
'chocolate',
'pollen',
'cats'
}, allergies.list(255))
assert.same({ 'eggs', 'peanuts', 'shellfish', 'strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats' },
allergies.list(255))
end)

it('should indicate that someone with a score of 0 is allergic to nothing', function()
Expand Down
12 changes: 7 additions & 5 deletions exercises/practice/alphametics/.meta/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ local function generate_combinations(a, n, offset)
end

function combinations(a, n, offset)
return coroutine.wrap(function() generate_combinations(a, n, offset or 0) end)
return coroutine.wrap(function()
generate_combinations(a, n, offset or 0)
end)
end

local function generate_permutations(a, n)
Expand All @@ -37,7 +39,9 @@ local function generate_permutations(a, n)
end

local function permutations(a)
return coroutine.wrap(function () generate_permutations(a, #a) end)
return coroutine.wrap(function()
generate_permutations(a, #a)
end)
end

local function unique_letters(s)
Expand Down Expand Up @@ -83,6 +87,4 @@ local function solve(puzzle)
end
end

return {
solve = solve
}
return { solve = solve }
5 changes: 1 addition & 4 deletions exercises/practice/alphametics/alphametics.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
local function solve(puzzle)

end

return {
solve = solve
}
return { solve = solve }
2 changes: 1 addition & 1 deletion exercises/practice/alphametics/alphametics_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('alphametics', function()

it('should solve long puzzles', function()
local actual = alphametics.solve('SEND + MORE == MONEY')
local expected = { S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8,Y = 2 }
local expected = { S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2 }
assert.same(expected, actual)
end)

Expand Down
28 changes: 14 additions & 14 deletions exercises/practice/anagram/.meta/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ local Anagram = {}

function Anagram:new(a_word)
self.__index = self
return setmetatable({word = a_word:lower()}, self)
return setmetatable({ word = a_word:lower() }, self)
end

local function alphagram(a_word)
local str = a_word
local t = {}
for i = 1,#str do
t[i] = str:sub(i, i) -- string library sets metatable so can be accessed in object oriented style
for i = 1, #str do
t[i] = str:sub(i, i) -- string library sets metatable so can be accessed in object oriented style
end
table.sort(t) -- sorts in place, no return value
return table.concat(t,'')
end
function Anagram:match( list )
table.sort(t) -- sorts in place, no return value
return table.concat(t, '')
end

function Anagram:match(list)
local result = {}
local t = list
for i =1,#t do
if (t[i]:lower() == self.word) then
table.insert(result, t[i])
elseif (alphagram(t[i]:lower()) == alphagram(self.word) ) then
for i = 1, #t do
if (t[i]:lower() == self.word) then
table.insert(result, t[i])
elseif (alphagram(t[i]:lower()) == alphagram(self.word)) then
table.insert(result, t[i])
end
end
end
return result
end

return Anagram
return Anagram
2 changes: 1 addition & 1 deletion exercises/practice/anagram/anagram_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('anagram', function()

it('does not detect anagram subsets', function()
local detector = Anagram:new('good')
local result = detector:match({'dog', 'goody'})
local result = detector:match({ 'dog', 'goody' })
local expected = {}
assert.are.same(expected, result)
end)
Expand Down
18 changes: 10 additions & 8 deletions exercises/practice/armstrong-numbers/.meta/example.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
local ArmstrongNumbers = {}

function ArmstrongNumbers.is_armstrong_number(number)
local digits = tostring(number)
local pow_special = function(digit) return tonumber(digit) ^ string.len(digits) end
local digits = tostring(number)
local pow_special = function(digit)
return tonumber(digit) ^ string.len(digits)
end

local sum = 0
for i = 1, string.len(digits) do
local digit = tonumber(string.sub(digits, i, i))
sum = sum + pow_special(digit)
end
local sum = 0
for i = 1, string.len(digits) do
local digit = tonumber(string.sub(digits, i, i))
sum = sum + pow_special(digit)
end

return sum == number
return sum == number
end

return ArmstrongNumbers
1 change: 0 additions & 1 deletion exercises/practice/armstrong-numbers/armstrong-numbers.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local ArmstrongNumbers = {}

function ArmstrongNumbers.is_armstrong_number(number)

end

return ArmstrongNumbers
6 changes: 5 additions & 1 deletion exercises/practice/atbash-cipher/.meta/example.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
local alphabet = 'abcdefghijklmnopqrstuvwxyz'
local decoder_ring = setmetatable({}, { __index = function() return '' end })
local decoder_ring = setmetatable({}, {
__index = function()
return ''
end
})

for i = 1, #alphabet do
decoder_ring[alphabet:sub(i, i)] = alphabet:reverse():sub(i, i)
Expand Down
1 change: 0 additions & 1 deletion exercises/practice/atbash-cipher/atbash-cipher.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
return {
encode = function(plaintext)

end
}
6 changes: 2 additions & 4 deletions exercises/practice/atbash-cipher/atbash-cipher_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ describe('atbash-cipher', function()
end)

it('should encode all letters', function()
assert.are.equal(
'gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt',
encode('The quick brown fox jumps over the lazy dog.')
)
assert.are
.equal('gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt', encode('The quick brown fox jumps over the lazy dog.'))
end)
end)
4 changes: 1 addition & 3 deletions exercises/practice/bank-account/.meta/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ function BankAccount:close(amount)
end

function BankAccount:new()
local o = setmetatable({
_value = 0
}, self)
local o = setmetatable({ _value = 0 }, self)
self.__index = self
return o
end
Expand Down
12 changes: 8 additions & 4 deletions exercises/practice/beer-song/.meta/example.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
local beer = {}

local GENERIC_VERSE = 'N bottles of beer on the wall, N bottles of beer.\nTake one down and pass it around, M bottles of beer on the wall.\n'
local GENERIC_VERSE =
'N bottles of beer on the wall, N bottles of beer.\nTake one down and pass it around, M bottles of beer on the wall.\n'

local VERSE_FOR_0 = 'No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n'
local VERSE_FOR_0 =
'No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n'

function beer.verse(number)
if number == 0 then
Expand All @@ -13,7 +15,7 @@ function beer.verse(number)
a_verse = a_verse:gsub('1 bottles', '1 bottle')
end
if number == 1 then
a_verse= a_verse:gsub('one', 'it'):gsub('0 bottles', 'no more bottles')
a_verse = a_verse:gsub('one', 'it'):gsub('0 bottles', 'no more bottles')
end
return a_verse
end
Expand All @@ -23,7 +25,9 @@ function beer.sing(start, finish)
local verses = ''
for i = start, finish, -1 do
verses = verses .. beer.verse(i)
if i ~= finish then verses = verses .. '\n' end
if i ~= finish then
verses = verses .. '\n'
end
end
return verses
end
Expand Down
2 changes: 0 additions & 2 deletions exercises/practice/beer-song/beer-song.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local beer = {}

function beer.verse(number)

end

function beer.sing(start, finish)

end

return beer
Loading

0 comments on commit d0df6d9

Please sign in to comment.