Ruleset for HTML code style and linting
-
Install this package
-
Add npm task in package.json
{ "scripts": { "lint:html": "htmlhint src -c ./node_modules/@josundt/htmlhint-config/.htmlhintrc --format unix" } }
-
When using Visual Studio Code:
a) Install the htmllint extension ("htmlhint.vscode-htmlhint"), and add it to the VSCode recommmended extensions for the workspace (".vscode/extensions.json").
Then make sure the following two propeties are added to VSCode workspace settings (".vscode/settings.json"):{ // ... "htmlhint.documentSelector": ["html", "ejs"], "htmlhint.configFile": "./node_modules/@josundt/htmlhint-config/.htmlhintrc", // ... }
b) Add a task in ".vscode/tasks.json" to run sass-lint as a VSCode task for the whole workspace:
{ "version": "2.0.0", "runner": "terminal", "tasks": [ { "label": "lint:html", "type": "shell", "command": "npx", "args": [ "htmlhint", "src", "-c", "./node_modules/@josundt/htmlhint-config/.htmlhintrc", "--format", "unix" ], "group": "build", "presentation": { "echo": true, "reveal": "silent", "focus": false, "panel": "shared" }, "problemMatcher": { "applyTo": "allDocuments", "severity": "error", "fileLocation": "absolute", "source": "lint:sass", "pattern": [ { "regexp": "(.*):(\\d+):(\\d+): (.*)", "file": 1, "line": 2, "column": 3, "message": 4 } ] } } ] }