-
Notifications
You must be signed in to change notification settings - Fork 174
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
discussion: plugin support #175
Comments
The protocol for serialization between plugins and |
That's highly unlikely, there's no need to introduce cap'n'proto because AST is already JSON serializable. |
Update: the plugin system had been implemented long time ago by @magurotuna in deno_lint/examples/dlint/main.rs Lines 181 to 184 in 8295bc9
Once denoland/deno#11776 lands we'll be unblocked to add support for plugins in |
Discussed offline with @magurotuna, we got a clear plan how to ship this feature in the near future. Most likely we'll go with simple JS API to register multiple rules from a single plugin: import NoConsole from "./no_console.ts";
import Eqeqeq from "./eqeqeq.ts";
DenoLint.register({
name: "mySuperPlugin",
rules: [
NoConsole,
Eqeqeq,
]
}); |
The bees knees would be an AST bridge between (deno_lint plugin, swc-ast) => (eslint plugin, babel-ast). i'd be excited to even contribute to it. iirc there was a thread w/ one of the eslint maintainers talkin' about ways to help. maybe we can start talkin along these lines w/ him? |
@cdaringe that would require support for emitting ESLint compatible AST (estree) from SWC. There was swc-project/swc#2123 but it hadn't moved anywhere. Current idea by @dsherret is to add a slower path to |
Gotcha, thanks for the ref. Genuine ask, is the I'd vote to keep deno developers' precious time (your precious time!) to be reserved for doing the rad stuff, vs shimming in the less rad stuff (wiring in a JS parser runnin in v8 :) ). |
+1 on having a js api available. |
@jespertheend the trouble is, we got a bespoke API ready for plugins, but that API is completely different to ESLint's API. Different as in, the AST is different and methods for visiting AST nodes are different. It is still unclear if we want to do that, instead of adding ESLint compatible API that would allow to use existing ESLint plugins in Deno. @dsherret and yours truly are gonna look into PoC for ESLint compatibility in Q1 2022. |
Just a suggestion for dogfooding this... perhaps leverage mdn/browser-compat-data to add a linting rule to check that Deno code can be deployed to Deno Deploy? You'd need to add a Deploy target to the browser compat JSON but that might have other uses as well. |
The mantainer of swc is working on a separate package that can emit ESTree AST |
Any updates on this? For now waiting for ESTree compatibility doesn't seem feasible to me (unless I've overlooked a finished implementation): swc-project/extra-bindings#24. What do you think about exposing an incompatible (low effort from your side) api for now, just to enable the community to recreate plugins if they want to? Personally I wouldn't mind doing it in Rust (compiled to WASM I guess) either, I just want to have the option and have it go fast :D this is what's stopping our project from adopting the linter. |
Hey, any update on when plugin support will be available? |
There's no concrete ETA at the moment, we plan to look into this after Deno 2 is released. |
Follow denoland/deno#27203 for updates. |
supporting gritql would make it a lot more easier to write lint rules, as it's very declarative:
rule #1184 can be written in 1 line. biome also plans to support gritql: https://biomejs.dev/reference/gritql/ |
Closing: denoland/deno#27203 has landed and linting plugins will be supported in the upcoming Deno |
It would be great if deno_lint had support for plugins that can add rules. Here are my thoughts:
Constraints:
Possible solution:
Most likely the best solution that satisfies these constraints is WebAssembly. You can write your rules in Rust, and then compile them to WebAssembly that deno_lint could load and run. WebAssembly is also safe because it is sandboxed and only gets access to resources that deno_lint exposes to it. Here is how I imagine this would work:
deno_lint
should initialise all plugins at startup, by creating a WebAssembly VM for each plugin.deno_lint
parses the source code into a swc AST. This ASTs raw memory is stored in a shared memory area with the WebAssembly plugin.deno_lint
calls a function in WebAssembly to kick off code checking in the plugin. It can now do its analysis and create diagnostics. These diagnostics are stored in a separate section of shared memory between the plugin anddeno_lint
.deno_lint
extracts these diagnostics and augments them with information about plugin origin and returns them to the user.This approach would allow you to start multiple instances of the same plugin easily, to paralelnize code analysis for large modules.
There are definitely some issues with this. The biggest one I can see right now is how to pass the AST between plugin and
deno_lint
. If we only support rust, we might be able to pass the raw backing of the object, but I don't know if this is feasible and how likely it is to break (probably very). Another solution would be to serialise to JSON or protobuf and then deserialise on the plugin side. This is definitely possible, but requires a lot of careful translation of the swc structs into JSON. This might be very complicated and time intensive, and would probably not be great for performance. The third solution would be to have the plugin do the parsing of code itself - this would also slow down the process significantly though.Prior art:
dprint
also makes use of WebAssembly for its plugin system. To the end user looks like this: https://dprint.dev/plugin-dev/ (very clean)The text was updated successfully, but these errors were encountered: