简体   繁体   English

是否可以使用 ESLint 来 lint Handlebars 模板?

[英]Is it possible to use ESLint to lint Handlebars template?

I'm trying to write an ESLint plugin for Ember to check if the handlebars template together with javascript code has no issues.我正在尝试为 Ember 编写一个 ESLint 插件来检查把手模板和 javascript 代码是否没有问题。

To achieve that, I need to lint .js component code together with .hbs component template.为了实现这一点,我需要将.js组件代码与.hbs组件模板一起.hbs

I don't have much experience with writing ESLint rules, but I guess all I need is to somehow turn those .hbs files into AST and then lint it as usually, but I don't know how to do that.我在编写 ESLint 规则方面没有太多经验,但我想我所需要的只是以某种方式将这些.hbs文件转换为 AST,然后像.hbs进行 lint,但我不知道该怎么做。

Are those AST produced by Js and Handlebars even compatible? Js 和 Handlebars 产生的那些 AST 甚至兼容吗?

I believe https://www.npmjs.com/package/eslint-plugin-html does what you're looking for:我相信https://www.npmjs.com/package/eslint-plugin-html可以满足您的需求:

A[n] ESLint plugin to lint and fix inline scripts contained in HTML files. A[n] ESLint 插件,用于 lint 和修复 HTML 文件中包含的内联脚本。

By default, this plugin will only consider files ending with those extensions as HTML: .erb, .handlebars, .hbs, .htm, .html, .mustache, .nunjucks, .php, .tag, .twig, .we.默认情况下,此插件只会将以这些扩展名结尾的文件视为 HTML:.erb、.handlebars、.hbs、.htm、.html、.mustache、.nunjucks、.php、.tag、.twig、.we。 You can set your own list of HTML extensions by using this setting.您可以使用此设置来设置您自己的 HTML 扩展列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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