diff --git a/.prettierignore b/.prettierignore index ab70b0cd..01c3f683 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,9 +2,7 @@ **/fixtures **/__snapshots__ lerna.json -packages/website/out -packages/website/src/out -packages/website/**/*.html +packages/website/ packages/web-linter/out .next dist diff --git a/docs/getting-started.md b/docs/getting-started.md index 065dd1e5..bc818d36 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1,5 +1,15 @@ # Getting Started +## Contents + +- [Prerequisite](#prerequisite) +- [Installation](#installation) +- [Configuration](#configuration) + - [Flat config](#flat-config) + - [eslintrc config (.eslintrc.\*)](#eslintrc-config-eslintrc) +- [Lint HTML in JavaScript Template Literal](#lint-html-in-javascript-template-literals) +- [Editor Configuration](#editor-configuration) + ## Prerequisite - Node.js: `^12.22.0 || ^14.17.0 || >=16.0.0`. @@ -156,6 +166,57 @@ module.exports = { }; ``` +## Lint HTML in JavaScript Template Literals + +This plugin provides the ability to lint not only HTML files, but also HTML written in [JavaScript Template Literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). +You can set the [@html-eslint rules](./rules.md) in your settings to lint JavaScript code without any additional configuration. + +```js,eslint.config.js +import eslintHTML from "@html-eslint/eslint-plugin"; +export default [ + // You can use the @html-eslint rules in your ESLint configuration for JS! + // This is used to lint HTML written inside Template Literal. + "plugins": { + "@html-eslint": eslintHTML + }, + "rules": { + // Specifies the @html-eslint rules to apply to Template Literal. + "@html-eslint/no-inline-styles": 1, + "@html-eslint/indent": 1, + } +]; +``` + +Not all Template literals are recognized as HTML. +There are two ways to get the plugin to recognize them as HTML. + +```js +// 1. Tagged Templates with a function named `html` +html`
`; + +// 2. Template Literal after a html comment (/* html */) +const code = /* html */ ``; +``` + +If you want to specify that linting should be done with keywords other than `html`, you can change the settings option. + +```js + { + "plugins": { + "@html-eslint": eslintHTML + }, + settings: { + html: { + templateLiterals: { + // default options + tags: ["^html$"], + comments: ["^\\s*html\\s*$"], + } + } + }, +} +``` + ## Editor Configuration ### VSCode diff --git a/packages/website/.eslintrc.js b/packages/website/.eslintrc.js index 78cf1073..37cfb8af 100644 --- a/packages/website/.eslintrc.js +++ b/packages/website/.eslintrc.js @@ -2,6 +2,15 @@ module.exports = { root: true, plugins: ["@html-eslint"], parserOptions: { ecmaVersion: 2020, sourceType: "module" }, + rules: { + "@html-eslint/indent": ["error", 2], + "@html-eslint/element-newline": "error", + "@html-eslint/lowercase": "error", + "@html-eslint/no-extra-spacing-attrs": "error", + "@html-eslint/no-multiple-empty-lines": "error", + "@html-eslint/no-trailing-spaces": "error", + "@html-eslint/quotes": "error", + }, overrides: [ { files: ["**/*.html"], diff --git a/packages/website/scripts/generates/renderer.js b/packages/website/scripts/generates/renderer.js index 21cb6f32..08cfb9d4 100644 --- a/packages/website/scripts/generates/renderer.js +++ b/packages/website/scripts/generates/renderer.js @@ -12,7 +12,10 @@ module.exports = { const id = text .toLowerCase() .replace(/^@/, "") - .replace(/[\s\/]/g, "-"); + .replace(/[^a-zA-Z0-9]/g, "-") + .replace(/[\s\/]/g, "-") + .replace(/-+/g, "-") + .replace(/-$/, ""); return `
- ESLint is a popular linting tool, but it only supports JavaScript.
- This plugin allows you to lint your HTML code without having to install a separate linting tool or worry about editor support.
-
+ ESLint is a popular linting tool, but it only supports JavaScript.
+ This plugin allows you to lint HTML files and HTML code in JavaScript Template Literals.
+
- A: This ESLint plugin supports linting HTML syntax and does not provide JavaScript syntax linting. To lint JavaScript in HTML, such as inline scripts, you can use eslint-plugin-html -
-
- If you find this project useful,
- Please support this project with a Github Star!
-
+ A: This ESLint plugin supports linting HTML syntax and does not provide JavaScript syntax linting. To lint JavaScript in HTML, such as inline scripts, you can use eslint-plugin-html +
+
+ If you find this project useful,
+ Please support this project with a Github Star!
+
HERE-