From 0705c1fbc38642aa0381c7c161484369ade3cb70 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Mon, 6 Jul 2020 16:59:37 +0200 Subject: [PATCH] feat: move rules into dedicated attribute (#476) * feat: move rules into dedicated attribute * test: update tests --- src/cli/htmlhint.ts | 6 ++-- src/core/core.ts | 15 ++++++-- src/core/types.ts | 4 +++ test/core.spec.js | 24 +++++++++---- test/rules/alt-require.spec.js | 26 +++++++------- test/rules/attr-lowercase.spec.js | 14 ++++---- test/rules/attr-no-duplication.spec.js | 4 +-- .../attr-no-unnecessary-whitespace.spec.js | 4 +-- test/rules/attr-sort.spec.js | 6 ++-- test/rules/attr-unsafe-chars.spec.js | 6 ++-- test/rules/attr-value-double-quotes.spec.js | 4 +-- test/rules/attr-value-not-empty.spec.js | 6 ++-- test/rules/attr-value-single-quotes.spec.js | 4 +-- test/rules/attr-whitespace.spec.js | 6 ++-- test/rules/doctype-first.spec.js | 4 +-- test/rules/doctype-html5.spec.js | 4 +-- test/rules/head-require.spec.js | 16 ++++----- test/rules/head-script-disabled.spec.js | 16 ++++----- test/rules/href-abs-or-rel.spec.js | 8 ++--- test/rules/id-class-ad-disabled.spec.js | 34 +++++++++--------- test/rules/id-class-value.spec.js | 18 +++++----- test/rules/id-unique.spec.js | 4 +-- test/rules/inline-script-disabled.spec.js | 8 ++--- test/rules/inline-style-disabled.spec.js | 4 +-- test/rules/input-requires-label.spec.js | 12 +++---- test/rules/script-disabled.spec.js | 4 +-- test/rules/space-tab-mixed-disabled.spec.js | 36 +++++++++---------- test/rules/spec-char-escape.spec.js | 8 ++--- test/rules/src-not-empty.spec.js | 6 ++-- test/rules/style-disabled.spec.js | 4 +-- test/rules/tag-pair.spec.js | 8 ++--- test/rules/tag-self-close.spec.js | 4 +-- test/rules/tagname-lowercase.spec.js | 4 +-- test/rules/tagname-specialchars.spec.js | 4 +-- test/rules/tags-check.spec.js | 16 ++++----- test/rules/title-require.spec.js | 14 ++++---- 36 files changed, 196 insertions(+), 169 deletions(-) diff --git a/src/cli/htmlhint.ts b/src/cli/htmlhint.ts index ce8aa8ab1..1236feb64 100644 --- a/src/cli/htmlhint.ts +++ b/src/cli/htmlhint.ts @@ -465,7 +465,7 @@ function hintFile(filepath: string, ruleset?: Ruleset) { // ignore } - return HTMLHint.verify(content, ruleset) + return HTMLHint.verify(content, { rules: ruleset }) } // hint stdin @@ -483,7 +483,7 @@ function hintStdin( process.stdin.on('end', () => { const content = buffers.join('') - const messages = HTMLHint.verify(content, ruleset) + const messages = HTMLHint.verify(content, { rules: ruleset }) callback(messages) }) } @@ -496,7 +496,7 @@ function hintUrl( ) { request.get(url, (error, response, body) => { if (!error && response.statusCode == 200) { - const messages = HTMLHint.verify(body, ruleset) + const messages = HTMLHint.verify(body, { rules: ruleset }) callback(messages) } else { callback([]) diff --git a/src/core/core.ts b/src/core/core.ts index cd78c6cfd..bf6c55482 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -1,7 +1,14 @@ import HTMLParser from './htmlparser' import Reporter, { ReportMessageCallback } from './reporter' import * as HTMLRules from './rules' -import { Hint, isRuleSeverity, Rule, Ruleset, RuleSeverity } from './types' +import { + Configuration, + Hint, + isRuleSeverity, + Rule, + Ruleset, + RuleSeverity, +} from './types' export interface FormatOptions { colors?: boolean @@ -27,7 +34,11 @@ class HTMLHintCore { this.rules[rule.id] = rule } - public verify(html: string, ruleset: Ruleset = this.defaultRuleset) { + public verify( + html: string, + config: Configuration = { rules: this.defaultRuleset } + ) { + let ruleset = config.rules ?? this.defaultRuleset if (Object.keys(ruleset).length === 0) { ruleset = this.defaultRuleset } diff --git a/src/core/types.ts b/src/core/types.ts index 1f202047c..959ca4824 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -1,6 +1,10 @@ import { HTMLParser } from './core' import { ReportMessageCallback } from './reporter' +export interface Configuration { + rules?: Ruleset +} + export interface Rule { id: string description: string diff --git a/test/core.spec.js b/test/core.spec.js index d66669cb2..b7eddb548 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -5,7 +5,7 @@ const HTMLHint = require('../dist/htmlhint.js').HTMLHint describe('Core', () => { it('Set false to rule no effected should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, { 'alt-require': 'off' }) + const messages = HTMLHint.verify(code, { rules: { 'alt-require': 'off' } }) expect(messages.length).to.be(0) }) @@ -27,7 +27,9 @@ describe('Core', () => { // With value = 'error' let code = '\r\n' let messages = HTMLHint.verify(code, { - 'alt-require': 'off', + rules: { + 'alt-require': 'off', + }, }) expect(messages.length).to.be(1) @@ -38,7 +40,9 @@ describe('Core', () => { // Without value code = '\r\n' messages = HTMLHint.verify(code, { - 'alt-require': 'off', + rules: { + 'alt-require': 'off', + }, }) expect(messages.length).to.be(1) @@ -49,14 +53,18 @@ describe('Core', () => { // With value = 'off' code = '\r\n' messages = HTMLHint.verify(code, { - 'alt-require': 'error', + rules: { + 'alt-require': 'error', + }, }) expect(messages.length).to.be(0) // Without rule code = '\r\n' messages = HTMLHint.verify(code, { - 'alt-require': 'off', + rules: { + 'alt-require': 'off', + }, }) expect(messages.length).to.be(0) @@ -66,8 +74,10 @@ describe('Core', () => { const code = 'tttttttttttttttttttttttttttttttttttt
中文tttttttttttttttttttttttttttttttttttttttttttttt' const messages = HTMLHint.verify(code, { - 'tag-pair': 'error', - 'alt-require': 'error', + rules: { + 'tag-pair': 'error', + 'alt-require': 'error', + }, }) let arrLogs = HTMLHint.format(messages) expect(arrLogs.length).to.be(4) diff --git a/test/rules/alt-require.spec.js b/test/rules/alt-require.spec.js index 716e8d75b..f79347e5b 100644 --- a/test/rules/alt-require.spec.js +++ b/test/rules/alt-require.spec.js @@ -10,19 +10,19 @@ ruleOptions[ruldId] = 'warn' describe(`Rules: ${ruldId}`, () => { it('Img tag have empty alt attribute should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Img tag have non empty alt attribute should not result in an error', () => { const code = 'test' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Img tag have not alt attribute should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -33,19 +33,19 @@ describe(`Rules: ${ruldId}`, () => { /* A tag can have shape and coords attributes and not have alt attribute */ it('A tag have not alt attribute should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Area tag have not href and alt attributes should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Area[href] tag have not alt attribute should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -55,7 +55,7 @@ describe(`Rules: ${ruldId}`, () => { it('Area[href] tag have empty alt attribute should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -65,25 +65,25 @@ describe(`Rules: ${ruldId}`, () => { it('Area[href] tag have non emtpy alt attribute should not result in an error', () => { const code = 'test' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Input tag have not type and alt attributes should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Input[type="text"] tag have not alt attribute should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Input[type="image"] tag have not alt attribute should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -93,7 +93,7 @@ describe(`Rules: ${ruldId}`, () => { it('Input[type="image"] tag have empty alt attribute should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -103,7 +103,7 @@ describe(`Rules: ${ruldId}`, () => { it('Input[type="image"] tag have non emtpy alt attribute should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-lowercase.spec.js b/test/rules/attr-lowercase.spec.js index 1070c6f03..3164cdfb7 100644 --- a/test/rules/attr-lowercase.spec.js +++ b/test/rules/attr-lowercase.spec.js @@ -10,14 +10,14 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Not all lowercase attr should result in an error', () => { let code = '

' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(3) code = '

' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(2) @@ -29,35 +29,35 @@ describe(`Rules: ${ruldId}`, () => { it('Lowercase attr should not result in an error', () => { const code = '

' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Set is false should not result in an error', () => { const code = '

' ruleOptions[ruldId] = 'off' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Set to array list should not result in an error', () => { const code = '

' ruleOptions[ruldId] = ['error', { exceptions: ['testBox', 'tttAAA'] }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Set to array list with RegExp should not result in an error', () => { const code = '

' ruleOptions[ruldId] = ['error', { exceptions: ['testBox', /bind:.*/] }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Set to array list with regex string should not result in an error', () => { const code = '

' ruleOptions[ruldId] = ['error', { exceptions: ['testBox', '/\\[.*\\]/'] }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-no-duplication.spec.js b/test/rules/attr-no-duplication.spec.js index f3744dbda..e1fba4edb 100644 --- a/test/rules/attr-no-duplication.spec.js +++ b/test/rules/attr-no-duplication.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Attribute name been duplication should result in an error', () => { const code = 'bbb' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -19,7 +19,7 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute name not been duplication should not result in an error', () => { const code = 'bbb' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-no-unnecessary-whitespace.spec.js b/test/rules/attr-no-unnecessary-whitespace.spec.js index 9ed09972a..0a8e1d79e 100644 --- a/test/rules/attr-no-unnecessary-whitespace.spec.js +++ b/test/rules/attr-no-unnecessary-whitespace.spec.js @@ -15,7 +15,7 @@ describe(`Rules: ${ruldId}`, () => { '

', ] for (let i = 0; i < codes.length; i++) { - const messages = HTMLHint.verify(codes[i], ruleOptions) + const messages = HTMLHint.verify(codes[i], { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -26,7 +26,7 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute without spaces should not result in an error', () => { const codes = ['
', '
'] for (let i = 0; i < codes.length; i++) { - const messages = HTMLHint.verify(codes[i], ruleOptions) + const messages = HTMLHint.verify(codes[i], { rules: ruleOptions }) expect(messages.length).to.be(0) } }) diff --git a/test/rules/attr-sort.spec.js b/test/rules/attr-sort.spec.js index 80b9a7ac9..a12f2269a 100644 --- a/test/rules/attr-sort.spec.js +++ b/test/rules/attr-sort.spec.js @@ -11,7 +11,7 @@ describe(`Rules: ${ruleId}`, () => { it('Attribute unsorted tags must result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruleId) @@ -21,7 +21,7 @@ describe(`Rules: ${ruleId}`, () => { it('Attribute unsorted tags that are unrecognizable should not throw error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) @@ -29,7 +29,7 @@ describe(`Rules: ${ruleId}`, () => { it('Attribute unsorted of tags of various types should throw error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruleId) diff --git a/test/rules/attr-unsafe-chars.spec.js b/test/rules/attr-unsafe-chars.spec.js index 53d39a759..1ca55ef0b 100644 --- a/test/rules/attr-unsafe-chars.spec.js +++ b/test/rules/attr-unsafe-chars.spec.js @@ -11,7 +11,7 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute value have unsafe chars should result in an error', () => { const code = 'Sud Web 2012' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -21,14 +21,14 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute value have no unsafe chars should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Attribute value have \\r\\n\\t should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-value-double-quotes.spec.js b/test/rules/attr-value-double-quotes.spec.js index 3c85f93e7..06ea4a030 100644 --- a/test/rules/attr-value-double-quotes.spec.js +++ b/test/rules/attr-value-double-quotes.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Attribute value closed by single quotes should result in an error', () => { const code = "" - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(3) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -25,7 +25,7 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute value no closed should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-value-not-empty.spec.js b/test/rules/attr-value-not-empty.spec.js index d11848140..ced884191 100644 --- a/test/rules/attr-value-not-empty.spec.js +++ b/test/rules/attr-value-not-empty.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'warn' describe(`Rules: ${ruldId}`, () => { it('Attribute value have no value should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -20,13 +20,13 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute value closed by quote but no value should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Attribute value closed by quote and have value should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-value-single-quotes.spec.js b/test/rules/attr-value-single-quotes.spec.js index 4d797864c..2660c9b70 100644 --- a/test/rules/attr-value-single-quotes.spec.js +++ b/test/rules/attr-value-single-quotes.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Attribute value closed by double quotes should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(3) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -25,7 +25,7 @@ describe(`Rules: ${ruldId}`, () => { it('Attribute value no closed should not result in an error', () => { const code = "" - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/attr-whitespace.spec.js b/test/rules/attr-whitespace.spec.js index 0130097f1..5f0ba5f62 100644 --- a/test/rules/attr-whitespace.spec.js +++ b/test/rules/attr-whitespace.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Double spaces in attributes should result in an error', () => { const code = '

' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -18,7 +18,7 @@ describe(`Rules: ${ruldId}`, () => { it('Leading/trailing white space should result in an error', () => { const code = '

' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -26,7 +26,7 @@ describe(`Rules: ${ruldId}`, () => { it('Double spaces and leading/trailing white space should result in an error', () => { const code = '

' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) diff --git a/test/rules/doctype-first.spec.js b/test/rules/doctype-first.spec.js index ac5e9fb03..630541c1f 100644 --- a/test/rules/doctype-first.spec.js +++ b/test/rules/doctype-first.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Doctype not be first should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -19,7 +19,7 @@ describe(`Rules: ${ruldId}`, () => { it('Doctype be first should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/doctype-html5.spec.js b/test/rules/doctype-html5.spec.js index 0a6a3a303..b796ddb28 100644 --- a/test/rules/doctype-html5.spec.js +++ b/test/rules/doctype-html5.spec.js @@ -11,7 +11,7 @@ describe(`Rules: ${ruldId}`, () => { it('Doctype not html5 should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -21,7 +21,7 @@ describe(`Rules: ${ruldId}`, () => { it('Doctype html5 should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/head-require.spec.js b/test/rules/head-require.spec.js index 697f9776c..576efc041 100644 --- a/test/rules/head-require.spec.js +++ b/test/rules/head-require.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'warn' describe(`Rules: ${ruldId}`, () => { it('External script in head should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -20,40 +20,40 @@ describe(`Rules: ${ruldId}`, () => { it('Internal Script in head should result in an error', () => { let code = '' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(7) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) }) it('Script in body not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Template script in head not result in an error', () => { let code = '' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('No head not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/head-script-disabled.spec.js b/test/rules/head-script-disabled.spec.js index 697f9776c..576efc041 100644 --- a/test/rules/head-script-disabled.spec.js +++ b/test/rules/head-script-disabled.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'warn' describe(`Rules: ${ruldId}`, () => { it('External script in head should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -20,40 +20,40 @@ describe(`Rules: ${ruldId}`, () => { it('Internal Script in head should result in an error', () => { let code = '' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(7) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) }) it('Script in body not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Template script in head not result in an error', () => { let code = '' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('No head not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/href-abs-or-rel.spec.js b/test/rules/href-abs-or-rel.spec.js index 2d29ac142..3a7420c2b 100644 --- a/test/rules/href-abs-or-rel.spec.js +++ b/test/rules/href-abs-or-rel.spec.js @@ -10,7 +10,7 @@ describe(`Rules: ${ruldId}`, () => { const code = 'aaabbbcccddd' ruleOptions[ruldId] = ['error', { mode: 'absolute' }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -24,7 +24,7 @@ describe(`Rules: ${ruldId}`, () => { const code = 'aaabbbcccddd' ruleOptions[ruldId] = ['error', { mode: 'absolute' }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) @@ -32,7 +32,7 @@ describe(`Rules: ${ruldId}`, () => { const code = 'aaabbbcccddd' ruleOptions[ruldId] = ['error', { mode: 'relative' }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -46,7 +46,7 @@ describe(`Rules: ${ruldId}`, () => { const code = 'aaabbbcccddd' ruleOptions[ruldId] = ['error', { mode: 'relative' }] - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/id-class-ad-disabled.spec.js b/test/rules/id-class-ad-disabled.spec.js index 791624aff..599e2f37a 100644 --- a/test/rules/id-class-ad-disabled.spec.js +++ b/test/rules/id-class-ad-disabled.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'warn' describe(`Rules: ${ruldId}`, () => { it('Id use ad keyword should result in an error', () => { let code = '

' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].type).to.be('warning') expect(messages[0].rule.id).to.be(ruldId) @@ -18,42 +18,42 @@ describe(`Rules: ${ruldId}`, () => { expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -62,49 +62,49 @@ describe(`Rules: ${ruldId}`, () => { it('Class use ad keyword should result in an error', () => { let code = '
test
' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) expect(messages[0].col).to.be(5) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -113,15 +113,15 @@ describe(`Rules: ${ruldId}`, () => { it('Id and class no ad keyword used should not result in an error', () => { let code = '
test
' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) code = '
test
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/id-class-value.spec.js b/test/rules/id-class-value.spec.js index 01c472f40..a28cce0f1 100644 --- a/test/rules/id-class-value.spec.js +++ b/test/rules/id-class-value.spec.js @@ -22,7 +22,7 @@ ruleOptionsReg[ruldId] = [ describe(`Rules: ${ruldId}`, () => { it('Id and class value be not lower case and split by underline should result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsUnderline) + const messages = HTMLHint.verify(code, { rules: ruleOptionsUnderline }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be('id-class-value') expect(messages[0].line).to.be(1) @@ -36,14 +36,16 @@ describe(`Rules: ${ruldId}`, () => { it('Id and class value be lower case and split by underline should not result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsUnderline) + const messages = HTMLHint.verify(code, { rules: ruleOptionsUnderline }) expect(messages.length).to.be(0) }) it('Id and class value be not lower case and split by dash should result in an error', () => { const code = '
' const messages = HTMLHint.verify(code, { - 'id-class-value': ['error', 'dash'], + rules: { + 'id-class-value': ['error', 'dash'], + }, }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be('id-class-value') @@ -56,13 +58,13 @@ describe(`Rules: ${ruldId}`, () => { it('Id and class value be lower case and split by dash should not result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsDash) + const messages = HTMLHint.verify(code, { rules: ruleOptionsDash }) expect(messages.length).to.be(0) }) it('Id and class value be not meet hump style should result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsHump) + const messages = HTMLHint.verify(code, { rules: ruleOptionsHump }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be('id-class-value') expect(messages[0].line).to.be(1) @@ -74,13 +76,13 @@ describe(`Rules: ${ruldId}`, () => { it('Id and class value be meet hump style should not result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsHump) + const messages = HTMLHint.verify(code, { rules: ruleOptionsHump }) expect(messages.length).to.be(0) }) it('Id and class value be not meet regexp should result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsReg) + const messages = HTMLHint.verify(code, { rules: ruleOptionsReg }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be('id-class-value') expect(messages[0].line).to.be(1) @@ -92,7 +94,7 @@ describe(`Rules: ${ruldId}`, () => { it('Id and class value be meet regexp should not result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptionsReg) + const messages = HTMLHint.verify(code, { rules: ruleOptionsReg }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/id-unique.spec.js b/test/rules/id-unique.spec.js index 0c2286151..75fc84868 100644 --- a/test/rules/id-unique.spec.js +++ b/test/rules/id-unique.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'error' describe(`Rules: ${ruldId}`, () => { it('Id redefine should result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -20,7 +20,7 @@ describe(`Rules: ${ruldId}`, () => { it('Id no redefine should not result in an error', () => { const code = '
' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) }) diff --git a/test/rules/inline-script-disabled.spec.js b/test/rules/inline-script-disabled.spec.js index 98a2c0a2e..869eb53c1 100644 --- a/test/rules/inline-script-disabled.spec.js +++ b/test/rules/inline-script-disabled.spec.js @@ -11,7 +11,7 @@ describe(`Rules: ${ruldId}`, () => { it('Inline on event should result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -22,14 +22,14 @@ describe(`Rules: ${ruldId}`, () => { it('onttt should not result in an error', () => { const code = '' - const messages = HTMLHint.verify(code, ruleOptions) + const messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(0) }) it('Javascript protocol [ javascript: ] should result in an error', () => { let code = '' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -39,7 +39,7 @@ describe(`Rules: ${ruldId}`, () => { code = 'test1test2' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(2) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) diff --git a/test/rules/inline-style-disabled.spec.js b/test/rules/inline-style-disabled.spec.js index 09251e266..fec36f2d2 100644 --- a/test/rules/inline-style-disabled.spec.js +++ b/test/rules/inline-style-disabled.spec.js @@ -10,7 +10,7 @@ ruleOptions[ruldId] = 'warn' describe(`Rules: ${ruldId}`, () => { it('Inline style should result in an error', () => { let code = '
' - let messages = HTMLHint.verify(code, ruleOptions) + let messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) expect(messages[0].rule.id).to.be(ruldId) expect(messages[0].line).to.be(1) @@ -18,7 +18,7 @@ describe(`Rules: ${ruldId}`, () => { expect(messages[0].type).to.be('warning') code = '
' - messages = HTMLHint.verify(code, ruleOptions) + messages = HTMLHint.verify(code, { rules: ruleOptions }) expect(messages.length).to.be(1) }) }) diff --git a/test/rules/input-requires-label.spec.js b/test/rules/input-requires-label.spec.js index f1e86f027..8d2637e92 100644 --- a/test/rules/input-requires-label.spec.js +++ b/test/rules/input-requires-label.spec.js @@ -12,14 +12,14 @@ describe(`Rules: ${ruleId}`, () => { it('Input tag with a matching label before should result in no error', () => { const code = '