From f0ad770e8de9704404253d9a5cccf30f1aa9cc61 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 17 May 2020 13:04:13 -0400 Subject: [PATCH] fix: add prettier and eslint (#388) * add eslintrc * eslint and prettier all files * fix: replace by npm script * fix: prettify more files * fixes based on review --- .eslintrc.js | 13 + .github/ISSUE_TEMPLATE/bug_report.md | 18 +- .github/ISSUE_TEMPLATE/feature_request.md | 1 - .github/workflows/ci.yml | 3 + .prettierignore | 4 +- .prettierrc | 9 + .prettierrc.json | 6 - CHANGELOG.md | 7 +- CONTRIBUTING.md | 3 +- bin/formatter.js | 98 +-- bin/formatters/checkstyle.js | 96 +-- bin/formatters/compact.js | 49 +- bin/formatters/default.js | 81 ++- bin/formatters/html.js | 59 +- bin/formatters/json.js | 12 +- bin/formatters/junit.js | 102 +-- bin/formatters/markdown.js | 73 +- bin/formatters/unix.js | 52 +- bin/htmlhint | 679 +++++++++--------- codecov.yml | 2 - commitizen.config.js | 87 ++- commitlint.config.js | 26 +- package-lock.json | 629 +++++++++++++++++ package.json | 21 +- parser-preset.js | 10 +- rollup.config.js | 19 +- src/core.js | 123 ++-- src/htmlparser.js | 192 +++--- src/reporter.js | 46 +- src/rules/alt-require.js | 20 +- src/rules/attr-lowercase.js | 43 +- src/rules/attr-no-duplication.js | 30 +- src/rules/attr-no-unnecessary-whitespace.js | 49 +- src/rules/attr-sorted.js | 42 +- src/rules/attr-unsafe-chars.js | 27 +- src/rules/attr-value-double-quotes.js | 18 +- src/rules/attr-value-not-empty.js | 18 +- src/rules/attr-value-single-quotes.js | 18 +- src/rules/attr-whitespace.js | 30 +- src/rules/doctype-first.js | 20 +- src/rules/doctype-html5.js | 18 +- src/rules/head-script-disabled.js | 30 +- src/rules/href-abs-or-rel.js | 26 +- src/rules/id-class-ad-disabled.js | 26 +- src/rules/id-class-value.js | 42 +- src/rules/id-unique.js | 28 +- src/rules/index.js | 62 +- src/rules/inline-script-disabled.js | 30 +- src/rules/inline-style-disabled.js | 22 +- src/rules/input-requires-label.js | 89 +-- src/rules/script-disabled.js | 16 +- src/rules/space-tab-mixed-disabled.js | 42 +- src/rules/spec-char-escape.js | 19 +- src/rules/src-not-empty.js | 18 +- src/rules/style-disabled.js | 14 +- src/rules/tag-pair.js | 52 +- src/rules/tag-self-close.js | 18 +- src/rules/tagname-lowercase.js | 18 +- src/rules/tagname-specialchars.js | 18 +- src/rules/tags-check.js | 282 +++++--- src/rules/title-require.js | 34 +- test/core.spec.js | 92 +-- test/executable.spec.js | 44 +- test/htmlparser.spec.js | 686 +++++++++---------- test/rules/alt-require.spec.js | 214 +++--- test/rules/attr-lowercase.spec.js | 126 ++-- test/rules/attr-no-duplication.spec.js | 40 +- test/rules/attr-no-unnecessary-whitespace.js | 48 +- test/rules/attr-sort.spec.js | 52 +- test/rules/attr-unsafe-chars.spec.js | 52 +- test/rules/attr-value-double-quotes.spec.js | 52 +- test/rules/attr-value-not-empty.spec.js | 52 +- test/rules/attr-value-single-quotes.spec.js | 52 +- test/rules/attr-whitespace.spec.js | 56 +- test/rules/default.spec.js | 18 +- test/rules/doctype-first.spec.js | 40 +- test/rules/doctype-html5.spec.js | 42 +- test/rules/head-require.spec.js | 113 ++- test/rules/head-script-disabled.spec.js | 113 ++- test/rules/href-abs-or-rel.spec.js | 84 +-- test/rules/id-class-ad-disabled.spec.js | 254 +++---- test/rules/id-class-value.spec.js | 152 ++-- test/rules/id-unique.spec.js | 42 +- test/rules/inline-script-disabled.spec.js | 80 +-- test/rules/inline-style-disabled.spec.js | 38 +- test/rules/input-requires-label.spec.js | 138 ++-- test/rules/script-disabled.spec.js | 42 +- test/rules/space-tab-mixed-disabled.spec.js | 224 +++--- test/rules/spec-char-escape.spec.js | 88 ++- test/rules/src-not-empty.spec.js | 44 +- test/rules/style-disabled.spec.js | 42 +- test/rules/tag-pair.spec.js | 72 +- test/rules/tag-self-close.spec.js | 52 +- test/rules/tagname-lowercase.spec.js | 58 +- test/rules/tagname-specialchars.spec.js | 46 +- test/rules/tags-check.spec.js | 109 ++- test/rules/title-require.spec.js | 92 +-- 97 files changed, 4042 insertions(+), 3246 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .prettierrc delete mode 100644 .prettierrc.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..da234b69a --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + extends: ['eslint:recommended', 'plugin:prettier/recommended'], + env: { + browser: true, + amd: true, + node: true, + mocha: true, + }, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + }, +} diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b73537336..297b12238 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,7 +1,6 @@ --- name: Bug report about: Create a report to help us improve - --- **Describe the bug** @@ -9,6 +8,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -21,15 +21,17 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] **Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 066b2d920..a09db44fb 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,7 +1,6 @@ --- name: Feature request about: Suggest an idea for this project - --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25fa41bce..152008a3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,9 @@ jobs: - name: Install dependencies run: npm ci + - name: Run lint + run: npm run lint + - name: Build run: npm run build --if-present env: diff --git a/.prettierignore b/.prettierignore index a2d374c2c..3f165cf8d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,8 +7,10 @@ /coverage # production -/lib +/dist # npm package-lock.json npm-debug.log* +.nyc_output +test/html diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..22c2e20d7 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "semi": false, + "singleQuote": true, + "bracketSpacing": true, + "trailingComma": "es5", + "useTabs": false, + "tabWidth": 2, + "printWidth": 80 +} diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index 44c416271..000000000 --- a/.prettierrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "printWidth": 80, - "tabWidth": 2, - "useTabs": false, - "singleQuote": true -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8259a763c..f39b627ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,4 @@ -HTMLHint change log -==================== +# HTMLHint change log ## ver 0.9.14 (2016-5-2) @@ -57,7 +56,7 @@ fix: 1. close issue: #79, fix exit with 0 when hint errors 2. fix end event col -2. attr-unsafe-chars(rule): exclude `\r\n` +3. attr-unsafe-chars(rule): exclude `\r\n` ## ver 0.9.8 (2015-10-7) @@ -129,7 +128,7 @@ add: fix: -1. compatible with: +1. compatible with:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 553b6f5e3..1991f93fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,6 +5,7 @@ First, thank you for considering contributing to HTMLHint! It's people like you that make the open source community such a great community! 😊 We welcome any type of contribution, not only code. You can help with + - **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open) - **Marketing**: writing blog posts, howto's, printing stickers, ... - **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ... @@ -12,7 +13,7 @@ We welcome any type of contribution, not only code. You can help with ## Your First Contribution -Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). +Working on your first Pull Request? You can learn how from this _free_ series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). ## Submitting code diff --git a/bin/formatter.js b/bin/formatter.js index a95f5b6d5..e54254a72 100644 --- a/bin/formatter.js +++ b/bin/formatter.js @@ -1,57 +1,59 @@ -var path = require('path'); -var events = require('events'); -var glob = require('glob'); -path.parse = path.parse || require('path-parse'); +var path = require('path') +var events = require('events') +var glob = require('glob') +path.parse = path.parse || require('path-parse') -var mapFormatters; -var arrSupportedFormatters; -var HTMLHint; -var options; +var mapFormatters +var arrSupportedFormatters +var HTMLHint +var options // load formatters -mapFormatters = loadFormatters(); -arrSupportedFormatters = []; -for(var formatterName in mapFormatters){ - if(formatterName !== 'default'){ - arrSupportedFormatters.push(formatterName); - } +mapFormatters = loadFormatters() +arrSupportedFormatters = [] +for (var formatterName in mapFormatters) { + if (formatterName !== 'default') { + arrSupportedFormatters.push(formatterName) + } } // load all formatters -function loadFormatters(){ - var arrFiles = glob.sync('./formatters/*.js', { - 'cwd': __dirname, - 'dot': false, - 'nodir': true, - 'strict': false, - 'silent': true - }); - var mapFormatters = {}; - arrFiles.forEach(function(file){ - var fileInfo = path.parse(file); - var formatterPath = path.resolve(__dirname, file); - mapFormatters[fileInfo.name] = require(formatterPath); - }); - return mapFormatters; +function loadFormatters() { + var arrFiles = glob.sync('./formatters/*.js', { + cwd: __dirname, + dot: false, + nodir: true, + strict: false, + silent: true, + }) + var mapFormatters = {} + arrFiles.forEach(function (file) { + var fileInfo = path.parse(file) + var formatterPath = path.resolve(__dirname, file) + mapFormatters[fileInfo.name] = require(formatterPath) + }) + return mapFormatters } -var formatter =new events.EventEmitter(); -formatter.getSupported = function(){ - return arrSupportedFormatters; -}; -formatter.init = function(tmpHTMLHint, tmpOptions){ - HTMLHint = tmpHTMLHint; - options = tmpOptions; -}; -formatter.setFormat = function(format){ - var formatHandel = mapFormatters[format]; - if(formatHandel === undefined){ - console.log('No supported formatter, supported formatters: %s'.red, arrSupportedFormatters.join(', ')); - process.exit(1); - } - else{ - formatHandel(formatter, HTMLHint, options); - } -}; +var formatter = new events.EventEmitter() +formatter.getSupported = function () { + return arrSupportedFormatters +} +formatter.init = function (tmpHTMLHint, tmpOptions) { + HTMLHint = tmpHTMLHint + options = tmpOptions +} +formatter.setFormat = function (format) { + var formatHandel = mapFormatters[format] + if (formatHandel === undefined) { + console.log( + 'No supported formatter, supported formatters: %s'.red, + arrSupportedFormatters.join(', ') + ) + process.exit(1) + } else { + formatHandel(formatter, HTMLHint, options) + } +} -module.exports = formatter; +module.exports = formatter diff --git a/bin/formatters/checkstyle.js b/bin/formatters/checkstyle.js index 1319430a5..fd54e7c25 100644 --- a/bin/formatters/checkstyle.js +++ b/bin/formatters/checkstyle.js @@ -1,48 +1,50 @@ -var xml = require('xml'); +var xml = require('xml') -var checkstyleFormatter = function(formatter){ - formatter.on('end', function(event){ - var arrFiles = []; - var arrAllMessages = event.arrAllMessages; - arrAllMessages.forEach(function(fileInfo){ - var arrMessages = fileInfo.messages; - var arrErrors = []; - arrMessages.forEach(function(message){ - arrErrors.push({ - error: { - _attr: { - line: message.line, - column: message.col, - severity: message.type, - message: message.message, - source: 'htmlhint.'+message.rule.id - } - } - }); - }); - arrFiles.push({ - file: [ - { - _attr: { - name: fileInfo.file - } - } - ].concat(arrErrors) - }); - }); - var objXml = { - checkstyle: [ - { - _attr: { - version: '4.3' - } - } - ].concat(arrFiles) - }; - console.log(xml(objXml, { - declaration: true, - indent: ' ' - })); - }); -}; -module.exports = checkstyleFormatter; +var checkstyleFormatter = function (formatter) { + formatter.on('end', function (event) { + var arrFiles = [] + var arrAllMessages = event.arrAllMessages + arrAllMessages.forEach(function (fileInfo) { + var arrMessages = fileInfo.messages + var arrErrors = [] + arrMessages.forEach(function (message) { + arrErrors.push({ + error: { + _attr: { + line: message.line, + column: message.col, + severity: message.type, + message: message.message, + source: 'htmlhint.' + message.rule.id, + }, + }, + }) + }) + arrFiles.push({ + file: [ + { + _attr: { + name: fileInfo.file, + }, + }, + ].concat(arrErrors), + }) + }) + var objXml = { + checkstyle: [ + { + _attr: { + version: '4.3', + }, + }, + ].concat(arrFiles), + } + console.log( + xml(objXml, { + declaration: true, + indent: ' ', + }) + ) + }) +} +module.exports = checkstyleFormatter diff --git a/bin/formatters/compact.js b/bin/formatters/compact.js index fc4ae8ae8..6748c3ba5 100644 --- a/bin/formatters/compact.js +++ b/bin/formatters/compact.js @@ -1,24 +1,25 @@ -var compactFormatter = function(formatter, HTMLHint, options){ - var nocolor = options.nocolor; - formatter.on('file', function(event){ - event.messages.forEach(function (message) { - console.log('%s: line %d, col %d, %s - %s (%s)', - event.file, - message.line, - message.col, - message.type, - message.message, - message.rule.id - ); - }); - }); - formatter.on('end', function(event){ - var allHintCount = event.allHintCount; - if(allHintCount > 0){ - console.log(''); - var message = '%d problems'; - console.log(nocolor ? message : message.red, event.allHintCount); - } - }); -}; -module.exports = compactFormatter; +var compactFormatter = function (formatter, HTMLHint, options) { + var nocolor = options.nocolor + formatter.on('file', function (event) { + event.messages.forEach(function (message) { + console.log( + '%s: line %d, col %d, %s - %s (%s)', + event.file, + message.line, + message.col, + message.type, + message.message, + message.rule.id + ) + }) + }) + formatter.on('end', function (event) { + var allHintCount = event.allHintCount + if (allHintCount > 0) { + console.log('') + var message = '%d problems' + console.log(nocolor ? message : message.red, event.allHintCount) + } + }) +} +module.exports = compactFormatter diff --git a/bin/formatters/default.js b/bin/formatters/default.js index 121348071..5c3c55f82 100644 --- a/bin/formatters/default.js +++ b/bin/formatters/default.js @@ -1,39 +1,44 @@ -var defaultFormatter = function(formatter, HTMLHint, options){ - var nocolor = options.nocolor; - formatter.on('start', function(){ - console.log(''); - }); - formatter.on('config', function(event){ - var configPath = event.configPath; - console.log(' Config loaded: %s', nocolor ? configPath : configPath.cyan); - console.log(''); - }); - formatter.on('file', function(event){ - console.log(' '+event.file.white); - var arrLogs = HTMLHint.format(event.messages, { - colors: nocolor ? false : true, - indent: 6 - }); - arrLogs.forEach(function(str){ - console.log(str); - }); - console.log(''); - }); - formatter.on('end', function(event){ - var allFileCount = event.allFileCount; - var allHintCount = event.allHintCount; - var allHintFileCount = event.allHintFileCount; - var time = event.time; - var message; - if(allHintCount > 0){ - message = 'Scanned %d files, found %d errors in %d files (%d ms)'; - console.log(nocolor ? message : message.red, allFileCount, allHintCount, allHintFileCount, time); - } - else{ - message = 'Scanned %d files, no errors found (%d ms).'; - console.log(nocolor ? message : message.green, allFileCount, time); - } - }); -}; +var defaultFormatter = function (formatter, HTMLHint, options) { + var nocolor = options.nocolor + formatter.on('start', function () { + console.log('') + }) + formatter.on('config', function (event) { + var configPath = event.configPath + console.log(' Config loaded: %s', nocolor ? configPath : configPath.cyan) + console.log('') + }) + formatter.on('file', function (event) { + console.log(' ' + event.file.white) + var arrLogs = HTMLHint.format(event.messages, { + colors: nocolor ? false : true, + indent: 6, + }) + arrLogs.forEach(function (str) { + console.log(str) + }) + console.log('') + }) + formatter.on('end', function (event) { + var allFileCount = event.allFileCount + var allHintCount = event.allHintCount + var allHintFileCount = event.allHintFileCount + var time = event.time + var message + if (allHintCount > 0) { + message = 'Scanned %d files, found %d errors in %d files (%d ms)' + console.log( + nocolor ? message : message.red, + allFileCount, + allHintCount, + allHintFileCount, + time + ) + } else { + message = 'Scanned %d files, no errors found (%d ms).' + console.log(nocolor ? message : message.green, allFileCount, time) + } + }) +} -module.exports = defaultFormatter; +module.exports = defaultFormatter diff --git a/bin/formatters/html.js b/bin/formatters/html.js index 8b2b9394e..da3631f52 100644 --- a/bin/formatters/html.js +++ b/bin/formatters/html.js @@ -1,26 +1,39 @@ -var fs = require('fs'); +var fs = require('fs') -var htmlFormatter = function(formatter){ - formatter.on('end', function(event){ - var fileContent; - fileContent = ''; - fileContent = fileContent + 'HTML Hint Violation Report'; - fileContent = fileContent + ''; - fileContent = fileContent + '

Violation Report

'; +var htmlFormatter = function (formatter) { + formatter.on('end', function (event) { + var fileContent + fileContent = '' + fileContent = + fileContent + 'HTML Hint Violation Report' + fileContent = fileContent + '' + fileContent = fileContent + '

Violation Report

' - fileContent = fileContent + ''; - fileContent = fileContent + ''; - var arrAllMessages = event.arrAllMessages; - arrAllMessages.forEach(function(fileInfo){ - var arrMessages = fileInfo.messages; - arrMessages.forEach(function(message){ - fileContent = fileContent + ''; - }); - }); - fileContent = fileContent.replace('
Number#File NameLine NumberMessage
'+(i+1)+''+fileInfo.file+''+message.line+''+message.message+'
'); - console.log(fileContent); - fs.writeFileSync('report.html', fileContent); - }); -}; + fileContent = fileContent + '' + fileContent = + fileContent + + '' + var arrAllMessages = event.arrAllMessages + arrAllMessages.forEach(function (fileInfo) { + var arrMessages = fileInfo.messages + arrMessages.forEach(function (message, i) { + fileContent = + fileContent + + '' + }) + }) + fileContent = fileContent.replace('
Number#File NameLine NumberMessage
' + + (i + 1) + + '' + + fileInfo.file + + '' + + message.line + + '' + + message.message + + '
') + console.log(fileContent) + fs.writeFileSync('report.html', fileContent) + }) +} -module.exports = htmlFormatter; +module.exports = htmlFormatter diff --git a/bin/formatters/json.js b/bin/formatters/json.js index 96c968988..117ba324b 100644 --- a/bin/formatters/json.js +++ b/bin/formatters/json.js @@ -1,6 +1,6 @@ -var jsonFormatter = function(formatter){ - formatter.on('end', function(event){ - console.log(JSON.stringify(event.arrAllMessages)); - }); -}; -module.exports = jsonFormatter; +var jsonFormatter = function (formatter) { + formatter.on('end', function (event) { + console.log(JSON.stringify(event.arrAllMessages)) + }) +} +module.exports = jsonFormatter diff --git a/bin/formatters/junit.js b/bin/formatters/junit.js index 7ed0da426..8d66b7ad5 100644 --- a/bin/formatters/junit.js +++ b/bin/formatters/junit.js @@ -1,51 +1,53 @@ -var xml = require('xml'); +var xml = require('xml') -var junitFormatter = function(formatter, HTMLHint){ - formatter.on('end', function(event){ - var arrTestcase = []; - var arrAllMessages = event.arrAllMessages; - arrAllMessages.forEach(function(fileInfo){ - var arrMessages = fileInfo.messages; - var arrLogs = HTMLHint.format(arrMessages); - arrTestcase.push({ - testcase: [ - { - _attr: { - name: fileInfo.file, - time: (fileInfo.time / 1000).toFixed(3) - } - }, - { - failure: { - _attr: { - message: 'Found '+arrMessages.length+' errors' - }, - _cdata: arrLogs.join('\r\n') - } - } - ] - }); - }); - var objXml = { - testsuites: [ - { - testsuite: [ - { - _attr: { - name: 'HTMLHint Tests', - time: (event.time / 1000).toFixed(3), - tests: event.allFileCount, - failures: arrAllMessages.length - } - } - ].concat(arrTestcase) - } - ] - }; - console.log(xml(objXml, { - declaration: true, - indent: ' ' - })); - }); -}; -module.exports = junitFormatter; +var junitFormatter = function (formatter, HTMLHint) { + formatter.on('end', function (event) { + var arrTestcase = [] + var arrAllMessages = event.arrAllMessages + arrAllMessages.forEach(function (fileInfo) { + var arrMessages = fileInfo.messages + var arrLogs = HTMLHint.format(arrMessages) + arrTestcase.push({ + testcase: [ + { + _attr: { + name: fileInfo.file, + time: (fileInfo.time / 1000).toFixed(3), + }, + }, + { + failure: { + _attr: { + message: 'Found ' + arrMessages.length + ' errors', + }, + _cdata: arrLogs.join('\r\n'), + }, + }, + ], + }) + }) + var objXml = { + testsuites: [ + { + testsuite: [ + { + _attr: { + name: 'HTMLHint Tests', + time: (event.time / 1000).toFixed(3), + tests: event.allFileCount, + failures: arrAllMessages.length, + }, + }, + ].concat(arrTestcase), + }, + ], + } + console.log( + xml(objXml, { + declaration: true, + indent: ' ', + }) + ) + }) +} +module.exports = junitFormatter diff --git a/bin/formatters/markdown.js b/bin/formatters/markdown.js index 1b2bcb82b..1d962e689 100644 --- a/bin/formatters/markdown.js +++ b/bin/formatters/markdown.js @@ -1,36 +1,37 @@ -var markdownFormatter = function(formatter, HTMLHint){ - formatter.on('end', function(event){ - console.log('# TOC'); - var arrToc = []; - var arrContents = []; - var arrAllMessages = event.arrAllMessages; - arrAllMessages.forEach(function(fileInfo){ - var filePath = fileInfo.file; - var arrMessages = fileInfo.messages; - var errorCount = 0; - var warningCount = 0; - arrMessages.forEach(function(message){ - if(message.type === 'error'){ - errorCount ++; - } - else{ - warningCount ++; - } - }); - arrToc.push(' - ['+filePath+'](#'+filePath+')'); - arrContents.push(''); - arrContents.push('# '+filePath); - arrContents.push(''); - arrContents.push('Found '+errorCount+' errors, '+warningCount+' warnings'); - var arrLogs = HTMLHint.format(arrMessages); - arrContents.push(''); - arrLogs.forEach(function(log){ - arrContents.push(' '+log); - }); - arrContents.push(''); - }); - console.log(arrToc.join('\r\n')+'\r\n'); - console.log(arrContents.join('\r\n')); - }); -}; -module.exports = markdownFormatter; +var markdownFormatter = function (formatter, HTMLHint) { + formatter.on('end', function (event) { + console.log('# TOC') + var arrToc = [] + var arrContents = [] + var arrAllMessages = event.arrAllMessages + arrAllMessages.forEach(function (fileInfo) { + var filePath = fileInfo.file + var arrMessages = fileInfo.messages + var errorCount = 0 + var warningCount = 0 + arrMessages.forEach(function (message) { + if (message.type === 'error') { + errorCount++ + } else { + warningCount++ + } + }) + arrToc.push(' - [' + filePath + '](#' + filePath + ')') + arrContents.push('') + arrContents.push('# ' + filePath) + arrContents.push('') + arrContents.push( + 'Found ' + errorCount + ' errors, ' + warningCount + ' warnings' + ) + var arrLogs = HTMLHint.format(arrMessages) + arrContents.push('') + arrLogs.forEach(function (log) { + arrContents.push(' ' + log) + }) + arrContents.push('') + }) + console.log(arrToc.join('\r\n') + '\r\n') + console.log(arrContents.join('\r\n')) + }) +} +module.exports = markdownFormatter diff --git a/bin/formatters/unix.js b/bin/formatters/unix.js index 3cf4efade..25bbfabe5 100644 --- a/bin/formatters/unix.js +++ b/bin/formatters/unix.js @@ -1,22 +1,30 @@ -var unixFormatter = function(formatter, HTMLHint, options){ - var nocolor = options.nocolor; - formatter.on('file', function(event){ - event.messages.forEach(function (message) { - console.log([ - event.file, - message.line, - message.col, - " " + message.message + ' ['+message.type+'/'+message.rule.id+']' - ].join(":")); - }); - }); - formatter.on('end', function(event){ - var allHintCount = event.allHintCount; - if(allHintCount > 0){ - console.log(''); - var message = '%d problems'; - console.log(nocolor ? message : message.red, event.allHintCount); - } - }); -}; -module.exports = unixFormatter; +var unixFormatter = function (formatter, HTMLHint, options) { + var nocolor = options.nocolor + formatter.on('file', function (event) { + event.messages.forEach(function (message) { + console.log( + [ + event.file, + message.line, + message.col, + ' ' + + message.message + + ' [' + + message.type + + '/' + + message.rule.id + + ']', + ].join(':') + ) + }) + }) + formatter.on('end', function (event) { + var allHintCount = event.allHintCount + if (allHintCount > 0) { + console.log('') + var message = '%d problems' + console.log(nocolor ? message : message.red, event.allHintCount) + } + }) +} +module.exports = unixFormatter diff --git a/bin/htmlhint b/bin/htmlhint index 241e6f9dc..e1f656d7f 100755 --- a/bin/htmlhint +++ b/bin/htmlhint @@ -1,393 +1,408 @@ #!/usr/bin/env node -var program = require('commander'); -var fs = require('fs'); -var path = require('path'); -var stripJsonComments = require('strip-json-comments'); -var async = require('async'); -var glob = require("glob"); -var parseGlob = require('parse-glob'); -var request = require('request'); +var program = require('commander') +var fs = require('fs') +var path = require('path') +var stripJsonComments = require('strip-json-comments') +var async = require('async') +var glob = require('glob') +var parseGlob = require('parse-glob') +var request = require('request') -var HTMLHint = require("../dist/htmlhint.js").HTMLHint; -var formatter = require('./formatter'); -var pkg = require('../package.json'); +var HTMLHint = require('../dist/htmlhint.js').HTMLHint +var formatter = require('./formatter') +var pkg = require('../package.json') -require('colors'); +require('colors') function map(val) { - var objMap = {}; - val.split(',').forEach(function(item){ - var arrItem = item.split(/\s*=\s*/); - objMap[arrItem[0]] = arrItem[1]?arrItem[1]:true; - }); - return objMap; + var objMap = {} + val.split(',').forEach(function (item) { + var arrItem = item.split(/\s*=\s*/) + objMap[arrItem[0]] = arrItem[1] ? arrItem[1] : true + }) + return objMap } -program.on('--help', function(){ - console.log(' Examples:'); - console.log(''); - console.log(' htmlhint'); - console.log(' htmlhint www'); - console.log(' htmlhint www/test.html'); - console.log(' htmlhint www/**/*.xhtml'); - console.log(' htmlhint www/**/*.{htm,html}'); - console.log(' htmlhint http://www.alibaba.com/'); - console.log(' cat test.html | htmlhint stdin'); - console.log(' htmlhint --list'); - console.log(' htmlhint --rules tag-pair,id-class-value=underline test.html'); - console.log(' htmlhint --config .htmlhintrc test.html'); - console.log(' htmlhint --ignore **/build/**,**/test/**'); - console.log(' htmlhint --rulesdir ./rules/'); - console.log(''); -}); - -var arrSupportedFormatters = formatter.getSupported(); +program.on('--help', function () { + console.log(' Examples:') + console.log('') + console.log(' htmlhint') + console.log(' htmlhint www') + console.log(' htmlhint www/test.html') + console.log(' htmlhint www/**/*.xhtml') + console.log(' htmlhint www/**/*.{htm,html}') + console.log(' htmlhint http://www.alibaba.com/') + console.log(' cat test.html | htmlhint stdin') + console.log(' htmlhint --list') + console.log( + ' htmlhint --rules tag-pair,id-class-value=underline test.html' + ) + console.log(' htmlhint --config .htmlhintrc test.html') + console.log(' htmlhint --ignore **/build/**,**/test/**') + console.log(' htmlhint --rulesdir ./rules/') + console.log('') +}) + +var arrSupportedFormatters = formatter.getSupported() program - .version(pkg.version) - .usage(' [options]') - .option('-l, --list', 'show all of the rules available') - .option('-c, --config ', 'custom configuration file') - .option('-r, --rules ', 'set all of the rules available', map) - .option('-R, --rulesdir ', 'load custom rules from file or folder') - .option('-f, --format <'+arrSupportedFormatters.join('|')+'>', 'output messages as custom format') - .option('-i, --ignore ', 'add pattern to exclude matches') - .option('--nocolor', 'disable color') - .option('--warn', 'Warn only, exit with 0') - .parse(process.argv); - -if(program.list){ - listRules(); - process.exit(0); + .version(pkg.version) + .usage(' [options]') + .option('-l, --list', 'show all of the rules available') + .option('-c, --config ', 'custom configuration file') + .option( + '-r, --rules ', + 'set all of the rules available', + map + ) + .option( + '-R, --rulesdir ', + 'load custom rules from file or folder' + ) + .option( + '-f, --format <' + arrSupportedFormatters.join('|') + '>', + 'output messages as custom format' + ) + .option( + '-i, --ignore ', + 'add pattern to exclude matches' + ) + .option('--nocolor', 'disable color') + .option('--warn', 'Warn only, exit with 0') + .parse(process.argv) + +if (program.list) { + listRules() + process.exit(0) } -var arrTargets = program.args; -if(arrTargets.length === 0){ - arrTargets.push('./'); +var arrTargets = program.args +if (arrTargets.length === 0) { + arrTargets.push('./') } // init formatter formatter.init(HTMLHint, { - 'nocolor': program.nocolor -}); -var format = program.format || 'default'; -if(format){ - formatter.setFormat(format); + nocolor: program.nocolor, +}) +var format = program.format || 'default' +if (format) { + formatter.setFormat(format) } hintTargets(arrTargets, { - rulesdir: program.rulesdir, - ruleset: program.rules, - formatter: formatter, - ignore: program.ignore -}); + rulesdir: program.rulesdir, + ruleset: program.rules, + formatter: formatter, + ignore: program.ignore, +}) // list all rules -function listRules(){ - var rules = HTMLHint.rules; - var rule; - console.log(' All rules:'); - console.log(' =================================================='); - for (var id in rules){ - rule = rules[id]; - console.log(' %s : %s', rule.id.bold, rule.description); - } +function listRules() { + var rules = HTMLHint.rules + var rule + console.log(' All rules:') + console.log(' ==================================================') + for (var id in rules) { + rule = rules[id] + console.log(' %s : %s', rule.id.bold, rule.description) + } } -function hintTargets(arrTargets, options){ - var arrAllMessages = []; - var allFileCount = 0; - var allHintFileCount = 0; - var allHintCount = 0; - var startTime = new Date().getTime(); - - var formatter = options.formatter; - - // load custom rules - var rulesdir = options.rulesdir; - if(rulesdir){ - loadCustomRules(rulesdir); - } - - // start hint - formatter.emit('start'); - - var arrTasks = []; - arrTargets.forEach(function(target){ - arrTasks.push(function(next){ - hintAllFiles(target, options, function(result){ - allFileCount += result.targetFileCount; - allHintFileCount += result.targetHintFileCount; - allHintCount += result.targetHintCount; - arrAllMessages = arrAllMessages.concat(result.arrTargetMessages); - next(); - }); - }); - }); - async.series(arrTasks, function(){ - // end hint - var spendTime = new Date().getTime() - startTime; - formatter.emit('end', { - arrAllMessages: arrAllMessages, - allFileCount: allFileCount, - allHintFileCount: allHintFileCount, - allHintCount: allHintCount, - time: spendTime - }); - process.exit(!program.warn && allHintCount > 0 ? 1 : 0); - }); +function hintTargets(arrTargets, options) { + var arrAllMessages = [] + var allFileCount = 0 + var allHintFileCount = 0 + var allHintCount = 0 + var startTime = new Date().getTime() + + var formatter = options.formatter + + // load custom rules + var rulesdir = options.rulesdir + if (rulesdir) { + loadCustomRules(rulesdir) + } + + // start hint + formatter.emit('start') + + var arrTasks = [] + arrTargets.forEach(function (target) { + arrTasks.push(function (next) { + hintAllFiles(target, options, function (result) { + allFileCount += result.targetFileCount + allHintFileCount += result.targetHintFileCount + allHintCount += result.targetHintCount + arrAllMessages = arrAllMessages.concat(result.arrTargetMessages) + next() + }) + }) + }) + async.series(arrTasks, function () { + // end hint + var spendTime = new Date().getTime() - startTime + formatter.emit('end', { + arrAllMessages: arrAllMessages, + allFileCount: allFileCount, + allHintFileCount: allHintFileCount, + allHintCount: allHintCount, + time: spendTime, + }) + process.exit(!program.warn && allHintCount > 0 ? 1 : 0) + }) } // load custom rles -function loadCustomRules(rulesdir){ - rulesdir = rulesdir.replace(/\\/g, '/'); - if(fs.existsSync(rulesdir)){ - if(fs.statSync(rulesdir).isDirectory()){ - rulesdir += /\/$/.test(rulesdir)?'':'/'; - rulesdir += '**/*.js'; - var arrFiles = glob.sync(rulesdir, { - 'dot': false, - 'nodir': true, - 'strict': false, - 'silent': true - }); - arrFiles.forEach(function(file){ - loadRule(file); - }); - } - else{ - loadRule(rulesdir); - } +function loadCustomRules(rulesdir) { + rulesdir = rulesdir.replace(/\\/g, '/') + if (fs.existsSync(rulesdir)) { + if (fs.statSync(rulesdir).isDirectory()) { + rulesdir += /\/$/.test(rulesdir) ? '' : '/' + rulesdir += '**/*.js' + var arrFiles = glob.sync(rulesdir, { + dot: false, + nodir: true, + strict: false, + silent: true, + }) + arrFiles.forEach(function (file) { + loadRule(file) + }) + } else { + loadRule(rulesdir) } + } } // load rule -function loadRule(filepath){ - filepath = path.resolve(filepath); - try{ - var module = require(filepath); - module(HTMLHint); - } - catch(e){} +function loadRule(filepath) { + filepath = path.resolve(filepath) + try { + var module = require(filepath) + module(HTMLHint) + } catch (e) {} } // hint all files -function hintAllFiles(target, options, onFinised){ - var globInfo = getGlobInfo(target); - globInfo.ignore = options.ignore; - - var formatter = options.formatter; - - // hint result - var targetFileCount = 0; - var targetHintFileCount = 0; - var targetHintCount = 0; - var arrTargetMessages = []; - - // init ruleset - var ruleset = options.ruleset; - if(ruleset === undefined){ - ruleset = getConfig(program.config, globInfo.base, formatter); +function hintAllFiles(target, options, onFinised) { + var globInfo = getGlobInfo(target) + globInfo.ignore = options.ignore + + var formatter = options.formatter + + // hint result + var targetFileCount = 0 + var targetHintFileCount = 0 + var targetHintCount = 0 + var arrTargetMessages = [] + + // init ruleset + var ruleset = options.ruleset + if (ruleset === undefined) { + ruleset = getConfig(program.config, globInfo.base, formatter) + } + + // hint queue + var hintQueue = async.queue(function (filepath, next) { + var startTime = new Date().getTime() + if (filepath === 'stdin') { + hintStdin(ruleset, hintNext) + } else if (/^https?:\/\//.test(filepath)) { + hintUrl(filepath, ruleset, hintNext) + } else { + var messages = hintFile(filepath, ruleset) + hintNext(messages) } - - // hint queue - var hintQueue = async.queue(function (filepath, next) { - var startTime = new Date().getTime(); - if(filepath === 'stdin'){ - hintStdin(ruleset, hintNext); - } - else if(/^https?:\/\//.test(filepath)){ - hintUrl(filepath, ruleset, hintNext); - } - else{ - var messages = hintFile(filepath, ruleset); - hintNext(messages); - } - function hintNext(messages){ - var spendTime = new Date().getTime() - startTime; - var hintCount = messages.length; - if(hintCount > 0){ - formatter.emit('file', { - 'file': filepath, - 'messages': messages, - 'time': spendTime - }); - arrTargetMessages.push({ - 'file': filepath, - 'messages': messages, - 'time': spendTime - }); - targetHintFileCount ++; - targetHintCount += hintCount; - } - targetFileCount ++; - setImmediate(next); - } - }, 10); - // start hint - var isWalkDone = false; - var isHintDone = true; - hintQueue.drain = function() { - isHintDone = true; - checkAllHinted(); - }; - function checkAllHinted(){ - if(isWalkDone && isHintDone){ - onFinised({ - targetFileCount: targetFileCount, - targetHintFileCount: targetHintFileCount, - targetHintCount: targetHintCount, - arrTargetMessages: arrTargetMessages - }); - } + function hintNext(messages) { + var spendTime = new Date().getTime() - startTime + var hintCount = messages.length + if (hintCount > 0) { + formatter.emit('file', { + file: filepath, + messages: messages, + time: spendTime, + }) + arrTargetMessages.push({ + file: filepath, + messages: messages, + time: spendTime, + }) + targetHintFileCount++ + targetHintCount += hintCount + } + targetFileCount++ + setImmediate(next) } - if(target === 'stdin'){ - isWalkDone = true; - hintQueue.push(target); - } - else if(/^https?:\/\//.test(target)){ - isWalkDone = true; - hintQueue.push(target); - } - else{ - walkPath(globInfo, function(filepath){ - isHintDone = false; - hintQueue.push(filepath); - }, function(){ - isWalkDone = true; - checkAllHinted(); - }); + }, 10) + // start hint + var isWalkDone = false + var isHintDone = true + hintQueue.drain = function () { + isHintDone = true + checkAllHinted() + } + function checkAllHinted() { + if (isWalkDone && isHintDone) { + onFinised({ + targetFileCount: targetFileCount, + targetHintFileCount: targetHintFileCount, + targetHintCount: targetHintCount, + arrTargetMessages: arrTargetMessages, + }) } + } + if (target === 'stdin') { + isWalkDone = true + hintQueue.push(target) + } else if (/^https?:\/\//.test(target)) { + isWalkDone = true + hintQueue.push(target) + } else { + walkPath( + globInfo, + function (filepath) { + isHintDone = false + hintQueue.push(filepath) + }, + function () { + isWalkDone = true + checkAllHinted() + } + ) + } } // split target to base & glob -function getGlobInfo(target){ - // fix windows sep - target = target.replace(/\\/g, '/'); - var globInfo = parseGlob(target); - var base = path.resolve(globInfo.base); - base += /\/$/.test(base) ? '' : '/'; - var pattern = globInfo.glob; - var globPath = globInfo.path; - var defaultGlob = '*.{htm,html}'; - if(globInfo.is.glob === true){ - // no basename - if(globPath.basename === ''){ - pattern += defaultGlob; - } +function getGlobInfo(target) { + // fix windows sep + target = target.replace(/\\/g, '/') + var globInfo = parseGlob(target) + var base = path.resolve(globInfo.base) + base += /\/$/.test(base) ? '' : '/' + var pattern = globInfo.glob + var globPath = globInfo.path + var defaultGlob = '*.{htm,html}' + if (globInfo.is.glob === true) { + // no basename + if (globPath.basename === '') { + pattern += defaultGlob + } + } else { + // no basename + if (globPath.basename === '') { + pattern += '**/' + defaultGlob } - else{ - // no basename - if(globPath.basename === ''){ - pattern += '**/' + defaultGlob; - } - // detect directory - else if(fs.existsSync(target) && fs.statSync(target).isDirectory()){ - base += globPath.basename + '/'; - pattern = '**/' + defaultGlob; - } + // detect directory + else if (fs.existsSync(target) && fs.statSync(target).isDirectory()) { + base += globPath.basename + '/' + pattern = '**/' + defaultGlob } - return { - base: base, - pattern: pattern - }; + } + return { + base: base, + pattern: pattern, + } } // search and load config -function getConfig(configPath, base, formatter){ - if(configPath === undefined && fs.existsSync(base)){ - // find default config file in parent directory - if(fs.statSync(base).isDirectory() === false){ - base = path.dirname(base); - } - while(base){ - var tmpConfigFile = path.resolve(base, '.htmlhintrc'); - if(fs.existsSync(tmpConfigFile)){ - configPath = tmpConfigFile; - break; - } - if (!base) {break;} - base = base.substring(0,base.lastIndexOf(path.sep)); - } +function getConfig(configPath, base, formatter) { + if (configPath === undefined && fs.existsSync(base)) { + // find default config file in parent directory + if (fs.statSync(base).isDirectory() === false) { + base = path.dirname(base) } - - if(fs.existsSync(configPath)){ - var config = fs.readFileSync(configPath, 'utf-8'), - ruleset; - try{ - ruleset = JSON.parse(stripJsonComments(config)); - formatter.emit('config', { - ruleset: ruleset, - configPath: configPath - }); - } - catch(e){} - return ruleset; + while (base) { + var tmpConfigFile = path.resolve(base, '.htmlhintrc') + if (fs.existsSync(tmpConfigFile)) { + configPath = tmpConfigFile + break + } + if (!base) { + break + } + base = base.substring(0, base.lastIndexOf(path.sep)) } + } + + if (fs.existsSync(configPath)) { + var config = fs.readFileSync(configPath, 'utf-8'), + ruleset + try { + ruleset = JSON.parse(stripJsonComments(config)) + formatter.emit('config', { + ruleset: ruleset, + configPath: configPath, + }) + } catch (e) {} + return ruleset + } } // walk path function walkPath(globInfo, callback, onFinish) { - var base = globInfo.base; - var pattern = globInfo.pattern; - var ignore = globInfo.ignore; - var arrIgnores = ['**/node_modules/**']; - if(ignore){ - ignore.split(',').forEach(function(pattern){ - arrIgnores.push(pattern); - }); + var base = globInfo.base + var pattern = globInfo.pattern + var ignore = globInfo.ignore + var arrIgnores = ['**/node_modules/**'] + if (ignore) { + ignore.split(',').forEach(function (pattern) { + arrIgnores.push(pattern) + }) + } + var walk = glob( + pattern, + { + cwd: base, + dot: false, + ignore: arrIgnores, + nodir: true, + strict: false, + silent: true, + }, + function () { + onFinish() } - var walk = glob(pattern, { - 'cwd': base, - 'dot': false, - 'ignore': arrIgnores, - 'nodir': true, - 'strict': false, - 'silent': true - },function() { - onFinish(); - }); - walk.on('match', function(file){ - base = base.replace(/^.\//, ''); - callback(base + file); - }); + ) + walk.on('match', function (file) { + base = base.replace(/^.\//, '') + callback(base + file) + }) } // hint file -function hintFile(filepath, ruleset){ - var content = ''; - try{ - content = fs.readFileSync(filepath, 'utf-8'); - } - catch(e){} - return HTMLHint.verify(content, ruleset); +function hintFile(filepath, ruleset) { + var content = '' + try { + content = fs.readFileSync(filepath, 'utf-8') + } catch (e) {} + return HTMLHint.verify(content, ruleset) } // hint stdin -function hintStdin(ruleset, callback){ - process.stdin.setEncoding('utf8'); - var buffers = []; - process.stdin.on('data', function(text){ - buffers.push(text); - }); - - process.stdin.on('end', function(){ - var content = buffers.join(''); - var messages = HTMLHint.verify(content, ruleset); - callback(messages); - }); +function hintStdin(ruleset, callback) { + process.stdin.setEncoding('utf8') + var buffers = [] + process.stdin.on('data', function (text) { + buffers.push(text) + }) + + process.stdin.on('end', function () { + var content = buffers.join('') + var messages = HTMLHint.verify(content, ruleset) + callback(messages) + }) } // hint url -function hintUrl(url, ruleset, callback){ - request.get(url, function(error, response, body){ - if(!error && response.statusCode == 200){ - var messages = HTMLHint.verify(body, ruleset); - callback(messages); - } - else{ - callback([]); - } - }); +function hintUrl(url, ruleset, callback) { + request.get(url, function (error, response, body) { + if (!error && response.statusCode == 200) { + var messages = HTMLHint.verify(body, ruleset) + callback(messages) + } else { + callback([]) + } + }) } diff --git a/codecov.yml b/codecov.yml index beada4e2e..e69de29bb 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +0,0 @@ -ignore: - - "lib/.*" diff --git a/commitizen.config.js b/commitizen.config.js index 8e1f00ab6..c218f004b 100644 --- a/commitizen.config.js +++ b/commitizen.config.js @@ -1,49 +1,48 @@ /* eslint-env node */ const types = [ - { - value: 'feat', - name: 'feat: A new feature' - }, - { - value: 'fix', - name: 'fix: A bug fix' - }, - { - value: 'docs', - name: 'docs: Documentation only changes' - }, - { - value: 'style', - name: `style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)` - }, - { - value: 'refactor', - name: - 'refactor: A code change that neither fixes a bug nor adds a feature' - }, - { - value: 'perf', - name: 'perf: A code change that improves performance' - }, - { - value: 'test', - name: 'test: Adding missing tests' - }, - { - value: 'chore', - name: `chore: Changes to the build process or auxiliary tools and libraries such as documentation generation` - }, - { - value: 'revert', - name: 'revert: Revert to a commit' - } -]; + { + value: 'feat', + name: 'feat: A new feature', + }, + { + value: 'fix', + name: 'fix: A bug fix', + }, + { + value: 'docs', + name: 'docs: Documentation only changes', + }, + { + value: 'style', + name: `style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)`, + }, + { + value: 'refactor', + name: 'refactor: A code change that neither fixes a bug nor adds a feature', + }, + { + value: 'perf', + name: 'perf: A code change that improves performance', + }, + { + value: 'test', + name: 'test: Adding missing tests', + }, + { + value: 'chore', + name: `chore: Changes to the build process or auxiliary tools and libraries such as documentation generation`, + }, + { + value: 'revert', + name: 'revert: Revert to a commit', + }, +] -const scopes = ['core', 'cli', 'htmlhint'].map(name => ({ name })); +const scopes = ['core', 'cli', 'htmlhint'].map((name) => ({ name })) module.exports = { - types, - scopes, - allowCustomScopes: true, - allowBreakingChanges: ['feat', 'fix', 'perf', 'refactor'] -}; + types, + scopes, + allowCustomScopes: true, + allowBreakingChanges: ['feat', 'fix', 'perf', 'refactor'], +} diff --git a/commitlint.config.js b/commitlint.config.js index adf99da81..c95b02700 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,18 +1,18 @@ /* eslint-env node */ -const { types, scopes, allowCustomScopes } = require('./commitizen.config'); +const { types, scopes, allowCustomScopes } = require('./commitizen.config') -const validTypes = types.map(type => type.value); -const validScopes = scopes.map(scope => scope.name); -const scopeValidationLevel = allowCustomScopes ? 1 : 2; +const validTypes = types.map((type) => type.value) +const validScopes = scopes.map((scope) => scope.name) +const scopeValidationLevel = allowCustomScopes ? 1 : 2 module.exports = { - extends: ['@commitlint/config-conventional'], - parserPreset: './parser-preset', + extends: ['@commitlint/config-conventional'], + parserPreset: './parser-preset', - // Add your own rules. See http://marionebl.github.io/commitlint - rules: { - // Apply valid scopes and types - 'scope-enum': [scopeValidationLevel, 'always', validScopes], - 'type-enum': [2, 'always', validTypes] - } -}; + // Add your own rules. See http://marionebl.github.io/commitlint + rules: { + // Apply valid scopes and types + 'scope-enum': [scopeValidationLevel, 'always', validScopes], + 'type-enum': [2, 'always', validTypes], + }, +} diff --git a/package-lock.json b/package-lock.json index e61db33db..26dd0b2d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1154,6 +1154,18 @@ "integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=", "dev": true }, + "acorn": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.2.0.tgz", + "integrity": "sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ==", + "dev": true + }, + "acorn-jsx": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.2.0.tgz", + "integrity": "sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==", + "dev": true + }, "agent-base": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.0.tgz", @@ -2827,6 +2839,15 @@ } } }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "dot-prop": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz", @@ -3010,17 +3031,457 @@ } } }, + "eslint": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.0.0.tgz", + "integrity": "sha512-qY1cwdOxMONHJfGqw52UOpZDeqXy8xmD0u8CT6jIstil72jkhURC704W8CFyTPDPllz4z4lu0Ql1+07PG/XdIg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0", + "eslint-visitor-keys": "^1.1.0", + "espree": "^7.0.0", + "esquery": "^1.2.0", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "inquirer": "^7.0.0", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash": "^4.17.14", + "minimatch": "^3.0.4", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "progress": "^2.0.0", + "regexpp": "^3.1.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.0", + "strip-json-comments": "^3.1.0", + "table": "^5.2.3", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "ansi-escapes": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz", + "integrity": "sha512-JWF7ocqNrp8u9oqpgV+wH5ftbt+cfvv+PTjOvKLT3AdYly/LmORARfEVT1iyjwN+4MqE5UmVKoAdIBqeoCHgLA==", + "dev": true, + "requires": { + "type-fest": "^0.11.0" + } + }, + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz", + "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "cli-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", + "dev": true, + "requires": { + "restore-cursor": "^3.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "figures": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", + "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, + "inquirer": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.1.0.tgz", + "integrity": "sha512-5fJMWEmikSYu0nv/flMc475MhGbB7TSPd/2IpFV4I4rMklboCH2rQjYY5kKiYGHqUF9gvaambupcJFFG9dvReg==", + "dev": true, + "requires": { + "ansi-escapes": "^4.2.1", + "chalk": "^3.0.0", + "cli-cursor": "^3.1.0", + "cli-width": "^2.0.0", + "external-editor": "^3.0.3", + "figures": "^3.0.0", + "lodash": "^4.17.15", + "mute-stream": "0.0.8", + "run-async": "^2.4.0", + "rxjs": "^6.5.3", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0", + "through": "^2.3.6" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } + } + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "mute-stream": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", + "dev": true + }, + "onetime": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", + "integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==", + "dev": true, + "requires": { + "mimic-fn": "^2.1.0" + } + }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, + "restore-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "dev": true, + "requires": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + } + }, + "run-async": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", + "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==", + "dev": true + }, + "rxjs": { + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.5.tgz", + "integrity": "sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1" + } + }, + "type-fest": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.11.0.tgz", + "integrity": "sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ==", + "dev": true + } + } + }, + "eslint-config-prettier": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz", + "integrity": "sha512-oB8cpLWSAjOVFEJhhyMZh6NOEOtBVziaqdDQ86+qhDHFbZXoRTM7pNSvFRfW/W/L/LrQ38C99J5CGuRBBzBsdA==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + }, + "dependencies": { + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + } + } + }, + "eslint-plugin-prettier": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.3.tgz", + "integrity": "sha512-+HG5jmu/dN3ZV3T6eCD7a4BlAySdN7mLIbJYo0z1cFQuI+r2DiTJEFeF68ots93PsnrMxbzIZ2S/ieX+mkrBeQ==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, + "eslint-scope": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", + "integrity": "sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + }, + "dependencies": { + "estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true + } + } + }, + "eslint-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.0.0.tgz", + "integrity": "sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, + "eslint-visitor-keys": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", + "integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", + "dev": true + }, "esm": { "version": "3.2.25", "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==" }, + "espree": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.0.0.tgz", + "integrity": "sha512-/r2XEx5Mw4pgKdyb7GNLQNsu++asx/dltf/CI8RFi9oGHxmQFgvLbc5Op4U6i8Oaj+kdslhJtVlEZeAqH5qOTw==", + "dev": true, + "requires": { + "acorn": "^7.1.1", + "acorn-jsx": "^5.2.0", + "eslint-visitor-keys": "^1.1.0" + } + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, + "esquery": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz", + "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==", + "dev": true, + "requires": { + "estraverse": "^5.1.0" + }, + "dependencies": { + "estraverse": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.1.0.tgz", + "integrity": "sha512-FyohXK+R0vE+y1nHLoBM7ZTyqRpqAlhdZHCWIWEviFLiGB8b04H6bQs8G+XTthacvT8VuwvteiP7RJSxMs8UEw==", + "dev": true + } + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "^4.1.0" + }, + "dependencies": { + "estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true + } + } + }, "estraverse": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.9.3.tgz", @@ -3235,6 +3696,12 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-glob": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.2.tgz", @@ -3353,6 +3820,15 @@ "escape-string-regexp": "^1.0.5" } }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "^2.0.1" + } + }, "fill-range": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", @@ -3456,6 +3932,34 @@ } } }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + }, + "dependencies": { + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } + } + }, + "flatted": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", + "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", + "dev": true + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -3557,6 +4061,12 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -3949,6 +4459,23 @@ "which": "^1.2.14" } }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + }, + "dependencies": { + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + } + } + }, "globby": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.0.tgz", @@ -4316,6 +4843,12 @@ "resolve-from": "^5.0.0" } }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, "indent-string": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-3.2.0.tgz", @@ -4801,6 +5334,12 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -6137,6 +6676,12 @@ "to-regex": "^3.0.1" } }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, "neo-async": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz", @@ -10200,6 +10745,15 @@ "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-quick": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/pretty-quick/-/pretty-quick-2.0.1.tgz", @@ -10385,6 +10939,12 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -10509,6 +11069,12 @@ "safe-regex": "^1.1.0" } }, + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + }, "registry-auth-token": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.1.1.tgz", @@ -11686,6 +12252,48 @@ } } }, + "table": { + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", + "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", + "dev": true, + "requires": { + "ajv": "^6.10.2", + "lodash": "^4.17.14", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" + }, + "dependencies": { + "astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "dev": true + }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + } + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + } + } + }, "temp-dir": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz", @@ -11743,6 +12351,12 @@ "integrity": "sha512-wiBrwC1EhBelW12Zy26JeOUkQ5mRu+5o8rpsJk5+2t+Y5vE7e842qtZDQ2g1NpX/29HdyFeJ4nSIhI47ENSxlQ==", "dev": true }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -12061,6 +12675,12 @@ "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" }, + "v8-compile-cache": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", + "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", + "dev": true + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -12297,6 +12917,15 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + }, "xml": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", diff --git a/package.json b/package.json index 943f5535d..114d13660 100644 --- a/package.json +++ b/package.json @@ -23,17 +23,29 @@ "module": "src/core.js", "scripts": { "commit": "npx git-cz", - "prettier": "prettier --write ./**/*.{js,json,md} --ignore-path ./.prettierignore", + "prettier": "prettier --write .", "test": "mocha --recursive \"./test/**/*.spec.js\"", "build": "npm run build:min && npm run build:unmin", "build:min": "rollup -c --environment NODE_ENV:production --file dist/htmlhint.min.js", - "build:unmin": "rollup -c" + "build:unmin": "rollup -c", + "lint:fix": "eslint src/ test/ bin/ --ext .js --max-warnings 0", + "lint": "eslint --fix src/ test/ bin/ --ext .js --max-warnings 0" }, "husky": { "hooks": { - "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true" + "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true", + "pre-commit": "lint-staged" } }, + "lint-staged": { + "*.(js|md)": [ + "npm run prettier" + ], + ".js": [ + "npm run lint:fix", + "npm run lint" + ] + }, "config": { "commitizen": { "path": "cz-conventional-changelog" @@ -67,6 +79,9 @@ "@semantic-release/release-notes-generator": "9.0.1", "commitizen": "4.1.2", "commitlint": "8.3.5", + "eslint": "7.0.0", + "eslint-config-prettier": "6.11.0", + "eslint-plugin-prettier": "3.1.3", "expect.js": "0.3.1", "husky": "4.2.5", "istanbul": "0.4.5", diff --git a/parser-preset.js b/parser-preset.js index d750156db..3df7c2652 100644 --- a/parser-preset.js +++ b/parser-preset.js @@ -1,6 +1,6 @@ module.exports = { - parserOpts: { - headerPattern: /^(\w*)\((\w*)\)\:\s(.*)$/, - headerCorrespondence: ['type', 'scope', 'subject'] - } -}; + parserOpts: { + headerPattern: /^(\w*)\((\w*)\)\:\s(.*)$/, + headerCorrespondence: ['type', 'scope', 'subject'], + }, +} diff --git a/rollup.config.js b/rollup.config.js index 2810c5f83..b97ca865c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,22 +1,19 @@ -import resolve from '@rollup/plugin-node-resolve'; -import commonjs from '@rollup/plugin-commonjs'; -import { terser } from "rollup-plugin-terser"; +import resolve from '@rollup/plugin-node-resolve' +import commonjs from '@rollup/plugin-commonjs' +import { terser } from 'rollup-plugin-terser' const config = { input: './src/core.js', output: { file: 'dist/htmlhint.js', format: 'umd', - name: 'HTMLHint' + name: 'HTMLHint', }, - plugins: [ - commonjs(), - resolve() - ], -}; + plugins: [commonjs(), resolve()], +} if (process.env.NODE_ENV === 'production') { - config.plugins.push(terser()); + config.plugins.push(terser()) } -export default config; +export default config diff --git a/src/core.js b/src/core.js index fff528dd3..7f1fad8d8 100644 --- a/src/core.js +++ b/src/core.js @@ -1,9 +1,9 @@ -import HTMLParser from './htmlparser'; -import Reporter from './reporter'; -import * as HTMLRules from './rules'; +import HTMLParser from './htmlparser' +import Reporter from './reporter' +import * as HTMLRules from './rules' class HTMLHintCore { constructor() { - this.rules = {}; + this.rules = {} this.defaultRuleset = { 'tagname-lowercase': true, 'attr-lowercase': true, @@ -14,93 +14,94 @@ class HTMLHintCore { 'id-unique': true, 'src-not-empty': true, 'attr-no-duplication': true, - 'title-require': true - }; + 'title-require': true, + } } addRule(rule) { - this.rules[rule.id] = rule; + this.rules[rule.id] = rule } verify(html, ruleset) { if (ruleset === undefined || Object.keys(ruleset).length === 0) { - ruleset = this.defaultRuleset; + ruleset = this.defaultRuleset } // parse inline ruleset - html = html.replace(/^\s*/i, function( + html = html.replace(/^\s*/i, function ( all, strRuleset ) { if (ruleset === undefined) { - ruleset = {}; + ruleset = {} } - strRuleset.replace(/(?:^|,)\s*([^:,]+)\s*(?:\:\s*([^,\s]+))?/g, function( + // eslint-disable-next-line + strRuleset.replace(/(?:^|,)\s*([^:,]+)\s*(?:\:\s*([^,\s]+))?/g, function ( all, key, value ) { if (value === 'false') { - value = false; + value = false } else if (value === 'true') { - value = true; + value = true } - ruleset[key] = value === undefined ? true : value; - }); - return ''; - }); + ruleset[key] = value === undefined ? true : value + }) + return '' + }) - var parser = new HTMLParser(); - var reporter = new Reporter(html, ruleset); + var parser = new HTMLParser() + var reporter = new Reporter(html, ruleset) var rules = this.rules, - rule; + rule for (var id in ruleset) { - rule = rules[id]; + rule = rules[id] if (rule !== undefined && ruleset[id] !== false) { - rule.init(parser, reporter, ruleset[id]); + rule.init(parser, reporter, ruleset[id]) } } - parser.parse(html); + parser.parse(html) - return reporter.messages; + return reporter.messages } format(arrMessages, options) { - options = options || {}; - var arrLogs = []; + options = options || {} + var arrLogs = [] var colors = { white: '', grey: '', red: '', - reset: '' - }; + reset: '', + } if (options.colors) { - colors.white = '\x1b[37m'; - colors.grey = '\x1b[90m'; - colors.red = '\x1b[31m'; - colors.reset = '\x1b[39m'; + colors.white = '\x1b[37m' + colors.grey = '\x1b[90m' + colors.red = '\x1b[31m' + colors.reset = '\x1b[39m' } - var indent = options.indent || 0; - arrMessages.forEach(hint => { - var leftWindow = 40; - var rightWindow = leftWindow + 20; - var evidence = hint.evidence; - var line = hint.line; - var col = hint.col; - var evidenceCount = evidence.length; - var leftCol = col > leftWindow + 1 ? col - leftWindow : 1; + var indent = options.indent || 0 + arrMessages.forEach((hint) => { + var leftWindow = 40 + var rightWindow = leftWindow + 20 + var evidence = hint.evidence + var line = hint.line + var col = hint.col + var evidenceCount = evidence.length + var leftCol = col > leftWindow + 1 ? col - leftWindow : 1 var rightCol = - evidence.length > col + rightWindow ? col + rightWindow : evidenceCount; + evidence.length > col + rightWindow ? col + rightWindow : evidenceCount if (col < leftWindow + 1) { - rightCol += leftWindow - col + 1; + rightCol += leftWindow - col + 1 } - evidence = evidence.replace(/\t/g, ' ').substring(leftCol - 1, rightCol); + evidence = evidence.replace(/\t/g, ' ').substring(leftCol - 1, rightCol) // add ... if (leftCol > 1) { - evidence = '...' + evidence; - leftCol -= 3; + evidence = '...' + evidence + leftCol -= 3 } if (rightCol < evidenceCount) { - evidence += '...'; + evidence += '...' } // show evidence arrLogs.push( @@ -112,13 +113,14 @@ class HTMLHintCore { colors.grey + evidence + colors.reset - ); + ) // show pointer & message - var pointCol = col - leftCol; + var pointCol = col - leftCol // add double byte character - var match = evidence.substring(0, pointCol).match(/[^\u0000-\u00ff]/g); + //eslint-disable-next-line + var match = evidence.substring(0, pointCol).match(/[^\u0000-\u00ff]/g) if (match !== null) { - pointCol += match.length; + pointCol += match.length } arrLogs.push( colors.white + @@ -131,22 +133,21 @@ class HTMLHintCore { hint.rule.id + ')' + colors.reset - ); - }); - return arrLogs; + ) + }) + return arrLogs } } // repeat string function repeatStr(n, str) { - return new Array(n + 1).join(str || ' '); + return new Array(n + 1).join(str || ' ') } -const HTMLHint = new HTMLHintCore(); - -Object.keys(HTMLRules).forEach(key => { - HTMLHint.addRule(HTMLRules[key]); -}); +const HTMLHint = new HTMLHintCore() -export { HTMLRules, Reporter, HTMLParser, HTMLHint }; +Object.keys(HTMLRules).forEach((key) => { + HTMLHint.addRule(HTMLRules[key]) +}) +export { HTMLRules, Reporter, HTMLParser, HTMLHint } diff --git a/src/htmlparser.js b/src/htmlparser.js index f23b7c28f..d005374c4 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -1,25 +1,27 @@ class HTMLParser { constructor() { - this._listeners = {}; - this._mapCdataTags = this.makeMap('script,style'); - this._arrBlocks = []; - this.lastEvent = null; + this._listeners = {} + this._mapCdataTags = this.makeMap('script,style') + this._arrBlocks = [] + this.lastEvent = null } makeMap(str) { var obj = {}, - items = str.split(','); + items = str.split(',') for (var i = 0; i < items.length; i++) { - obj[items[i]] = true; + obj[items[i]] = true } - return obj; + return obj } parse(html) { var self = this, - mapCdataTags = self._mapCdataTags; + mapCdataTags = self._mapCdataTags + // eslint-disable-next-line var regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g, + // eslint-disable-next-line regAttr = /\s*([^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+)(?:\s*=\s*(?:(")([^"]*)"|(')([^']*)'|([^\s"'>]*)))?/g, - regLine = /\r?\n/g; + regLine = /\r?\n/g var match, matchIndex, @@ -30,215 +32,217 @@ class HTMLParser { attrsCDATA, arrCDATA, lastCDATAIndex = 0, - text; + text var lastLineIndex = 0, - line = 1; - var arrBlocks = self._arrBlocks; + line = 1 + var arrBlocks = self._arrBlocks self.fire('start', { pos: 0, line: 1, - col: 1 - }); + col: 1, + }) // Memory block function saveBlock(type, raw, pos, data) { - var col = pos - lastLineIndex + 1; + var col = pos - lastLineIndex + 1 if (data === undefined) { - data = {}; + data = {} } - data.raw = raw; - data.pos = pos; - data.line = line; - data.col = col; - arrBlocks.push(data); - self.fire(type, data); - var lineMatch; + data.raw = raw + data.pos = pos + data.line = line + data.col = col + arrBlocks.push(data) + self.fire(type, data) + + // eslint-disable-next-line + var lineMatch while ((lineMatch = regLine.exec(raw))) { - line++; - lastLineIndex = pos + regLine.lastIndex; + line++ + lastLineIndex = pos + regLine.lastIndex } } while ((match = regTag.exec(html))) { - matchIndex = match.index; + matchIndex = match.index if (matchIndex > lastIndex) { // Save the previous text or CDATA - text = html.substring(lastIndex, matchIndex); + text = html.substring(lastIndex, matchIndex) if (tagCDATA) { - arrCDATA.push(text); + arrCDATA.push(text) } else { // text - saveBlock('text', text, lastIndex); + saveBlock('text', text, lastIndex) } } - lastIndex = regTag.lastIndex; + lastIndex = regTag.lastIndex if ((tagName = match[1])) { if (tagCDATA && tagName === tagCDATA) { // Output CDATA before closing the label - text = arrCDATA.join(''); + text = arrCDATA.join('') saveBlock('cdata', text, lastCDATAIndex, { tagName: tagCDATA, - attrs: attrsCDATA - }); - tagCDATA = null; - attrsCDATA = null; - arrCDATA = null; + attrs: attrsCDATA, + }) + tagCDATA = null + attrsCDATA = null + arrCDATA = null } if (!tagCDATA) { // End of label saveBlock('tagend', match[0], matchIndex, { - tagName: tagName - }); - continue; + tagName: tagName, + }) + continue } } if (tagCDATA) { - arrCDATA.push(match[0]); + arrCDATA.push(match[0]) } else { if ((tagName = match[4])) { // Label start - arrAttrs = []; + arrAttrs = [] var attrs = match[5], attrMatch, - attrMatchCount = 0; + attrMatchCount = 0 while ((attrMatch = regAttr.exec(attrs))) { var name = attrMatch[1], quote = attrMatch[2] ? attrMatch[2] : attrMatch[4] - ? attrMatch[4] - : '', + ? attrMatch[4] + : '', value = attrMatch[3] ? attrMatch[3] : attrMatch[5] - ? attrMatch[5] - : attrMatch[6] - ? attrMatch[6] - : ''; + ? attrMatch[5] + : attrMatch[6] + ? attrMatch[6] + : '' arrAttrs.push({ name: name, value: value, quote: quote, index: attrMatch.index, - raw: attrMatch[0] - }); - attrMatchCount += attrMatch[0].length; + raw: attrMatch[0], + }) + attrMatchCount += attrMatch[0].length } if (attrMatchCount === attrs.length) { saveBlock('tagstart', match[0], matchIndex, { tagName: tagName, attrs: arrAttrs, - close: match[6] - }); + close: match[6], + }) if (mapCdataTags[tagName]) { - tagCDATA = tagName; - attrsCDATA = arrAttrs.concat(); - arrCDATA = []; - lastCDATAIndex = lastIndex; + tagCDATA = tagName + attrsCDATA = arrAttrs.concat() + arrCDATA = [] + lastCDATAIndex = lastIndex } } else { // If a miss match occurs, the current content is matched to text - saveBlock('text', match[0], matchIndex); + saveBlock('text', match[0], matchIndex) } } else if (match[2] || match[3]) { // Comment tag saveBlock('comment', match[0], matchIndex, { content: match[2] || match[3], - long: match[2] ? true : false - }); + long: match[2] ? true : false, + }) } } } if (html.length > lastIndex) { // End text - text = html.substring(lastIndex, html.length); - saveBlock('text', text, lastIndex); + text = html.substring(lastIndex, html.length) + saveBlock('text', text, lastIndex) } self.fire('end', { pos: lastIndex, line: line, - col: html.length - lastLineIndex + 1 - }); + col: html.length - lastLineIndex + 1, + }) } addListener(types, listener) { - var _listeners = this._listeners; + var _listeners = this._listeners var arrTypes = types.split(/[,\s]/), - type; + type for (var i = 0, l = arrTypes.length; i < l; i++) { - type = arrTypes[i]; + type = arrTypes[i] if (_listeners[type] === undefined) { - _listeners[type] = []; + _listeners[type] = [] } - _listeners[type].push(listener); + _listeners[type].push(listener) } } fire(type, data) { if (data === undefined) { - data = {}; + data = {} } - data.type = type; + data.type = type var self = this, listeners = [], listenersType = self._listeners[type], - listenersAll = self._listeners['all']; + listenersAll = self._listeners['all'] if (listenersType !== undefined) { - listeners = listeners.concat(listenersType); + listeners = listeners.concat(listenersType) } if (listenersAll !== undefined) { - listeners = listeners.concat(listenersAll); + listeners = listeners.concat(listenersAll) } - var lastEvent = self.lastEvent; + var lastEvent = self.lastEvent if (lastEvent !== null) { - delete lastEvent['lastEvent']; - data.lastEvent = lastEvent; + delete lastEvent['lastEvent'] + data.lastEvent = lastEvent } - self.lastEvent = data; + self.lastEvent = data for (var i = 0, l = listeners.length; i < l; i++) { - listeners[i].call(self, data); + listeners[i].call(self, data) } } removeListener(type, listener) { - var listenersType = this._listeners[type]; + var listenersType = this._listeners[type] if (listenersType !== undefined) { for (var i = 0, l = listenersType.length; i < l; i++) { if (listenersType[i] === listener) { - listenersType.splice(i, 1); - break; + listenersType.splice(i, 1) + break } } } } fixPos(event, index) { - var text = event.raw.substr(0, index); + var text = event.raw.substr(0, index) var arrLines = text.split(/\r?\n/), lineCount = arrLines.length - 1, line = event.line, - col; + col if (lineCount > 0) { - line += lineCount; - col = arrLines[lineCount].length + 1; + line += lineCount + col = arrLines[lineCount].length + 1 } else { - col = event.col + index; + col = event.col + index } return { line: line, - col: col - }; + col: col, + } } getMapAttrs(arrAttrs) { var mapAttrs = {}, - attr; + attr for (var i = 0, l = arrAttrs.length; i < l; i++) { - attr = arrAttrs[i]; - mapAttrs[attr.name] = attr.value; + attr = arrAttrs[i] + mapAttrs[attr.name] = attr.value } - return mapAttrs; + return mapAttrs } } -export default HTMLParser; +export default HTMLParser diff --git a/src/reporter.js b/src/reporter.js index 753362a6f..b40631bef 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -1,32 +1,32 @@ class Reporter { constructor(html, ruleset) { - this.html = html; - this.lines = html.split(/\r?\n/); - var match = html.match(/\r?\n/); - this.brLen = match !== null ? match[0].length : 0; - this.ruleset = ruleset; - this.messages = []; + this.html = html + this.lines = html.split(/\r?\n/) + var match = html.match(/\r?\n/) + this.brLen = match !== null ? match[0].length : 0 + this.ruleset = ruleset + this.messages = [] - this.error = this.report.bind(this, 'error'); - this.warn = this.report.bind(this, 'warning'); - this.info = this.report.bind(this, 'info'); + this.error = this.report.bind(this, 'error') + this.warn = this.report.bind(this, 'warning') + this.info = this.report.bind(this, 'info') } report(type, message, line, col, rule, raw) { - var self = this; - var lines = self.lines; - var brLen = self.brLen; - var evidence, evidenceLen; + var self = this + var lines = self.lines + var brLen = self.brLen + var evidence, evidenceLen for (var i = line - 1, lineCount = lines.length; i < lineCount; i++) { - evidence = lines[i]; - evidenceLen = evidence.length; + evidence = lines[i] + evidenceLen = evidence.length if (col > evidenceLen && line < lineCount) { - line++; - col -= evidenceLen; + line++ + col -= evidenceLen if (col !== 1) { - col -= brLen; + col -= brLen } } else { - break; + break } } self.messages.push({ @@ -39,10 +39,10 @@ class Reporter { rule: { id: rule.id, description: rule.description, - link: 'https://github.com/thedaviddias/HTMLHint/wiki/' + rule.id - } - }); + link: 'https://github.com/thedaviddias/HTMLHint/wiki/' + rule.id, + }, + }) } } -export default Reporter; +export default Reporter diff --git a/src/rules/alt-require.js b/src/rules/alt-require.js index f172160e7..13e9b1009 100644 --- a/src/rules/alt-require.js +++ b/src/rules/alt-require.js @@ -2,13 +2,13 @@ export default { id: 'alt-require', description: 'The alt attribute of an element must be present and alt attribute of area[href] and input[type=image] must have a value.', - init: function(parser, reporter) { - var self = this; - parser.addListener('tagstart', function(event) { + init: function (parser, reporter) { + var self = this + parser.addListener('tagstart', function (event) { var tagName = event.tagName.toLowerCase(), mapAttrs = parser.getMapAttrs(event.attrs), col = event.col + tagName.length + 1, - selector; + selector if (tagName === 'img' && !('alt' in mapAttrs)) { reporter.warn( 'An alt attribute must be present on elements.', @@ -16,22 +16,22 @@ export default { col, self, event.raw - ); + ) } else if ( (tagName === 'area' && 'href' in mapAttrs) || (tagName === 'input' && mapAttrs['type'] === 'image') ) { if (!('alt' in mapAttrs) || mapAttrs['alt'] === '') { - selector = tagName === 'area' ? 'area[href]' : 'input[type=image]'; + selector = tagName === 'area' ? 'area[href]' : 'input[type=image]' reporter.warn( 'The alt attribute of ' + selector + ' must have a value.', event.line, col, self, event.raw - ); + ) } } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-lowercase.js b/src/rules/attr-lowercase.js index 2c1625787..aafe5aec3 100644 --- a/src/rules/attr-lowercase.js +++ b/src/rules/attr-lowercase.js @@ -9,50 +9,49 @@ function testAgainstStringOrRegExp(value, comparison) { if (comparison instanceof RegExp) { return comparison.test(value) ? { match: value, pattern: comparison } - : false; + : false } // Check if it's RegExp in a string - const firstComparisonChar = comparison[0]; - const lastComparisonChar = comparison[comparison.length - 1]; - const secondToLastComparisonChar = comparison[comparison.length - 2]; + const firstComparisonChar = comparison[0] + const lastComparisonChar = comparison[comparison.length - 1] + const secondToLastComparisonChar = comparison[comparison.length - 2] const comparisonIsRegex = firstComparisonChar === '/' && (lastComparisonChar === '/' || - (secondToLastComparisonChar === '/' && lastComparisonChar === 'i')); + (secondToLastComparisonChar === '/' && lastComparisonChar === 'i')) - const hasCaseInsensitiveFlag = - comparisonIsRegex && lastComparisonChar === 'i'; + const hasCaseInsensitiveFlag = comparisonIsRegex && lastComparisonChar === 'i' // If so, create a new RegExp from it if (comparisonIsRegex) { const valueMatches = hasCaseInsensitiveFlag ? new RegExp(comparison.slice(1, -2), 'i').test(value) - : new RegExp(comparison.slice(1, -1)).test(value); + : new RegExp(comparison.slice(1, -1)).test(value) - return valueMatches; + return valueMatches } // Otherwise, it's a string. Do a strict comparison - return value === comparison; + return value === comparison } export default { id: 'attr-lowercase', description: 'All attribute names must be in lowercase.', - init: function(parser, reporter, options) { - var self = this; - var exceptions = Array.isArray(options) ? options : []; - parser.addListener('tagstart', function(event) { + init: function (parser, reporter, options) { + var self = this + var exceptions = Array.isArray(options) ? options : [] + parser.addListener('tagstart', function (event) { var attrs = event.attrs, attr, - col = event.col + event.tagName.length + 1; + col = event.col + event.tagName.length + 1 for (var i = 0, l = attrs.length; i < l; i++) { - attr = attrs[i]; - var attrName = attr.name; + attr = attrs[i] + var attrName = attr.name if ( - !exceptions.find(exp => testAgainstStringOrRegExp(attrName, exp)) && + !exceptions.find((exp) => testAgainstStringOrRegExp(attrName, exp)) && attrName !== attrName.toLowerCase() ) { reporter.error( @@ -61,9 +60,9 @@ export default { col + attr.index, self, attr.raw - ); + ) } } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-no-duplication.js b/src/rules/attr-no-duplication.js index 0f563f91f..272b5a51d 100644 --- a/src/rules/attr-no-duplication.js +++ b/src/rules/attr-no-duplication.js @@ -1,18 +1,18 @@ export default { id: 'attr-no-duplication', description: 'Elements cannot have duplicate attributes.', - init: function(parser, reporter) { - var self = this; - parser.addListener('tagstart', function(event) { - var attrs = event.attrs; - var attr; - var attrName; - var col = event.col + event.tagName.length + 1; + init: function (parser, reporter) { + var self = this + parser.addListener('tagstart', function (event) { + var attrs = event.attrs + var attr + var attrName + var col = event.col + event.tagName.length + 1 - var mapAttrName = {}; + var mapAttrName = {} for (var i = 0, l = attrs.length; i < l; i++) { - attr = attrs[i]; - attrName = attr.name; + attr = attrs[i] + attrName = attr.name if (mapAttrName[attrName] === true) { reporter.error( 'Duplicate of attribute name [ ' + attr.name + ' ] was found.', @@ -20,10 +20,10 @@ export default { col + attr.index, self, attr.raw - ); + ) } - mapAttrName[attrName] = true; + mapAttrName[attrName] = true } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-no-unnecessary-whitespace.js b/src/rules/attr-no-unnecessary-whitespace.js index 167b21228..addfc8850 100644 --- a/src/rules/attr-no-unnecessary-whitespace.js +++ b/src/rules/attr-no-unnecessary-whitespace.js @@ -1,23 +1,28 @@ export default { - id: 'attr-no-unnecessary-whitespace', - description: 'No spaces between attribute names and values.', - init: function (parser, reporter, options) { - var self = this; - var exceptions = Array.isArray(options) ? options : []; - parser.addListener('tagstart', function (event) { - var attrs = event.attrs, - col = event.col + event.tagName.length + 1; - for (var i = 0; i < attrs.length; i++) { - if (exceptions.indexOf(attrs[i].name) === -1 && /[^=](\s+=\s+|=\s+|\s+=)/g.test(attrs[i].raw.trim())) { - reporter.error( - 'The attribute \'' + attrs[i].name + '\' must not have spaces between the name and value.', - event.line, - col + attrs[i].index, - self, - attrs[i].raw - ); - } - } - }); - } -}; + id: 'attr-no-unnecessary-whitespace', + description: 'No spaces between attribute names and values.', + init: function (parser, reporter, options) { + var self = this + var exceptions = Array.isArray(options) ? options : [] + parser.addListener('tagstart', function (event) { + var attrs = event.attrs, + col = event.col + event.tagName.length + 1 + for (var i = 0; i < attrs.length; i++) { + if ( + exceptions.indexOf(attrs[i].name) === -1 && + /[^=](\s+=\s+|=\s+|\s+=)/g.test(attrs[i].raw.trim()) + ) { + reporter.error( + "The attribute '" + + attrs[i].name + + "' must not have spaces between the name and value.", + event.line, + col + attrs[i].index, + self, + attrs[i].raw + ) + } + } + }) + }, +} diff --git a/src/rules/attr-sorted.js b/src/rules/attr-sorted.js index 707c0bfbe..a3556748a 100644 --- a/src/rules/attr-sorted.js +++ b/src/rules/attr-sorted.js @@ -1,9 +1,9 @@ export default { id: 'attr-sorted', description: 'Attribute tags must be in proper order.', - init: function(parser, reporter) { - var self = this; - var orderMap = {}; + init: function (parser, reporter) { + var self = this + var orderMap = {} var sortOrder = [ 'class', 'id', @@ -15,30 +15,30 @@ export default { 'value', 'title', 'alt', - 'role' - ]; + 'role', + ] for (var i = 0; i < sortOrder.length; i++) { - orderMap[sortOrder[i]] = i; + orderMap[sortOrder[i]] = i } - parser.addListener('tagstart', function(event) { - var attrs = event.attrs; - var listOfAttributes = []; + parser.addListener('tagstart', function (event) { + var attrs = event.attrs + var listOfAttributes = [] for (var i = 0; i < attrs.length; i++) { - listOfAttributes.push(attrs[i].name); + listOfAttributes.push(attrs[i].name) } - var originalAttrs = JSON.stringify(listOfAttributes); - listOfAttributes.sort(function(a, b) { + var originalAttrs = JSON.stringify(listOfAttributes) + listOfAttributes.sort(function (a, b) { if (orderMap[a] == undefined && orderMap[b] == undefined) { - return 0; + return 0 } if (orderMap[a] == undefined) { - return 1; + return 1 } else if (orderMap[b] == undefined) { - return -1; + return -1 } - return orderMap[a] - orderMap[b] || a.localeCompare(b); - }); + return orderMap[a] - orderMap[b] || a.localeCompare(b) + }) if (originalAttrs !== JSON.stringify(listOfAttributes)) { reporter.error( 'Inaccurate order ' + @@ -49,8 +49,8 @@ export default { event.line, event.col, self - ); + ) } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-unsafe-chars.js b/src/rules/attr-unsafe-chars.js index 84c786cd0..32012c801 100644 --- a/src/rules/attr-unsafe-chars.js +++ b/src/rules/attr-unsafe-chars.js @@ -1,22 +1,23 @@ export default { id: 'attr-unsafe-chars', description: 'Attribute values cannot contain unsafe chars.', - init: function(parser, reporter) { - var self = this; - parser.addListener('tagstart', function(event) { + init: function (parser, reporter) { + var self = this + parser.addListener('tagstart', function (event) { var attrs = event.attrs, attr, - col = event.col + event.tagName.length + 1; + col = event.col + event.tagName.length + 1 // exclude \x09(\t), \x0a(\r), \x0d(\n) - var regUnsafe = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/; - var match; + // eslint-disable-next-line + var regUnsafe = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/ + var match for (var i = 0, l = attrs.length; i < l; i++) { - attr = attrs[i]; - match = attr.value.match(regUnsafe); + attr = attrs[i] + match = attr.value.match(regUnsafe) if (match !== null) { var unsafeCode = escape(match[0]) .replace(/%u/, '\\u') - .replace(/%/, '\\x'); + .replace(/%/, '\\x') reporter.warn( 'The value of attribute [ ' + attr.name + @@ -27,9 +28,9 @@ export default { col + attr.index, self, attr.raw - ); + ) } } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-value-double-quotes.js b/src/rules/attr-value-double-quotes.js index dc7b88d95..a499024eb 100644 --- a/src/rules/attr-value-double-quotes.js +++ b/src/rules/attr-value-double-quotes.js @@ -1,14 +1,14 @@ export default { id: 'attr-value-double-quotes', description: 'Attribute values must be in double quotes.', - init: function(parser, reporter) { - var self = this; - parser.addListener('tagstart', function(event) { + init: function (parser, reporter) { + var self = this + parser.addListener('tagstart', function (event) { var attrs = event.attrs, attr, - col = event.col + event.tagName.length + 1; + col = event.col + event.tagName.length + 1 for (var i = 0, l = attrs.length; i < l; i++) { - attr = attrs[i]; + attr = attrs[i] if ( (attr.value !== '' && attr.quote !== '"') || (attr.value === '' && attr.quote === "'") @@ -21,9 +21,9 @@ export default { col + attr.index, self, attr.raw - ); + ) } } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-value-not-empty.js b/src/rules/attr-value-not-empty.js index e6814568b..dd08679af 100644 --- a/src/rules/attr-value-not-empty.js +++ b/src/rules/attr-value-not-empty.js @@ -1,14 +1,14 @@ export default { id: 'attr-value-not-empty', description: 'All attributes must have values.', - init: function(parser, reporter) { - var self = this; - parser.addListener('tagstart', function(event) { + init: function (parser, reporter) { + var self = this + parser.addListener('tagstart', function (event) { var attrs = event.attrs, attr, - col = event.col + event.tagName.length + 1; + col = event.col + event.tagName.length + 1 for (var i = 0, l = attrs.length; i < l; i++) { - attr = attrs[i]; + attr = attrs[i] if (attr.quote === '' && attr.value === '') { reporter.warn( 'The attribute [ ' + attr.name + ' ] must have a value.', @@ -16,9 +16,9 @@ export default { col + attr.index, self, attr.raw - ); + ) } } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-value-single-quotes.js b/src/rules/attr-value-single-quotes.js index 4a1517f38..9a0873c52 100644 --- a/src/rules/attr-value-single-quotes.js +++ b/src/rules/attr-value-single-quotes.js @@ -1,14 +1,14 @@ export default { id: 'attr-value-single-quotes', description: 'Attribute values must be in single quotes.', - init: function(parser, reporter) { - var self = this; - parser.addListener('tagstart', function(event) { + init: function (parser, reporter) { + var self = this + parser.addListener('tagstart', function (event) { var attrs = event.attrs, attr, - col = event.col + event.tagName.length + 1; + col = event.col + event.tagName.length + 1 for (var i = 0, l = attrs.length; i < l; i++) { - attr = attrs[i]; + attr = attrs[i] if ( (attr.value !== '' && attr.quote !== "'") || (attr.value === '' && attr.quote === '"') @@ -21,9 +21,9 @@ export default { col + attr.index, self, attr.raw - ); + ) } } - }); - } -}; + }) + }, +} diff --git a/src/rules/attr-whitespace.js b/src/rules/attr-whitespace.js index 2c1346d49..06534732d 100644 --- a/src/rules/attr-whitespace.js +++ b/src/rules/attr-whitespace.js @@ -2,20 +2,20 @@ export default { id: 'attr-whitespace', description: 'All attributes should be separated by only one space and not have leading/trailing whitespace.', - init: function(parser, reporter, options) { - var self = this; - var exceptions = Array.isArray(options) ? options : []; + init: function (parser, reporter, options) { + var self = this + var exceptions = Array.isArray(options) ? options : [] - parser.addListener('tagstart', function(event) { + parser.addListener('tagstart', function (event) { var attrs = event.attrs, attr, - col = event.col + event.tagName.length + 1; - attrs.forEach(function(elem) { - attr = elem; - var attrName = elem.name; + col = event.col + event.tagName.length + 1 + attrs.forEach(function (elem) { + attr = elem + var attrName = elem.name if (exceptions.indexOf(attrName) !== -1) { - return; + return } //Check first and last characters for spaces @@ -28,7 +28,7 @@ export default { col + attr.index, self, attr.raw - ); + ) } if (elem.value.replace(/ +(?= )/g, '') !== elem.value) { reporter.error( @@ -39,9 +39,9 @@ export default { col + attr.index, self, attr.raw - ); + ) } - }); - }); - } -}; + }) + }) + }, +} diff --git a/src/rules/doctype-first.js b/src/rules/doctype-first.js index 2f2a2094a..e3c3f0444 100644 --- a/src/rules/doctype-first.js +++ b/src/rules/doctype-first.js @@ -1,14 +1,14 @@ export default { id: 'doctype-first', description: 'Doctype must be declared first.', - init: function(parser, reporter) { - var self = this; - var allEvent = function(event) { + init: function (parser, reporter) { + var self = this + var allEvent = function (event) { if ( event.type === 'start' || (event.type === 'text' && /^\s*$/.test(event.raw)) ) { - return; + return } if ( (event.type !== 'comment' && event.long === false) || @@ -20,10 +20,10 @@ export default { event.col, self, event.raw - ); + ) } - parser.removeListener('all', allEvent); - }; - parser.addListener('all', allEvent); - } -}; + parser.removeListener('all', allEvent) + } + parser.addListener('all', allEvent) + }, +} diff --git a/src/rules/doctype-html5.js b/src/rules/doctype-html5.js index efc734381..7dc16f889 100644 --- a/src/rules/doctype-html5.js +++ b/src/rules/doctype-html5.js @@ -1,8 +1,8 @@ export default { id: 'doctype-html5', description: 'Invalid doctype. Use: ""', - init: function(parser, reporter) { - var self = this; + init: function (parser, reporter) { + var self = this function onComment(event) { if ( event.long === false && @@ -14,14 +14,14 @@ export default { event.col, self, event.raw - ); + ) } } function onTagStart() { - parser.removeListener('comment', onComment); - parser.removeListener('tagstart', onTagStart); + parser.removeListener('comment', onComment) + parser.removeListener('tagstart', onTagStart) } - parser.addListener('all', onComment); - parser.addListener('tagstart', onTagStart); - } -}; + parser.addListener('all', onComment) + parser.addListener('tagstart', onTagStart) + }, +} diff --git a/src/rules/head-script-disabled.js b/src/rules/head-script-disabled.js index 3ed55e56f..e12908dbf 100644 --- a/src/rules/head-script-disabled.js +++ b/src/rules/head-script-disabled.js @@ -1,16 +1,16 @@ export default { id: 'head-script-disabled', description: 'The ' - ); - }); + ) + }) - it('should parse cdata: style', function(done) { - const parser = new HTMLParser(); - const arrEvents = []; + it('should parse cdata: style', function (done) { + const parser = new HTMLParser() + const arrEvents = [] getAllEvents(parser, arrEvents, () => { expect(arrEvents[1]).to.event('tagstart', { tagName: 'style', - type: 'text/css' - }); + type: 'text/css', + }) expect(arrEvents[2]).to.event('cdata', { tagName: 'style', - raw: 'body{font-size:12px;\r\nbackground-color:green;}' - }); + raw: 'body{font-size:12px;\r\nbackground-color:green;}', + }) expect(arrEvents[3]).to.event('tagend', { - tagName: 'style' - }); - done(); - }); + tagName: 'style', + }) + done() + }) parser.parse( '' - ); - }); -}); + ) + }) +}) describe('HTMLParser: Case parse', () => { - it('should parse special end tag', function(done) { - const parser = new HTMLParser(); - const arrEvents = []; + it('should parse special end tag', function (done) { + const parser = new HTMLParser() + const arrEvents = [] getAllEvents(parser, arrEvents, () => { expect(arrEvents[1]).to.event('tagend', { - tagName: 'p' - }); - done(); - }); - parser.parse('

'); - }); - - it('should parse special no quotes tags', function(done) { - const parser = new HTMLParser(); - const arrEvents = []; + tagName: 'p', + }) + done() + }) + parser.parse('

') + }) + + it('should parse special no quotes tags', function (done) { + const parser = new HTMLParser() + const arrEvents = [] getAllEvents(parser, arrEvents, () => { expect(arrEvents[1]).to.event('tagstart', { - tagName: 'link' - }); + tagName: 'link', + }) expect(arrEvents[2]).to.event('tagstart', { - tagName: 'link' - }); - done(); - }); - parser.parse(''); - }); - - it('should parse special empty attr', function(done) { - const parser = new HTMLParser(); - const arrEvents = []; + tagName: 'link', + }) + done() + }) + parser.parse('') + }) + + it('should parse special empty attr', function (done) { + const parser = new HTMLParser() + const arrEvents = [] getAllEvents(parser, arrEvents, () => { expect(arrEvents[1]).to.event('tagstart', { tagName: 'img', - close: '' - }); - const attrs = arrEvents[1].attrs; - expect(attrs.length).to.be(2); - expect(attrs[1].name).to.be('alt'); - expect(attrs[1].value).to.be('/'); - done(); - }); - parser.parse('/'); - }); -}); + close: '', + }) + const attrs = arrEvents[1].attrs + expect(attrs.length).to.be(2) + expect(attrs[1].name).to.be('alt') + expect(attrs[1].value).to.be('/') + done() + }) + parser.parse('/') + }) +}) diff --git a/test/rules/alt-require.spec.js b/test/rules/alt-require.spec.js index c3d75e065..f8d707684 100644 --- a/test/rules/alt-require.spec.js +++ b/test/rules/alt-require.spec.js @@ -1,109 +1,109 @@ -const expect = require('expect.js'); - -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; - -const ruldId = 'alt-require'; -const ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe(`Rules: ${ruldId}`, function() { - it('Img tag have empty alt attribute should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Img tag have non empty alt attribute should not result in an error', function() { - const code = 'test'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Img tag have not alt attribute should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); +const expect = require('expect.js') + +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint + +const ruldId = 'alt-require' +const ruleOptions = {} + +ruleOptions[ruldId] = true + +describe(`Rules: ${ruldId}`, function () { + it('Img tag have empty alt attribute should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Img tag have non empty alt attribute should not result in an error', function () { + const code = 'test' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Img tag have not alt attribute should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) /* 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', function() { - const code = '
'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Area tag have not href and alt attributes should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Area[href] tag have not alt attribute should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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(6); - expect(messages[0].type).to.be('warning'); - }); - - it('Area[href] tag have empty alt attribute should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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(6); - expect(messages[0].type).to.be('warning'); - }); - - it('Area[href] tag have non emtpy alt attribute should not result in an error', function() { - const code = 'test'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Input tag have not type and alt attributes should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Input[type="text"] tag have not alt attribute should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Input[type="image"] tag have not alt attribute should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); - - it('Input[type="image"] tag have empty alt attribute should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); - - it('Input[type="image"] tag have non emtpy alt attribute should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('A tag have not alt attribute should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Area tag have not href and alt attributes should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Area[href] tag have not alt attribute should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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(6) + expect(messages[0].type).to.be('warning') + }) + + it('Area[href] tag have empty alt attribute should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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(6) + expect(messages[0].type).to.be('warning') + }) + + it('Area[href] tag have non emtpy alt attribute should not result in an error', function () { + const code = 'test' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Input tag have not type and alt attributes should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Input[type="text"] tag have not alt attribute should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Input[type="image"] tag have not alt attribute should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) + + it('Input[type="image"] tag have empty alt attribute should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) + + it('Input[type="image"] tag have non emtpy alt attribute should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/attr-lowercase.spec.js b/test/rules/attr-lowercase.spec.js index c13383b07..807cf28f2 100644 --- a/test/rules/attr-lowercase.spec.js +++ b/test/rules/attr-lowercase.spec.js @@ -1,63 +1,63 @@ -const expect = require('expect.js'); - -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; - -const ruldId = 'attr-lowercase'; -const ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe(`Rules: ${ruldId}`, function() { - it('Not all lowercase attr should result in an error', function() { - let code = '

'; - let messages = HTMLHint.verify(code, 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); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(2); - expect(messages[0].col).to.be(1); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(2); - expect(messages[1].col).to.be(13); - }); - - it('Lowercase attr should not result in an error', function() { - const code = '

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

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

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

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

'; - ruleOptions[ruldId] = ['testBox', '/\\[.*\\]/']; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); +const expect = require('expect.js') + +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint + +const ruldId = 'attr-lowercase' +const ruleOptions = {} + +ruleOptions[ruldId] = true + +describe(`Rules: ${ruldId}`, function () { + it('Not all lowercase attr should result in an error', function () { + let code = '

' + let messages = HTMLHint.verify(code, 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) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(2) + expect(messages[0].col).to.be(1) + expect(messages[1].rule.id).to.be(ruldId) + expect(messages[1].line).to.be(2) + expect(messages[1].col).to.be(13) + }) + + it('Lowercase attr should not result in an error', function () { + const code = '

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

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

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

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

' + ruleOptions[ruldId] = ['testBox', '/\\[.*\\]/'] + const messages = HTMLHint.verify(code, 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 8a94e5a68..0db0caf58 100644 --- a/test/rules/attr-no-duplication.spec.js +++ b/test/rules/attr-no-duplication.spec.js @@ -1,25 +1,25 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'attr-no-duplication'; -const ruleOptions = {}; +const ruldId = 'attr-no-duplication' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Attribute name been duplication should result in an error', function() { - const code = 'bbb'; - const messages = HTMLHint.verify(code, 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(12); - }); +describe(`Rules: ${ruldId}`, function () { + it('Attribute name been duplication should result in an error', function () { + const code = 'bbb' + const messages = HTMLHint.verify(code, 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(12) + }) - it('Attribute name not been duplication should not result in an error', function() { - const code = 'bbb'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Attribute name not been duplication should not result in an error', function () { + const code = 'bbb' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/attr-no-unnecessary-whitespace.js b/test/rules/attr-no-unnecessary-whitespace.js index 6476dd893..18fc2b1b2 100644 --- a/test/rules/attr-no-unnecessary-whitespace.js +++ b/test/rules/attr-no-unnecessary-whitespace.js @@ -1,31 +1,31 @@ -var expect = require('expect.js'); +var expect = require('expect.js') -var HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +var HTMLHint = require('../../dist/htmlhint.js').HTMLHint var ruldId = 'attr-no-unnecessary-whitespace', - ruleOptions = {}; + ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true describe('Rules: ' + ruldId, function () { - it('Attribute with spaces should result in an error', function () { - var codes = [ - '

', - '
', - '
', - ]; - for (var i = 0; i < codes.length; i++) { - var messages = HTMLHint.verify(codes[i], 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); - } - }); + it('Attribute with spaces should result in an error', function () { + var codes = [ + '
', + '
', + '
', + ] + for (var i = 0; i < codes.length; i++) { + var messages = HTMLHint.verify(codes[i], 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) + } + }) - it('Attribute without spaces should not result in an error', function () { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Attribute without spaces should not result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/attr-sort.spec.js b/test/rules/attr-sort.spec.js index 66688eefc..b95268092 100644 --- a/test/rules/attr-sort.spec.js +++ b/test/rules/attr-sort.spec.js @@ -1,38 +1,38 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruleId = 'attr-sorted'; -const ruleOptions = {}; +const ruleId = 'attr-sorted' +const ruleOptions = {} -ruleOptions[ruleId] = true; +ruleOptions[ruleId] = true -describe(`Rules: ${ruleId}`, function() { - it('Attribute unsorted tags must result in an error', function() { - const code = '
'; +describe(`Rules: ${ruleId}`, function () { + it('Attribute unsorted tags must result in an error', function () { + const code = '
' - const messages = HTMLHint.verify(code, ruleOptions); + const messages = HTMLHint.verify(code, ruleOptions) - expect(messages.length).to.be(1); - expect(messages[0].rule.id).to.be(ruleId); - expect(messages[0].message).to.contain('["id","class","title"]'); - }); + expect(messages.length).to.be(1) + expect(messages[0].rule.id).to.be(ruleId) + expect(messages[0].message).to.contain('["id","class","title"]') + }) - it('Attribute unsorted tags that are unrecognizable should not throw error', function() { - const code = '
'; + it('Attribute unsorted tags that are unrecognizable should not throw error', function () { + const code = '
' - const messages = HTMLHint.verify(code, ruleOptions); + const messages = HTMLHint.verify(code, ruleOptions) - expect(messages.length).to.be(0); - }); + expect(messages.length).to.be(0) + }) - it('Attribute unsorted of tags of various types should throw error', function() { - const code = '
'; + it('Attribute unsorted of tags of various types should throw error', function () { + const code = '
' - const messages = HTMLHint.verify(code, ruleOptions); + const messages = HTMLHint.verify(code, ruleOptions) - expect(messages.length).to.be(1); - expect(messages[0].rule.id).to.be(ruleId); - expect(messages[0].message).to.contain('["type","img","id","font"]'); - }); -}); + expect(messages.length).to.be(1) + expect(messages[0].rule.id).to.be(ruleId) + expect(messages[0].message).to.contain('["type","img","id","font"]') + }) +}) diff --git a/test/rules/attr-unsafe-chars.spec.js b/test/rules/attr-unsafe-chars.spec.js index a3a3098fe..4b4068b27 100644 --- a/test/rules/attr-unsafe-chars.spec.js +++ b/test/rules/attr-unsafe-chars.spec.js @@ -1,34 +1,34 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'attr-unsafe-chars'; -const ruleOptions = {}; +const ruldId = 'attr-unsafe-chars' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Attribute value have unsafe chars should result in an error', function() { +describe(`Rules: ${ruldId}`, function () { + it('Attribute value have unsafe chars should result in an error', function () { const code = - 'Sud Web 2012'; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); + 'Sud Web 2012' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) - it('Attribute value have no unsafe chars should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); + it('Attribute value have no unsafe chars should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) - it('Attribute value have \\r\\n\\t should not result in an error', function() { + it('Attribute value have \\r\\n\\t should not result in an error', function () { const code = - ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + '' + const messages = HTMLHint.verify(code, 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 eaeac9764..6deb78b45 100644 --- a/test/rules/attr-value-double-quotes.spec.js +++ b/test/rules/attr-value-double-quotes.spec.js @@ -1,31 +1,31 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'attr-value-double-quotes'; -const ruleOptions = {}; +const ruldId = 'attr-value-double-quotes' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Attribute value closed by single quotes should result in an error', function() { - const code = ""; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(3); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(3); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(14); - expect(messages[2].rule.id).to.be(ruldId); - expect(messages[2].line).to.be(1); - expect(messages[2].col).to.be(24); - }); +describe(`Rules: ${ruldId}`, function () { + it('Attribute value closed by single quotes should result in an error', function () { + const code = "" + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(3) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(3) + expect(messages[1].rule.id).to.be(ruldId) + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(14) + expect(messages[2].rule.id).to.be(ruldId) + expect(messages[2].line).to.be(1) + expect(messages[2].col).to.be(24) + }) - it('Attribute value no closed should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Attribute value no closed should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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 4d54da5cb..7d60984b5 100644 --- a/test/rules/attr-value-not-empty.spec.js +++ b/test/rules/attr-value-not-empty.spec.js @@ -1,32 +1,32 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'attr-value-not-empty'; -const ruleOptions = {}; +const ruldId = 'attr-value-not-empty' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Attribute value have no value should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); +describe(`Rules: ${ruldId}`, function () { + it('Attribute value have no value should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) - it('Attribute value closed by quote but no value should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); + it('Attribute value closed by quote but no value should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) - it('Attribute value closed by quote and have value should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Attribute value closed by quote and have value should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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 fc2f19b64..1efd5de9d 100644 --- a/test/rules/attr-value-single-quotes.spec.js +++ b/test/rules/attr-value-single-quotes.spec.js @@ -1,31 +1,31 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'attr-value-single-quotes'; -const ruleOptions = {}; +const ruldId = 'attr-value-single-quotes' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe('Rules: ' + ruldId, function() { - it('Attribute value closed by double quotes should result in an error', function() { - var code = ''; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(3); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(3); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(14); - expect(messages[2].rule.id).to.be(ruldId); - expect(messages[2].line).to.be(1); - expect(messages[2].col).to.be(24); - }); +describe('Rules: ' + ruldId, function () { + it('Attribute value closed by double quotes should result in an error', function () { + var code = '' + var messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(3) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(3) + expect(messages[1].rule.id).to.be(ruldId) + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(14) + expect(messages[2].rule.id).to.be(ruldId) + expect(messages[2].line).to.be(1) + expect(messages[2].col).to.be(24) + }) - it('Attribute value no closed should not result in an error', function() { - var code = ""; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Attribute value no closed should not result in an error', function () { + var code = "" + var messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/attr-whitespace.spec.js b/test/rules/attr-whitespace.spec.js index 3f4b5d4ba..d689dc186 100644 --- a/test/rules/attr-whitespace.spec.js +++ b/test/rules/attr-whitespace.spec.js @@ -1,34 +1,34 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'attr-whitespace'; -const ruleOptions = {}; +const ruldId = 'attr-whitespace' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Double spaces in attributes should result in an error', function() { - let code = '

'; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - }); +describe(`Rules: ${ruldId}`, function () { + it('Double spaces in attributes should result in an error', function () { + let code = '

' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(1) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + }) - it('Leading/trailing white space should result in an error', function() { - let code = '

'; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - }); + it('Leading/trailing white space should result in an error', function () { + let code = '

' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(1) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + }) - it('Double spaces and leading/trailing white space should result in an error', function() { - let code = '

'; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - }); -}); + it('Double spaces and leading/trailing white space should result in an error', function () { + let code = '

' + let messages = HTMLHint.verify(code, 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/default.spec.js b/test/rules/default.spec.js index 7280ac258..5577f5d4b 100644 --- a/test/rules/default.spec.js +++ b/test/rules/default.spec.js @@ -1,11 +1,11 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -describe('Rules: default', function() { - it('should result 3 errors', function() { - const code = '

'; - const messages = HTMLHint.verify(code); - expect(messages.length).to.be(3); - }); -}); +describe('Rules: default', function () { + it('should result 3 errors', function () { + const code = '

' + const messages = HTMLHint.verify(code) + expect(messages.length).to.be(3) + }) +}) diff --git a/test/rules/doctype-first.spec.js b/test/rules/doctype-first.spec.js index fcb349f01..3988937fa 100644 --- a/test/rules/doctype-first.spec.js +++ b/test/rules/doctype-first.spec.js @@ -1,25 +1,25 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'doctype-first'; -const ruleOptions = {}; +const ruldId = 'doctype-first' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Doctype not be first should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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(1); - }); +describe(`Rules: ${ruldId}`, function () { + it('Doctype not be first should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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(1) + }) - it('Doctype be first should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Doctype be first should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/doctype-html5.spec.js b/test/rules/doctype-html5.spec.js index ba417f66d..49fdd3115 100644 --- a/test/rules/doctype-html5.spec.js +++ b/test/rules/doctype-html5.spec.js @@ -1,27 +1,27 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'doctype-html5'; -const ruleOptions = {}; +const ruldId = 'doctype-html5' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Doctype not html5 should result in an error', function() { +describe(`Rules: ${ruldId}`, function () { + it('Doctype not html5 should result in an error', function () { const code = - ''; - const messages = HTMLHint.verify(code, 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(1); - expect(messages[0].type).to.be('warning'); - }); + '' + const messages = HTMLHint.verify(code, 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(1) + expect(messages[0].type).to.be('warning') + }) - it('Doctype html5 should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Doctype html5 should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/head-require.spec.js b/test/rules/head-require.spec.js index f509c348f..c5a1d4c27 100644 --- a/test/rules/head-require.spec.js +++ b/test/rules/head-require.spec.js @@ -1,60 +1,59 @@ -const expect = require('expect.js'); - -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; - -const ruldId = 'head-script-disabled'; -const ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe(`Rules: ${ruldId}`, function() { - it('External script in head should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); - - it('Internal Script in head should result in an error', function() { - let code = ''; - let messages = HTMLHint.verify(code, 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); +const expect = require('expect.js') + +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint + +const ruldId = 'head-script-disabled' +const ruleOptions = {} + +ruleOptions[ruldId] = true + +describe(`Rules: ${ruldId}`, function () { + it('External script in head should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) + + it('Internal Script in head should result in an error', function () { + let code = '' + let messages = HTMLHint.verify(code, 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) + expect(messages.length).to.be(1) code = - ''; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - code = - ''; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - }); - - it('Script in body not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Template script in head not result in an error', function() { + '' + messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(1) + }) + + it('Script in body not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Template script in head not result in an error', function () { let code = - ''; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); + '' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) code = - ''; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('No head not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + '' + messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('No head not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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 f509c348f..c5a1d4c27 100644 --- a/test/rules/head-script-disabled.spec.js +++ b/test/rules/head-script-disabled.spec.js @@ -1,60 +1,59 @@ -const expect = require('expect.js'); - -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; - -const ruldId = 'head-script-disabled'; -const ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe(`Rules: ${ruldId}`, function() { - it('External script in head should result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, 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); - expect(messages[0].type).to.be('warning'); - }); - - it('Internal Script in head should result in an error', function() { - let code = ''; - let messages = HTMLHint.verify(code, 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); +const expect = require('expect.js') + +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint + +const ruldId = 'head-script-disabled' +const ruleOptions = {} + +ruleOptions[ruldId] = true + +describe(`Rules: ${ruldId}`, function () { + it('External script in head should result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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) + expect(messages[0].type).to.be('warning') + }) + + it('Internal Script in head should result in an error', function () { + let code = '' + let messages = HTMLHint.verify(code, 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) + expect(messages.length).to.be(1) code = - ''; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - code = - ''; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - }); - - it('Script in body not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Template script in head not result in an error', function() { + '' + messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(1) + }) + + it('Script in body not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('Template script in head not result in an error', function () { let code = - ''; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); + '' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) code = - ''; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('No head not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + '' + messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) + + it('No head not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, 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 e59665f22..cea0c03be 100644 --- a/test/rules/href-abs-or-rel.spec.js +++ b/test/rules/href-abs-or-rel.spec.js @@ -1,52 +1,52 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'href-abs-or-rel'; -const ruleOptions = {}; +const ruldId = 'href-abs-or-rel' +const ruleOptions = {} -describe(`Rules: ${ruldId}`, function() { - it('Href value is not absolute with abs mode should result in an error', function() { +describe(`Rules: ${ruldId}`, function () { + it('Href value is not absolute with abs mode should result in an error', function () { const code = - 'aaabbbcccddd'; - ruleOptions[ruldId] = 'abs'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(3); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(27); - }); + 'aaabbbcccddd' + ruleOptions[ruldId] = 'abs' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(3) + expect(messages[1].rule.id).to.be(ruldId) + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(27) + }) - it('Href value is absolute with abs mode should not result in an error', function() { + it('Href value is absolute with abs mode should not result in an error', function () { const code = - 'aaabbbcccddd'; - ruleOptions[ruldId] = 'abs'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); + 'aaabbbcccddd' + ruleOptions[ruldId] = 'abs' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) - it('Href value is not relative with rel mode should result in an error', function() { + it('Href value is not relative with rel mode should result in an error', function () { const code = - 'aaabbbcccddd'; - ruleOptions[ruldId] = 'rel'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(3); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(44); - }); + 'aaabbbcccddd' + ruleOptions[ruldId] = 'rel' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(3) + expect(messages[1].rule.id).to.be(ruldId) + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(44) + }) - it('Href value is relative with rel mode should not result in an error', function() { + it('Href value is relative with rel mode should not result in an error', function () { const code = - 'aaabbbcccddd'; - ruleOptions[ruldId] = 'rel'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + 'aaabbbcccddd' + ruleOptions[ruldId] = 'rel' + const messages = HTMLHint.verify(code, 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 c92957498..7c72c1bb1 100644 --- a/test/rules/id-class-ad-disabled.spec.js +++ b/test/rules/id-class-ad-disabled.spec.js @@ -1,127 +1,127 @@ -const expect = require('expect.js'); - -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; - -const ruldId = 'id-class-ad-disabled'; -const ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe(`Rules: ${ruldId}`, function() { - it('Id use ad keyword should result in an error', function() { - let code = '

'; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - expect(messages[0].type).to.be('warning'); - 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); - 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); - 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); - 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); - 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); - 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); - 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); - }); - - it('Class use ad keyword should result in an error', function() { - let code = '
test
'; - let messages = HTMLHint.verify(code, 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); - 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); - 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); - 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); - 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); - 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); - 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); - }); - - it('Id and class no ad keyword used should not result in an error', function() { - let code = '
test
'; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - - code = '
test
'; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - - code = '
test
'; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); +const expect = require('expect.js') + +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint + +const ruldId = 'id-class-ad-disabled' +const ruleOptions = {} + +ruleOptions[ruldId] = true + +describe(`Rules: ${ruldId}`, function () { + it('Id use ad keyword should result in an error', function () { + let code = '' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(1) + expect(messages[0].type).to.be('warning') + 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) + 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) + 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) + 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) + 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) + 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) + 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) + }) + + it('Class use ad keyword should result in an error', function () { + let code = '
test
' + let messages = HTMLHint.verify(code, 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) + 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) + 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) + 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) + 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) + 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) + 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) + }) + + it('Id and class no ad keyword used should not result in an error', function () { + let code = '
test
' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + + code = '
test
' + messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + + code = '
test
' + messages = HTMLHint.verify(code, 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 369eb6962..1b6c04542 100644 --- a/test/rules/id-class-value.spec.js +++ b/test/rules/id-class-value.spec.js @@ -1,93 +1,93 @@ -var expect = require('expect.js'); +var expect = require('expect.js') -var HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +var HTMLHint = require('../../dist/htmlhint.js').HTMLHint var ruldId = 'id-class-value', ruleOptionsUnderline = {}, ruleOptionsDash = {}, ruleOptionsHump = {}, - ruleOptionsReg = {}; + ruleOptionsReg = {} -ruleOptionsUnderline[ruldId] = 'underline'; -ruleOptionsDash[ruldId] = 'dash'; -ruleOptionsHump[ruldId] = 'hump'; +ruleOptionsUnderline[ruldId] = 'underline' +ruleOptionsDash[ruldId] = 'dash' +ruleOptionsHump[ruldId] = 'hump' ruleOptionsReg[ruldId] = { regId: /^_[a-z\d]+(-[a-z\d]+)*$/, - message: 'Id and class value must meet regexp' -}; + message: 'Id and class value must meet regexp', +} -describe('Rules: ' + ruldId, function() { - it('Id and class value be not lower case and split by underline should result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsUnderline); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be('id-class-value'); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(5); - expect(messages[0].type).to.be('warning'); - expect(messages[1].rule.id).to.be('id-class-value'); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(17); - expect(messages[1].type).to.be('warning'); - }); +describe('Rules: ' + ruldId, function () { + it('Id and class value be not lower case and split by underline should result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptionsUnderline) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be('id-class-value') + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(5) + expect(messages[0].type).to.be('warning') + expect(messages[1].rule.id).to.be('id-class-value') + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(17) + expect(messages[1].type).to.be('warning') + }) - it('Id and class value be lower case and split by underline should not result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsUnderline); - expect(messages.length).to.be(0); - }); + it('Id and class value be lower case and split by underline should not result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, 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', function() { - var code = '
'; - var messages = HTMLHint.verify(code, { 'id-class-value': 'dash' }); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be('id-class-value'); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(5); - expect(messages[1].rule.id).to.be('id-class-value'); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(17); - }); + it('Id and class value be not lower case and split by dash should result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, { 'id-class-value': 'dash' }) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be('id-class-value') + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(5) + expect(messages[1].rule.id).to.be('id-class-value') + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(17) + }) - it('Id and class value be lower case and split by dash should not result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsDash); - expect(messages.length).to.be(0); - }); + it('Id and class value be lower case and split by dash should not result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptionsDash) + expect(messages.length).to.be(0) + }) - it('Id and class value be not meet hump style should result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsHump); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be('id-class-value'); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(5); - expect(messages[1].rule.id).to.be('id-class-value'); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(17); - }); + it('Id and class value be not meet hump style should result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptionsHump) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be('id-class-value') + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(5) + expect(messages[1].rule.id).to.be('id-class-value') + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(17) + }) - it('Id and class value be meet hump style should not result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsHump); - expect(messages.length).to.be(0); - }); + it('Id and class value be meet hump style should not result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptionsHump) + expect(messages.length).to.be(0) + }) - it('Id and class value be not meet regexp should result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsReg); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be('id-class-value'); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(5); - expect(messages[1].rule.id).to.be('id-class-value'); - expect(messages[1].line).to.be(1); - expect(messages[1].col).to.be(16); - }); + it('Id and class value be not meet regexp should result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptionsReg) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be('id-class-value') + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(5) + expect(messages[1].rule.id).to.be('id-class-value') + expect(messages[1].line).to.be(1) + expect(messages[1].col).to.be(16) + }) - it('Id and class value be meet regexp should not result in an error', function() { - var code = '
'; - var messages = HTMLHint.verify(code, ruleOptionsReg); - expect(messages.length).to.be(0); - }); -}); + it('Id and class value be meet regexp should not result in an error', function () { + var code = '
' + var messages = HTMLHint.verify(code, ruleOptionsReg) + expect(messages.length).to.be(0) + }) +}) diff --git a/test/rules/id-unique.spec.js b/test/rules/id-unique.spec.js index 7350d0de6..700f8ba1a 100644 --- a/test/rules/id-unique.spec.js +++ b/test/rules/id-unique.spec.js @@ -1,26 +1,26 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'id-unique'; -const ruleOptions = {}; +const ruldId = 'id-unique' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Id redefine should result in an error', function() { - const code = '
'; - const messages = HTMLHint.verify(code, 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(26); - expect(messages[0].type).to.be('error'); - }); +describe(`Rules: ${ruldId}`, function () { + it('Id redefine should result in an error', function () { + const code = '
' + const messages = HTMLHint.verify(code, 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(26) + expect(messages[0].type).to.be('error') + }) - it('Id no redefine should not result in an error', function() { - const code = '
'; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); + it('Id no redefine should not result in an error', function () { + const code = '
' + const messages = HTMLHint.verify(code, 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 cd7d57f82..d7771ade5 100644 --- a/test/rules/inline-script-disabled.spec.js +++ b/test/rules/inline-script-disabled.spec.js @@ -1,50 +1,50 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'inline-script-disabled'; -const ruleOptions = {}; +const ruldId = 'inline-script-disabled' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Inline on event should result in an error', function() { +describe(`Rules: ${ruldId}`, function () { + it('Inline on event should result in an error', function () { const code = - ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(26); - expect(messages[0].type).to.be('warning'); - expect(messages[1].col).to.be(66); - }); + '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(26) + expect(messages[0].type).to.be('warning') + expect(messages[1].col).to.be(66) + }) - it('onttt should not result in an error', function() { - const code = ''; - const messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); + it('onttt should not result in an error', function () { + const code = '' + const messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(0) + }) - it('Javascript protocol [ javascript: ] should result in an error', function() { + it('Javascript protocol [ javascript: ] should result in an error', function () { let code = - ''; - let messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(11); - expect(messages[0].type).to.be('warning'); - expect(messages[1].col).to.be(42); + '' + let messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(11) + expect(messages[0].type).to.be('warning') + expect(messages[1].col).to.be(42) code = - 'test1test2'; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(2); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(1); - expect(messages[0].col).to.be(9); - expect(messages[0].type).to.be('warning'); - expect(messages[1].col).to.be(48); - }); -}); + 'test1test2' + messages = HTMLHint.verify(code, ruleOptions) + expect(messages.length).to.be(2) + expect(messages[0].rule.id).to.be(ruldId) + expect(messages[0].line).to.be(1) + expect(messages[0].col).to.be(9) + expect(messages[0].type).to.be('warning') + expect(messages[1].col).to.be(48) + }) +}) diff --git a/test/rules/inline-style-disabled.spec.js b/test/rules/inline-style-disabled.spec.js index a9883292f..1369ae215 100644 --- a/test/rules/inline-style-disabled.spec.js +++ b/test/rules/inline-style-disabled.spec.js @@ -1,24 +1,24 @@ -const expect = require('expect.js'); +const expect = require('expect.js') -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint -const ruldId = 'inline-style-disabled'; -const ruleOptions = {}; +const ruldId = 'inline-style-disabled' +const ruleOptions = {} -ruleOptions[ruldId] = true; +ruleOptions[ruldId] = true -describe(`Rules: ${ruldId}`, function() { - it('Inline style should result in an error', function() { - let code = '
'; - let messages = HTMLHint.verify(code, 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(11); - expect(messages[0].type).to.be('warning'); +describe(`Rules: ${ruldId}`, function () { + it('Inline style should result in an error', function () { + let code = '
' + let messages = HTMLHint.verify(code, 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(11) + expect(messages[0].type).to.be('warning') - code = '
'; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(1); - }); -}); + code = '
' + messages = HTMLHint.verify(code, 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 700786683..7b2c0ad47 100644 --- a/test/rules/input-requires-label.spec.js +++ b/test/rules/input-requires-label.spec.js @@ -1,71 +1,67 @@ -const expect = require("expect.js"); - -const HTMLHint = require('../../dist/htmlhint.js').HTMLHint; - -const ruleId = 'input-requires-label'; -const ruleOptions = {}; - -ruleOptions[ruleId] = true; - -describe(`Rules: ${ruleId}`, function(){ - - describe('Successful cases', function() { - - it('Input tag with a matching label before should result in no error', function () { - var code = '