简体   繁体   English

VS Code HTML / CSS Linter 验证器定制

[英]VS Code HTML / CSS Linter validator customization

is there an easy way how to customize behavior of VSCode HTML / CSS linter validation rules?有没有一种简单的方法来自定义 VSCode HTML / CSS linter 验证规则的行为?

I would like to have possibility to put data placeholders to the code to styles, attributes, text nodes such as:我希望有可能将数据占位符放入 styles 的代码、属性、文本节点,例如:

<style type="text/css">

   .testa {
      color: white;
      background-color: navy;
      transition: color 1s, background-color 1s;
   }

</style>

<template>

   <div class="testa" onclick="{{testClick}}" style="background-color: {{backgroundColor}}; color: {{color}}" >
      {{firstName}} {{lastName}} {{firstName} {{lastName}}
   </div>

   <div style="{{style}}">
      {{firstName}} {{lastName}}
   </div>

</template>

It does not need to be {{...}} placeholder, it can be whatever else, such as ${}, but I would like to VSCode not report this as errors while there is still possibility to have intellisense and validation enabled.它不需要是 {{...}} 占位符,它可以是任何其他内容,例如 ${},但我希望 VSCode 不将此报告为错误,同时仍有可能启用智能感知和验证。

What if you install a Twig plugin for VS Code.如果你为 VS Code 安装一个 Twig 插件会怎么样。 ( Here's first one I found ). 这是我找到的第一个)。 Then tell VS Code to associate .html files with Twig under the file.associations setting.然后告诉 VS Codefile.associations设置下将.html文件与 Twig 相关联。 {{firstName}} is valid twig code so VS Code will think it's ok. {{firstName}}是有效的 twig 代码,因此 VS Code 会认为它没问题。

Yes, you can customize the behavior of the VSCode HTML/CSS linter by configuring its settings.是的,您可以通过配置其设置来自定义 VSCode HTML/CSS linter 的行为。 You can do this by going to the settings editor (File > Preferences > Settings or by using the keyboard shortcut Ctrl +,) and searching for "html" or "css" in the search bar.您可以通过转到设置编辑器(文件 > 首选项 > 设置或使用键盘快捷键 Ctrl +,)并在搜索栏中搜索"html""css"来执行此操作。 You should see a list of settings related to the linter, such as "html.validate.scripts" and "css.validate" .您应该会看到与 linter 相关的设置列表,例如"html.validate.scripts""css.validate" You can then change the values of these settings to customize the linter's behavior.然后,您可以更改这些设置的值以自定义 linter 的行为。

Regarding your specific requirement, you can use template literals and string interpolation to achieve this.根据您的具体要求,您可以使用模板文字和字符串插值来实现。 You can also use templating frameworks like mustache, handlebars, etc for this.您还可以为此使用模板框架,如 mustache、handlebars 等。

Please note that this is not a feature of the linter, but a way of writing your code.请注意,这不是 linter 的功能,而是一种编写代码的方式。

You can use Twigcs Linter ( https://marketplace.visualstudio.com/items?itemName=cerzat43.twigcs ) for Visual Studio Code.您可以将Twigcs Linter ( https://marketplace.visualstudio.com/items?itemName=cerzat43.twigcs ) 用于 Visual Studio Code。

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

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