1
1
import HTMLParser from './htmlparser'
2
- import Reporter from './reporter'
2
+ import Reporter , { ReportMessageCallback } from './reporter'
3
3
import * as HTMLRules from './rules'
4
- import { Hint , Rule , Ruleset } from './types'
4
+ import { Hint , isRuleSeverity , Rule , Ruleset , RuleSeverity } from './types'
5
5
6
6
export interface FormatOptions {
7
7
colors ?: boolean
@@ -11,16 +11,16 @@ export interface FormatOptions {
11
11
class HTMLHintCore {
12
12
public rules : { [ id : string ] : Rule } = { }
13
13
public readonly defaultRuleset : Ruleset = {
14
- 'tagname-lowercase' : true ,
15
- 'attr-lowercase' : true ,
16
- 'attr-value-double-quotes' : true ,
17
- 'doctype-first' : true ,
18
- 'tag-pair' : true ,
19
- 'spec-char-escape' : true ,
20
- 'id-unique' : true ,
21
- 'src-not-empty' : true ,
22
- 'attr-no-duplication' : true ,
23
- 'title-require' : true ,
14
+ 'tagname-lowercase' : 'error' ,
15
+ 'attr-lowercase' : 'error' ,
16
+ 'attr-value-double-quotes' : 'error' ,
17
+ 'doctype-first' : 'error' ,
18
+ 'tag-pair' : 'error' ,
19
+ 'spec-char-escape' : 'error' ,
20
+ 'id-unique' : 'error' ,
21
+ 'src-not-empty' : 'error' ,
22
+ 'attr-no-duplication' : 'error' ,
23
+ 'title-require' : 'error' ,
24
24
}
25
25
26
26
public addRule ( rule : Rule ) {
@@ -37,18 +37,17 @@ class HTMLHintCore {
37
37
/ ^ \s * < ! - - \s * h t m l h i n t \s + ( [ ^ \r \n ] + ?) \s * - - > / i,
38
38
( all , strRuleset : string ) => {
39
39
// For example:
40
- // all is '<!-- htmlhint alt-require:true -->'
41
- // strRuleset is 'alt-require:true '
40
+ // all is '<!-- htmlhint alt-require:warn -->'
41
+ // strRuleset is 'alt-require:warn '
42
42
strRuleset . replace (
43
43
/ (?: ^ | , ) \s * ( [ ^ : , ] + ) \s * (?: \: \s * ( [ ^ , \s ] + ) ) ? / g,
44
44
( all , ruleId : string , value : string | undefined ) => {
45
45
// For example:
46
- // all is 'alt-require:true '
46
+ // all is 'alt-require:warn '
47
47
// ruleId is 'alt-require'
48
- // value is 'true '
48
+ // value is 'warn '
49
49
50
- ruleset [ ruleId ] =
51
- value !== undefined && value . length > 0 ? JSON . parse ( value ) : true
50
+ ruleset [ ruleId ] = isRuleSeverity ( value ) ? value : 'error'
52
51
53
52
return ''
54
53
}
@@ -66,8 +65,19 @@ class HTMLHintCore {
66
65
67
66
for ( const id in ruleset ) {
68
67
rule = rules [ id ]
69
- if ( rule !== undefined && ruleset [ id ] !== false ) {
70
- rule . init ( parser , reporter , ruleset [ id ] )
68
+ const ruleConfig = ruleset [ id ]
69
+ const ruleSeverity : RuleSeverity = Array . isArray ( ruleConfig )
70
+ ? ruleConfig [ 0 ]
71
+ : ruleConfig
72
+ if ( rule !== undefined && ruleSeverity !== 'off' ) {
73
+ const reportMessageCallback : ReportMessageCallback = reporter [
74
+ ruleSeverity
75
+ ] . bind ( reporter )
76
+ rule . init (
77
+ parser ,
78
+ reportMessageCallback ,
79
+ Array . isArray ( ruleConfig ) ? ruleConfig [ 1 ] : undefined
80
+ )
71
81
}
72
82
}
73
83
0 commit comments