Skip to content

Commit bc18038

Browse files
committed
Initial commit
0 parents  commit bc18038

File tree

5 files changed

+275
-0
lines changed

5 files changed

+275
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = tab
6+
indent_size = 4
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = false
10+
11+
[*.md]
12+
trim_trailing_whitespace = true

.eslintrc

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"node": true,
5+
"amd": false,
6+
"mocha": true,
7+
"jasmine": false,
8+
"es6": true
9+
},
10+
11+
"rules": {
12+
"comma-dangle": [2, "never"],
13+
"no-cond-assign": 2,
14+
"no-console": 0,
15+
"no-constant-condition": 2,
16+
"no-control-regex": 2,
17+
"no-debugger": 2,
18+
"no-dupe-args": 2,
19+
"no-dupe-keys": 2,
20+
"no-duplicate-case": 2,
21+
"no-empty-character-class": 2,
22+
"no-empty": 2,
23+
"no-ex-assign": 2,
24+
"no-extra-boolean-cast": 2,
25+
"no-extra-parens": 0,
26+
"no-extra-semi": 2,
27+
"no-func-assign": 2,
28+
"no-inner-declarations": [2, "functions"],
29+
"no-invalid-regexp": 2,
30+
"no-irregular-whitespace": 2,
31+
"no-negated-in-lhs": 2,
32+
"no-obj-calls": 2,
33+
"no-regex-spaces": 2,
34+
"no-sparse-arrays": 2,
35+
"no-unreachable": 2,
36+
"use-isnan": 2,
37+
"valid-jsdoc": 0,
38+
"valid-typeof": 2,
39+
"no-unexpected-multiline": 2,
40+
41+
"accessor-pairs": 0,
42+
"block-scoped-var": 2,
43+
"complexity": [0, 5],
44+
"consistent-return": 2,
45+
"curly": [2, "all"],
46+
"default-case": 2,
47+
"dot-notation": 2,
48+
"eqeqeq": 2,
49+
"guard-for-in": 2,
50+
"no-alert": 2,
51+
"no-caller": 2,
52+
"no-div-regex": 2,
53+
"no-else-return": 2,
54+
"no-eq-null": 2,
55+
"no-eval": 2,
56+
"no-extend-native": 2,
57+
"no-extra-bind": 2,
58+
"no-fallthrough": 2,
59+
"no-floating-decimal": 2,
60+
"no-implicit-coercion": 0,
61+
"no-implied-eval": 2,
62+
"no-invalid-this": 2,
63+
"no-iterator": 2,
64+
"no-labels": 2,
65+
"no-lone-blocks": 2,
66+
"no-loop-func": 2,
67+
"no-multi-spaces": 2,
68+
"no-multi-str": 2,
69+
"no-native-reassign": 2,
70+
"no-new-func": 2,
71+
"no-new-wrappers": 2,
72+
"no-new": 2,
73+
"no-octal-escape": 2,
74+
"no-octal": 2,
75+
"no-param-reassign":[2, {"props": false}],
76+
"no-process-env": 2,
77+
"no-proto": 2,
78+
"no-redeclare": 2,
79+
"no-return-assign": 2,
80+
"no-script-url": 2,
81+
"no-self-compare": 2,
82+
"no-sequences": 2,
83+
"no-throw-literal": 2,
84+
"no-unused-expressions": 2,
85+
"no-useless-call": 2,
86+
"no-void": 0,
87+
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
88+
"no-with": 2,
89+
"radix": 0,
90+
"vars-on-top": 0,
91+
"wrap-iife": [2, "outside"],
92+
"yoda": [2, "never"],
93+
94+
"strict": [2, "global"],
95+
96+
"init-declarations": 0,
97+
"no-catch-shadow": 2,
98+
"no-delete-var": 2,
99+
"no-label-var": 2,
100+
"no-shadow-restricted-names": 2,
101+
"no-shadow": 2,
102+
"no-undef-init": 2,
103+
"no-undef": 2,
104+
"no-undefined": 2,
105+
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
106+
"no-use-before-define": 2,
107+
108+
"callback-return": [2, ["callback", "cb", "next"]],
109+
"handle-callback-err": 2,
110+
"no-mixed-requires": [1, true],
111+
"no-new-require": 2,
112+
"no-path-concat": 2,
113+
"no-process-exit": 2,
114+
"no-restricted-modules": 0,
115+
"no-sync": 0,
116+
117+
"array-bracket-spacing": [2, "never"],
118+
"brace-style": [2, "1tbs"],
119+
"camelcase": [2, {"properties": "always"}],
120+
"comma-spacing": [2, {"before": false, "after": true}],
121+
"comma-style": [2, "last"],
122+
"computed-property-spacing": [2, "never"],
123+
"consistent-this": [2, "that"],
124+
"eol-last": 0,
125+
"func-names": 0,
126+
"func-style": [2, "expression"],
127+
"id-length": 0,
128+
"id-match": 0,
129+
"indent": [2, "tab", {"SwitchCase": 1, "VariableDeclarator": 1}],
130+
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
131+
"lines-around-comment": 0,
132+
"linebreak-style": 0,
133+
"max-nested-callbacks": [2, 5],
134+
"new-cap": 2,
135+
"new-parens": 2,
136+
"newline-after-var": [0, "always"],
137+
"no-array-constructor": 2,
138+
"no-continue": 0,
139+
"no-inline-comments": 0,
140+
"no-lonely-if": 2,
141+
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
142+
"no-multiple-empty-lines": [1, {"max": 2}],
143+
"no-nested-ternary": 2,
144+
"no-new-object": 2,
145+
"no-spaced-func": 2,
146+
"no-ternary": 0,
147+
"no-trailing-spaces": 2,
148+
"no-underscore-dangle": 0,
149+
"no-unneeded-ternary": 2,
150+
"object-curly-spacing": [0, "always", {
151+
"objectsInObjects": false,
152+
"arraysInObjects": false
153+
}],
154+
"one-var": 0,
155+
"operator-assignment": [2, "always"],
156+
"operator-linebreak": [2, "after"],
157+
"padded-blocks": [2, "never"],
158+
"quote-props": [2, "as-needed"],
159+
"quotes": [2, "single"],
160+
"semi-spacing": [2, {"before": false, "after": true}],
161+
"semi": [2, "always"],
162+
"sort-vars": 0,
163+
"space-after-keywords": [2, "always"],
164+
"space-before-blocks": [2, "always"],
165+
"space-in-parens": [2, "never"],
166+
"space-infix-ops": 2,
167+
"space-return-throw-case": 2,
168+
"space-unary-ops": [2, { "words": true, "nonwords": false }],
169+
"spaced-comment": 0,
170+
"wrap-regex": 2
171+
}
172+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
var fs = require('fs');
3+
var path = require('path');
4+
var _ = require('lodash');
5+
var HTMLHint = require('htmlhint').HTMLHint;
6+
var configFile = path.join(process.cwd(), '.htmlhintrc');
7+
8+
var defaultConfig = {
9+
'alt-require': true,
10+
'attr-lowercase': true,
11+
'attr-no-duplication': true,
12+
'attr-unsafe-chars': true,
13+
'attr-value-double-quotes': true,
14+
'doctype-first': true,
15+
'doctype-html5': true,
16+
'id-unique': true,
17+
'inline-script-disabled': false,
18+
'inline-style-disabled': false,
19+
'space-tab-mixed-disabled': true,
20+
'spec-char-escape': true,
21+
'src-not-empty': true,
22+
'style-disabled': true,
23+
'tag-pair': true,
24+
'tag-self-close': true,
25+
'tagname-lowercase': true,
26+
'title-require': true
27+
};
28+
29+
var configs = [defaultConfig];
30+
31+
if (fs.existsSync(configFile)) {
32+
var contentFile = fs.readFileSync(configFile, 'utf8');
33+
var newConfig = JSON.parse(contentFile);
34+
configs.unshift(newConfig);
35+
}
36+
37+
var config = {};
38+
configs.unshift(config);
39+
40+
_.defaults.apply(null, configs);
41+
42+
var plugin = function (chai) {
43+
var Assertion = chai.Assertion;
44+
45+
Assertion.addProperty('validHtml', function () {
46+
/*eslint-disable no-invalid-this*/
47+
var content = this._obj;
48+
var messages = HTMLHint.verify(content, config);
49+
var textMessage = HTMLHint.format(messages).join('\n');
50+
51+
var notValidMessage = 'expected content to be valid HTML5\n' + textMessage;
52+
53+
this.assert(messages.length === 0,
54+
notValidMessage,
55+
'expected content to not be valid HTML5');
56+
/*eslint-enable no-invalid-this*/
57+
});
58+
};
59+
60+
module.exports = plugin;

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "chai-htmlhint",
3+
"version": "1.0.0",
4+
"description": "Matcher for chai to validate that HTML is valid using HTMLHint",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/molant/chai-htmlhint.git"
12+
},
13+
"keywords": [
14+
"chai",
15+
"htmlhint",
16+
"html",
17+
"hint",
18+
"lint"
19+
],
20+
"author": "molant",
21+
"license": "Apache-2.0",
22+
"bugs": {
23+
"url": "https://github.com/molant/chai-htmlhint/issues"
24+
},
25+
"homepage": "https://github.com/molant/chai-htmlhint#readme",
26+
"dependencies": {
27+
"lodash": "^4.11.1",
28+
"request": "^2.71.0"
29+
}
30+
}

0 commit comments

Comments
 (0)