Skip to content

Commit ca8a555

Browse files
committed
Add code
1 parent 2b2e405 commit ca8a555

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
# airtight-css-lint-loader
2-
Webpack loader for Airtight CSS Linter
1+
# Airtight CSS Lint Webpack Loader
2+
A webpack loader for [Airtight CSS Linter](https://github.com/unframework/airtight-css-lint)
3+
4+
## Options
5+
6+
### failTypeError
7+
8+
`boolean` `default: true`
9+
10+
This will output errors if true. If this is set to false warnings will be used instead. The difference is messaging as well as ability to fail on error.
11+
12+
### failOnError
13+
14+
`boolean` `default: true`
15+
16+
If the `failTypeError` is set to `true` this option grants the ability to fail the webpack process.

index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var checkCSS = require('airtight-css-lint');
2+
var loaderUtils = require('loader-utils');
3+
var assign = require("object-assign");
4+
5+
function checkCSSLoader(input, options, webpack, callback) {
6+
var results = [];
7+
8+
checkCSS(input, function (line, col, msg) {
9+
results.push([ 'Line ' + line + ':' + col + ' - ' + msg ]);
10+
});
11+
12+
if (results) {
13+
for (var i = 0; i < results.length; i++){
14+
if (options.failTypeError) {
15+
webpack.emitError(results[i]);
16+
} else {
17+
webpack.emitWarning(results[i]);
18+
}
19+
}
20+
21+
if (options.failTypeError && options.failOnError) {
22+
throw new Error("Airtight CSS Lint Error");
23+
}
24+
}
25+
26+
if (callback) {
27+
callback(null, input);
28+
}
29+
}
30+
31+
module.exports = function(input) {
32+
var options = assign(
33+
{
34+
failTypeError: true, // Use warning if false
35+
failOnError: true // Only applies to errors
36+
},
37+
loaderUtils.parseQuery(this.query)
38+
);
39+
40+
this.cacheable();
41+
var callback = this.async();
42+
43+
if (!callback) {
44+
checkCSSLoader(input, options, this);
45+
46+
return input;
47+
} else {
48+
try {
49+
checkCSSLoader(input, options, this, callback);
50+
} catch(e) {
51+
callback(e);
52+
}
53+
}
54+
}

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "airtight-css-lint-loader",
3+
"version": "0.0.1",
4+
"description": "A webpack loader for Airtight CSS linter",
5+
"main": "index.js",
6+
"author": "Jerry Low <lowjer@gmail.com>",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/jerrylow/airtight-css-lint-loader.git"
10+
},
11+
"license": "BSD",
12+
"dependencies": {
13+
"airtight-css-lint": "~0.3.1",
14+
"loader-utils": "^0.2.16",
15+
"object-assign": "^4.1.1"
16+
}
17+
}

0 commit comments

Comments
 (0)