简体   繁体   中英

How to ESlint a string on the client?

I am building a in-browser IDE and am looking for a way to run ESlint on the JS code my users are writing. I am using react and the code that was written is stored in the state as a string. Is there any tool to just take that string and execute ESlint on it? I did not find anything.

If this is not available: Any ideas how to do what i want to do in the browser on the client?

Officially, ESLint doesn't support running in the browser , but it is possible . When run on Node.js, ESLint reads built-in rules, plugins, and custom rules from the filesystem. For the demo, a build step replaces the rule loader with static require() calls so that ESLint and its built-in rules can be combined into a single package for the browser. I'd suggest starting there. If you can get it loaded in the browser, then you can use the Linter API by passing it your string and a configuration object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM