Skip to content

Commit 836ab76

Browse files
committedJun 18, 2023
feat(eslint-config): added @html-eslint/eslint-plugin to the html plugin, improved the prettier console log output
Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent dfb6f19 commit 836ab76

File tree

9 files changed

+71
-52
lines changed

9 files changed

+71
-52
lines changed
 

‎packages/eslint-config/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
},
6767
"dependencies": {
6868
"@anolilab/package-json-utils": "1.3.0",
69+
"@html-eslint/eslint-plugin": "^0.19.0",
70+
"@html-eslint/parser": "^0.19.0",
6971
"@rushstack/eslint-patch": "^1.3.1",
7072
"@rushstack/eslint-plugin-security": "^0.6.0",
7173
"@typescript-eslint/eslint-plugin": ">=5.55.0",

‎packages/eslint-config/src/config/plugins/babel.ts

-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { hasAnyDep } from "@anolilab/package-json-utils";
22
import type { Linter } from "eslint";
33

44
import createConfig from "../../utils/create-config";
5-
import { consoleLog } from "../../utils/loggers";
65
import bestPracticesConfig from "../best-practices";
76
import errorsConfig from "../errors";
87
import styleConfig from "../style";
@@ -18,13 +17,6 @@ if (
1817
peerDeps: false,
1918
})
2019
) {
21-
// Workaround VS Code trying to run this file twice!
22-
if (!global.hasAnolilabEsLintConfigBabelPrettier) {
23-
global.hasAnolilabEsLintConfigBabelPrettier = true;
24-
25-
consoleLog("\nFound prettier as dependency, disabling some rules to fix wrong behavior of the rule with eslint and prettier");
26-
}
27-
2820
prettierRules = {
2921
"babel/quotes": 0,
3022

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
1+
import { hasAnyDep } from "@anolilab/package-json-utils";
12
import type { Linter } from "eslint";
23

4+
import styleConfig from "../style";
5+
6+
const styleRules = styleConfig.rules as Linter.RulesRecord;
7+
8+
let hasPrettier = false;
9+
10+
let prettierRules: Linter.RulesRecord = {};
11+
12+
if (
13+
hasAnyDep(["prettier"], {
14+
peerDeps: false,
15+
})
16+
) {
17+
hasPrettier = true;
18+
19+
prettierRules = {
20+
"@html-eslint/no-extra-spacing-attrs": "off",
21+
"@html-eslint/element-newline": "off",
22+
"@html-eslint/quotes": "off",
23+
}
24+
}
25+
326
const config: Linter.Config = {
4-
plugins: ["html"],
27+
overrides: [
28+
{
29+
files: ["*.erb", "*.handlebars", "*.hbs", "*.htm", "*.html", "*.mustache", "*.nunjucks", "*.php", "*.tag", "*.twig", "*.we"],
30+
plugins: ["html", "@html-eslint"],
31+
parser: "@html-eslint/parser",
32+
extends: ["plugin:@html-eslint/recommended"],
33+
globals: {
34+
sourceCode: true,
35+
},
36+
settings: {
37+
"html/indent": `+${(styleRules["indent"] as any[])[1]}`,
38+
"html/report-bad-indent": hasPrettier ? "off" : "error",
39+
},
40+
rules: {
41+
// @see https://github.com/yeonjuan/html-eslint/issues/67 bug in html-eslint
42+
"spaced-comment": "off",
43+
"capitalized-comments": "off",
44+
"@html-eslint/indent": hasPrettier ? "off" : ["error", (styleRules["indent"] as any[])[1]],
45+
46+
...prettierRules,
47+
}
48+
},
49+
],
550
};
651

752
export default config;

‎packages/eslint-config/src/config/plugins/jsonc.ts

-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import { hasAnyDep } from "@anolilab/package-json-utils";
22
import type { Linter } from "eslint";
33

4-
import { consoleLog } from "../../utils/loggers";
5-
64
const extendedPlugins: string[] = [];
75

86
if (
97
hasAnyDep(["prettier"], {
108
peerDeps: false,
119
})
1210
) {
13-
// Workaround VS Code trying to run this file twice!
14-
if (!global.hasAnolilabEsLintConfigJsonCPrettier) {
15-
global.hasAnolilabEsLintConfigJsonCPrettier = true;
16-
17-
consoleLog("\nFound prettier as dependency, disabling the jsonc prettier rules.");
18-
}
19-
2011
extendedPlugins.push("plugin:jsonc/prettier");
2112
}
2213

‎packages/eslint-config/src/config/plugins/react.ts

-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ if (
1616
peerDeps: false,
1717
})
1818
) {
19-
// Workaround VS Code trying to run this file twice!
20-
if (!global.hasAnolilabEsLintConfigReactPrettier) {
21-
global.hasAnolilabEsLintConfigReactPrettier = true;
22-
23-
consoleLog("\nFound prettier as dependency, disabling some rules to fix wrong behavior of the rule with eslint and prettier");
24-
}
25-
2619
prettierReactRules = {
2720
"react/jsx-child-element-spacing": "off",
2821
"react/jsx-closing-bracket-location": "off",

‎packages/eslint-config/src/config/plugins/typescript.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { hasAnyDep, pkg } from "@anolilab/package-json-utils";
22
import type { Linter } from "eslint";
33
import { env } from "node:process";
44

5-
import { consoleLog } from "../../utils/loggers";
65
import bestPracticesConfig from "../best-practices";
76
import errorsConfig from "../errors";
87
// eslint-disable-next-line unicorn/prevent-abbreviations
@@ -19,8 +18,7 @@ const eS6Rules = eS6Config.rules as Linter.RulesRecord;
1918
const importsRules = importsConfig.rules as Linter.RulesRecord;
2019
const variablesRules = variablesConfig.rules as Linter.RulesRecord;
2120

22-
const { quotes, semi } = styleRules;
23-
const { indent } = styleRules;
21+
const { quotes, semi, indent } = styleRules;
2422

2523
let prettierRules: Linter.RulesRecord = {};
2624

@@ -29,13 +27,6 @@ if (
2927
peerDeps: false,
3028
})
3129
) {
32-
// Workaround VS Code trying to run this file twice!
33-
if (!global.hasAnolilabEsLintConfigTypescriptPrettier) {
34-
global.hasAnolilabEsLintConfigTypescriptPrettier = true;
35-
36-
consoleLog("\nFound prettier as dependency, disabling some rules to fix wrong behavior of the rule with eslint and prettier");
37-
}
38-
3930
prettierRules = {
4031
"@typescript-eslint/lines-around-comment": 0,
4132
"@typescript-eslint/quotes": 0,

‎packages/eslint-config/src/config/plugins/unicorn.ts

-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { hasAnyDep, packageIsTypeModule } from "@anolilab/package-json-utils";
22
import type { Linter } from "eslint";
33
import semver from "semver";
44

5-
import { consoleLog } from "../../utils/loggers";
65
import styleConfig from "../style";
76

87
const styleRules = styleConfig.rules as Linter.RulesRecord;
@@ -14,13 +13,6 @@ if (
1413
peerDeps: false,
1514
})
1615
) {
17-
// Workaround VS Code trying to run this file twice!
18-
if (!global.hasAnolilabEsLintConfigUnicornPrettier) {
19-
global.hasAnolilabEsLintConfigUnicornPrettier = true;
20-
21-
consoleLog("\nFound prettier as dependency, disabling some rules to fix wrong behavior of the rule with eslint and prettier");
22-
}
23-
2416
prettierRules = {
2517
"unicorn/empty-brace-spaces": "off",
2618
"unicorn/no-nested-ternary": "off",

‎packages/eslint-config/src/global.d.ts

-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@ export {};
22

33
declare global {
44
var hasAnolilabEsLintConfigLoaded: boolean;
5-
var hasAnolilabEsLintConfigJsonCPrettier: boolean;
6-
var hasAnolilabEsLintConfigTypescriptPrettier: boolean;
75

86
var hasAnolilabEsLintConfigReactRuntimePath: boolean;
97

108
var hasAnolilabEsLintTestConfigLoaded: boolean;
119

12-
var hasAnolilabEsLintConfigUnicornPrettier: boolean;
13-
14-
var hasAnolilabEsLintConfigReactPrettier: boolean;
15-
16-
var hasAnolilabEsLintConfigBabelPrettier: boolean;
17-
1810
var hasAnolilabEsLintConfigPrettier: boolean;
1911
}

‎pnpm-lock.yaml

+22-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.