From c9d60e58397abb8254af88a91e35e8dd3fb07105 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 26 Aug 2018 12:45:00 -0400 Subject: [PATCH 01/13] Add discord badge (#266) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fe002c419..ae94bbae8 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ [![NPM version](https://img.shields.io/npm/v/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) [![NPM count](https://img.shields.io/npm/dm/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) [![License](https://img.shields.io/npm/l/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) +[![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?style=flat)](https://discord.gg/nJ6J9CP) + + HTMLHint is a Static Code Analysis Tool for HTML, you can use it with IDE or in build system. From 0a8f6645d8ea51a14c9f3350f1b525615f9b01ef Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 26 Aug 2018 13:35:06 -0400 Subject: [PATCH 02/13] docs: reorganise content inside README (#267) --- README.md | 122 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index ae94bbae8..8d05a7569 100644 --- a/README.md +++ b/README.md @@ -7,78 +7,90 @@ [![License](https://img.shields.io/npm/l/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) [![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?style=flat)](https://discord.gg/nJ6J9CP) - - HTMLHint is a Static Code Analysis Tool for HTML, you can use it with IDE or in build system. -## Getting started - -1. Installation & hints - - npm install htmlhint -g - htmlhint -V - htmlhint --help - htmlhint www - htmlhint www/test.html - htmlhint www/**/*.xhtml - htmlhint www/**/*.{htm,html} - htmlhint http://www.alibaba.com/ - cat test.html | htmlhint stdin - -2. Results - - test.html - L5 | - ^ must be present in <head> tag. (title-require) - L8 | </body> - ^ Tag must be paired, missing: [ </div> ], start tag match failed [ <div> ] on line 7. (tag-pair) - - 2 errors in 1 files - -3. Config rules - - search `.htmlhintrc` file in current directory and all parent directories: - - htmlhint - htmlhint test.html - - custom config file: - - htmlhint --config htmlhint.conf test.html - - custom rules: - - htmlhint --rules tag-pair,id-class-value=underline test.html - - Inline rules in `test.html`: - - <!--htmlhint tag-pair,id-class-value:underline --> - <html> - <head> - ... - -## Guide +## 📟 Installation and Usage + +Prerequisites: Node.js (>=6.14), npm version 3+. + +There are two ways to install HTMLHint: globally and locally. + +### Local Installation and Usage + +In case you want to include HTMLHint as part of your project, you can install it locally using NPM: + +``` +$ npm install htmlhint --save-dev +``` +After that, You can run HTMLHint on any file or directory like this: +``` +$ ./node_modules/.bin/htmlhint www/index.html +$ ./node_modules/.bin/htmlhint www/**/*.html +``` +### Global Installation and Usage + +If you want to make HTMLHint available to tools that run across all of your projects, you can instal HTMLHint globally using NPM: + +``` +$ npm install htmlhint -g +``` +After that, you can run HTMLHint on any file like this: +``` +$ htmlhint www/index.html +$ htmlhint www/**/*.html +``` +You can even launch HTMLHint to analyse an URL: +``` +$ htmlhint https://htmlhint.io/ +``` +## 📃 Example output + + +## 🔧 Configuration + +Search `.htmlhintrc` file in current directory and all parent directories: +``` +$ htmlhint +$ htmlhint test.html +``` +Custom config file: +``` +$ htmlhint --config htmlhint.conf test.html +``` +Custom rules: +``` +$ htmlhint --rules tag-pair,id-class-value=underline index.html +``` + +Inline rules in `test.html`: +``` +<!--htmlhint tag-pair,id-class-value:underline --> +<html> +<head> +... +``` +## 🗺 Guide 1. [How to use](https://github.com/thedaviddias/HTMLHint/wiki/Usage) 2. [All Rules](https://github.com/thedaviddias/HTMLHint/wiki/Rules) -2. [How to Develop](https://github.com/thedaviddias/HTMLHint/wiki/Developer-guide) +3. [How to Develop](https://github.com/thedaviddias/HTMLHint/wiki/Developer-guide) -## License +## © License -[The MIT License](https://raw.githubusercontent.com/thedaviddias/HTMLHint/master/LICENSE). +[MIT License](./LICENSE). -## Contributors +## 💪🏻 Contributors This project exists thanks to all these people. [Contribute](CONTRIBUTING.md). <a href="https://github.com/thedaviddias/HTMLHint/graphs/contributors"><img src="https://opencollective.com/htmlhint/contributors.svg?width=890" /></a> -## Backers +## 🏅 Backers Thank you to all our backers! [Become a backer](https://opencollective.com/stylelint#backer). <a href="https://opencollective.com/htmlhint#backers" target="_blank"><img src="https://opencollective.com/htmlhint/backers.svg?width=890"></a> -## Sponsors +## 🎖 Sponsors Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](https://opencollective.com/htmlhint#sponsor). From aa2bd9e26a25ff98d8f888b0cac6a05ab085e604 Mon Sep 17 00:00:00 2001 From: Shinigami <chrissi92@hotmail.de> Date: Sun, 26 Aug 2018 19:39:07 +0200 Subject: [PATCH 03/13] style: translated chinese comments (#265) * Translated chinese comments --- Gruntfile.js | 14 +++++++------- src/core.js | 2 +- src/htmlparser.js | 18 +++++++++--------- src/rules/tag-pair.js | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 70805e333..906ed2a13 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -92,13 +92,13 @@ module.exports = function(grunt) { date = new Date(); } var map = { - "M": date.getMonth() + 1, //月份 - "d": date.getDate(), //日 - "h": date.getHours(), //小时 - "m": date.getMinutes(), //分 - "s": date.getSeconds(), //秒 - "q": Math.floor((date.getMonth() + 3) / 3), //季度 - "S": date.getMilliseconds() //毫秒 + "M": date.getMonth() + 1, // Monat + "d": date.getDate(), // Tag + "h": date.getHours(), // Hour + "m": date.getMinutes(), // Minute + "s": date.getSeconds(), // Second + "q": Math.floor((date.getMonth() + 3) / 3), // Quarter + "S": date.getMilliseconds() // Millisecond }; format = format.replace(/([yMdhmsqS])(\1)*/g, function(all, t){ var v = map[t]; diff --git a/src/core.js b/src/core.js index f9da415b8..3a3da57fe 100644 --- a/src/core.js +++ b/src/core.js @@ -12,7 +12,7 @@ var HTMLHint = (function (undefined) { HTMLHint.rules = {}; - //默认配置 + // standard configuration HTMLHint.defaultRuleset = { 'tagname-lowercase': true, 'attr-lowercase': true, diff --git a/src/htmlparser.js b/src/htmlparser.js index 0b2302a7a..9b6da399f 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -49,19 +49,19 @@ var HTMLParser = (function(undefined){ while((match = regTag.exec(html))){ matchIndex = match.index; - if(matchIndex > lastIndex){//保存前面的文本或者CDATA + if(matchIndex > lastIndex){// Save the previous text or CDATA text = html.substring(lastIndex, matchIndex); if(tagCDATA){ arrCDATA.push(text); } - else{//文本 + else{// text saveBlock('text', text, lastIndex); } } lastIndex = regTag.lastIndex; if((tagName = match[1])){ - if(tagCDATA && tagName === tagCDATA){//结束标签前输出CDATA + if(tagCDATA && tagName === tagCDATA){// Output CDATA before closing the label text = arrCDATA.join(''); saveBlock('cdata', text, lastCDATAIndex, { 'tagName': tagCDATA, @@ -72,7 +72,7 @@ var HTMLParser = (function(undefined){ arrCDATA = null; } if(!tagCDATA){ - //标签结束 + // End of label saveBlock('tagend', match[0], matchIndex, { 'tagName': tagName }); @@ -84,7 +84,7 @@ var HTMLParser = (function(undefined){ arrCDATA.push(match[0]); } else{ - if((tagName = match[4])){//标签开始 + if((tagName = match[4])){// Label start arrAttrs = []; var attrs = match[5], attrMatch, @@ -112,11 +112,11 @@ var HTMLParser = (function(undefined){ lastCDATAIndex = lastIndex; } } - else{//如果出现漏匹配,则把当前内容匹配为text + else{// If a miss match occurs, the current content is matched to text saveBlock('text', match[0], matchIndex); } } - else if(match[2] || match[3]){//注释标签 + else if(match[2] || match[3]){// Comment tag saveBlock('comment', match[0], matchIndex, { 'content': match[2] || match[3], 'long': match[2]?true:false @@ -126,7 +126,7 @@ var HTMLParser = (function(undefined){ } if(html.length > lastIndex){ - //结尾文本 + // End text text = html.substring(lastIndex, html.length); saveBlock('text', text, lastIndex); } @@ -137,7 +137,7 @@ var HTMLParser = (function(undefined){ col: html.length - lastLineIndex + 1 }); - //存储区块 + // Memory block function saveBlock(type, raw, pos, data){ var col = pos - lastLineIndex + 1; if(data === undefined){ diff --git a/src/rules/tag-pair.js b/src/rules/tag-pair.js index 060e941b9..bb51e2108 100644 --- a/src/rules/tag-pair.js +++ b/src/rules/tag-pair.js @@ -21,7 +21,7 @@ HTMLHint.addRule({ }); parser.addListener('tagend', function(event){ var tagName = event.tagName.toLowerCase(); - //向上寻找匹配的开始标签 + // Look up the matching start tag for(var pos = stack.length-1;pos >= 0; pos--){ if(stack[pos].tagName === tagName){ break; From d30c24e18baf30ebbad003138516f1c1890f5be2 Mon Sep 17 00:00:00 2001 From: Shinigami <chrissi92@hotmail.de> Date: Sun, 26 Aug 2018 19:40:47 +0200 Subject: [PATCH 04/13] style: translated chinese comments (#261) (#264) From edbd0953b157028408997cd92ce8f6eb17d6f8ba Mon Sep 17 00:00:00 2001 From: Snyk bot <github+bot@snyk.io> Date: Sun, 26 Aug 2018 21:10:06 +0300 Subject: [PATCH 05/13] [Snyk] Fix for 6 vulnerable dependencies (#260) * fix: package.json to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/npm:cryptiles:20180710 - https://snyk.io/vuln/npm:hoek:20180212 - https://snyk.io/vuln/npm:lodash:20180130 - https://snyk.io/vuln/npm:tough-cookie:20160722 - https://snyk.io/vuln/npm:tough-cookie:20170905 - https://snyk.io/vuln/npm:tunnel-agent:20170305 * style: translated chinese comments (#261) --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3b2d2dba7..c8b6f1579 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ "commander": "2.9.0", "csslint": "0.10.0", "glob": "7.0.3", - "jshint": "2.9.4", + "jshint": "2.9.6", "parse-glob": "3.0.4", "path-parse": "1.0.5", - "request": "2.72.0", + "request": "2.84.0", "strip-json-comments": "2.0.1", "xml": "1.0.1" }, From 8fd7e097fb5bf0b3e923cad4f7abf6b2da9e2261 Mon Sep 17 00:00:00 2001 From: David Dias <thedaviddias@gmail.com> Date: Sun, 26 Aug 2018 14:56:45 -0400 Subject: [PATCH 06/13] fix: remove base resolve (#269) --- bin/htmlhint | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/htmlhint b/bin/htmlhint index 89e6e656b..f6255777c 100755 --- a/bin/htmlhint +++ b/bin/htmlhint @@ -268,7 +268,6 @@ function getGlobInfo(target){ var globInfo = parseGlob(target); var base = path.resolve(globInfo.base); base += /\/$/.test(base) ? '' : '/'; - base = path.resolve(base); var pattern = globInfo.glob; var globPath = globInfo.path; var defaultGlob = '*.{htm,html}'; From 23eb869fb71f00098cf5512281d633b7c54b4c6e Mon Sep 17 00:00:00 2001 From: David Dias <thedaviddias@gmail.com> Date: Sun, 26 Aug 2018 15:00:22 -0400 Subject: [PATCH 07/13] Add develop as branches for travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92a4f5560..f20eeb07d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,11 +19,10 @@ script: - "grunt" - istanbul cover ./node_modules/mocha/bin/_mocha --reporter test -- -R spec - codecov -after_success: - - npm run travis-deploy-once "npm run semantic-release" branches: only: - master + - develop - /^greenkeeper/.*$/ except: - /^v\d+\.\d+\.\d+$/ From e0338c5088d39859c75e5d1dd05ba690bf98b0bd Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <greenkeeper[bot]@users.noreply.github.com> Date: Sun, 26 Aug 2018 15:16:51 -0400 Subject: [PATCH 08/13] =?UTF-8?q?Update=20dependencies=20to=20enable=20Gre?= =?UTF-8?q?enkeeper=20=F0=9F=8C=B4=20(#251)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let’s get started with automated dependency management for HTMLHint :muscle: This pull request **updates all your dependencies to their latest version**. Having them all up to date really is the best starting point for keeping up with new releases. Greenkeeper will look out for further dependency updates and make sure to handle them in isolation and in real-time, but only after **you merge this pull request**. **Important: Greenkeeper will only start watching this repository’s dependency updates after you merge this initial pull request**. --- <details> <summary>💥 Tests on this branch are failing. Here’s how to proceed.</summary> To solve the issue, first find out which of the dependency’s updates is causing the problem. Then fix your code to accomodate the changes in the updated dependency. [next-update](https://www.npmjs.com/package/next-update) is a really handy tool to help you with this. Then push your changes to this branch and merge it. </details> <details> <summary>🏷 How to check the status of this repository</summary> Greenkeeper adds a badge to your README which indicates the status of this repository. This is what your badge looks like right now :point_right: ![Greenkeeper badge](https://badges.greenkeeper.io/thedaviddias/HTMLHint.svg) </details> <details> <summary>🙈 How to ignore certain dependencies</summary> You may have good reasons for not wanting to update to a certain dependency right now. In this case, you can [change the dependency’s version string in the `package.json` file back to whatever you prefer](https://github.com/thedaviddias/HTMLHint/edit/greenkeeper/initial/package.json). To make sure Greenkeeper doesn’t nag you again on the next update, add a `greenkeeper.ignore` field to your `package.json`, containing a list of dependencies you don’t want to update. ```js // package.json { … "greenkeeper": { "ignore": [ "package-names", "you-want-me-to-ignore" ] } } ``` </details> <details> <summary>👩‍💻 How to update this pull request</summary> ```bash # Change into your repository’s directory git fetch --all git checkout greenkeeper/initial npm install-test # Adapt your code until everything works again git commit -m 'chore: adapt code to updated dependencies' git push https://github.com/thedaviddias/HTMLHint.git greenkeeper/initial ``` </details> <details> <summary>✨ How do dependency updates work with Greenkeeper?</summary> After you merge this pull request, **Greenkeeper will create a new branch whenever a dependency is updated**, with the new version applied. The branch creation should trigger your testing services and check whether your code still works with the new dependency version. Depending on the the results of these tests Greenkeeper will try to open meaningful and helpful pull requests and issues, so your dependencies remain working and up-to-date. ```diff - "underscore": "^1.6.0" + "underscore": "^1.7.0" ``` The above example shows an in-range update. `1.7.0` is included in the old `^1.6.0` range, because of the [caret `^` character ](https://docs.npmjs.com/misc/semver#ranges). When the test services report success Greenkeeper will silently delete the branch again, because no action needs to be taken – everything is fine. However, should the tests fail, Greenkeeper will create an issue to inform you about the problem immediately. This way, you’ll never be surprised by a dependency breaking your code. As long as everything still works, Greenkeeper will stay out of your way, and as soon as something goes wrong, you’ll be the first to know. ```diff - "lodash": "^3.0.0" + "lodash": "^4.0.0" ``` In this example, the new version `4.0.0` is _not_ included in the old `^3.0.0` range. For version updates like these – let’s call them “out of range” updates – you’ll receive a pull request. This means that **you no longer need to check for new versions manually** – Greenkeeper will keep you up to date automatically. These pull requests not only serve as reminders to update: If you have solid tests and good coverage, and the pull requests passes those tests, you can very likely just merge it and release a new version of your software straight away :shipit: To get a better idea of which ranges apply to which releases, check out the extremely useful [semver calculator](https://semver.npmjs.com/) provided by npm. </details> <details> <summary>FAQ and help</summary> There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new). </details> --- Good luck with your project and see you soon :sparkles: Your [Greenkeeper](https://greenkeeper.io) bot :palm_tree: --- README.md | 2 ++ package.json | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 8d05a7569..0de70edf3 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![codecov](https://codecov.io/gh/thedaviddias/HTMLHint/branch/master/graph/badge.svg)](https://codecov.io/gh/thedaviddias/HTMLHint) [![NPM version](https://img.shields.io/npm/v/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) [![NPM count](https://img.shields.io/npm/dm/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) +[![Greenkeeper badge](https://badges.greenkeeper.io/thedaviddias/HTMLHint.svg?style=flat)](https://greenkeeper.io/) +[![NPM count](https://img.shields.io/npm/dt/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) [![License](https://img.shields.io/npm/l/htmlhint.svg?style=flat)](https://www.npmjs.com/package/htmlhint) [![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?style=flat)](https://discord.gg/nJ6J9CP) diff --git a/package.json b/package.json index c8b6f1579..e04dfffe7 100644 --- a/package.json +++ b/package.json @@ -4,30 +4,30 @@ "description": "The Static Code Analysis Tool for your HTML", "main": "./index", "dependencies": { - "async": "1.5.2", - "colors": "1.1.2", - "commander": "2.9.0", - "csslint": "0.10.0", - "glob": "7.0.3", + "async": "2.6.1", + "colors": "1.3.1", + "commander": "2.17.1", + "csslint": "1.0.5", + "glob": "7.1.2", "jshint": "2.9.6", "parse-glob": "3.0.4", - "path-parse": "1.0.5", - "request": "2.84.0", + "path-parse": "1.0.6", + "request": "2.88.0", "strip-json-comments": "2.0.1", "xml": "1.0.1" }, "devDependencies": { "expect.js": "0.3.1", - "grunt": "0.4.1", - "grunt-cli": "0.1.6", - "grunt-contrib-clean": "0.4.0", - "grunt-contrib-concat": "0.1.3", - "grunt-contrib-jshint": "0.11.3", - "grunt-contrib-uglify": "0.2.0", - "grunt-contrib-watch": "0.3.1", - "grunt-exec": "0.4.6", - "grunt-replace": "0.4.0", - "istanbul": "0.4.3", + "grunt": "1.0.3", + "grunt-cli": "1.3.1", + "grunt-contrib-clean": "1.1.0", + "grunt-contrib-concat": "1.0.1", + "grunt-contrib-jshint": "1.1.0", + "grunt-contrib-uglify": "3.4.0", + "grunt-contrib-watch": "1.1.0", + "grunt-exec": "3.0.0", + "grunt-replace": "1.0.1", + "istanbul": "0.4.5", "istanbul-coveralls": "1.0.3", "mocha": "2.4.5", "semantic-release": "^15.9.9" From 14fd3aa7fa9abdd207b98be212e1c3f0218b065a Mon Sep 17 00:00:00 2001 From: Shinigami <chrissi92@hotmail.de> Date: Mon, 27 Aug 2018 13:19:17 +0200 Subject: [PATCH 09/13] docs: package author and contributors (#270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Partially fixes**: #259 - [x] Check the commit's or even all commits' message styles matches our requested structure. - [x] Check your code additions will fail neither code linting checks nor unit test. #### Short description of what this resolves: Give the main contributor some credits #### Proposed changes: - Added main contributors to the package.json 👍 Thank you! --- package.json | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e04dfffe7..a4ebe4a0d 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,25 @@ "analysis", "javascript" ], - "author": "David Dias (thedaviddias@gmail.com)", + "author": { + "name": "David Dias", + "email": "thedaviddias@gmail.com", + "url": "https://thedaviddias.me" + }, + "contributors": [ + { + "name": "Yanis Wang", + "email": "yanis.wang@gmail.com" + }, + { + "name": "Serj Lavrin", + "url": "https://lavrins.com" + }, + { + "name": "Christopher Quadflieg", + "email": "chrissi92@hotmail.de" + } + ], "license": "MIT", "scripts": { "semantic-release": "semantic-release" From 087c77895f8ce19f95298e7e294aa89e583c37f8 Mon Sep 17 00:00:00 2001 From: Shinigami <chrissi92@hotmail.de> Date: Mon, 27 Aug 2018 18:27:23 +0200 Subject: [PATCH 10/13] style: remove all license headers from code (#274) * remove all license headers from code * remove generated header --- Gruntfile.js | 1 - bin/formatters/checkstyle.js | 4 - bin/formatters/compact.js | 4 - bin/formatters/default.js | 4 - bin/formatters/json.js | 4 - bin/formatters/junit.js | 4 - bin/formatters/markdown.js | 4 - bin/formatters/unix.js | 4 - src/core.js | 4 - src/htmlparser.js | 4 - src/reporter.js | 4 - src/rules/alt-require.js | 5 - src/rules/attr-lowercase.js | 4 - src/rules/attr-no-duplication.js | 6 +- src/rules/attr-unsafe-chars.js | 4 - src/rules/attr-value-double-quotes.js | 6 +- src/rules/attr-value-not-empty.js | 6 +- src/rules/csslint.js | 6 +- src/rules/doctype-first.js | 6 +- src/rules/doctype-html5.js | 6 +- src/rules/head-script-disabled.js | 4 - src/rules/href-abs-or-rel.js | 6 +- src/rules/id-class-ad-disabled.js | 6 +- src/rules/id-class-value.js | 6 +- src/rules/id-unique.js | 6 +- src/rules/inline-script-disabled.js | 4 - src/rules/inline-style-disabled.js | 4 - src/rules/jshint.js | 6 +- src/rules/space-tab-mixed-disabled.js | 4 - src/rules/spec-char-escape.js | 6 +- src/rules/src-not-empty.js | 6 +- src/rules/style-disabled.js | 4 - src/rules/tag-pair.js | 4 - src/rules/tag-self-close.js | 4 - src/rules/tagname-lowercase.js | 6 +- src/rules/title-require.js | 4 - test/core-spec.js | 5 - test/htmlparser.spec.js | 5 - test/rules/alt-require.spec.js | 226 ++++++++--------- test/rules/attr-lowercase.spec.js | 5 - test/rules/attr-no-duplication.spec.js | 59 ++--- test/rules/attr-unsafe-chars.spec.js | 5 - test/rules/attr-value-double-quotes.spec.js | 7 +- test/rules/attr-value-not-empty.spec.js | 7 +- test/rules/csslint.spec.js | 63 +++-- test/rules/default.spec.js | 7 +- test/rules/doctype-first.spec.js | 7 +- test/rules/doctype-html5.spec.js | 5 - test/rules/head-require.spec.js | 5 - test/rules/head-script-disabled.spec.js | 5 - test/rules/href-abs-or-rel.spec.js | 105 ++++---- test/rules/id-class-ad-disabled.spec.js | 263 ++++++++++---------- test/rules/id-class-value.spec.js | 7 +- test/rules/id-unique.spec.js | 7 +- test/rules/inline-script-disabled.spec.js | 5 - test/rules/inline-style-disabled.spec.js | 5 - test/rules/jshint.spec.js | 115 ++++----- test/rules/space-tab-mixed-disabled.spec.js | 5 - test/rules/spec-char-escape.spec.js | 7 +- test/rules/src-not-empty.spec.js | 65 +++-- test/rules/style-disabled.spec.js | 7 +- test/rules/tag-pair.spec.js | 5 - test/rules/tag-self-close.spec.js | 7 +- test/rules/tagname-lowercase.spec.js | 7 +- test/rules/title-require.spec.js | 5 - 65 files changed, 454 insertions(+), 742 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 906ed2a13..763dfbd79 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -48,7 +48,6 @@ module.exports = function(grunt) { uglify: { htmlhint: { options: { - banner: "/*!\r\n * HTMLHint v<%= pkg.version %>\r\n * https://github.com/yaniswang/HTMLHint\r\n *\r\n * (c) 2014-"+new Date().getFullYear()+" Yanis Wang <yanis.wang@gmail.com>.\r\n * MIT Licensed\r\n */\n", beautify: { ascii_only: true } diff --git a/bin/formatters/checkstyle.js b/bin/formatters/checkstyle.js index ae770bd21..1319430a5 100644 --- a/bin/formatters/checkstyle.js +++ b/bin/formatters/checkstyle.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var xml = require('xml'); var checkstyleFormatter = function(formatter){ diff --git a/bin/formatters/compact.js b/bin/formatters/compact.js index 75797d4e8..fc4ae8ae8 100644 --- a/bin/formatters/compact.js +++ b/bin/formatters/compact.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var compactFormatter = function(formatter, HTMLHint, options){ var nocolor = options.nocolor; formatter.on('file', function(event){ diff --git a/bin/formatters/default.js b/bin/formatters/default.js index 03a48d4a9..121348071 100644 --- a/bin/formatters/default.js +++ b/bin/formatters/default.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var defaultFormatter = function(formatter, HTMLHint, options){ var nocolor = options.nocolor; formatter.on('start', function(){ diff --git a/bin/formatters/json.js b/bin/formatters/json.js index 47186e96c..96c968988 100644 --- a/bin/formatters/json.js +++ b/bin/formatters/json.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var jsonFormatter = function(formatter){ formatter.on('end', function(event){ console.log(JSON.stringify(event.arrAllMessages)); diff --git a/bin/formatters/junit.js b/bin/formatters/junit.js index af4eeb597..7ed0da426 100644 --- a/bin/formatters/junit.js +++ b/bin/formatters/junit.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var xml = require('xml'); var junitFormatter = function(formatter, HTMLHint){ diff --git a/bin/formatters/markdown.js b/bin/formatters/markdown.js index 1f20a6fd7..1b2bcb82b 100644 --- a/bin/formatters/markdown.js +++ b/bin/formatters/markdown.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var markdownFormatter = function(formatter, HTMLHint){ formatter.on('end', function(event){ console.log('# TOC'); diff --git a/bin/formatters/unix.js b/bin/formatters/unix.js index 06358466a..3cf4efade 100644 --- a/bin/formatters/unix.js +++ b/bin/formatters/unix.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var unixFormatter = function(formatter, HTMLHint, options){ var nocolor = options.nocolor; formatter.on('file', function(event){ diff --git a/src/core.js b/src/core.js index 3a3da57fe..c0f9e2e29 100644 --- a/src/core.js +++ b/src/core.js @@ -1,8 +1,4 @@ /* jshint -W079 */ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var HTMLHint = (function (undefined) { var HTMLHint = {}; diff --git a/src/htmlparser.js b/src/htmlparser.js index 9b6da399f..7cc1ef9f7 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -1,8 +1,4 @@ /* jshint -W079 */ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ var HTMLParser = (function(undefined){ var HTMLParser = function(){ diff --git a/src/reporter.js b/src/reporter.js index 444b6da0f..e7d379ddf 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ (function(HTMLHint, undefined){ var Reporter = function(){ diff --git a/src/rules/alt-require.js b/src/rules/alt-require.js index 9804791c9..c2df01954 100644 --- a/src/rules/alt-require.js +++ b/src/rules/alt-require.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * Copyright (c) 2014, Takeshi Kurosawa <taken.spc@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'alt-require', description: 'The alt attribute of an <img> element must be present and alt attribute of area[href] and input[type=image] must have a value.', diff --git a/src/rules/attr-lowercase.js b/src/rules/attr-lowercase.js index 058d24d95..55648bf6e 100644 --- a/src/rules/attr-lowercase.js +++ b/src/rules/attr-lowercase.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'attr-lowercase', description: 'All attribute names must be in lowercase.', diff --git a/src/rules/attr-no-duplication.js b/src/rules/attr-no-duplication.js index 60e1b7cf3..ae2e8fcdb 100644 --- a/src/rules/attr-no-duplication.js +++ b/src/rules/attr-no-duplication.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'attr-no-duplication', description: 'Elements cannot have duplicate attributes.', @@ -24,4 +20,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/attr-unsafe-chars.js b/src/rules/attr-unsafe-chars.js index de6b7fdcd..b91d988f2 100644 --- a/src/rules/attr-unsafe-chars.js +++ b/src/rules/attr-unsafe-chars.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'attr-unsafe-chars', description: 'Attribute values cannot contain unsafe chars.', diff --git a/src/rules/attr-value-double-quotes.js b/src/rules/attr-value-double-quotes.js index 971fd9524..c54833570 100644 --- a/src/rules/attr-value-double-quotes.js +++ b/src/rules/attr-value-double-quotes.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'attr-value-double-quotes', description: 'Attribute values must be in double quotes.', @@ -20,4 +16,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/attr-value-not-empty.js b/src/rules/attr-value-not-empty.js index 5fecf48ac..7ad85e794 100644 --- a/src/rules/attr-value-not-empty.js +++ b/src/rules/attr-value-not-empty.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'attr-value-not-empty', description: 'All attributes must have values.', @@ -19,4 +15,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/csslint.js b/src/rules/csslint.js index a5fd62394..ba546e163 100644 --- a/src/rules/csslint.js +++ b/src/rules/csslint.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'csslint', description: 'Scan css with csslint.', @@ -35,4 +31,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/doctype-first.js b/src/rules/doctype-first.js index 566b970c1..f5eb55c87 100644 --- a/src/rules/doctype-first.js +++ b/src/rules/doctype-first.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'doctype-first', description: 'Doctype must be declared first.', @@ -18,4 +14,4 @@ HTMLHint.addRule({ }; parser.addListener('all', allEvent); } -}); \ No newline at end of file +}); diff --git a/src/rules/doctype-html5.js b/src/rules/doctype-html5.js index 6586c7d6e..d134de8ff 100644 --- a/src/rules/doctype-html5.js +++ b/src/rules/doctype-html5.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'doctype-html5', description: 'Invalid doctype. Use: "<!DOCTYPE html>"', @@ -19,4 +15,4 @@ HTMLHint.addRule({ parser.addListener('all', onComment); parser.addListener('tagstart', onTagStart); } -}); \ No newline at end of file +}); diff --git a/src/rules/head-script-disabled.js b/src/rules/head-script-disabled.js index 9f9ffd0f9..f8afed300 100644 --- a/src/rules/head-script-disabled.js +++ b/src/rules/head-script-disabled.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'head-script-disabled', description: 'The <script> tag cannot be used in a <head> tag.', diff --git a/src/rules/href-abs-or-rel.js b/src/rules/href-abs-or-rel.js index 05ffcc3e1..5f5d9fe80 100644 --- a/src/rules/href-abs-or-rel.js +++ b/src/rules/href-abs-or-rel.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'href-abs-or-rel', description: 'An href attribute must be either absolute or relative.', @@ -27,4 +23,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/id-class-ad-disabled.js b/src/rules/id-class-ad-disabled.js index d934b426a..7d5c60b2f 100644 --- a/src/rules/id-class-ad-disabled.js +++ b/src/rules/id-class-ad-disabled.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'id-class-ad-disabled', description: 'The id and class attributes cannot use the ad keyword, it will be blocked by adblock software.', @@ -24,4 +20,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/id-class-value.js b/src/rules/id-class-value.js index d050e6141..6a8f505e6 100644 --- a/src/rules/id-class-value.js +++ b/src/rules/id-class-value.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'id-class-value', description: 'The id and class attribute values must meet the specified rules.', @@ -54,4 +50,4 @@ HTMLHint.addRule({ }); } } -}); \ No newline at end of file +}); diff --git a/src/rules/id-unique.js b/src/rules/id-unique.js index 6e671347e..9f416b48e 100644 --- a/src/rules/id-unique.js +++ b/src/rules/id-unique.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'id-unique', description: 'The value of id attributes must be unique.', @@ -33,4 +29,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/inline-script-disabled.js b/src/rules/inline-script-disabled.js index cbdddd79a..0c764f9f6 100644 --- a/src/rules/inline-script-disabled.js +++ b/src/rules/inline-script-disabled.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'inline-script-disabled', description: 'Inline script cannot be used.', diff --git a/src/rules/inline-style-disabled.js b/src/rules/inline-style-disabled.js index b56ce81be..4747ded00 100644 --- a/src/rules/inline-style-disabled.js +++ b/src/rules/inline-style-disabled.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'inline-style-disabled', description: 'Inline style cannot be used.', diff --git a/src/rules/jshint.js b/src/rules/jshint.js index 336d1b987..7d015be1d 100644 --- a/src/rules/jshint.js +++ b/src/rules/jshint.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'jshint', description: 'Scan script with jshint.', @@ -46,4 +42,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/space-tab-mixed-disabled.js b/src/rules/space-tab-mixed-disabled.js index 7b5212ed3..5b879cb57 100644 --- a/src/rules/space-tab-mixed-disabled.js +++ b/src/rules/space-tab-mixed-disabled.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'space-tab-mixed-disabled', description: 'Do not mix tabs and spaces for indentation.', diff --git a/src/rules/spec-char-escape.js b/src/rules/spec-char-escape.js index c074db09b..d68569985 100644 --- a/src/rules/spec-char-escape.js +++ b/src/rules/spec-char-escape.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'spec-char-escape', description: 'Special characters must be escaped.', @@ -17,4 +13,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/src-not-empty.js b/src/rules/src-not-empty.js index d864aa455..5f5ed2a25 100644 --- a/src/rules/src-not-empty.js +++ b/src/rules/src-not-empty.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'src-not-empty', description: 'The src attribute of an img(script,link) must have a value.', @@ -23,4 +19,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/style-disabled.js b/src/rules/style-disabled.js index f04d2c88f..5d84d39f9 100644 --- a/src/rules/style-disabled.js +++ b/src/rules/style-disabled.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'style-disabled', description: '<style> tags cannot be used.', diff --git a/src/rules/tag-pair.js b/src/rules/tag-pair.js index bb51e2108..8f6fe359f 100644 --- a/src/rules/tag-pair.js +++ b/src/rules/tag-pair.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'tag-pair', description: 'Tag must be paired.', diff --git a/src/rules/tag-self-close.js b/src/rules/tag-self-close.js index cb89a2dbe..e7b00ca8b 100644 --- a/src/rules/tag-self-close.js +++ b/src/rules/tag-self-close.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'tag-self-close', description: 'Empty tags must be self closed.', diff --git a/src/rules/tagname-lowercase.js b/src/rules/tagname-lowercase.js index 39bf157e7..3ae51fdc2 100644 --- a/src/rules/tagname-lowercase.js +++ b/src/rules/tagname-lowercase.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'tagname-lowercase', description: 'All html element names must be in lowercase.', @@ -14,4 +10,4 @@ HTMLHint.addRule({ } }); } -}); \ No newline at end of file +}); diff --git a/src/rules/title-require.js b/src/rules/title-require.js index 199fde820..c6aaaee8e 100644 --- a/src/rules/title-require.js +++ b/src/rules/title-require.js @@ -1,7 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ HTMLHint.addRule({ id: 'title-require', description: '<title> must be present in <head> tag.', diff --git a/test/core-spec.js b/test/core-spec.js index c5e61e155..1b6cd4fbe 100644 --- a/test/core-spec.js +++ b/test/core-spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../index").HTMLHint; diff --git a/test/htmlparser.spec.js b/test/htmlparser.spec.js index 2fc46aa57..3a1afc4f0 100644 --- a/test/htmlparser.spec.js +++ b/test/htmlparser.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLParser = require("../index").HTMLParser; diff --git a/test/rules/alt-require.spec.js b/test/rules/alt-require.spec.js index 04ee3bff3..fc89a3107 100644 --- a/test/rules/alt-require.spec.js +++ b/test/rules/alt-require.spec.js @@ -1,116 +1,110 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * Copyright (c) 2014, Takeshi Kurosawa <taken.spc@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'alt-require', - ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe('Rules: '+ruldId, function(){ - - it('Img tag have empty alt attribute should not result in an error', function(){ - var code = '<img width="200" height="300" alt="">'; - var 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(){ - var code = '<img width="200" height="300" alt="test">'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Img tag have not alt attribute should result in an error', function(){ - var code = '<img width="200" height="300">'; - var 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(){ - var code = '<a>'; - var 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(){ - var code = '<area>'; - var 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(){ - var code = '<area href="#test">'; - var 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(){ - var code = '<area href="#test" alt="">'; - var 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(){ - var code = '<area href="#test" alt="test">'; - var 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(){ - var code = '<input>'; - var 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(){ - var code = '<input type="text">'; - var 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(){ - var code = '<input type="image">'; - var 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(){ - var code = '<input type="image" alt="">'; - var 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(){ - var code = '<input type="image" alt="test">'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); -}); +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'alt-require', + ruleOptions = {}; + +ruleOptions[ruldId] = true; + +describe('Rules: '+ruldId, function(){ + + it('Img tag have empty alt attribute should not result in an error', function(){ + var code = '<img width="200" height="300" alt="">'; + var 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(){ + var code = '<img width="200" height="300" alt="test">'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + }); + + it('Img tag have not alt attribute should result in an error', function(){ + var code = '<img width="200" height="300">'; + var 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(){ + var code = '<a>'; + var 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(){ + var code = '<area>'; + var 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(){ + var code = '<area href="#test">'; + var 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(){ + var code = '<area href="#test" alt="">'; + var 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(){ + var code = '<area href="#test" alt="test">'; + var 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(){ + var code = '<input>'; + var 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(){ + var code = '<input type="text">'; + var 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(){ + var code = '<input type="image">'; + var 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(){ + var code = '<input type="image" alt="">'; + var 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(){ + var code = '<input type="image" alt="test">'; + var 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 ae3c7aea6..ff03d4e8c 100644 --- a/test/rules/attr-lowercase.spec.js +++ b/test/rules/attr-lowercase.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/attr-no-duplication.spec.js b/test/rules/attr-no-duplication.spec.js index 04f859449..c5358c806 100644 --- a/test/rules/attr-no-duplication.spec.js +++ b/test/rules/attr-no-duplication.spec.js @@ -1,32 +1,27 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'attr-no-duplication', - ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe('Rules: '+ruldId, function(){ - - it('Attribute name been duplication should result in an error', function(){ - var code = '<a href="a" href="b">bbb</a>'; - var 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(){ - var code = '<a href="a">bbb</a>'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - -}); \ No newline at end of file +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'attr-no-duplication', + ruleOptions = {}; + +ruleOptions[ruldId] = true; + +describe('Rules: '+ruldId, function(){ + + it('Attribute name been duplication should result in an error', function(){ + var code = '<a href="a" href="b">bbb</a>'; + var 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(){ + var code = '<a href="a">bbb</a>'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + }); + +}); diff --git a/test/rules/attr-unsafe-chars.spec.js b/test/rules/attr-unsafe-chars.spec.js index 538bbe8e3..614955411 100644 --- a/test/rules/attr-unsafe-chars.spec.js +++ b/test/rules/attr-unsafe-chars.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/attr-value-double-quotes.spec.js b/test/rules/attr-value-double-quotes.spec.js index 04093be21..4ad99555f 100644 --- a/test/rules/attr-value-double-quotes.spec.js +++ b/test/rules/attr-value-double-quotes.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -35,4 +30,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/attr-value-not-empty.spec.js b/test/rules/attr-value-not-empty.spec.js index 5c7a58ebd..9c4d54f27 100644 --- a/test/rules/attr-value-not-empty.spec.js +++ b/test/rules/attr-value-not-empty.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -36,4 +31,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/csslint.spec.js b/test/rules/csslint.spec.js index 191c5f0aa..b7705260c 100644 --- a/test/rules/csslint.spec.js +++ b/test/rules/csslint.spec.js @@ -1,34 +1,29 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'csslint', - ruleOptions = {}; - -ruleOptions[ruldId] = { - "display-property-grouping": true, - "known-properties": true - }; - -describe('Rules: '+ruldId, function(){ - - it('should result in an error', function(){ - var code = 'a<style> \r\n body{color:red1;\r\ndisplay:inline;height:100px;}</style>b'; - var 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(7); - expect(messages[0].type).to.be('warning'); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(3); - expect(messages[1].col).to.be(16); - expect(messages[1].type).to.be('warning'); - }); - -}); \ No newline at end of file +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'csslint', + ruleOptions = {}; + +ruleOptions[ruldId] = { + "display-property-grouping": true, + "known-properties": true + }; + +describe('Rules: '+ruldId, function(){ + + it('should result in an error', function(){ + var code = 'a<style> \r\n body{color:red1;\r\ndisplay:inline;height:100px;}</style>b'; + var 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(7); + expect(messages[0].type).to.be('warning'); + expect(messages[1].rule.id).to.be(ruldId); + expect(messages[1].line).to.be(3); + expect(messages[1].col).to.be(16); + expect(messages[1].type).to.be('warning'); + }); + +}); diff --git a/test/rules/default.spec.js b/test/rules/default.spec.js index a7840ae8b..e7af0307d 100644 --- a/test/rules/default.spec.js +++ b/test/rules/default.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -15,4 +10,4 @@ describe('Rules: default', function(){ expect(messages.length).to.be(3); }); -}); \ No newline at end of file +}); diff --git a/test/rules/doctype-first.spec.js b/test/rules/doctype-first.spec.js index 5b35b3152..6cd2ec1d2 100644 --- a/test/rules/doctype-first.spec.js +++ b/test/rules/doctype-first.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -29,4 +24,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/doctype-html5.spec.js b/test/rules/doctype-html5.spec.js index 94abdf9e5..6d3e02b59 100644 --- a/test/rules/doctype-html5.spec.js +++ b/test/rules/doctype-html5.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/head-require.spec.js b/test/rules/head-require.spec.js index 650c4cd96..0a15b09cb 100644 --- a/test/rules/head-require.spec.js +++ b/test/rules/head-require.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/head-script-disabled.spec.js b/test/rules/head-script-disabled.spec.js index 650c4cd96..0a15b09cb 100644 --- a/test/rules/head-script-disabled.spec.js +++ b/test/rules/head-script-disabled.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/href-abs-or-rel.spec.js b/test/rules/href-abs-or-rel.spec.js index 5799f1cb4..7c4ebf801 100644 --- a/test/rules/href-abs-or-rel.spec.js +++ b/test/rules/href-abs-or-rel.spec.js @@ -1,55 +1,50 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'href-abs-or-rel'; -var ruleOptions = {}; - -describe('Rules: '+ruldId, function(){ - - it('Href value is not absolute with abs mode should result in an error', function(){ - var code = '<a href="a.html">aaa</a><a href="../b.html">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; - ruleOptions[ruldId] = 'abs'; - var 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(){ - var code = '<a href="http://www.alibaba.com/">aaa</a><a href="https://www.alibaba.com/">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; - ruleOptions[ruldId] = 'abs'; - var 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(){ - var code = '<a href="http://www.alibaba.com/">aaa</a><a href="https://www.alibaba.com/">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; - ruleOptions[ruldId] = 'rel'; - var 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(){ - var code = '<a href="a.html">aaa</a><a href="../b.html">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; - ruleOptions[ruldId] = 'rel'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - -}); \ No newline at end of file +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'href-abs-or-rel'; +var ruleOptions = {}; + +describe('Rules: '+ruldId, function(){ + + it('Href value is not absolute with abs mode should result in an error', function(){ + var code = '<a href="a.html">aaa</a><a href="../b.html">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; + ruleOptions[ruldId] = 'abs'; + var 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(){ + var code = '<a href="http://www.alibaba.com/">aaa</a><a href="https://www.alibaba.com/">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; + ruleOptions[ruldId] = 'abs'; + var 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(){ + var code = '<a href="http://www.alibaba.com/">aaa</a><a href="https://www.alibaba.com/">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; + ruleOptions[ruldId] = 'rel'; + var 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(){ + var code = '<a href="a.html">aaa</a><a href="../b.html">bbb</a><a href="tel:12345678">ccc</a><a href="javascript:void()">ddd</a>'; + ruleOptions[ruldId] = 'rel'; + var 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 5cafe4f46..d34c64e84 100644 --- a/test/rules/id-class-ad-disabled.spec.js +++ b/test/rules/id-class-ad-disabled.spec.js @@ -1,134 +1,129 @@ -/** - * Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'id-class-ad-disabled', - ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe('Rules: '+ruldId, function(){ - - it('Id use ad keyword should result in an error', function(){ - var code = '<div id="ad">test</div>'; - var 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 = '<div id="ad-222">test</div>'; - 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 = '<div id="ad_222">test</div>'; - 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 = '<div id="111-ad">test</div>'; - 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 = '<div id="111_ad">test</div>'; - 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 = '<div id="111-ad-222">test</div>'; - 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 = '<div id="111_ad_222">test</div>'; - 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(){ - var code = '<div class="ad">test</div>'; - var 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 = '<div class="ad-222">test</div>'; - 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 = '<div class="ad_222">test</div>'; - 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 = '<div class="111-ad">test</div>'; - 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 = '<div class="111_ad">test</div>'; - 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 = '<div class="111-ad-222">test</div>'; - 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 = '<div class="111_ad_222">test</div>'; - 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(){ - var code = '<div id="ad1" class="ad2">test</div>'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - - code = '<div id="ad1-222" class="ad2-222">test</div>'; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - - code = '<div id="111-ad1" class="111-ad2">test</div>'; - messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - -}); \ No newline at end of file +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'id-class-ad-disabled', + ruleOptions = {}; + +ruleOptions[ruldId] = true; + +describe('Rules: '+ruldId, function(){ + + it('Id use ad keyword should result in an error', function(){ + var code = '<div id="ad">test</div>'; + var 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 = '<div id="ad-222">test</div>'; + 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 = '<div id="ad_222">test</div>'; + 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 = '<div id="111-ad">test</div>'; + 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 = '<div id="111_ad">test</div>'; + 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 = '<div id="111-ad-222">test</div>'; + 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 = '<div id="111_ad_222">test</div>'; + 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(){ + var code = '<div class="ad">test</div>'; + var 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 = '<div class="ad-222">test</div>'; + 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 = '<div class="ad_222">test</div>'; + 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 = '<div class="111-ad">test</div>'; + 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 = '<div class="111_ad">test</div>'; + 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 = '<div class="111-ad-222">test</div>'; + 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 = '<div class="111_ad_222">test</div>'; + 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(){ + var code = '<div id="ad1" class="ad2">test</div>'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + + code = '<div id="ad1-222" class="ad2-222">test</div>'; + messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + + code = '<div id="111-ad1" class="111-ad2">test</div>'; + 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 ddc54730e..894b0cc63 100644 --- a/test/rules/id-class-value.spec.js +++ b/test/rules/id-class-value.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -94,4 +89,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/id-unique.spec.js b/test/rules/id-unique.spec.js index 5c9f33781..86c3008cf 100644 --- a/test/rules/id-unique.spec.js +++ b/test/rules/id-unique.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -30,4 +25,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/inline-script-disabled.spec.js b/test/rules/inline-script-disabled.spec.js index 831c1b58a..3db0675bb 100644 --- a/test/rules/inline-script-disabled.spec.js +++ b/test/rules/inline-script-disabled.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/inline-style-disabled.spec.js b/test/rules/inline-style-disabled.spec.js index 866bf281b..67c3855ea 100644 --- a/test/rules/inline-style-disabled.spec.js +++ b/test/rules/inline-style-disabled.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/jshint.spec.js b/test/rules/jshint.spec.js index e32d1001c..847b6e597 100644 --- a/test/rules/jshint.spec.js +++ b/test/rules/jshint.spec.js @@ -1,60 +1,55 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'jshint', - ruleOptions = {}; - -ruleOptions[ruldId] = { - "undef": true, - "unused": true - }; - -describe('Rules: '+ruldId, function(){ - - it('should result in an error', function(){ - var code = 'a<script>\r\nvar b;\r\n debugger;\r\na=1</script>b'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(4); - expect(messages[0].rule.id).to.be(ruldId); - expect(messages[0].line).to.be(3); - expect(messages[0].col).to.be(3); - expect(messages[0].type).to.be('warning'); - expect(messages[1].rule.id).to.be(ruldId); - expect(messages[1].line).to.be(4); - expect(messages[1].col).to.be(4); - expect(messages[1].type).to.be('warning'); - expect(messages[2].rule.id).to.be(ruldId); - expect(messages[2].line).to.be(4); - expect(messages[2].col).to.be(1); - expect(messages[2].type).to.be('warning'); - expect(messages[3].rule.id).to.be(ruldId); - expect(messages[3].line).to.be(2); - expect(messages[3].col).to.be(5); - expect(messages[3].type).to.be('warning'); - }); - - it('type of script be not text/javascript should not result in an error', function(){ - var code = 'a<script type="text/html">\r\nvar b;\r\n debugger;\r\na=1</script>b'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('type of script be text/javascript should result in an error', function(){ - var code = 'a<script type="text/javascript">\r\nvar b;\r\n debugger;\r\na=1</script>b'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).not.to.be(0); - }); - - it('type of script be text/javascript but have src should not result in an error', function(){ - var code = 'a<script type="text/javascript" src="test.js">\r\nvar b;\r\n debugger;\r\na=1</script>b'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - -}); \ No newline at end of file +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'jshint', + ruleOptions = {}; + +ruleOptions[ruldId] = { + "undef": true, + "unused": true + }; + +describe('Rules: '+ruldId, function(){ + + it('should result in an error', function(){ + var code = 'a<script>\r\nvar b;\r\n debugger;\r\na=1</script>b'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(4); + expect(messages[0].rule.id).to.be(ruldId); + expect(messages[0].line).to.be(3); + expect(messages[0].col).to.be(3); + expect(messages[0].type).to.be('warning'); + expect(messages[1].rule.id).to.be(ruldId); + expect(messages[1].line).to.be(4); + expect(messages[1].col).to.be(4); + expect(messages[1].type).to.be('warning'); + expect(messages[2].rule.id).to.be(ruldId); + expect(messages[2].line).to.be(4); + expect(messages[2].col).to.be(1); + expect(messages[2].type).to.be('warning'); + expect(messages[3].rule.id).to.be(ruldId); + expect(messages[3].line).to.be(2); + expect(messages[3].col).to.be(5); + expect(messages[3].type).to.be('warning'); + }); + + it('type of script be not text/javascript should not result in an error', function(){ + var code = 'a<script type="text/html">\r\nvar b;\r\n debugger;\r\na=1</script>b'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + }); + + it('type of script be text/javascript should result in an error', function(){ + var code = 'a<script type="text/javascript">\r\nvar b;\r\n debugger;\r\na=1</script>b'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).not.to.be(0); + }); + + it('type of script be text/javascript but have src should not result in an error', function(){ + var code = 'a<script type="text/javascript" src="test.js">\r\nvar b;\r\n debugger;\r\na=1</script>b'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + }); + +}); diff --git a/test/rules/space-tab-mixed-disabled.spec.js b/test/rules/space-tab-mixed-disabled.spec.js index 21528aa37..e85205d2a 100644 --- a/test/rules/space-tab-mixed-disabled.spec.js +++ b/test/rules/space-tab-mixed-disabled.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2014-2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/spec-char-escape.spec.js b/test/rules/spec-char-escape.spec.js index 89e4b24d2..67384a3ae 100644 --- a/test/rules/spec-char-escape.spec.js +++ b/test/rules/spec-char-escape.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -35,4 +30,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/src-not-empty.spec.js b/test/rules/src-not-empty.spec.js index 5df5f34d1..701129cf5 100644 --- a/test/rules/src-not-empty.spec.js +++ b/test/rules/src-not-empty.spec.js @@ -1,35 +1,30 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - -var expect = require("expect.js"); - -var HTMLHint = require("../../index").HTMLHint; - -var ruldId = 'src-not-empty', - ruleOptions = {}; - -ruleOptions[ruldId] = true; - -describe('Rules: '+ruldId, function(){ - - it('Src be emtpy should result in an error', function(){ - var code = '<img src="" /><img src /><script src=""></script><script src></script><link href="" type="text/css" /><link href type="text/css" /><embed src=""><embed src><bgsound src="" /><bgsound src /><iframe src=""><iframe src><object data=""><object data>'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(14); - }); - - it('Src be non-empty should not result in an error', function(){ - var code = '<img src="test.png" /><script src="test.js"></script><link href="test.css" type="text/css" /><embed src="test.swf"><bgsound src="test.mid" /><iframe src="test.html"><object data="test.swf">'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - - it('Src be not set value should not result in an error', function(){ - var code = '<img width="200" /><script></script><link type="text/css" /><embed width="200"><bgsound /><iframe width="200"><object width="200">'; - var messages = HTMLHint.verify(code, ruleOptions); - expect(messages.length).to.be(0); - }); - -}); \ No newline at end of file +var expect = require("expect.js"); + +var HTMLHint = require("../../index").HTMLHint; + +var ruldId = 'src-not-empty', + ruleOptions = {}; + +ruleOptions[ruldId] = true; + +describe('Rules: '+ruldId, function(){ + + it('Src be emtpy should result in an error', function(){ + var code = '<img src="" /><img src /><script src=""></script><script src></script><link href="" type="text/css" /><link href type="text/css" /><embed src=""><embed src><bgsound src="" /><bgsound src /><iframe src=""><iframe src><object data=""><object data>'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(14); + }); + + it('Src be non-empty should not result in an error', function(){ + var code = '<img src="test.png" /><script src="test.js"></script><link href="test.css" type="text/css" /><embed src="test.swf"><bgsound src="test.mid" /><iframe src="test.html"><object data="test.swf">'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + }); + + it('Src be not set value should not result in an error', function(){ + var code = '<img width="200" /><script></script><link type="text/css" /><embed width="200"><bgsound /><iframe width="200"><object width="200">'; + var messages = HTMLHint.verify(code, ruleOptions); + expect(messages.length).to.be(0); + }); + +}); diff --git a/test/rules/style-disabled.spec.js b/test/rules/style-disabled.spec.js index ba4a9c04f..63eda6f17 100644 --- a/test/rules/style-disabled.spec.js +++ b/test/rules/style-disabled.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -30,4 +25,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/tag-pair.spec.js b/test/rules/tag-pair.spec.js index 94dbf0ee1..7546fe471 100644 --- a/test/rules/tag-pair.spec.js +++ b/test/rules/tag-pair.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; diff --git a/test/rules/tag-self-close.spec.js b/test/rules/tag-self-close.spec.js index 0d62caed0..260d7235f 100644 --- a/test/rules/tag-self-close.spec.js +++ b/test/rules/tag-self-close.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -34,4 +29,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/tagname-lowercase.spec.js b/test/rules/tagname-lowercase.spec.js index cda6611d1..edd960445 100644 --- a/test/rules/tagname-lowercase.spec.js +++ b/test/rules/tagname-lowercase.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; @@ -38,4 +33,4 @@ describe('Rules: '+ruldId, function(){ expect(messages.length).to.be(0); }); -}); \ No newline at end of file +}); diff --git a/test/rules/title-require.spec.js b/test/rules/title-require.spec.js index 1f9905f97..889f3c82b 100644 --- a/test/rules/title-require.spec.js +++ b/test/rules/title-require.spec.js @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com> - * MIT Licensed - */ - var expect = require("expect.js"); var HTMLHint = require("../../index").HTMLHint; From c30d0b36fddcfca6e24f371e80f87b414f759050 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <greenkeeper[bot]@users.noreply.github.com> Date: Mon, 27 Aug 2018 13:22:11 -0400 Subject: [PATCH 11/13] chore(package): update dependencies (#275) --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a4ebe4a0d..f0f0db8d1 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "main": "./index", "dependencies": { "async": "2.6.1", - "colors": "1.3.1", + "colors": "1.3.2", "commander": "2.17.1", "csslint": "1.0.5", - "glob": "7.1.2", + "glob": "7.1.3", "jshint": "2.9.6", "parse-glob": "3.0.4", "path-parse": "1.0.6", @@ -29,7 +29,7 @@ "grunt-replace": "1.0.1", "istanbul": "0.4.5", "istanbul-coveralls": "1.0.3", - "mocha": "2.4.5", + "mocha": "5.2.0", "semantic-release": "^15.9.9" }, "bin": { From e56286d57e5e107f9a571154af31b70d4539ba08 Mon Sep 17 00:00:00 2001 From: Weston Ruter <weston@xwp.co> Date: Fri, 31 Aug 2018 20:31:38 -0700 Subject: [PATCH 12/13] refactor: pass options.global as predef arg to JSHINT (#216) The JSHINT [API](http://jshint.com/docs/api/) specifies that `globals` actually get passed as the `predef`, the 3rd argument to the function and not part of the `options`. This fixes that. Compare with CodeMirror's jshint integration: https://github.com/codemirror/CodeMirror/blob/e49a19f5cacb447558f162014eb26b8c45b30941/addon/lint/javascript-lint.js#L31 --- src/rules/jshint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/jshint.js b/src/rules/jshint.js index 7d015be1d..c00c29edf 100644 --- a/src/rules/jshint.js +++ b/src/rules/jshint.js @@ -28,7 +28,7 @@ HTMLHint.addRule({ styleCol = event.col - 1; var code = event.raw.replace(/\t/g,' '); try{ - var status = jsVerify(code, options); + var status = jsVerify(code, options, options.globals); if(status === false){ jsVerify.errors.forEach(function(error){ var line = error.line; From 6a0adf6c5eab0ff5b3d470f5cf29ef25f8456de5 Mon Sep 17 00:00:00 2001 From: Christopher Quadflieg <chrissi92@hotmail.de> Date: Sat, 1 Sep 2018 10:39:38 +0200 Subject: [PATCH 13/13] feat: read rules object from config file --- bin/htmlhint | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/htmlhint b/bin/htmlhint index f6255777c..ebb06f8e7 100755 --- a/bin/htmlhint +++ b/bin/htmlhint @@ -312,10 +312,11 @@ function getConfig(configPath, base, formatter){ } if(fs.existsSync(configPath)){ - var config = fs.readFileSync(configPath, 'utf-8'), + var configJson = fs.readFileSync(configPath, 'utf-8'), ruleset; try{ - ruleset = JSON.parse(stripJsonComments(config)); + var config = JSON.parse(stripJsonComments(configJson)); + ruleset = config.rules; formatter.emit('config', { ruleset: ruleset, configPath: configPath