yeonjuan / html-eslint

ESLint plugin for linting HTML
https://html-eslint.org
MIT License
155 stars 28 forks source link

Minor adjustment to Flat config example in docs #189

Closed gian1200 closed 3 months ago

gian1200 commented 3 months ago

In https://html-eslint.org/docs/getting-started, I think the example for flat config should be adjusted.

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",
    },
  },
];
import html from "@html-eslint/eslint-plugin";
import htmlParser from "@html-eslint/parser"; // <-- renamed to avoid confusion with other parsers

export default [
  // your own configurations.
  {
    // recommended configuration included in the plugin
    ...html.configs["flat/recommended"], // <-- to limit scope of recommendations
    files: ["**/*.html"],
    plugins: {
      "@html-eslint": html,
    },
    languageOptions: {
      parser: htmlParser, // <-- make explicit assignment
    },
    rules: {
      "@html-eslint/indent": "error"
    }
  }
];

Reasoning:

Update:

In summary:

This works:

import html from "@html-eslint/eslint-plugin";

export default [
  // your own configurations.
  {
    files: ["**/*.html"],
    ...html.configs["flat/recommended"]
  }
];

This, too:

import html from "@html-eslint/eslint-plugin";

export default [
  // your own configurations.
  {
    files: ["**/*.html"],
    ...html.configs["flat/recommended"],
    rules: {
      ...html.configs["flat/recommended"].rules, // <-- Mandatory. If not, rules are lost
      "@html-eslint/indent": "error"
    }
  }
];

Or:

import html from "@html-eslint/eslint-plugin";
import htmlParser from "@html-eslint/parser"; // <-- renamed to avoid confusion with other parsers

export default [
  // your own configurations.
  {
    files: ["**/*.html"],
    plugins: {
      "@html-eslint": html,
    },
    languageOptions: {
      parser: htmlParser, // <-- make explicit assignment
    },
    rules: {
      ...html.configs["flat/recommended"].rules, // <-- Mandatory. If not, rules are lost
      "@html-eslint/indent": "error"
    }
  }
];
yeonjuan commented 3 months ago

@gian1200 agree 👍 Thanks for the report, let me know if you plan to create a PR