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

Provide regal fix and LSP Code Action for directory-package-mismatch #1025

Closed
anderseknert opened this issue Aug 29, 2024 · 1 comment · Fixed by #1035
Closed

Provide regal fix and LSP Code Action for directory-package-mismatch #1025

anderseknert opened this issue Aug 29, 2024 · 1 comment · Fixed by #1035

Comments

@anderseknert
Copy link
Member

anderseknert commented Aug 29, 2024

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:

code/
  foo/
    policy1.rego  # package policy.foo.bar
    policy2.rego. # package policy.foo.baz
README.md

Running regal fix . in the project root directory, the result would be:

policy/
  foo/
    bar/
      policy1.rego  # package policy.foo.bar
    baz/
      policy2.rego. # package policy.foo.baz
README.md

And the code directory no longer there.

  • 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.

@anderseknert
Copy link
Member Author

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.

anderseknert added a commit that referenced this issue Sep 1, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 1, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 2, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 2, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 2, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 2, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 2, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 2, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes #1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Sep 3, 2024
Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
srenatus pushed a commit to srenatus/regal that referenced this issue Oct 1, 2024
…#1035)

Following the recent addition of the `directory-package-mismatch` rule,
this PR brings a corresponding `regal fix` remediator as well as a code
action to fix this directly in the editor.

Fixes StyraInc#1025

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant