diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..63b6465b7 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + extends: ['eslint:recommended', 'plugin:prettier/recommended'], + env: { + browser: true, + amd: true, + node: true, + mocha: true, + }, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + }, + rules: { + 'one-var': ['error', 'never'], + }, +} 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/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..3ba13e0ce --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6d037fe3b..ab151c898 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,17 +1,5 @@ -**Fixes**: # +***Short description of what this resolves:*** -🚨 Please review the [guidelines for contributing](CONTRIBUTING.md) and our [code of conduct](../CODE_OF_CONDUCT.md) to this repository. 🚨 -**Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your PR:** -- [ ] Check the commit's or even all commits' message styles matches our requested structure. -- [ ] Check your code additions will fail neither code linting checks nor unit test. +***Proposed changes:*** -#### Short description of what this resolves: - -#### Proposed changes: - -## - - -- - -👍 Thank you! diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 000000000..fd160e519 --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1 @@ +titleOnly: true diff --git a/.github/stale.yml b/.github/stale.yml index b0b57c9c7..d8eed242b 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,9 +1,9 @@ daysUntilStale: 60 daysUntilClose: 14 exemptLabels: - - pinned + - keep-unstale - security -staleLabel: resolution:wontfix +staleLabel: bot:stale markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you 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/.github/workflows/test-release.yml b/.github/workflows/test-release.yml new file mode 100644 index 000000000..133d0f0f0 --- /dev/null +++ b/.github/workflows/test-release.yml @@ -0,0 +1,34 @@ +name: Test Release + +on: + pull_request: + branches: + - master + +jobs: + release: + runs-on: ubuntu-latest + strategy: + matrix: + node: [12.x] + os: [ubuntu-latest] + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Use Node.js ${{ matrix.node }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build --if-present + + - name: Semantic Release + run: npx semantic-release --dry-run + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 2fbbfc511..2ff81bbe7 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,7 @@ yarn.lock test/unit/coverage test/e2e/reports + +/website/node_modules +/website/build +/website/.docusaurus diff --git a/.prettierignore b/.prettierignore index a2d374c2c..6dcd6b60e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,8 +7,18 @@ /coverage # production -/lib +/dist # npm package-lock.json npm-debug.log* +.nyc_output +test/html + +# Ignore formatting of ***x*** to **_x_** +.github/PULL_REQUEST_TEMPLATE.md + +/website/playground +/website/.docusaurus +/website/plugins +/website/static 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..c564fee30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ -HTMLHint change log -==================== +# [0.13.0](https://github.com/htmlhint/HTMLHint/compare/v0.12.2...v0.13.0) (2020-05-18) + + +### Bug Fixes + +* add prettier and eslint ([#388](https://github.com/htmlhint/HTMLHint/issues/388)) ([aba3249](https://github.com/htmlhint/HTMLHint/commit/aba3249652181055f5897e0b4367b243f83ede3f)) +* add semantic release test ([#399](https://github.com/htmlhint/HTMLHint/issues/399)) ([616f9cd](https://github.com/htmlhint/HTMLHint/commit/616f9cd74a9463e6596198f867f35aab24094110)) +* ignore PULL_REQUEST_TEMPLATE.md ([30b0af2](https://github.com/htmlhint/HTMLHint/commit/30b0af2f86a4daa7ef3bd07e91e8220b7d4b75f3)) +* use yml in semantic.yml ([86f6700](https://github.com/htmlhint/HTMLHint/commit/86f67007a32f5e978921507c05a2620edc1f9afc)) + + +### Features + +* Add tags checking rule - allows specify rules for any tag and validate that ([#384](https://github.com/htmlhint/HTMLHint/issues/384)) ([475aaca](https://github.com/htmlhint/HTMLHint/commit/475aaca431fab90a0ead7b21af7a73d4f0324514)) +* added attr-no-unnecessary-whitespace rule ([#385](https://github.com/htmlhint/HTMLHint/issues/385)) ([03bfd4f](https://github.com/htmlhint/HTMLHint/commit/03bfd4f7f6b60543a4253cad74758c794fc8cd18)) +* new rule: input-requires-label - All inputs require a label ([#159](https://github.com/htmlhint/HTMLHint/issues/159)) ([5bd40fb](https://github.com/htmlhint/HTMLHint/commit/5bd40fbc06b0d178cff4b9665ca992232dcb1f43)) +* new website for htmlhint.com ([#395](https://github.com/htmlhint/HTMLHint/issues/395)) ([5d0d95f](https://github.com/htmlhint/HTMLHint/commit/5d0d95f39dddddf94a22d3c6294e4e50472fa0a0)) + +# HTMLHint change log ## ver 0.9.14 (2016-5-2) @@ -57,7 +74,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 +146,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..2549d96ff 100644 --- a/bin/formatter.js +++ b/bin/formatter.js @@ -1,57 +1,66 @@ -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..a590ec8c9 100644 --- a/bin/formatters/checkstyle.js +++ b/bin/formatters/checkstyle.js @@ -1,48 +1,56 @@ -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..b96a84a18 100644 --- a/bin/formatters/compact.js +++ b/bin/formatters/compact.js @@ -1,24 +1,28 @@ -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..983f6ca58 100644 --- a/bin/formatters/default.js +++ b/bin/formatters/default.js @@ -1,39 +1,52 @@ -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; +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 diff --git a/bin/formatters/html.js b/bin/formatters/html.js index 8b2b9394e..e638820c3 100644 --- a/bin/formatters/html.js +++ b/bin/formatters/html.js @@ -1,26 +1,41 @@ -var fs = require('fs'); +var fs = require('fs') -var htmlFormatter = function(formatter){ - formatter.on('end', function(event){ - var fileContent; - fileContent = ''; - fileContent = fileContent + 'Codestin Search App'; - fileContent = fileContent + ''; - fileContent = fileContent + '

Violation Report

'; +var htmlFormatter = function (formatter) { + formatter.on('end', function (event) { + var fileContent + fileContent = '' + fileContent = + fileContent + 'Codestin Search App' + 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 + + '' -module.exports = htmlFormatter; + 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 diff --git a/bin/formatters/json.js b/bin/formatters/json.js index 96c968988..e1cb77d7b 100644 --- a/bin/formatters/json.js +++ b/bin/formatters/json.js @@ -1,6 +1,7 @@ -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..70541dfc8 100644 --- a/bin/formatters/junit.js +++ b/bin/formatters/junit.js @@ -1,51 +1,58 @@ -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..09c0ceed4 100644 --- a/bin/formatters/markdown.js +++ b/bin/formatters/markdown.js @@ -1,36 +1,44 @@ -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..6b1bb8932 100644 --- a/bin/formatters/unix.js +++ b/bin/formatters/unix.js @@ -1,22 +1,32 @@ -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..f47ab7d8e 100755 --- a/bin/htmlhint +++ b/bin/htmlhint @@ -1,393 +1,435 @@ #!/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 hintTargets(arrTargets, options){ - var arrAllMessages = []; - var allFileCount = 0; - var allHintFileCount = 0; - var allHintCount = 0; - var startTime = new Date().getTime(); +function listRules() { + var rules = HTMLHint.rules + var rule - var formatter = options.formatter; + console.log(' All rules:') + console.log(' ==================================================') - // load custom rules - var rulesdir = options.rulesdir; - if(rulesdir){ - loadCustomRules(rulesdir); - } + for (var id in rules) { + rule = rules[id] + console.log(' %s : %s', rule.id.bold, rule.description) + } +} - // 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; - } - // detect directory - else if(fs.existsSync(target) && fs.statSync(target).isDirectory()){ - base += globPath.basename + '/'; - pattern = '**/' + defaultGlob; - } + } else { + // no basename + if (globPath.basename === '') { + pattern += '**/' + defaultGlob } - return { - base: base, - pattern: pattern - }; + // detect directory + else if (fs.existsSync(target) && fs.statSync(target).isDirectory()) { + base += globPath.basename + '/' + pattern = '**/' + defaultGlob + } + } + + 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/docs/toc.md b/docs/toc.md new file mode 100644 index 000000000..22ee5821e --- /dev/null +++ b/docs/toc.md @@ -0,0 +1,15 @@ +# Docs + +- User guide + - [Getting started](user-guide/getting-started.md) + - [Configuration](user-guide/configuration.md) + - Rules + - [About](user-guide/rules/about.md) + - [List](user-guide/list-rules.md) + - Usage + - [CLI](user-guide/usage/cli.md) + - [Options](user-guide/usage/options.md) + - Integrations + - [Editor](user-guide/integrations/editor.md) + - [Task runner](user-guide/integrations/task-runner.md) + - [Other](user-guide/integrations/other.md) diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md new file mode 100644 index 000000000..bc103f107 --- /dev/null +++ b/docs/user-guide/configuration.md @@ -0,0 +1,33 @@ +--- +id: configuration +title: Configuration +--- + +Search `.htmlhintrc` file in current directory and all parent directories: + +```sh +$ htmlhint +$ htmlhint test.html +``` + +Custom config file: + +```sh +$ htmlhint --config htmlhint.conf test.html +``` + +Custom rules: + +```sh +$ htmlhint --rules tag-pair,id-class-value=underline index.html +``` + +Inline rules in `test.html`: + + +```html + + + +... +``` diff --git a/docs/user-guide/getting-started.mdx b/docs/user-guide/getting-started.mdx new file mode 100644 index 000000000..dee1d3f6f --- /dev/null +++ b/docs/user-guide/getting-started.mdx @@ -0,0 +1,49 @@ +--- +id: getting-started +title: Getting Started +--- + +import Tabs from '@theme/Tabs' +import TabItem from '@theme/TabItem' + +1\. Use npm to install HTMLHint: + + + + + +```shell +npm install --save-dev htmlhint +``` + + + + + +```shell +yarn add --dev htmlhint +``` + + + + + +2\. Create a `.htmlhintrc` configuration file in the root of your project: + +```shell +{ + "attr-value-not-empty": false +} +``` + +3\. Run HTMLHint on, for example, all the CSS files in your project: + +```shell +npx htmlhint "**/*.html" +``` diff --git a/docs/user-guide/integrations/editor.md b/docs/user-guide/integrations/editor.md new file mode 100644 index 000000000..5ae66f5d3 --- /dev/null +++ b/docs/user-guide/integrations/editor.md @@ -0,0 +1,11 @@ +--- +id: editor +title: Editor integrations +--- + +Editor integrations built and maintained by the HTMLHint organization and some by the community. + +- [atom-htmlhint](https://github.com/htmlhint/atom-htmlhint) - Atom plugin for HTMLHint. +- [brackets-htmlhint](https://github.com/htmlhint/brackets-htmlhint) - Brackets wrapper for HTMLHint. +- [SublimeLinter-contrib-htmlhint](https://github.com/htmlhint/SublimeLinter-contrib-htmlhint) - Sublime Text plugin for HTMLHint. +- [vscode-htmlhint](https://marketplace.visualstudio.com/items?itemName=mkaufman.HTMLHint) - VS Code extension for HTMLHint. diff --git a/docs/user-guide/integrations/other.md b/docs/user-guide/integrations/other.md new file mode 100644 index 000000000..83d8ad0a1 --- /dev/null +++ b/docs/user-guide/integrations/other.md @@ -0,0 +1,8 @@ +--- +id: other +title: Other integrations +--- + +Other integrations built and maintained by the HTMLHint organization and some by the community. + +- [chai-htmlhint](https://github.com/htmlhint/chai-htmlhint) - Extends Chai with assertions for HTMLHint. diff --git a/docs/user-guide/integrations/task-runner.md b/docs/user-guide/integrations/task-runner.md new file mode 100644 index 000000000..d3145bb50 --- /dev/null +++ b/docs/user-guide/integrations/task-runner.md @@ -0,0 +1,11 @@ +--- +id: task-runner +title: Task runners +--- + +Task runner integrations built and maintained by HTMLHint organization and the community. + +- [grunt-htmlhint-inline](https://github.com/htmlhint/grunt-htmlhint-inline) - Grunt plugin for linting inline html. +- [grunt-htmlhint](https://github.com/htmlhint/grunt-htmlhint) - Grunt plugin for HTMLHint. +- [gulp-htmlhint-inline](https://github.com/htmlhint/gulp-htmlhint-inline) - Gulp plugin for linting inline html. +- [htmlhint-loader](https://github.com/htmlhint/htmlhint-loader) - webpack loader for HTMLHint. diff --git a/docs/user-guide/list-rules.md b/docs/user-guide/list-rules.md new file mode 100644 index 000000000..873dcda2a --- /dev/null +++ b/docs/user-guide/list-rules.md @@ -0,0 +1,50 @@ +--- +id: list-rules +title: List of rules +--- + +## Possible errors + +### Doctype and Head + +- [`doctype-first`](/docs/user-guide/rules/doctype-first): Doctype must be declared first. +- [`doctype-html5`](/docs/user-guide/rules/doctype-html5): Invalid doctype. +- [`head-script-disabled`](/docs/user-guide/rules/head-script-disabled): 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 new file mode 100644 index 000000000..5952c4806 --- /dev/null +++ b/test/rules/attr-no-unnecessary-whitespace.js @@ -0,0 +1,31 @@ +var expect = require('expect.js') + +var HTMLHint = require('../../dist/htmlhint.js').HTMLHint + +var ruldId = 'attr-no-unnecessary-whitespace' +var ruleOptions = {} + +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 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..1f6614ac4 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 = {}; +var ruldId = 'id-class-value' +var ruleOptionsUnderline = {} +var ruleOptionsDash = {} +var ruleOptionsHump = {} +var 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 new file mode 100644 index 000000000..7b2c0ad47 --- /dev/null +++ b/test/rules/input-requires-label.spec.js @@ -0,0 +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 = '