Skip to content

Commit 144798f

Browse files
committed
Use coding style from eslint-config-peerigon
1 parent 1c089f1 commit 144798f

File tree

8 files changed

+321
-314
lines changed

8 files changed

+321
-314
lines changed

.editorconfig

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
# EditorConfig is awesome: http://EditorConfig.org
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://EditorConfig.org
23

3-
# top-most EditorConfig file
4+
# No .editorconfig files above the root directory
45
root = true
56

6-
# Unix-style newlines with a newline ending every file
77
[*]
8+
indent_style = space
9+
indent_size = 4
810
charset = utf-8
9-
end_of_line = lf
11+
trim_trailing_whitespace = true
1012
insert_final_newline = true
11-
indent_style = tab
12-
indent_size = 4
1313

14-
# Matches the exact files either package.json or .travis.yml
15-
[{package.json,.travis.yml}]
16-
indent_style = space
14+
[package.json]
1715
indent_size = 2

.nycrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"include": [
77
"lib/**/*.js"
88
],
9-
"lines": 94,
9+
"lines": 92,
1010
"statements": 92,
1111
"functions": 100,
1212
"branches": 70,

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Chain the less-loader with the [css-loader](https://github.com/webpack-contrib/c
3333
```js
3434
// webpack.config.js
3535
module.exports = {
36-
...
36+
...
3737
module: {
3838
rules: [{
3939
test: /\.less$/,
@@ -54,7 +54,7 @@ You can pass any Less specific options to the less-loader via [loader options](h
5454
```js
5555
// webpack.config.js
5656
module.exports = {
57-
...
57+
...
5858
module: {
5959
rules: [{
6060
test: /\.less$/,
@@ -86,7 +86,7 @@ const extractLess = new ExtractTextPlugin({
8686
});
8787

8888
module.exports = {
89-
...
89+
...
9090
module: {
9191
rules: [{
9292
test: /\.less$/,
@@ -130,7 +130,7 @@ In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the `le
130130
const CleanCSSPlugin = require("less-plugin-clean-css");
131131

132132
module.exports = {
133-
...
133+
...
134134
{
135135
loader: "less-loader", options: {
136136
lessPlugins: [

lib/loader.js

Lines changed: 125 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,133 @@
11
"use strict";
2-
/*
3-
MIT License http://www.opensource.org/licenses/mit-license.php
4-
Authors
5-
Tobias Koppers @sokra
6-
Johannes Ewald @jhnns
7-
*/
8-
var less = require("less");
9-
var loaderUtils = require("loader-utils");
10-
var cloneDeep = require("clone-deep");
11-
12-
var trailingSlash = /[\\\/]$/;
13-
14-
module.exports = function(source) {
15-
var loaderContext = this;
16-
var options = Object.assign(
17-
{
18-
filename: this.resource,
19-
paths: [],
20-
plugins: [],
21-
relativeUrls: true,
22-
compress: Boolean(this.minimize)
23-
},
24-
cloneDeep(loaderUtils.getOptions(this))
25-
);
26-
var cb = this.async();
27-
var isSync = typeof cb !== "function";
28-
var finalCb = cb || this.callback;
29-
var webpackPlugin = {
30-
install: function(less, pluginManager) {
31-
var WebpackFileManager = getWebpackFileManager(less, loaderContext, options);
32-
33-
pluginManager.addFileManager(new WebpackFileManager());
34-
},
35-
minVersion: [2, 1, 1]
36-
};
37-
38-
if (isSync) {
39-
throw new Error("Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/less-loader/issues/84");
40-
}
41-
42-
options.plugins.push(webpackPlugin);
43-
44-
if (options.sourceMap) {
45-
options.sourceMap = {
46-
outputSourceFiles: true
47-
};
48-
}
49-
50-
less.render(source, options, function(e, result) {
51-
var cb = finalCb;
52-
// Less is giving us double callbacks sometimes :(
53-
// Thus we need to mark the callback as "has been called"
54-
if(!finalCb) return;
55-
finalCb = null;
56-
if(e) return cb(formatLessRenderError(e));
57-
58-
cb(null, result.css, result.map);
59-
});
2+
3+
const less = require("less");
4+
const loaderUtils = require("loader-utils");
5+
const cloneDeep = require("clone-deep");
6+
7+
const trailingSlash = /[\\\/]$/;
8+
9+
module.exports = function (source) {
10+
const loaderContext = this;
11+
const options = Object.assign(
12+
{
13+
filename: this.resource,
14+
paths: [],
15+
plugins: [],
16+
relativeUrls: true,
17+
compress: Boolean(this.minimize)
18+
},
19+
cloneDeep(loaderUtils.getOptions(this))
20+
);
21+
const cb = this.async();
22+
const isSync = typeof cb !== "function";
23+
let finalCb = cb || this.callback;
24+
const webpackPlugin = {
25+
install(less, pluginManager) {
26+
const WebpackFileManager = getWebpackFileManager(less, loaderContext, options);
27+
28+
pluginManager.addFileManager(new WebpackFileManager());
29+
},
30+
minVersion: [2, 1, 1]
31+
};
32+
33+
if (isSync) {
34+
throw new Error("Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/less-loader/issues/84");
35+
}
36+
37+
options.plugins.push(webpackPlugin);
38+
39+
if (options.sourceMap) {
40+
options.sourceMap = {
41+
outputSourceFiles: true
42+
};
43+
}
44+
45+
less.render(source, options, (e, result) => {
46+
const cb = finalCb;
47+
// Less is giving us double callbacks sometimes :(
48+
// Thus we need to mark the callback as "has been called"
49+
50+
if (!finalCb) {
51+
return;
52+
}
53+
finalCb = null;
54+
if (e) {
55+
cb(formatLessRenderError(e));
56+
return;
57+
}
58+
59+
cb(null, result.css, result.map);
60+
});
6061
};
6162

6263
function getWebpackFileManager(less, loaderContext, query, isSync) {
63-
64-
function WebpackFileManager() {
65-
less.FileManager.apply(this, arguments);
66-
}
67-
68-
WebpackFileManager.prototype = Object.create(less.FileManager.prototype);
69-
70-
WebpackFileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
71-
// Our WebpackFileManager handles all the files
72-
return true;
73-
};
74-
75-
WebpackFileManager.prototype.supportsSync = function(filename, currentDirectory, options, environment) {
76-
return false;
77-
};
78-
79-
WebpackFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) {
80-
var moduleRequest = loaderUtils.urlToRequest(filename, query.root);
81-
// Less is giving us trailing slashes, but the context should have no trailing slash
82-
var context = currentDirectory.replace(trailingSlash, "");
83-
84-
loaderContext.resolve(context, moduleRequest, function(err, filename) {
85-
if(err) {
86-
callback(err);
87-
return;
88-
}
89-
90-
loaderContext.dependency && loaderContext.dependency(filename);
91-
// The default (asynchronous)
92-
loaderContext.loadModule("-!" + __dirname + "/stringify.loader.js!" + filename, function(err, data) {
93-
if(err) {
94-
callback(err);
95-
return;
96-
}
97-
98-
callback(null, {
99-
contents: JSON.parse(data),
100-
filename: filename
101-
});
102-
});
103-
});
104-
};
105-
106-
return WebpackFileManager;
64+
function WebpackFileManager() {
65+
less.FileManager.apply(this, arguments);
66+
}
67+
68+
WebpackFileManager.prototype = Object.create(less.FileManager.prototype);
69+
70+
WebpackFileManager.prototype.supports = function (filename, currentDirectory, options, environment) {
71+
// Our WebpackFileManager handles all the files
72+
return true;
73+
};
74+
75+
WebpackFileManager.prototype.supportsSync = function (filename, currentDirectory, options, environment) {
76+
return false;
77+
};
78+
79+
WebpackFileManager.prototype.loadFile = function (filename, currentDirectory, options, environment, callback) {
80+
const moduleRequest = loaderUtils.urlToRequest(filename, query.root);
81+
// Less is giving us trailing slashes, but the context should have no trailing slash
82+
const context = currentDirectory.replace(trailingSlash, "");
83+
84+
loaderContext.resolve(context, moduleRequest, (err, filename) => {
85+
if (err) {
86+
callback(err);
87+
return;
88+
}
89+
90+
loaderContext.dependency && loaderContext.dependency(filename);
91+
// The default (asynchronous)
92+
// loadModule() accepts a request. Thus it's ok to not use path.resolve()
93+
loaderContext.loadModule("-!" + __dirname + "/stringify.loader.js!" + filename, (err, data) => { // eslint-disable-line no-path-concat
94+
if (err) {
95+
callback(err);
96+
return;
97+
}
98+
99+
callback(null, {
100+
contents: JSON.parse(data),
101+
filename
102+
});
103+
});
104+
});
105+
};
106+
107+
return WebpackFileManager;
107108
}
108109

109110
function formatLessRenderError(e) {
110-
// Example ``e``:
111-
// { type: 'Name',
112-
// message: '.undefined-mixin is undefined',
113-
// filename: '/path/to/style.less',
114-
// index: 352,
115-
// line: 31,
116-
// callLine: NaN,
117-
// callExtract: undefined,
118-
// column: 6,
119-
// extract:
120-
// [ ' .my-style {',
121-
// ' .undefined-mixin;',
122-
// ' display: block;' ] }
123-
var extract = e.extract? "\n near lines:\n " + e.extract.join("\n ") : "";
124-
var err = new Error(
125-
e.message + "\n @ " + e.filename +
126-
" (line " + e.line + ", column " + e.column + ")" +
127-
extract
128-
);
129-
err.hideStack = true;
130-
return err;
111+
// Example ``e``:
112+
// { type: 'Name',
113+
// message: '.undefined-mixin is undefined',
114+
// filename: '/path/to/style.less',
115+
// index: 352,
116+
// line: 31,
117+
// callLine: NaN,
118+
// callExtract: undefined,
119+
// column: 6,
120+
// extract:
121+
// [ ' .my-style {',
122+
// ' .undefined-mixin;',
123+
// ' display: block;' ] }
124+
const extract = e.extract ? "\n near lines:\n " + e.extract.join("\n ") : "";
125+
const err = new Error(
126+
e.message + "\n @ " + e.filename +
127+
" (line " + e.line + ", column " + e.column + ")" +
128+
extract
129+
);
130+
131+
err.hideStack = true;
132+
return err;
131133
}

lib/stringify.loader.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/*
2-
MIT License http://www.opensource.org/licenses/mit-license.php
3-
Author Tobias Koppers @sokra
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
44
*/
5-
module.exports = function(source) {
6-
if(this.cacheable) this.cacheable();
7-
return JSON.stringify(source);
5+
module.exports = function (source) {
6+
if (this.cacheable) {
7+
this.cacheable();
8+
}
9+
return JSON.stringify(source);
810
};

0 commit comments

Comments
 (0)