Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rewrite configuration structure #286

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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+$/
15 changes: 7 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -92,13 +91,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];
Expand Down
123 changes: 70 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,95 @@
[![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)

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 | </head>
^ <title> 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).

Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/checkstyle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
var xml = require('xml');

var checkstyleFormatter = function(formatter){
Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/compact.js
Original file line number Diff line number Diff line change
@@ -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){
Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/default.js
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/json.js
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/junit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
var xml = require('xml');

var junitFormatter = function(formatter, HTMLHint){
Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/markdown.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
4 changes: 0 additions & 4 deletions bin/formatters/unix.js
Original file line number Diff line number Diff line change
@@ -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){
Expand Down
6 changes: 3 additions & 3 deletions bin/htmlhint
Original file line number Diff line number Diff line change
Expand Up @@ -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}';
Expand Down Expand Up @@ -313,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
Expand Down
58 changes: 38 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
"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",
"jshint": "2.9.4",
"async": "2.6.1",
"colors": "1.3.2",
"commander": "2.17.1",
"csslint": "1.0.5",
"glob": "7.1.3",
"jshint": "2.9.6",
"parse-glob": "3.0.4",
"path-parse": "1.0.5",
"request": "2.72.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",
"mocha": "5.2.0",
"semantic-release": "^15.9.9"
},
"bin": {
Expand All @@ -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"
Expand Down
6 changes: 1 addition & 5 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* jshint -W079 */
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
var HTMLHint = (function (undefined) {

var HTMLHint = {};
Expand All @@ -12,7 +8,7 @@ var HTMLHint = (function (undefined) {

HTMLHint.rules = {};

//默认配置
// standard configuration
HTMLHint.defaultRuleset = {
'tagname-lowercase': true,
'attr-lowercase': true,
Expand Down
Loading