Skip to content

Commit

Permalink
feat: support flat config (#176)
Browse files Browse the repository at this point in the history
* feat: support flat config

* chore: add exported plugin types

* fix: wrong key

* docs: update

* docs: update
  • Loading branch information
yeonjuan committed Jan 23, 2024
1 parent a915944 commit 4db98c5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 21 deletions.
54 changes: 54 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,60 @@ yarn add -D eslint @html-eslint/parser @html-eslint/eslint-plugin

## Configuration

### Flat config

If you are using the ESLint [Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), see examples below.

```js,eslint.config.js
import html from "@html-eslint/eslint-plugin";
import parser from "@html-eslint/parser";

export default [
// recommended configuration included in the plugin
html.configs["flat/recommended"],
// your own configurations.
{
files: ["**/*.html"],
plugins: {
"@html-eslint": html,
},
languageOptions: {
parser,
},
rules: {
"@html-eslint/indent": "error",
},
},
];
```

or if using `require(..);`

```js,eslint.config.js
const html = require("@html-eslint/eslint-plugin");
const parser = require("@html-eslint/parser");

module.exports = [
// recommended configuration included in the plugin
html.configs["flat/recommended"],
// your own configurations.
{
files: ["**/*.html"],
plugins: {
"@html-eslint": html,
},
languageOptions: {
parser,
},
rules: {
"@html-eslint/indent": "error",
},
},
];
```

### eslintrc config (.eslintrc.\*)

Populate it with the following on your `.eslintrc.js`. If it does not exist create a `.eslintrc.js` config file in the root of your project.
We can apply [HTML-ESLint plugin rules](rules) to only HTML files(`*.html`) by using `overrides` in `.eslintrc.js`. (see [ESLint Configuration](https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns))

Expand Down
27 changes: 24 additions & 3 deletions packages/eslint-plugin/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
const rules = require("./rules");
const recommended = require("./configs/recommended");
const parser = require("@html-eslint/parser");

module.exports.rules = rules;
module.exports.configs = {
recommended,
/**
* @type {{configs: {recommended: typeof recommended,"flat/recommended": import("eslint").Linter.FlatConfig , rules: typeof rules}}}
*/
const plugin = {
// @ts-ignore
configs: {
recommended,
},
rules,
};

Object.assign(plugin.configs, {
"flat/recommended": {
plugins: {
"@html-eslint": plugin,
},
languageOptions: {
parser,
},
rules: recommended.rules,
},
});

module.exports = plugin;
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"devDependencies": {
"@html-eslint/parser": "^0.22.0",
"@types/eslint": "^7.2.10",
"@types/eslint": "^8.56.2",
"@types/estree": "^0.0.47",
"es-html-parser": "^0.0.8",
"typescript": "^4.4.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@parcel/transformer-sass": "2.10.3",
"@types/codemirror": "^5.60.5",
"@types/eslint": "^8.4.10",
"@types/eslint": "^8.56.2",
"@types/node": "17.0.23",
"@types/react": "^18.0.26",
"@types/react-dom": "18.0.9",
Expand Down
22 changes: 6 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ __metadata:
resolution: "@html-eslint/eslint-plugin@workspace:packages/eslint-plugin"
dependencies:
"@html-eslint/parser": "npm:^0.22.0"
"@types/eslint": "npm:^7.2.10"
"@types/eslint": "npm:^8.56.2"
"@types/estree": "npm:^0.0.47"
es-html-parser: "npm:^0.0.8"
typescript: "npm:^4.4.4"
Expand Down Expand Up @@ -3431,23 +3431,13 @@ __metadata:
languageName: node
linkType: hard

"@types/eslint@npm:^7.2.10":
version: 7.29.0
resolution: "@types/eslint@npm:7.29.0"
"@types/eslint@npm:^8.56.2":
version: 8.56.2
resolution: "@types/eslint@npm:8.56.2"
dependencies:
"@types/estree": "npm:*"
"@types/json-schema": "npm:*"
checksum: 780ea3f4abba77a577a9ca5c4b66f74acc0f5ff5162b9a361ca931763ed65bca062389fc26027b416ed0a54d390e2206412db6c682f565e523d2b82159e6c46f
languageName: node
linkType: hard

"@types/eslint@npm:^8.4.10":
version: 8.44.7
resolution: "@types/eslint@npm:8.44.7"
dependencies:
"@types/estree": "npm:*"
"@types/json-schema": "npm:*"
checksum: 447b55ccff47668fc63466728e7e598ae16a03de8d489350e855b6020ad16f58a703e75b875376dd6cd5fcab630311a805fa7f934476637ea35819f01c9db3ca
checksum: e33ca87a30a9454ba9943e1270ac759996f5fe598a1c1afbaec1d1e7346a339e20bf2a9d81f177067116bbaa6cfa4f748993cb338f57978ae862ad38ffae56fe
languageName: node
linkType: hard

Expand Down Expand Up @@ -15758,7 +15748,7 @@ __metadata:
"@html-eslint/web-linter": "npm:^0.22.0"
"@parcel/transformer-sass": "npm:2.10.3"
"@types/codemirror": "npm:^5.60.5"
"@types/eslint": "npm:^8.4.10"
"@types/eslint": "npm:^8.56.2"
"@types/node": "npm:17.0.23"
"@types/react": "npm:^18.0.26"
"@types/react-dom": "npm:18.0.9"
Expand Down

0 comments on commit 4db98c5

Please sign in to comment.