Skip to content

Commit a2c68dd

Browse files
committed
feat: upgrade htmlhint 1.0 and markuplint 2.0
1 parent 189e6a9 commit a2c68dd

16 files changed

+3688
-4077
lines changed

.changeset/little-queens-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-htm': minor
3+
---
4+
5+
feat: upgrade htmlhint 1.0

.changeset/little-steaks-burn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-utils': minor
3+
---
4+
5+
feat: update entry files extensions

.changeset/old-oranges-dream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-markup': minor
3+
---
4+
5+
feat: upgrade markuplint 2.0

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
"typecov": "type-coverage"
2424
},
2525
"devDependencies": {
26-
"@1stg/lib-config": "^3.0.0",
27-
"@changesets/changelog-github": "^0.4.0",
28-
"@changesets/cli": "^2.16.0",
29-
"@markuplint/rule-textlint": "^0.2.0-alpha.1",
30-
"@types/eslint": "^7.28.0",
31-
"@types/htmlhint": "^0.9.3",
32-
"@types/jest": "^26.0.24",
33-
"@types/node": "^16.3.1",
26+
"@1stg/lib-config": "^5.0.0",
27+
"@changesets/changelog-github": "^0.4.3",
28+
"@changesets/cli": "^2.21.1",
29+
"@markuplint/rule-textlint": "^2.2.0",
30+
"@types/eslint": "^8.4.1",
31+
"@types/htmlhint": "^1.1.2",
32+
"@types/jest": "^27.4.1",
33+
"@types/node": "^17.0.21",
3434
"textlint-rule-max-comma": "^2.0.2",
35-
"ts-jest": "^27.0.3",
36-
"ts-node": "^10.1.0",
37-
"type-coverage": "^2.18.0",
38-
"typescript": "^4.3.5"
35+
"ts-jest": "^27.1.3",
36+
"ts-node": "^10.7.0",
37+
"type-coverage": "^2.21.0",
38+
"typescript": "^4.6.2"
3939
},
4040
"commitlint": {
4141
"extends": "@1stg"
@@ -73,7 +73,7 @@
7373
]
7474
},
7575
"typeCoverage": {
76-
"atLeast": 99.6,
76+
"atLeast": 100,
7777
"cache": true,
7878
"detail": true,
7979
"ignoreAsAssertion": true,

packages/htm/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"node": ">=10"
1111
},
1212
"main": "lib",
13-
"module": "lib/esm",
14-
"es2015": "lib/es2015",
15-
"fesm5": "lib/esm",
13+
"module": "lib/esm.mjs",
14+
"es2015": "lib/es2015.mjs",
15+
"fesm5": "lib/esm.mjs",
1616
"types": "lib",
1717
"files": [
1818
"lib",
@@ -35,8 +35,8 @@
3535
},
3636
"dependencies": {
3737
"eslint-plugin-utils": "^0.1.0",
38-
"htmlhint": "^0.15.1",
39-
"tslib": "^2.3.0"
38+
"htmlhint": "^1.1.2",
39+
"tslib": "^2.3.1"
4040
},
4141
"publishConfig": {
4242
"access": "public"

packages/htm/src/index.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { registerJsonMessageHandler } from 'eslint-plugin-utils'
2-
import { LintResult } from 'htmlhint'
2+
import { Hint } from 'htmlhint/types'
33

4-
export * from './parser'
54
export * as configs from './configs'
5+
export * from './parser'
66
export * as rules from './rules'
77

8-
registerJsonMessageHandler(
9-
'htm/html',
10-
({ evidence, rule, message }: LintResult) => ({
11-
ruleId: `htm/${rule.id}`,
12-
message: `${message}
8+
registerJsonMessageHandler('htm/html', ({ evidence, rule, message }: Hint) => ({
9+
ruleId: `htm/${rule.id}`,
10+
message: `${message}
1311
evidence: ${evidence}
14-
reference: ${rule.link}`,
15-
}),
16-
)
12+
reference: ${rule.link ?? '-'}`,
13+
}))

packages/htm/test/__snapshots__/fixtures.spec.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Array [
77
"line": 1,
88
"message": "Doctype must be declared first.
99
evidence: <!--comment--><!DOCTYPE html>
10-
reference: https://github.com/thedaviddias/HTMLHint/wiki/doctype-first",
10+
reference: https://htmlhint.com/docs/user-guide/rules/doctype-first",
1111
"nodeType": null,
1212
"ruleId": "htm/doctype-first",
1313
"severity": 1,

packages/markup/package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"node": ">=10"
1111
},
1212
"main": "lib",
13-
"module": "lib/esm",
14-
"es2015": "lib/es2015",
15-
"fesm5": "lib/esm",
13+
"module": "lib/esm.mjs",
14+
"es2015": "lib/es2015.mjs",
15+
"fesm5": "lib/esm.mjs",
1616
"types": "lib",
1717
"files": [
1818
"lib",
@@ -35,12 +35,11 @@
3535
"eslint": ">=5.0.0"
3636
},
3737
"dependencies": {
38-
"cosmiconfig": "^7.0.0",
38+
"cosmiconfig": "^7.0.1",
3939
"eslint-plugin-utils": "^0.1.0",
40-
"markuplint": "^1.10.1",
41-
"markuplint-sync": "^0.3.2",
42-
"synckit": "^0.3.4",
43-
"tslib": "^2.3.0"
40+
"markuplint": "^2.2.0",
41+
"synckit": "^0.6.0",
42+
"tslib": "^2.3.1"
4443
},
4544
"publishConfig": {
4645
"access": "public"

packages/markup/src/helpers.ts

-31
This file was deleted.

packages/markup/src/index.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import { registerJsonMessageHandler } from 'eslint-plugin-utils'
2-
import { VerifiedResult } from '@markuplint/ml-config'
1+
import { Violation } from '@markuplint/ml-config'
32
import { Linter } from 'eslint'
3+
import { registerJsonMessageHandler } from 'eslint-plugin-utils'
44

5-
export * from './helpers'
5+
export * as configs from './configs'
66
export * from './parser'
77
export * from './rules'
8-
export * as configs from './configs'
98
export * as rules from './rules'
109

1110
const SEVERITIES = ['info', 'warning', 'error'] as const
1211

1312
registerJsonMessageHandler(
1413
'markup/markup',
15-
(
16-
{ ruleId, severity, message }: VerifiedResult,
17-
{ severity: eslintSeverity },
18-
) => ({
14+
({ ruleId, severity, message }: Violation, { severity: eslintSeverity }) => ({
1915
ruleId: `markup/${ruleId}`,
2016
message,
2117
severity: Math.max(

packages/markup/src/rules/markup.ts

+19-54
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1+
import { Target } from '@markuplint/file-resolver'
2+
import { Violation } from '@markuplint/ml-config'
13
import { Rule } from 'eslint'
2-
import { exec as execAsync } from 'markuplint'
3-
import { exec } from 'markuplint-sync'
44
import { createSyncFn } from 'synckit'
55

6-
import { getPhysicalFilename, resolveConfig } from '../helpers'
7-
86
const workerPath = require.resolve('../worker')
97

108
// call `creatSyncFn` lazily for performance, it is already cached inside, related #31
119
const _ = {
12-
get execSync() {
13-
return createSyncFn<typeof execAsync>(workerPath)
10+
get markuplintSync() {
11+
return createSyncFn<
12+
(
13+
target: Target,
14+
fix?: boolean,
15+
) => Promise<{ violations: Violation[]; fixedCode: string }>
16+
>(workerPath)
1417
},
1518
}
1619

17-
const brokenCache = new Map<string, true>()
18-
19-
const BROKEN_ERROR_PATTERN =
20-
/^`(verify|fix)Sync` finished async. Use `\1` instead$/
21-
2220
export const markup: Rule.RuleModule = {
2321
meta: {
2422
fixable: 'code',
@@ -28,58 +26,25 @@ export const markup: Rule.RuleModule = {
2826
const filename = context.getFilename()
2927
const sourceText = context.getSourceCode().text
3028

31-
const config = resolveConfig(getPhysicalFilename(filename))
32-
33-
const execOptions = {
34-
sourceCodes: sourceText,
35-
names: filename,
36-
config,
29+
const markuplintOptions = {
30+
sourceCode: sourceText,
31+
name: filename,
3732
}
3833

34+
const runMarkuplint = (fix?: boolean) =>
35+
_.markuplintSync(markuplintOptions, fix)
36+
3937
return {
40-
// eslint-disable-next-line sonarjs/cognitive-complexity
4138
Program() {
42-
if (!config) {
43-
return
44-
}
45-
46-
let broken = brokenCache.get(config)
47-
48-
const runMarkuplint = (fix?: boolean) => {
49-
const options = {
50-
...execOptions,
51-
fix,
52-
}
53-
54-
if (broken) {
55-
return _.execSync(options)
56-
}
57-
58-
try {
59-
return exec(options)
60-
} catch (err) {
61-
/* istanbul ignore else */
62-
if (BROKEN_ERROR_PATTERN.test((err as Error).message)) {
63-
brokenCache.set(config, (broken = true))
64-
return _.execSync(options)
65-
}
66-
// eslint-disable-next-line no-else-return -- https://github.com/istanbuljs/istanbuljs/issues/605
67-
else {
68-
throw err
69-
}
70-
}
71-
}
72-
73-
const resultInfos = runMarkuplint()
39+
const { violations } = runMarkuplint()
7440

75-
if (resultInfos.length === 0) {
41+
if (violations.length === 0) {
7642
return
7743
}
7844

7945
let fixed = 0
8046

81-
for (const { ruleId, severity, message, line, col } of resultInfos[0]
82-
.results) {
47+
for (const { ruleId, severity, message, line, col } of violations) {
8348
context.report({
8449
message: JSON.stringify({ severity, message, ruleId }),
8550
loc: {
@@ -91,7 +56,7 @@ export const markup: Rule.RuleModule = {
9156
if (fixed++) {
9257
return null
9358
}
94-
const { fixedCode } = runMarkuplint(true)[0]
59+
const { fixedCode } = runMarkuplint(true)
9560
return sourceText === fixedCode
9661
? null
9762
: {

packages/markup/src/worker.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { exec } from 'markuplint'
1+
import { Target } from '@markuplint/file-resolver'
2+
import { mlTestFile } from 'markuplint'
23
import { runAsWorker } from 'synckit'
34

4-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
5-
runAsWorker(async (options: Parameters<typeof exec>[0]) => {
6-
const results = await exec(options)
7-
return results.map(({ results, fixedCode }) => ({
8-
results,
9-
fixedCode,
10-
}))
11-
})
5+
runAsWorker((target: Target, fix?: boolean) =>
6+
mlTestFile(target, undefined, undefined, undefined, fix),
7+
)

packages/markup/test/__snapshots__/fixtures.spec.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Array [
138138
Object {
139139
"column": 1,
140140
"line": 1,
141-
"message": "Required doctype",
141+
"message": "Require doctype",
142142
"nodeType": null,
143143
"ruleId": "markup/doctype",
144144
"severity": 2,

packages/markup/test/rules.spec.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ tester.run('markup', markup, {
1515
valid: [
1616
{
1717
...options,
18-
code: /* HTML */ `<!DOCTYPE html>
18+
code: /* HTML */ `
19+
<!DOCTYPE html>
1920
<html>
2021
<head>
2122
<title>Any Page</title>
@@ -24,7 +25,8 @@ tester.run('markup', markup, {
2425
<h1>Any Page</h1>
2526
<p>Anonymous</p>
2627
</body>
27-
</html>`,
28+
</html>
29+
`,
2830
},
2931
{
3032
...options,
@@ -54,20 +56,22 @@ tester.run('markup', markup, {
5456
invalid: [
5557
{
5658
...options,
57-
code: /* HTML */ `<html>
58-
<head>
59-
<title>Any Page</title>
60-
</head>
61-
<body>
62-
<h1>Any Page</h1>
63-
<p>Anonymous</p>
64-
</body>
65-
</html>`,
59+
code: /* HTML */ `
60+
<html>
61+
<head>
62+
<title>Any Page</title>
63+
</head>
64+
<body>
65+
<h1>Any Page</h1>
66+
<p>Anonymous</p>
67+
</body>
68+
</html>
69+
`,
6670
errors: [
6771
{
6872
message: JSON.stringify({
6973
severity: 'error',
70-
message: 'Required doctype',
74+
message: 'Require doctype',
7175
ruleId: 'doctype',
7276
}),
7377
line: 1,

0 commit comments

Comments
 (0)