VScode插件——HTMLHint插件使用指南、规则配置说明指南、如何修改HTMLHint规则

本文针对VScode应用市场的插件HTMLHint进行说明

HTMLHint插件
平时做HTML页面demo的时候,总喜欢下载一些规则集,比如ESlint、JSlint等插件,这样有些错误就能在写代码时就能体现出来,再配合Error-Lens插件,在代码旁边显示,就能大大提高效率。

HTMLHint配合ErrorLens插件的效果↓↓↓
error-lens插件

1.HTMLHint插件简介

HTMLHint是一个用于检查HTML代码错误和潜在问题的插件。它提供了一系列的规则,用于检查HTML代码的语法、结构、标签使用等方面的问题。

说白了就是以.html后缀结束的文件,进行语法检查,方便我们及时找到代码错误

2.HTMLHint规则说明

HTMLHint总共有33条规则

**Doctype and Head 文档类型和标题**
doctype-first: //必须首先声明 Doctype。
doctype-html5: //无效的文档类型。
html-lang-require://HTML lang 属性是必需的。
head-script-disabled://<script>标签中不能使用标签。
style-disabled: //<style> 不能使用标签。
script-disabled: //<script不能使用标签。
title-require: //<title>必须出现在<head>标签中。

**Attributes 属性**
attr-lowercase://所有属性名称必须为小写。
attr-no-duplication://元素不能有重复的属性。
attr-no-unnecessary-whitespace://属性名称和值之间没有空格。
attr-unsafe-chars://属性值不能包含不安全字符。
attr-value-double-quotes://属性值必须用双引号引起来。
attr-value-single-quotes://属性值必须用单引号引起来。
attr-value-not-empty://所有属性都必须有值。
attr-sorted://属性应按顺序排序。
attr-whitespace://属性值中没有前导或尾随空格。
alt-require://元素的 alt 属性必须存在,并且区域[href]和输入[type=image]的 alt 属性必须有值。
input-requires-label://所有的[input]标签必须有一个对应的[label]标签。

**Tags 标签**
tags-check://允许为任何标签指定规则并验证
tag-pair://标签必须配对。
tag-self-close://空标签必须自动关闭。
tagname-lowercase://所有 html 元素名称必须为小写。
tagname-specialchars://标签名称只能包含字母、数字、“-”、“:”或“ _ ”。
empty-tag-not-self-closed://空标签不应自行关闭。
src-not-empty://img(script,link) 的 src 属性必须有一个值。
href-abs-or-rel:href //属性必须是绝对的或相对的。

**ID ID类属性**
id-class-ad-disabled://id和class属性不能使用ad关键字,会被adblock软件拦截。
id-class-value://id和class属性值必须满足指定的规则。
id-unique://id属性的值必须是唯一的。

**Inline 内联**
inline-script-disabled: //不能使用内联脚本。
inline-style-disabled: //不能使用内联样式。

**Formatting 格式化**
space-tab-mixed-disabled://不要混合使用制表符和空格进行缩进。
spec-char-escape://特殊字符必须转义。

详细的文档可以访问官网:https://htmlhint.com/docs/user-guide/list-rules

3.HTMLHint规则配置

这个是个性化需求,其实默认的HTMLHint下载下来就可以使用了,但是有些HTMLHint规则配置的让人很不舒服,所以你可以对这些规则进行详细的配置,达到自己满意的效果

点击VScode的“设置”,然后搜索HTMLHint,点击setting.json
在这里插入图片描述
附上我自己使用的规则组代码,你可以根据需求进行修改

"htmlhint.options": {
        "doctype-first": false,
        "doctype-html5": true,
        "html-lang-require": true,
        "head-script-disabled": true,
        "style-disabled": false,
        "script-disabled": false,
        "title-require": true,
        "attr-lowercase": true,
        "attr-no-duplication": true,
        "attr-no-unnecessary-whitespace": true,
        "attr-unsafe-chars": true,
        "attr-value-double-quotes": true,
        "attr-value-single-quotes": false,
        "attr-value-not-empty": true,
        "attr-sorted": true,
        "attr-whitespace": true,
        "alt-require": true,
        "input-requires-label": false,
        "tags-check": true,
        "tag-pair": true,
        "tag-self-close": false,
        "tagname-lowercase": true,
        "tagname-specialchars": true,
        "empty-tag-not-self-closed": false,
        "src-not-empty": true,
        "href-abs-or-rel": true,
        "id-class-ad-disabled": true,
        "id-class-value": true,
        "id-unique": true,
        "inline-script-disabled": true,
        "inline-style-disabled": true,
        "space-tab-mixed-disabled": true,
        "spec-char-escape": true,
    }

4.问题:我遇到的问题是在setting.json中不能针对HTMLHint某一个规则进行配置,只配置其中一个规则,整个插件就失效了

所以解决方案是:需要把所有规则都粘贴进去即可

5.拓展:除了HTML文件,能否把HTMLHint加入像VUE之类的文件,这样在VUE文件中也可进行相关代码提示?

可以,仍然是在VScode的“设置”,setting.json中配置
加入以下代码

 "files.associations": {
        "*.vue": "html"
    },

解释一下:files.associations是配置文件关联,而 “*.vue”:
"html"就是把所有以.vue后缀的文件当做html文件处理,自然就能运用HTMLHint规则了

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用VSCode件epub reader,你可以按照以下步骤进行操作: 1. 首先,在VSCode中打开件市场,搜索并安装epub reader件。你可以通过快捷键Ctrl + Shift + X打开件市场。 2. 安装完成后,可以通过快捷键Ctrl + Shift + P或Cmd + Shift + P(Mac)打开命令面板。 3. 在命令面板中,输入"epub reader"来查找epub reader的功能选项。 4. 选择相应的功能选项,如"epub reader: 打开文件",然后选择你想要阅读的epub文件。 5. 一旦打开了epub文件,你可以使用epub reader件的各种功能,如调整字体大小、字体颜色、自定义阅读进度显示等。 6. 如果需要跳转到目录,可以使用件提供的目录跳转功能。 7. 如果你想编辑书架,可以使用件提供的书架编辑功能。 请注意,以上步骤是基于epub reader件的常规用法,具体操作可能会因件版本和个人设置而有所不同。建议在使用件前,先查阅件的文档或官方网站,以了解更多详细的使用说明。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [read-vscode-e:一个vscode扩展以供研究](https://download.csdn.net/download/weixin_42132354/18588590)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [z-reader::blue_book: [vscode件] 小说阅读器,支持在线搜索和本地阅读,支持txt和epub格式](https://download.csdn.net/download/weixin_42098251/18668429)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值