Skip to content

Commit

Permalink
Update multline string format
Browse files Browse the repository at this point in the history
- Properly indents a multiline string, and trims as necessary
  • Loading branch information
JohnnyMorganz committed Dec 18, 2020
1 parent 4675254 commit 0094f40
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 223 deletions.
25 changes: 23 additions & 2 deletions luafmt-lib/src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ enum FormatTokenType {
TrailingTrivia,
}

fn get_indent_string(indent_type: &IndentType, indent_level: usize) -> String {
match indent_type {
IndentType::Tabs => "\t".repeat(indent_level - 1),
IndentType::Spaces => " ".repeat(indent_level - 1),
}
}

fn get_line_ending_character(line_endings: &LineEndings) -> String {
match line_endings {
LineEndings::Unix => String::from("\n"),
Expand Down Expand Up @@ -113,9 +120,23 @@ impl CodeFormatter {
fn format_multi_line_comment_string(&self, comment: String) -> String {
let comment = comment.trim();
let mut formatted_comment = get_line_ending_character(&self.config.line_endings); // Put starting braces seperately on its own line
formatted_comment += comment.trim_end_matches('-'); // Remove any "--" already present before the closing braces: TODO: Do we want to do this?

// Split multiline comment into its individual lines
// We want to take each line, trim any whitespace, and indent it one greater than the current indent level
let comment = comment
.lines()
.map(|line| {
// Check to see if the line is just whitespace
match line.split_whitespace().collect::<String>().is_empty() {
true => String::from(line.trim()), // If its just whitespace, return an empty line
false => get_indent_string(&self.config.indent_type, &self.indent_level + 1) + line.trim() // If not, trim the line and indent it
}
})
.collect::<Vec<String>>()
.join(&get_line_ending_character(&self.config.line_endings));

formatted_comment += &comment; // Add in the multiline comment
formatted_comment += &get_line_ending_character(&self.config.line_endings); // Put closing braces on a new line
formatted_comment += "--"; // Add "--" before closing braces: TODO: Do we want to do this?

formatted_comment
}
Expand Down
4 changes: 2 additions & 2 deletions luafmt-lib/tests/files/comments/output.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[
Testing this
--]]
Testing this
]]
local function foo(bar, baz)
print(bar, baz)
end -- this is a nice function
Expand Down
268 changes: 134 additions & 134 deletions luafmt-lib/tests/files/large-example-2/output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,207 +4,207 @@ adminlist = { "Person299" } -- Add in the names of the people you want to be abl
bannedlist = { "someoneyouhate", "noob" } -- If you want someone not to be able to enter your place, put thier name in here.
texture = "" -- If you want someone wearing a certain t-shirt to be an admin, put the t-shirt's texture in here.
--[[
I update this command script alot, so if you want to get the newest version of the script, go to http://www.roblox.com/Item.aspx?ID=5277383 every once in a while.
I update this command script alot, so if you want to get the newest version of the script, go to http://www.roblox.com/Item.aspx?ID=5277383 every once in a while.
If theres anything you think this command script needs, just message me (Person299) and i might put it in. :)
And also, if you find any bugs, report them to me.
If theres anything you think this command script needs, just message me (Person299) and i might put it in. :)
And also, if you find any bugs, report them to me.
The commands are,
The commands are,
commands
Shows a list of all the commands
commands
Shows a list of all the commands
fix
If the command script breaks for you, say this to fix it
fix
If the command script breaks for you, say this to fix it
kill/Person299
kills Person299
kill/Person299
kills Person299
loopkill/Person299
Repeatedly kills Person299 when he respawns
loopkill/Person299
Repeatedly kills Person299 when he respawns
unloopkill/Person299
Undos loopkill/
unloopkill/Person299
Undos loopkill/
heal/Person299
Returns Person299 to full health
heal/Person299
Returns Person299 to full health
damage/Person299/50
Makes Person299's character take 50 damage
damage/Person299/50
Makes Person299's character take 50 damage
health/Person299/999999
Makes Person299's MaxHealth and Health 999999
health/Person299/999999
Makes Person299's MaxHealth and Health 999999
kick/Person299
Removes Person299 from the game, cannot be used by admin/ed people
kick/Person299
Removes Person299 from the game, cannot be used by admin/ed people
ban/Person299
Removes Person299 from the game and keeps him from reenterring, cannot be used by admin/ed people
ban/Person299
Removes Person299 from the game and keeps him from reenterring, cannot be used by admin/ed people
bannedlist
Shows a list of everyone banned
bannedlist
Shows a list of everyone banned
unban/Person299
Unbans Person299
unban/Person299
Unbans Person299
explode/Person299
Explodes Person299's character
explode/Person299
Explodes Person299's character
rocket/Person299
Straps a rocket onto Person299's back
rocket/Person299
Straps a rocket onto Person299's back
removetools/Person299
Removes all of Person299's tools.
removetools/Person299
Removes all of Person299's tools.
givetools/Person299
Gives Person299 all the tools in StarterPack
givetools/Person299
Gives Person299 all the tools in StarterPack
givebtools/Person299
Gives Person299 the building tools
givebtools/Person299
Gives Person299 the building tools
sit/Person299
Makes Person299 sit
sit/Person299
Makes Person299 sit
part/4/1/2
Makes a part with the given dimensions appear over your character
part/4/1/2
Makes a part with the given dimensions appear over your character
respawn/Person299
Makes Person299's character respawn
respawn/Person299
Makes Person299's character respawn
jail/Person299
Makes a lil jail cell around Person299's character
jail/Person299
Makes a lil jail cell around Person299's character
unjail/Person299
Undos jail/
unjail/Person299
Undos jail/
punish/Person299
Puts Person299's character in game.Lighting
punish/Person299
Puts Person299's character in game.Lighting
unpunish/Person299
Undos punish/
unpunish/Person299
Undos punish/
merge/Person299/Farvei
Makes Person299 control Farvei's character
merge/Person299/Farvei
Makes Person299 control Farvei's character
teleport/Person299/nccvoyager
Teleports Person299's character to nccvoyager's character
teleport/Person299/nccvoyager
Teleports Person299's character to nccvoyager's character
control/Person299
Makes you control Person299's character
control/Person299
Makes you control Person299's character
change/Person299/Money/999999
Makes the Money value in Person299's leaderstats 999999
change/Person299/Money/999999
Makes the Money value in Person299's leaderstats 999999
tools
Gives you a list of all the tools available to be give/en, the tool must be in game.Lighting
tools
Gives you a list of all the tools available to be give/en, the tool must be in game.Lighting
give/Person299/Tool
Give's Person299 a tool, the toolname can be abbreviated
give/Person299/Tool
Give's Person299 a tool, the toolname can be abbreviated
time/15.30
Makes game.Lighting.TimeOfDay 15:30
time/15.30
Makes game.Lighting.TimeOfDay 15:30
ambient/255/0/0
Makes game.Lighting.Ambient 255,0,0
ambient/255/0/0
Makes game.Lighting.Ambient 255,0,0
maxplayers/20
Makes game.Players.MaxPlayers 20
maxplayers/20
Makes game.Players.MaxPlayers 20
nograv/Person299
Makes Person299 almost weightless
nograv/Person299
Makes Person299 almost weightless
antigrav/Person299
Gives Person299 antigravity properties
antigrav/Person299
Gives Person299 antigravity properties
grav/Person299
Returns Person299's gravity to normal
grav/Person299
Returns Person299's gravity to normal
highgrav/Person299
Makes Person299 heavier
highgrav/Person299
Makes Person299 heavier
setgrav/Person299/-196
Sets Person299's gravity
setgrav/Person299/-196
Sets Person299's gravity
trip/Person299
Makes Person299's character trip
trip/Person299
Makes Person299's character trip
walkspeed/Person299/99
Makes Person299's character's humanoid's WalkSpeed 99, 16 is average
walkspeed/Person299/99
Makes Person299's character's humanoid's WalkSpeed 99, 16 is average
invisible/Person299
Makes Person299's character invisible
invisible/Person299
Makes Person299's character invisible
visible/Person299
Undos invisible/
visible/Person299
Undos invisible/
freeze/Person299
Makes Person299's character unable to move
freeze/Person299
Makes Person299's character unable to move
thaw/Person299
Undos freeze/
thaw/Person299
Undos freeze/
unlock/Person299
Makes Person299's character unlocked
unlock/Person299
Makes Person299's character unlocked
lock/Person299
Makes Person299's character locked
lock/Person299
Makes Person299's character locked
ff/Person299
Gives Person299's character a ForceField
ff/Person299
Gives Person299's character a ForceField
unff/Person299
Undos ff/
unff/Person299
Undos ff/
sparkles/Person299
Makes Person299's character sparkly
sparkles/Person299
Makes Person299's character sparkly
unsparkles/Person299
Undos sparkles/
unsparkles/Person299
Undos sparkles/
shield/Person299
Makes a destructive shield thingy appear around Person299
shield/Person299
Makes a destructive shield thingy appear around Person299
unshield/Person299
Undos shield/
unshield/Person299
Undos shield/
god/Person299
Makes Person299 godish
god/Person299
Makes Person299 godish
ungod/Person299
Undos god/
ungod/Person299
Undos god/
zombify/Person299
Makes Person299 a infecting zombie
zombify/Person299
Makes Person299 a infecting zombie
admin/Person299
Makes Person299 able to use the command script, cannot be used by admin/ed people
admin/Person299
Makes Person299 able to use the command script, cannot be used by admin/ed people
adminlist
Shows a list of everyone in the adminlist
adminlist
Shows a list of everyone in the adminlist
unadmin/Person299
Undos admin/, cannot be used by admin/ed people
unadmin/Person299
Undos admin/, cannot be used by admin/ed people
shutdown
Shuts the server down, cannot be used by admin/ed people
shutdown
Shuts the server down, cannot be used by admin/ed people
m/Fallout 2 is one of the best games ever made
Makes a message appear on the screen saying "Fallout 2 is one of the best games ever made" for 2 seconds
m/Fallout 2 is one of the best games ever made
Makes a message appear on the screen saying "Fallout 2 is one of the best games ever made" for 2 seconds
h/i like pie
Makes a hint appear on the screen saying "i like pie" for 2 seconds
h/i like pie
Makes a hint appear on the screen saying "i like pie" for 2 seconds
c/ game.Workspace:remove()
Makes a script which source is whats after c/
c/ game.Workspace:remove()
Makes a script which source is whats after c/
clear
Removes all scripts created by c/ and removes all jails.
clear
Removes all scripts created by c/ and removes all jails.
Capitalisation doesnt matter, and name input can be abbreviated.
Just about any name input can be replaced with multiple names seperated by ","s, me, all, others, guests, admins, nonadmins, random, or team teamname.
Capitalisation doesnt matter, and name input can be abbreviated.
Just about any name input can be replaced with multiple names seperated by ","s, me, all, others, guests, admins, nonadmins, random, or team teamname.
--]]
--
]]
namelist = {}
variablelist = {}
flist = {}
Expand Down

0 comments on commit 0094f40

Please sign in to comment.