Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

feat(builtins): add xo code actions and diagnostics #707

Merged
merged 10 commits into from
Feb 27, 2022
Merged

feat(builtins): add xo code actions and diagnostics #707

merged 10 commits into from
Feb 27, 2022

Conversation

mvllow
Copy link
Contributor

@mvllow mvllow commented Feb 24, 2022

So far unable to get this to work properly. Help/feedback is much appreciated. I'll continue playing with this and hopefully get something working here 😌

Closes #702

@jose-elias-alvarez
Copy link
Owner

These changes seem to make things work on my end:

diff --git a/lua/null-ls/builtins/diagnostics/xo.lua b/lua/null-ls/builtins/diagnostics/xo.lua
index 6e849ea..0903615 100644
--- a/lua/null-ls/builtins/diagnostics/xo.lua
+++ b/lua/null-ls/builtins/diagnostics/xo.lua
@@ -29,9 +29,9 @@ return h.make_builtin({
     filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" },
     generator_opts = {
         command = "xo",
-        args = { "--stdin", "--stdin-filename", "$FILENAME" },
+        args = { "--reporter", "json", "--stdin", "--stdin-filename", "$FILENAME" },
         to_stdin = true,
-        -- format = "json_raw",
+        format = "json",
         check_exit_code = function(code)
             return code <= 1
         end,

I think that should work as a starting point. xo seems to be more different from ESLint than I expected, so I think it's a good idea to test this before we merge it. If we find that it's ultimately the same, we could set it up as a variant of eslint, kind of like what we do for eslint_d.

I also see that xo provides rule fixes, so we could investigate whether to add code actions as well, like ESLint. Again, if everything lines up with vanilla eslint, it would be simple to set this up as a variant.

@mvllow
Copy link
Contributor Author

mvllow commented Feb 24, 2022

Thanks for the help 😌 So now we have:

  • Diagnostics
  • Code actions (using "ESLint" verbiage, may want to change some to say XO?)
  • Formatting (this is implementing --fix but on second thought that seems more of a code action thing)

I agree that extending ESLint should be fine. I'm curious why ESLint diagnostics/code actions use format: "json_raw" whereas formatting uses format: "json". Other than that, we could simply overwrite filetypes, command, and args.

@jose-elias-alvarez
Copy link
Owner

Right, the eslint built-in has simple error handling to show runtime errors as editor diagnostics (like the VS Code extension) so we should also use json_raw here, too.

Formatting is a bit of a special case. We should investigate whether xo supports the --fix-dry-run flag, which is the approach used by the ESLint formatting built-in. Otherwise I think it's best to leave it out, since --fix may cause weird behavior.

@mvllow
Copy link
Contributor Author

mvllow commented Feb 24, 2022

I'll look into the --fix-dry-run and try to extend eslint to reduce duplication. Appreciate the insight 😌

@mvllow mvllow marked this pull request as ready for review February 24, 2022 18:30
@mvllow
Copy link
Contributor Author

mvllow commented Feb 24, 2022

Removed formatting as --fix is destructive. All tests in make test pass locally. Please let me know if there's anything else that needs tested/completed.

Are docs generated automatically or should I add those? (If not automatic, is there a preference on ordering when adding a new builtin?)

@jose-elias-alvarez
Copy link
Owner

Docs are still done manually, ideally in alphabetical order.

@mvllow mvllow changed the title wip: add xo diagnostics feat(builtins): add xo code actions and diagnostics Feb 25, 2022
@jose-elias-alvarez
Copy link
Owner

Excellent, glad we were able to get this solved with the minimal amount of code. Thanks for the contribution!

@jose-elias-alvarez jose-elias-alvarez merged commit bed5f29 into jose-elias-alvarez:main Feb 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add XO linter
2 participants