Skip to content

Commit 3235455

Browse files
authored
feat: node18 module stuff (#345)
* feat!: node18 module stuff * fix: more type errors * fix: use range for eslint packages ESLint obeys npm-flavored semver, so it's safe to use ranges for 0ver packages. * chore: yarn dedupe * fix: type inference * chore: yarn dedupe Missed some last time. * flake
1 parent 2b12bea commit 3235455

File tree

15 files changed

+161
-561
lines changed

15 files changed

+161
-561
lines changed

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "turbo run lint",
1212
"format": "prettier --write .",
1313
"dev": "turbo run dev",
14-
"build": "turbo run build --no-cache --force",
14+
"build": "turbo run build",
1515
"publish": "lerna publish",
1616
"publish:alpha": "lerna publish --dist-tag alpha",
1717
"check:ts": "turbo run ts",
@@ -31,7 +31,7 @@
3131
"@types/jest": "^29.5.14",
3232
"compute-baseline": "^0.3.1",
3333
"cspell": "^8.0.0",
34-
"eslint": "^9.19.0",
34+
"eslint": "^9.27.0",
3535
"eslint-plugin-jest": "^28.11.0",
3636
"eslint-plugin-n": "^17.15.1",
3737
"husky": "^9.1.4",
@@ -41,11 +41,10 @@
4141
"rimraf": "^6.0.1",
4242
"svgo": "^3",
4343
"turbo": "^2.0.11",
44-
"typescript": "^5.7.2"
44+
"typescript": "^5.8.3"
4545
},
4646
"engines": {
47-
"node": "^12.22.0 || ^14.17.0 || >=16.0.0",
48-
"npm": ">=7"
47+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
4948
},
5049
"packageManager": "[email protected]",
5150
"workspaces": [

packages/eslint-plugin/lib/configs/recommended.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = {
1+
/** @satisfies {import('eslint').Linter.FlatConfig} */
2+
const recommended = {
23
rules: {
34
"@html-eslint/require-lang": "error",
45
"@html-eslint/require-img-alt": "error",
@@ -23,3 +24,5 @@ module.exports = {
2324
"@html-eslint/use-baseline": "error",
2425
},
2526
};
27+
28+
module.exports = recommended;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import plugin = require("./index");
2-
export default plugin;
2+
export = plugin;

packages/eslint-plugin/lib/index.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,40 @@ const recommended = require("./configs/recommended");
33
const parser = require("@html-eslint/parser");
44
const { HTMLLanguage } = require("./languages/html-language");
55
const { name, version } = require("../package.json");
6+
67
/**
7-
* @typedef {import("./rules")} AllRules
8-
* @typedef {import("./configs/recommended")} RecommendedConfig
9-
* @typedef {{name: string, version: string}} PluginMeta
10-
* @typedef {{recommended: RecommendedConfig, "flat/recommended": import("eslint").Linter.FlatConfig }} HtmlESLintConfigs
11-
* @typedef {{html: HTMLLanguage}} Languages
8+
* @import { ESLint } from "eslint";
129
*/
1310

1411
/**
15-
* @type {{meta: PluginMeta, rules: AllRules, configs: HtmlESLintConfigs, languages: Languages}}
12+
* @satisfies {ESLint.Plugin}
1613
*/
1714
const plugin = {
1815
meta: {
1916
name,
2017
version,
2118
},
22-
// @ts-ignore
2319
configs: {
2420
recommended,
21+
22+
"flat/recommended": {
23+
plugins: {
24+
/** @type {ESLint.Plugin} */
25+
get "@html-eslint"() {
26+
return plugin;
27+
},
28+
},
29+
30+
languageOptions: {
31+
parser,
32+
},
33+
rules: recommended.rules,
34+
},
2535
},
2636
languages: {
2737
html: new HTMLLanguage(),
2838
},
2939
rules,
3040
};
3141

32-
Object.assign(plugin.configs, {
33-
"flat/recommended": {
34-
plugins: {
35-
"@html-eslint": plugin,
36-
},
37-
38-
languageOptions: {
39-
parser,
40-
},
41-
rules: recommended.rules,
42-
},
43-
});
44-
4542
module.exports = plugin;

packages/eslint-plugin/lib/languages/html-language.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ const { visitorKeys, parseForESLint } = require("@html-eslint/parser");
22
const { HTMLSourceCode } = require("./html-source-code");
33

44
/**
5-
* @typedef {import('@eslint/core').File} File
6-
* @typedef {import('@html-eslint/parser').ParserOptions} LanguageOptions
5+
* @import { Language, ParseResult, File, FileError, OkParseResult } from "@eslint/core";
6+
* @import { ParserOptions } from "@html-eslint/parser";
7+
* @import { AST } from "eslint";
8+
*/
9+
10+
/**
11+
* @implements {Language<{ LangOptions: ParserOptions; Code: HTMLSourceCode; RootNode: AST.Program; Node: {}}>}
712
*/
813
class HTMLLanguage {
914
constructor() {
@@ -31,14 +36,14 @@ class HTMLLanguage {
3136
this.nodeTypeKey = "type";
3237

3338
/**
34-
* The visitor keys for the CSSTree AST.
39+
* The visitor keys for the es-html-parser AST.
3540
* @type {Record<string, string[]>}
3641
*/
3742
this.visitorKeys = visitorKeys;
3843
}
3944

4045
/**
41-
* @param {LanguageOptions} languageOptions
46+
* @param {ParserOptions} languageOptions
4247
*/
4348
validateLanguageOptions(languageOptions) {
4449
if (!languageOptions) {
@@ -64,8 +69,8 @@ class HTMLLanguage {
6469
/**
6570
* @param {File} file
6671
* @param {Object} [context]
67-
* @param {LanguageOptions} context.languageOptions
68-
* @returns {{ok: true; ast: any; comments: any[]} | {ok: false, errors: unknown[]}}
72+
* @param {ParserOptions} context.languageOptions
73+
* @returns {ParseResult<AST.Program>}
6974
*/
7075
parse(file, context) {
7176
const code = /** @type {string} */ (file.body);
@@ -80,14 +85,14 @@ class HTMLLanguage {
8085
} catch (e) {
8186
return {
8287
ok: false,
83-
errors: [e],
88+
errors: [/** @type {FileError} */ (e)],
8489
};
8590
}
8691
}
8792

8893
/**
8994
* @param {File} file
90-
* @param {any} parseResult
95+
* @param {OkParseResult<AST.Program>} parseResult
9196
*/
9297
createSourceCode(file, parseResult) {
9398
return new HTMLSourceCode({

packages/eslint-plugin/lib/rules/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const noDuplicateClass = require("./no-duplicate-class");
5050
// import new rule here ↑
5151
// DO NOT REMOVE THIS COMMENT
5252

53-
module.exports = {
53+
const rules = {
5454
"require-lang": requireLang,
5555
"require-img-alt": requireImgAlt,
5656
"require-doctype": requireDoctype,
@@ -103,3 +103,8 @@ module.exports = {
103103
// export new rule here ↑
104104
// DO NOT REMOVE THIS COMMENT
105105
};
106+
107+
module.exports =
108+
/** @type {Record<string, import('@eslint/core').RuleDefinition>} */ (
109+
/** @type {unknown} */ (rules)
110+
);

packages/eslint-plugin/package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "@html-eslint/eslint-plugin",
33
"version": "0.40.3",
4-
"description": "ESLint plugin for html",
4+
"type": "commonjs",
5+
"description": "ESLint plugin for HTML",
56
"author": "yeonjuan",
67
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
78
"license": "MIT",
@@ -23,7 +24,7 @@
2324
"test:legacy": "TEST_ESLINT_LEGACY_CONFIG=true && jest",
2425
"ts": "tsc --noEmit",
2526
"lint": "eslint .",
26-
"build": "rimraf types && tsc --project tsconfig.build.json"
27+
"build": "rimraf types && tsc --project tsconfig.build.json"
2728
},
2829
"bugs": {
2930
"url": "https://github.com/yeonjuan/html-eslint/issues"
@@ -38,19 +39,24 @@
3839
"accessibility"
3940
],
4041
"dependencies": {
41-
"@eslint/plugin-kit": "0.2.8",
42+
"@eslint/plugin-kit": "^0.3.1",
4243
"@html-eslint/parser": "^0.40.0",
4344
"@html-eslint/template-parser": "^0.40.0",
4445
"@html-eslint/template-syntax-parser": "^0.40.0"
4546
},
47+
"peerDependencies": {
48+
"eslint": "^8.0.0 || ^9.0.0"
49+
},
4650
"devDependencies": {
47-
"@eslint/core": "0.13.0",
51+
"@eslint/core": "^0.14.0",
4852
"@html-eslint/types": "^0.40.0",
49-
"@types/eslint": "^9.6.1",
5053
"@types/estree": "^0.0.47",
5154
"es-html-parser": "0.2.0",
52-
"eslint": "^9.21.0",
55+
"eslint": "^9.27.0",
5356
"espree": "^10.3.0",
54-
"typescript": "^5.7.2"
57+
"typescript": "^5.8.3"
58+
},
59+
"engines": {
60+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
5561
}
5662
}

packages/eslint-plugin/tests/languages/html-language.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* @typedef {import('@eslint/core').File} File
2+
* @import { File, OkParseResult } from "@eslint/core";
3+
* @import { AST } from "eslint";
34
*/
45

56
const { HTMLLanguage } = require("../../lib/languages/html-language");
@@ -118,7 +119,10 @@ name: value
118119
const file = createFile("<div></div>");
119120
const language = new HTMLLanguage();
120121
const parsed = language.parse(file);
121-
const sourceCode = language.createSourceCode(file, parsed);
122+
const sourceCode = language.createSourceCode(
123+
file,
124+
/** @type {OkParseResult<AST.Program>} */ (parsed)
125+
);
122126
expect(sourceCode.constructor.name).toBe("HTMLSourceCode");
123127
expect(sourceCode.ast.type).toBe("Program");
124128
});

packages/integration-test/tests/integration.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { runESLint } = require("../lib/test-utils");
22

33
describe("integration tests", () => {
44
describe("eslint-v8-legacy-config", () => {
5-
it("should throw a lint error for invalid files ", async () => {
5+
it("should throw a lint error for invalid files", async () => {
66
const htmlResult = await runESLint({
77
fixtureName: "eslint-v8-legacy-config",
88
glob: "html/invalid.html",

packages/parser/lib/parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { getOptions } = require("./options");
1111
/**
1212
* @param {string} code
1313
* @param {ParserOptions | undefined} parserOptions
14-
* @returns {any}
14+
* @returns {import('eslint').Linter.ESLintParseResult}
1515
*/
1616
module.exports.parseForESLint = function parseForESLint(code, parserOptions) {
1717
const { options, html } = getOptions(code, parserOptions);
@@ -54,6 +54,6 @@ module.exports.parseForESLint = function parseForESLint(code, parserOptions) {
5454
return {
5555
ast: programNode,
5656
visitorKeys,
57-
scopeManager: null,
57+
scopeManager: undefined,
5858
};
5959
};

0 commit comments

Comments
 (0)