Skip to content
This repository was archived by the owner on Oct 23, 2018. It is now read-only.

Commit 0d4cc64

Browse files
committed
initial
0 parents  commit 0d4cc64

File tree

11 files changed

+367
-0
lines changed

11 files changed

+367
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
typings

Diff for: .travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "0.10"
5+
- "0.12"
6+
- iojs
7+
- "4"
8+
- "stable"
9+
10+
before_script:
11+
- npm install -g grunt-cli

Diff for: Gruntfile.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* grunt-puglint
3+
* https://github.com/mrmlnc/grunt-puglint
4+
*/
5+
6+
'use strict';
7+
8+
module.exports = function (grunt) {
9+
grunt.initConfig({
10+
puglint: {
11+
// Default test with default `clock` config
12+
clock: {
13+
src: ['test/fixtures/**/*.jade']
14+
},
15+
16+
// Custom config with the string in the options
17+
customConfigString: {
18+
options: {
19+
preset: 'jadelint'
20+
},
21+
src: ['test/fixtures/**/*.jade']
22+
},
23+
24+
// Custom config with the object in the options
25+
customConfigObject: {
26+
options: {
27+
preset: {
28+
disallowIdLiterals: true
29+
}
30+
},
31+
src: ['test/fixtures/**/*.jade']
32+
},
33+
34+
// RC file
35+
rcFile: {
36+
options: {
37+
puglintrc: 'test/fixtures/.pug-lintrc'
38+
},
39+
src: ['test/fixtures/**/*.jade']
40+
}
41+
}
42+
});
43+
44+
grunt.loadTasks('tasks');
45+
grunt.registerTask('default', ['puglint']);
46+
};

Diff for: LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 Denis Malinochkin
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

Diff for: README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# grunt-puglint
2+
3+
> Grunt plugin for [pug-lint](https://github.com/pugjs/pug-lint) (formerly Jade).
4+
5+
[![Travis](https://img.shields.io/travis/mrmlnc/grunt-puglint.svg?style=flat-square)](https://travis-ci.org/mrmlnc/grunt-puglint)
6+
[![NPM version](https://img.shields.io/npm/v/grunt-puglint.svg?style=flat-square)](https://www.npmjs.com/package/grunt-puglint)
7+
[![devDependency Status](https://img.shields.io/david/mrmlnc/grunt-puglint.svg?style=flat-square)](https://david-dm.org/mrmlnc/grunt-puglint#info=dependencies)
8+
[![devDependency Status](https://img.shields.io/david/dev/mrmlnc/grunt-puglint.svg?style=flat-square)](https://david-dm.org/mrmlnc/grunt-puglint#info=devDependencies)
9+
10+
## Getting Started
11+
This plugin requires Grunt `~0.4.5`
12+
13+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
14+
15+
```shell
16+
npm install grunt-puglint --save-dev
17+
```
18+
19+
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
20+
21+
```js
22+
grunt.loadNpmTasks('grunt-puglint');
23+
```
24+
25+
## Usage
26+
27+
If you need a clean config settings, then use the object(`preset: {}`) or config file (`puglintrc: '..'`).
28+
29+
```js
30+
puglint: {
31+
taskName: {
32+
options: {
33+
// The name of the preset: `clock` (default) or `jadelint`
34+
preset: 'clock',
35+
// If preset is an object, the standard preset is not loaded
36+
preset: {
37+
disallowHtmlText: true,
38+
validateIndentation: 4
39+
}
40+
// The path to the configuration file
41+
puglintrc: 'test/fixtures/.pug-lintrc',
42+
// Override preset settings (default: `clock`)
43+
disallowHtmlText: true,
44+
validateIndentation: 4
45+
},
46+
src: ['test/fixtures/**/*.jade]
47+
}
48+
49+
// Or short version
50+
options: {
51+
// ..
52+
},
53+
taskName: ['...']
54+
}
55+
```
56+
57+
## Configuration
58+
59+
Plugin can read [.pug-lintrc file](https://github.com/pugjs/pug-lint#configuration-file).
60+
61+
## Rules
62+
63+
[List of available rules](https://github.com/pugjs/pug-lint/blob/master/docs/rules.md).
64+
65+
## History
66+
67+
* **v0.1.0** [2015-12-26] - Initial release.

Diff for: lib/formatter.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var chalk = require('chalk');
5+
var table = require('text-table');
6+
var cwd = process.cwd();
7+
8+
/**
9+
* Formatting string for the table
10+
*
11+
* @param {Object} item
12+
*/
13+
var formatRow = function(item) {
14+
// Drop newline symbol in error string
15+
item.msg = item.msg.replace('\n', '');
16+
// Using zero instead of undefined
17+
item.column = (item.column === undefined) ? 0 : item.column;
18+
// Drop `PUG:LINT_` prefix in error code
19+
item.code = chalk.grey(item.code.replace(/(PUG:|LINT_)/g, ''));
20+
// Formatting output
21+
var position = chalk.grey(item.line + ':' + item.column);
22+
return ['', position, chalk.red('error'), item.msg, item.code];
23+
};
24+
25+
exports.formatOutput = function(block) {
26+
var blockName;
27+
var output = [];
28+
29+
// If the passed block errors is an array
30+
if (block.length) {
31+
blockName = block[0].filename;
32+
block.forEach(function(item) {
33+
output.push(formatRow(item));
34+
});
35+
} else {
36+
blockName = block.filename;
37+
output.push(formatRow(block));
38+
}
39+
40+
blockName = '\n' + path.join(cwd, blockName);
41+
42+
console.log(chalk.underline(blockName));
43+
console.log(table(output));
44+
};

Diff for: package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "grunt-puglint",
3+
"description": "Grunt plugin for pug-lint",
4+
"version": "0.1.0",
5+
"author": {
6+
"name": "Denis Malinochkin",
7+
"email": "[email protected]"
8+
},
9+
"repository": "mrmlnc/grunt-puglint",
10+
"license": "MIT",
11+
"engines": {
12+
"node": ">= 0.8.0"
13+
},
14+
"scripts": {
15+
"test": "ava test/test.js"
16+
},
17+
"devDependencies": {
18+
"ava": "^0.8.0",
19+
"grunt": "~0.4.5",
20+
"rcloader": "^0.1.4",
21+
"xo": "^0.12.1"
22+
},
23+
"dependencies": {
24+
"chalk": "^1.1.1",
25+
"pug-lint": "^2.1.1",
26+
"text-table": "^0.2.0"
27+
},
28+
"keywords": [
29+
"gruntplugin",
30+
"grunt",
31+
"pug",
32+
"pug lint",
33+
"pug hint",
34+
"jade",
35+
"jade lint",
36+
"jade hint",
37+
"lint",
38+
"hint"
39+
],
40+
"files": [
41+
"tasks",
42+
"lib"
43+
],
44+
"xo": {
45+
"space": true,
46+
"rules": {
47+
"object-curly-spacing": [
48+
2,
49+
"always"
50+
],
51+
"space-before-function-paren": 0
52+
},
53+
"envs": [
54+
"node"
55+
]
56+
}
57+
}

Diff for: tasks/puglint.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* grunt-puglint
3+
* https://github.com/mrmlnc/grunt-puglint
4+
*/
5+
6+
'use strict';
7+
8+
var PugLint = require('pug-lint');
9+
var linter = new PugLint();
10+
var formatter = require('../lib/formatter');
11+
12+
module.exports = function(grunt) {
13+
grunt.registerMultiTask('puglint', 'Grunt plugin for pug-lint', function () {
14+
var done = this.async();
15+
var options = this.options({
16+
preset: 'clock'
17+
});
18+
19+
if (typeof options.preset === 'object') {
20+
options = options.preset;
21+
}
22+
23+
var pugLintRc = options.puglintrc;
24+
if (pugLintRc) {
25+
if (grunt.file.exists(pugLintRc)) {
26+
options = grunt.file.readJSON(pugLintRc);
27+
} else {
28+
grunt.log.error('Configuration file not found. Used a standard config: `clock`.');
29+
}
30+
}
31+
32+
linter.configure(options);
33+
34+
if (this.filesSrc.length === 0) {
35+
done();
36+
return;
37+
}
38+
39+
var errors = [];
40+
this.filesSrc.forEach(function(filepath) {
41+
errors = linter.checkFile(filepath);
42+
43+
if (errors.length) {
44+
formatter.formatOutput(errors);
45+
}
46+
});
47+
48+
done(errors.length === 0);
49+
});
50+
};

Diff for: test/fixtures/.pug-lintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"requireClassLiteralsBeforeIdLiterals": true
3+
}

Diff for: test/fixtures/invalid.jade

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
doctype html
2+
html(lang='en')
3+
head
4+
title= pageTitle
5+
script(type='text/javascript').
6+
if (foo) {
7+
bar(1 + 5)
8+
}
9+
body
10+
h1 Jade - node template engine
11+
#container.col
12+
if youAreUsingJade
13+
p You are amazing
14+
else
15+
p Get on it!
16+
17+
br(role='invalid')
18+
19+
p.
20+
Jade is a terse and simple
21+
templating language with a
22+
strong focus on performance
23+
and powerful features.

Diff for: test/test.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const test = require('ava');
4+
const exec = require('child_process').exec;
5+
6+
test.cb('Default test with default `clock` config', function(t) {
7+
exec('grunt puglint:clock', function(err, stdout) {
8+
var isOneError = /ID literals must/.test(stdout.toString());
9+
var isTwoError = /REQUIRECLASSLITERALSBEFOREIDLITERALS/.test(stdout.toString());
10+
11+
t.same(isOneError && isTwoError, true);
12+
t.end();
13+
});
14+
});
15+
16+
test.cb('Custom config with the string in the options', function(t) {
17+
exec('grunt puglint:customConfigString', function(err, stdout) {
18+
var isOneError = /DISALLOWSPECIFICATTRIBUTES/.test(stdout.toString());
19+
20+
t.same(isOneError, true);
21+
t.end();
22+
});
23+
});
24+
25+
test.cb('Custom config with the object in the options', function(t) {
26+
exec('grunt puglint:customConfigObject', function(err, stdout) {
27+
var isOneError = /DISALLOWIDLITERALS/.test(stdout.toString());
28+
29+
t.same(isOneError, true);
30+
t.end();
31+
});
32+
});
33+
34+
test.cb('RC file', function(t) {
35+
exec('grunt puglint:rcFile', function(err, stdout) {
36+
var isOneError = /REQUIRECLASSLITERALSBEFOREIDLITERALS/.test(stdout.toString());
37+
38+
t.same(isOneError, true);
39+
t.end();
40+
});
41+
});

0 commit comments

Comments
 (0)