[英]How to enable lint on HTML in vs code?
我正在使用 Visual Studio 代碼開發 angular2 應用程序,我已經安裝了以下擴展,
和
我的組件模板如下,
@Component({
selector: 'userprofile',
template: `
<div class="profilecontainer">
<div class="row">
<img [src]="profile.profilePic" />
<div class="row">
<h2>{{profile.firstName}} {{profile.lastName}} </h2>
<a target="_blank" href="{{profile.detailUrl}}"> View profile</a>
<a target="-blank" href="{{profile.editUrl}}">Edit profile</a>
</div>
</div>`
})
Hml lint 在 vs 代碼上沒有顯示任何錯誤? 問題是什么?
現在, 你不能 。
為了向VS Code添加額外的功能(即linting ),你必須使用為它做的擴展,不幸的是,到這個答案的時候,沒有任何htmllint
VS Code擴展。
請注意,您共享的兩個鏈接都是節點模塊,而不是擴展。 與安裝的東西npm
(即npm install htmllint
)不會讓它與VS代碼工作。
您可以在VS Code中瀏覽和安裝擴展, 如文檔中所述 ,如下所示:
單擊VS Code側面的活動欄中的Extensions圖標或View:Extensions命令(⇧⌘X),打開Extensions視圖。
如果找不到所需的擴展名,可以選擇以下幾種方法:
建議的替代方案 :
npm i htmlhint-ng2 -D
) 將其cli命令添加到package.json
腳本:
"scripts": { "lint:html": "htmlhint-ng2 src/**/*.html" }
npm run lint:html
測試它 npm i npm-watch -D
將監視腳本和配置添加到package.json
"watch": { "lint:html": "src/**/*.html" }, "scripts": { "lint:html": "htmlhint-ng2 src/**/*.html" "watch": "npm-watch" }
npm run watch
現在有一個官方的 HTMLHint VS Code 擴展(它取代了由 Microsoft 構建的已棄用的擴展)。
https://marketplace.visualstudio.com/items?itemName=HTMLHint.vscode-htmlhint
可以將規則配置為與 HTML 中的 Angular 組件一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.