Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to convert require #107

Merged
merged 11 commits into from
Jul 31, 2023
Merged

Add rule to convert require #107

merged 11 commits into from
Jul 31, 2023

Conversation

jeparlefrancais
Copy link
Contributor

@jeparlefrancais jeparlefrancais commented Jul 10, 2023

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:

  • going up a directory means going up a parent
  • getting a file in a directory means indexing a child instance
  • init.lua (or init.luau) files turn their directory into an ModuleScript instance, which is what darklua will target when you require a folder (note: this can be configured to something else like index.lua or index.luau as preferred)

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.

  • add entry to the changelog
  • add tests for generating requires from Rojo sourcemaps in a DataModel
  • update docs

@github-actions
Copy link

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

@jeparlefrancais jeparlefrancais merged commit 77a0eb0 into main Jul 31, 2023
6 checks passed
@jeparlefrancais jeparlefrancais deleted the convert-require-rule branch July 31, 2023 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path imports
1 participant