seaofvoices / darklua

A command line tool that transforms Lua code
https://darklua.com/
MIT License
78 stars 10 forks source link

Add rule to convert require #107

Closed jeparlefrancais closed 1 year ago

jeparlefrancais commented 1 year ago

Closes #31

Darklua is getting a new rule "convert_require" that is able to generate Roblox style requires from file system path requires. The cool thing: it can work with and without a Rojo sourcemap šŸŽ‰

Without a Rojo sourcemap

When no sourcemap is provided, darklua will assume that your file system is laying out the files in the same way Roblox. Darklua will assume everything is relative:

With a Rojo sourcemap

If your setup is more complicated that described before (which I expect is not uncommon), you can provide a sourcemap file in the configuration file. This lets darklua find all your source files no matter where they are in the DataModel and generate the appropriate Instance paths.

github-actions[bot] commented 1 year ago

Coverage after merging convert-require-rule into main will be

89.36%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
src/frontend
   configuration.rs87.96%100%83.56%88.92%131–148, 178–182, 63–66
   error.rs70.34%100%60%71.58%110–115, 121–123, 125–127, 166, 171, 179, 193, 20, 220–224, 234–237, 239, 243–248, 261–266, 270–275, 279–284, 288–293, 305–306, 319–320, 322–323, 340, 349, 382, 384, 389–390, 408–412, 415–420, 76
   worker.rs70.81%100%63.16%71.25%100–107, 110, 114–115, 118–121, 140–142, 162–163, 165, 188, 193–195, 197, 21, 229, 253–257, 259, 283–286, 291–296, 298–305, 326–328, 336–338, 346–348, 356–358, 360–361, 370, 406, 422–424, 439–441, 49–56, 86–87
src/rules
   call_parens.rs89.19%100%75%93.10%
   configuration_error.rs67.50%100%83.33%64.71%65–66, 68–70, 72–74, 76–77, 79, 83–93
   convert_index_to_field.rs92.73%100%82.61%95.40%
   empty_do.rs94.23%100%85.71%96.39%
   filter_early_return.rs87.80%100%78.95%90.48%22–23
   inject_value.rs83.57%100%86.36%83.06%102–103, 111, 16, 174, 187, 189–201, 204–205, 211, 247–250, 253, 256, 40–43, 56–58, 64–66, 98
   method_def.rs92.45%100%85.71%94.87%
   mod.rs88.47%100%76.74%90%100–101, 105, 115–117, 135–137, 139, 170–172, 252, 293–294, 329–331, 381–383, 60, 99
   no_local_function.rs95.24%100%86.67%97.10%
   remove_comments.rs96.39%100%93.02%97.35%85
   remove_compound_assign.rs95.80%100%87.50%96.73%239–241, 53, 80
   remove_nil_declarations.rs96.46%100%88.24%97.92%
   remove_spaces.rs95.88%100%93.02%96.69%165, 85
   rule_property.rs88.05%100%94.29%86.29%107–112, 114–117, 121–122, 28, 36, 47, 65
   unused_if_branch.rs85.56%100%78.26%86.59%112–113, 142, 150–151, 170–172, 39, 47–48, 61, 67, 79–80, 94–96
   unused_while.rs88.73%100%76.47%92.59%
src/rules/bundle
   mod.rs87.97%100%87.50%88.07%108–112, 20, 36–40, 42, 76
   require_mode.rs89.19%100%77.78%92.86%
src/rules/bundle/path_require_mode
   mod.rs89.27%100%94.74%88.84%100–102, 119–121, 125–127, 129, 179, 205–207, 215–217, 233–235, 255, 291–294, 320, 35
   module_definitions.rs94.59%100%94.87%94.55%100, 15, 281–283, 41–44, 47–50, 67
src/rules/convert_require
   instance_path.rs84.21%100%64.71%89.83%
   mod.rs84.86%100%72.73%87.50%105–107, 130, 140–141, 151, 41, 52, 62–63, 88
   roblox_index_style.rs92%100%81.25%94.92%
   roblox_require_mode.rs56.35%100%62.50%55.76%105–106, 139–146, 149–157, 161, 166–170, 173, 177–182, 185–192, 205–208, 42–49, 59–61, 75–77, 87–90, 92, 95–97, 99
   rojo_sourcemap.rs95.69%100%83.33%97.39%90, 95
src/rules/rename_variables
   mod.rs95.43%100%92.59%95.95%124, 21, 49–50, 52
src/rules/require
   match_require.rs100%100%100%100%
   path_locator.rs85.23%100%75%86.25%33–35, 50–53, 6, 69
   path_require_mode.rs81.73%100%83.33%81.25%43–45, 75, 85–93
src/utils
   mod.rs97.18%100%97.56%97.06%55–56, 63
   serde_string_or_struct.rs92.45%100%75%93.88%22–23