Skip to content

Commit 2270c8b

Browse files
authored
feat: report correct ruleId from original linter (#22)
1 parent 1fcd7fa commit 2270c8b

27 files changed

+263
-82
lines changed

.changeset/light-fishes-try.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"eslint-plugin-htm": minor
3+
"eslint-plugin-markup": minor
4+
"eslint-plugin-utils": minor
5+
---
6+
7+
feat: report correct ruleId from original linter

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
This repository is a monorepo managed by [changesets][] what means we actually publish several packages to npm from same codebase, including:
2121

22-
| Package | Description | Version | (Peer) Dependencies |
23-
| ------------------------------------------ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24-
| [`eslint-plugin-htm`](/packages/htm) | An incredible ESLint plugin for HTML based on HTMLHint. | [![npm](https://img.shields.io/npm/v/eslint-plugin-htm.svg)](https://www.npmjs.com/package/eslint-plugin-htm) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/eslint-plugin-htm) | [![David Peer](https://img.shields.io/david/peer/rx-ts/eslint.svg?path=packages/htm)](https://david-dm.org/rx-ts/eslint?path=packages/htm&type=peer) [![David](https://img.shields.io/david/rx-ts/eslint.svg?path=packages/htm)](https://david-dm.org/rx-ts/eslint?path=packages/htm) |
25-
| [`eslint-plugin-markup`](/packages/markup) | An incredible ESLint plugin for all markup languages based on markuplint. | [![npm](https://img.shields.io/npm/v/eslint-plugin-markup.svg)](https://www.npmjs.com/package/eslint-plugin-markup) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/eslint-plugin-markup) | [![David Peer](https://img.shields.io/david/peer/rx-ts/eslint.svg?path=packages/markup)](https://david-dm.org/rx-ts/eslint?path=packages/markup&type=peer) [![David](https://img.shields.io/david/rx-ts/eslint.svg?path=packages/markup)](https://david-dm.org/rx-ts/eslint?path=packages/markup) |
22+
| Package | Description | Version | (Peer) Dependencies |
23+
| ------------------------------------------ | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24+
| [`eslint-plugin-htm`](/packages/htm) | An incredible ESLint plugin for HTML based on HTMLHint. | [![npm](https://img.shields.io/npm/v/eslint-plugin-htm.svg)](https://www.npmjs.com/package/eslint-plugin-htm) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/eslint-plugin-htm) | [![David Peer](https://img.shields.io/david/peer/rx-ts/eslint.svg?path=packages/htm)](https://david-dm.org/rx-ts/eslint?path=packages/htm&type=peer) [![David](https://img.shields.io/david/rx-ts/eslint.svg?path=packages/htm)](https://david-dm.org/rx-ts/eslint?path=packages/htm) |
25+
| [`eslint-plugin-markup`](/packages/markup) | An incredible ESLint plugin for all markup languages based on markuplint. | [![npm](https://img.shields.io/npm/v/eslint-plugin-markup.svg)](https://www.npmjs.com/package/eslint-plugin-markup) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/eslint-plugin-markup) | [![David Peer](https://img.shields.io/david/peer/rx-ts/eslint.svg?path=packages/markup)](https://david-dm.org/rx-ts/eslint?path=packages/markup&type=peer) [![David](https://img.shields.io/david/rx-ts/eslint.svg?path=packages/markup)](https://david-dm.org/rx-ts/eslint?path=packages/markup) |
26+
| [`eslinter-plugin-utils`](/packages/utils) | Utilities for ESLint plugins and custom rules. | [![npm](https://img.shields.io/npm/v/eslinter-plugin-utils.svg)](https://www.npmjs.com/package/eslinter-plugin-utils) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/eslinter-plugin-utils) | [![David Peer](https://img.shields.io/david/peer/rx-ts/eslint.svg?path=packages/utils)](https://david-dm.org/rx-ts/eslint?path=packages/utils&type=peer) [![David](https://img.shields.io/david/rx-ts/eslint.svg?path=packages/utils)](https://david-dm.org/rx-ts/eslint?path=packages/utils) |
2627

2728
## License
2829

package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"build": "run-p build:*",
1414
"build:r": "r -f esm,es2015",
15-
"build:tsc": "tsc -b",
15+
"build:ts": "tsc -b",
1616
"clean": "rimraf packages/*/{lib,*.tsbuildinfo}",
1717
"lint": "run-p lint:*",
1818
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
@@ -47,16 +47,17 @@
4747
},
4848
"eslintIgnore": [
4949
"coverage",
50-
"lib",
51-
"test/fixtures",
52-
"CHANGELOG.md"
50+
"**/lib",
51+
"**/test/fixtures",
52+
"**/CHANGELOG.md"
5353
],
5454
"jest": {
5555
"preset": "ts-jest",
5656
"collectCoverage": true,
5757
"moduleNameMapper": {
5858
"eslint-plugin-htm": "<rootDir>/packages/htm/src",
59-
"eslint-plugin-markup": "<rootDir>/packages/markup/src"
59+
"eslint-plugin-markup": "<rootDir>/packages/markup/src",
60+
"eslint-plugin-utils": "<rootDir>/packages/utils/src"
6061
},
6162
"modulePathIgnorePatterns": [
6263
"<rootDir>/package.json"
@@ -74,10 +75,12 @@
7475
]
7576
},
7677
"typeCoverage": {
77-
"atLeast": 100,
78+
"atLeast": 99.6,
7879
"cache": true,
7980
"detail": true,
81+
"ignoreAsAssertion": true,
8082
"ignoreCatch": true,
83+
"ignoreNonNullAssertion": true,
8184
"strict": true,
8285
"update": true
8386
}

packages/htm/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434
"eslint": ">=5.0.0"
3535
},
3636
"dependencies": {
37+
"eslint-plugin-utils": "^0.0.0",
3738
"htmlhint": "^0.15.1",
3839
"tslib": "^2.3.0"
3940
},
4041
"publishConfig": {
4142
"access": "public"
4243
},
43-
"sideEffects": false
44+
"sideEffects": [
45+
"./lib/es*.js",
46+
"./lib/index.js"
47+
]
4448
}

packages/htm/src/configs.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Linter } from 'eslint'
2+
3+
export const base: Linter.Config = {
4+
parser: 'eslint-plugin-htm',
5+
plugins: ['htm', 'utils'],
6+
processor: 'utils/jsonMessage',
7+
}
8+
9+
export const recommended: Linter.Config = {
10+
...base,
11+
rules: {
12+
'htm/html': 1,
13+
},
14+
}

packages/htm/src/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1+
import { registerJsonMessageHandler } from 'eslint-plugin-utils'
2+
import { LintResult } from 'htmlhint'
3+
14
export * from './parser'
5+
export * as configs from './configs'
26
export * as rules from './rules'
7+
8+
registerJsonMessageHandler(
9+
'htm/html',
10+
({ evidence, rule, message }: LintResult) => ({
11+
ruleId: `htm/${rule.id}`,
12+
message: `${message}
13+
evidence: ${evidence}
14+
reference: ${rule.link}`,
15+
}),
16+
)

packages/htm/src/rules/html.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export const html: Rule.RuleModule = {
1111
return {
1212
Program() {
1313
const results = HTMLHint.verify(sourceCode)
14-
for (const result of results) {
14+
for (const { evidence, message, line, col, rule } of results) {
1515
context.report({
16-
message: result.message,
16+
message: JSON.stringify({ evidence, message, rule }),
1717
loc: {
18-
line: result.line,
19-
column: result.col,
18+
line,
19+
column: col,
2020
},
2121
})
2222
}

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ Array [
55
Object {
66
"column": 2,
77
"line": 1,
8-
"message": "Doctype must be declared first.",
8+
"message": "Doctype must be declared first.
9+
evidence: <!--comment--><!DOCTYPE html>
10+
reference: https://github.com/thedaviddias/HTMLHint/wiki/doctype-first",
911
"nodeType": null,
10-
"ruleId": "htm/html",
11-
"severity": 2,
12+
"ruleId": "htm/doctype-first",
13+
"severity": 1,
1214
},
1315
]
1416
`;

packages/htm/test/fixtures.spec.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ import path from 'path'
22

33
import { ESLint } from 'eslint'
44

5-
import * as ESLintPluginHtm from 'eslint-plugin-htm'
6-
75
const eslint = new ESLint({
86
useEslintrc: false,
9-
plugins: {
10-
htm: ESLintPluginHtm,
11-
},
7+
ignore: false,
128
overrideConfig: {
139
overrides: [
1410
{
1511
files: '*.html',
16-
parser: 'eslint-plugin-htm',
17-
plugins: ['htm'],
18-
rules: {
19-
'htm/html': 2,
20-
},
12+
extends: 'plugin:htm/recommended',
2113
},
2214
],
2315
},

packages/htm/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../tsconfig.base",
2+
"extends": "../../tsconfig.lib",
33
"compilerOptions": {
44
"composite": true,
55
"rootDir": "src",

packages/markup/.eslintrc.js

-13
This file was deleted.

packages/markup/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
},
3737
"dependencies": {
3838
"cosmiconfig": "^7.0.0",
39+
"eslint-plugin-utils": "^0.0.0",
3940
"markuplint": "^1.9.1",
4041
"markuplint-sync": "^0.3.1",
4142
"synckit": "^0.1.5",
@@ -44,5 +45,8 @@
4445
"publishConfig": {
4546
"access": "public"
4647
},
47-
"sideEffects": false
48+
"sideEffects": [
49+
"./lib/es*.js",
50+
"./lib/index.js"
51+
]
4852
}

packages/markup/src/configs.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Linter } from 'eslint'
2+
3+
export const base: Linter.Config = {
4+
parser: 'eslint-plugin-markup',
5+
plugins: ['markup', 'utils'],
6+
processor: 'utils/jsonMessage',
7+
}
8+
9+
export const recommended: Linter.Config = {
10+
...base,
11+
rules: {
12+
'markup/markup': 1,
13+
},
14+
}

packages/markup/src/index.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1+
import { registerJsonMessageHandler } from 'eslint-plugin-utils'
2+
import { VerifiedResult } from '@markuplint/ml-config'
3+
import { Linter } from 'eslint'
4+
15
export * from './helpers'
26
export * from './parser'
37
export * from './rules'
8+
export * as configs from './configs'
49
export * as rules from './rules'
10+
11+
const SEVERITIES = ['info', 'warning', 'error'] as const
12+
13+
registerJsonMessageHandler(
14+
'markup/markup',
15+
(
16+
{ ruleId, severity, message }: VerifiedResult,
17+
{ severity: eslintSeverity },
18+
) => ({
19+
ruleId: `markup/${ruleId}`,
20+
message,
21+
severity: Math.max(
22+
eslintSeverity,
23+
SEVERITIES.indexOf(severity),
24+
) as Linter.Severity,
25+
}),
26+
)

packages/markup/src/rules/markup.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ export const markup: Rule.RuleModule = {
7171

7272
let fixed = 0
7373

74-
for (const { message, line, col } of resultInfos[0].results) {
74+
for (const { ruleId, severity, message, line, col } of resultInfos[0]
75+
.results) {
7576
context.report({
76-
message,
77+
message: JSON.stringify({ severity, message, ruleId }),
7778
loc: {
7879
line,
7980
column: col,

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ Array [
2121
"line": 1,
2222
"message": "Never insert space after equal sign of attribute",
2323
"nodeType": null,
24-
"ruleId": "markup/markup",
25-
"severity": 2,
24+
"ruleId": "markup/attr-equal-space-after",
25+
"severity": 1,
2626
},
2727
Object {
2828
"column": 10,
2929
"line": 2,
3030
"message": "Never insert space after equal sign of attribute",
3131
"nodeType": null,
32-
"ruleId": "markup/markup",
33-
"severity": 2,
32+
"ruleId": "markup/attr-equal-space-after",
33+
"severity": 1,
3434
},
3535
Object {
3636
"column": 9,
3737
"line": 4,
3838
"message": "Never insert space after equal sign of attribute",
3939
"nodeType": null,
40-
"ruleId": "markup/markup",
41-
"severity": 2,
40+
"ruleId": "markup/attr-equal-space-after",
41+
"severity": 1,
4242
},
4343
Object {
4444
"column": 9,
4545
"line": 7,
4646
"message": "Never insert space after equal sign of attribute",
4747
"nodeType": null,
48-
"ruleId": "markup/markup",
49-
"severity": 2,
48+
"ruleId": "markup/attr-equal-space-after",
49+
"severity": 1,
5050
},
5151
]
5252
`;
@@ -66,8 +66,8 @@ Array [
6666
"line": 1,
6767
"message": "Required space",
6868
"nodeType": null,
69-
"ruleId": "markup/markup",
70-
"severity": 2,
69+
"ruleId": "markup/attr-spacing",
70+
"severity": 1,
7171
},
7272
]
7373
`;
@@ -95,40 +95,40 @@ Array [
9595
"line": 1,
9696
"message": "Never insert space after equal sign of attribute",
9797
"nodeType": null,
98-
"ruleId": "markup/markup",
99-
"severity": 2,
98+
"ruleId": "markup/attr-equal-space-after",
99+
"severity": 1,
100100
},
101101
Object {
102102
"column": 10,
103103
"line": 2,
104104
"message": "Never insert space after equal sign of attribute",
105105
"nodeType": null,
106-
"ruleId": "markup/markup",
107-
"severity": 2,
106+
"ruleId": "markup/attr-equal-space-after",
107+
"severity": 1,
108108
},
109109
Object {
110110
"column": 9,
111111
"line": 4,
112112
"message": "Never insert space after equal sign of attribute",
113113
"nodeType": null,
114-
"ruleId": "markup/markup",
115-
"severity": 2,
114+
"ruleId": "markup/attr-equal-space-after",
115+
"severity": 1,
116116
},
117117
Object {
118118
"column": 9,
119119
"line": 7,
120120
"message": "Never insert space after equal sign of attribute",
121121
"nodeType": null,
122-
"ruleId": "markup/markup",
123-
"severity": 2,
122+
"ruleId": "markup/attr-equal-space-after",
123+
"severity": 1,
124124
},
125125
Object {
126126
"column": 20,
127127
"line": 11,
128128
"message": "Required space",
129129
"nodeType": null,
130-
"ruleId": "markup/markup",
131-
"severity": 2,
130+
"ruleId": "markup/attr-spacing",
131+
"severity": 1,
132132
},
133133
]
134134
`;
@@ -140,7 +140,7 @@ Array [
140140
"line": 1,
141141
"message": "Required doctype",
142142
"nodeType": null,
143-
"ruleId": "markup/markup",
143+
"ruleId": "markup/doctype",
144144
"severity": 2,
145145
},
146146
]

0 commit comments

Comments
 (0)