@shayanthenerd/eslint-config
Version:
A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style
88 lines (87 loc) • 3.92 kB
JavaScript
import { isEnabled } from "../utils/isEnabled.mjs";
import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
//#region src/rules/html.ts
function getHtmlRules(options) {
const { html, unicorn, tailwind, stylistic, baseline } = options.configs;
const { idNamingConvention } = isEnabled(html) ? html : defaultOptions.configs.html;
const { indent, maxLineLength, maxAttributesPerLine, maxConsecutiveEmptyLines, selfCloseVoidHtmlElements } = isEnabled(stylistic) ? stylistic : defaultOptions.configs.stylistic;
const htmlRules = {
"@html-eslint/css-no-empty-blocks": "error",
"@html-eslint/no-duplicate-attrs": "error",
"@html-eslint/no-duplicate-class": "warn",
"@html-eslint/no-duplicate-id": "error",
"@html-eslint/no-duplicate-in-head": "error",
"@html-eslint/no-ineffective-attrs": "warn",
"@html-eslint/no-inline-styles": ["warn", { allowExpressions: true }],
"@html-eslint/no-invalid-attr-value": "error",
"@html-eslint/no-invalid-entity": "error",
"@html-eslint/no-nested-interactive": "error",
"@html-eslint/no-obsolete-tags": "error",
"@html-eslint/no-script-style-type": "warn",
"@html-eslint/no-target-blank": "warn",
"@html-eslint/no-whitespace-only-children": "error",
"@html-eslint/prefer-https": "warn",
"@html-eslint/require-button-type": "error",
"@html-eslint/require-closing-tags": ["warn", {
selfClosingCustomPatterns: ["-"],
selfClosing: selfCloseVoidHtmlElements
}],
"@html-eslint/require-details-summary": "error",
"@html-eslint/require-doctype": "error",
"@html-eslint/require-explicit-size": "warn",
"@html-eslint/require-li-container": "error",
"@html-eslint/require-meta-charset": "error",
"@html-eslint/svg-require-viewbox": "error",
"@html-eslint/use-baseline": isEnabled(baseline) ? ["warn", { available: baseline.baseline }] : "off",
"@html-eslint/no-multiple-h1": "error",
"@html-eslint/require-lang": "error",
"@html-eslint/require-meta-description": "error",
"@html-eslint/require-open-graph-protocol": "error",
"@html-eslint/require-title": "error",
"@html-eslint/no-abstract-roles": "error",
"@html-eslint/no-accesskey-attrs": "error",
"@html-eslint/no-aria-hidden-body": "error",
"@html-eslint/no-aria-hidden-on-focusable": "error",
"@html-eslint/no-empty-headings": "error",
"@html-eslint/no-heading-inside-button": "error",
"@html-eslint/no-invalid-role": "error",
"@html-eslint/no-non-scalable-viewport": "error",
"@html-eslint/no-positive-tabindex": "error",
"@html-eslint/no-redundant-role": "error",
"@html-eslint/no-skip-heading-levels": "error",
"@html-eslint/require-content": "error",
"@html-eslint/require-frame-title": "error",
"@html-eslint/require-img-alt": "error",
"@html-eslint/require-input-label": "error",
"@html-eslint/require-meta-viewport": "error"
};
if (isEnabled(stylistic)) Object.assign(htmlRules, {
"@html-eslint/attrs-newline": ["warn", {
maxLen: maxLineLength,
ifAttrsMoreThan: maxAttributesPerLine
}],
"@html-eslint/element-newline": ["warn", { inline: ["$inline"] }],
"@html-eslint/id-naming-convention": ["warn", idNamingConvention],
"@html-eslint/indent": ["warn", indent],
"@html-eslint/lowercase": "warn",
"@html-eslint/no-extra-spacing-tags": ["warn", {
disallowTabs: true,
disallowMissing: true,
disallowInAssignment: true,
enforceBeforeSelfClose: true
}],
"@html-eslint/no-extra-spacing-text": ["warn", { skip: ["pre"] }],
"@html-eslint/no-multiple-empty-lines": ["warn", { max: maxConsecutiveEmptyLines }],
"@html-eslint/no-trailing-spaces": "warn",
"@html-eslint/quotes": [
"warn",
"double",
{ enforceTemplatedAttrValue: true }
]
});
if (isEnabled(tailwind)) htmlRules["better-tailwindcss/no-duplicate-classes"] = "off";
if (isEnabled(unicorn)) htmlRules["unicorn/no-invalid-file-input-accept"] = "error";
return htmlRules;
}
//#endregion
export { getHtmlRules };