0.4.1 • Published 7 years ago

htmlcs v0.4.1

Weekly downloads
795
License
MIT
Repository
github
Last release
7 years ago

htmlcs

Build Status NPM version Coverage Status Dependencies DevDependencies

HTML code style check & format tool.

Install

npm i -g htmlcs

Usage

  • in CLI

    	```bash
    	Usage: htmlcs <command> [options] [target...]
    
    	Commands:
    	  hint    Do hint given file(s)
    	  format  Do format given file(s)
    
    	Options:
    	  -h, --help      Show help                                            [boolean]
    	  -c, --config    Path to custom configuration file.                    [string]
    	  --diff          Check code style and output char diff.               [boolean]
    	  -i, --in-place  Edit input files in place; use with care!            [boolean]
    	  -v, --version   Show version number                                  [boolean]
    
    	Examples:
    	  htmlcs hint foo.html               do hint foo.html
    	  htmlcs hint foo.html bar.html      do hint foo.html & bar.html
    	  htmlcs hint ./                     do hint html files under ./
    	  htmlcs format foo.html             do format foo.html
    	  htmlcs format --diff foo.html      do format foo.html & show diff result
    	  htmlcs format --in-place foo.html  do format foo.html & write file in place
    
    	```
  • in Node.js / browser (with browserify)

    	* hint file
    
    		```javascript
    		var htmlcs = require('htmlcs');
    		var result = htmlcs.hintFile(filePath);
    		```
    
    	* hint code (string)
    
    		```javascript
    		var htmlcs = require('htmlcs');
    		var result = htmlcs.hint(code);
    		// Or
    		htmlcs.hintAsync(code).then(
    			result => { /* ... */ }
    		);
    		```
    
    	* use hint result
    
    		```javascript
    		result.forEach(function(item){
    		    console.log(
    		        '[%s] line %d, column %d: %s (%s, %s)',
    		        item.type,
    		        item.line,
    		        item.column,
    		        item.message,
    		        item.rule,
    		        item.code
    		    );
    		});
    		```
    
    	* format file
    
    		```javascript
    		var htmlcs = require('htmlcs');
    		console.log(htmlcs.formatFile(filePath));
    		```
    
    	* format code (string)
    
    		```javascript
    		var htmlcs = require('htmlcs');
    		console.log(htmlcs.format(code));
    		// Or
    		htmlcs.formatAsync(code).then(
    			result => console.log(result)
    		);
    		```
    
    	* add rule
    
    		```javascript
    		var htmlcs = require('htmlcs');
    		htmlcs.addRule({
    		    name: 'test-rule',
    		    desc: 'Just a test rule.',
    		    lint: function (getCfg, document, reporter) {
    		        reporter.warn(
    		            1,
    		            '099',
    		            'This is a test waring!'
    		        );
    		    }
    		});
    		var result = htmlcs.hint(code);
    		```
  • with Gulp/Grunt

    	There is no official Gulp/Grunt plugin yet. We recommend [fecs](https://github.com/ecomfe/fecs), which uses htmlcs to hint HTML code and provides a wealth of tools.
    
    	- [fecs-gulp](https://github.com/ecomfe/fecs-gulp)
    
    	- [fecs-grunt](https://github.com/ecomfe/fecs-grunt)

Rules & Codes

lib/rules/

rule map

Config

  • default: lib/default/.htmlcsrc

  • custom:

    	Custom rule file (.htmlcsrc) can be placed in the same/parent directory of target file, or the `~/` directory.
    
    	If found in neither paths, the default config will be used.
  • inline:

    	- disable
    
    		```html
    		<!-- htmlcs-disable -->
    		<!-- htmlcs-disable img-alt -->
    		<!-- htmlcs-disable img-alt, img-src, attr-value-double-quotes -->
    		```
    
    	- enable
    
    		```html
    		<!-- htmlcs-enable -->
    		<!-- htmlcs-enable img-alt -->
    		<!-- htmlcs-enable img-alt, img-src, attr-value-double-quotes -->
    		```
    
    	- config
    
    		```html
    		<!-- htmlcs img-width-height: true -->
    		<!-- htmlcs img-width-height: true, indent-char: "tab" -->
    		```

Relative third-party tools

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.4-beta.2

8 years ago

0.2.4-beta.1

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago