Having restructured our own code as part of building the directory-package-mismatch rule, I'm now more convinced that this change is good, or even great, for large projects in particular. In order to make it simpler for users to remediate this though, we'll need to follow up with a regal fix fixer (that potentially can fix entire projects) and a Code Action that can fix this for a single file from within the comfort of one's editor.
regal fix
One thing we need to ensure here is that the fix must not run if there are notices emitted by the linter. Notices mean we don't have enough information to determine whether the package is correct or not. So either we respect that, or we make a new and better attempt to find out.
Another thing we'll need to ensure is that this command cleans up empty directories that it has left behind. So for example, if there's a project that looks like this:
Ideally, we'd have a --dry-run option, that would print the structure after change without actually changing anything.. similar to the output of tree. But a better approach to be able to get this into the next release might be to try and detect if we're in a git repo, and that the working tree is clean. That way the user can try it out and easily revert using just git.
Code Action
Should not be too complicated. Really just a new code action triggering an execute command which does the fix. Since it'll involve moving a file, we'll want to ensure the result is immediately apparent in the editor, and that things like possible issues are now reported at the new location.
One obvious thing to take into account is whether a file of that name already exists in the directory targeted 😅 If that's the case, we could just add a number, or some identifer like _moved, or simply fail.
Having restructured our own code as part of building the
directory-package-mismatch
rule, I'm now more convinced that this change is good, or even great, for large projects in particular. In order to make it simpler for users to remediate this though, we'll need to follow up with aregal fix
fixer (that potentially can fix entire projects) and a Code Action that can fix this for a single file from within the comfort of one's editor.regal fix
One thing we need to ensure here is that the fix must not run if there are notices emitted by the linter. Notices mean we don't have enough information to determine whether the package is correct or not. So either we respect that, or we make a new and better attempt to find out.
Another thing we'll need to ensure is that this command cleans up empty directories that it has left behind. So for example, if there's a project that looks like this:
Running
regal fix .
in the project root directory, the result would be:And the
code
directory no longer there.--dry-run
option, that would print the structure after change without actually changing anything.. similar to the output oftree
. But a better approach to be able to get this into the next release might be to try and detect if we're in a git repo, and that the working tree is clean. That way the user can try it out and easily revert using just git.Code Action
Should not be too complicated. Really just a new code action triggering an execute command which does the fix. Since it'll involve moving a file, we'll want to ensure the result is immediately apparent in the editor, and that things like possible issues are now reported at the new location.