Skip to content

Commit 2adcca3

Browse files
style: use prettier (#644)
1 parent bc3b848 commit 2adcca3

29 files changed

+1219
-978
lines changed

.editorconfig

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# This file is for unifying the coding style for different editors and IDEs.
2-
# More information at http://EditorConfig.org
3-
4-
# No .editorconfig files above the root directory
5-
root = true
1+
# editorconfig.org
62

73
[*]
8-
indent_style = space
9-
indent_size = 4
104
charset = utf-8
11-
trim_trailing_whitespace = true
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
128
insert_final_newline = true
9+
trim_trailing_whitespace = true
1310

14-
[package.json]
15-
indent_size = 2
11+
[*.md]
12+
insert_final_newline = true
13+
trim_trailing_whitespace = false

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
/node_modules
12
# Compiled by webpack
23
test/output
3-
44
# Fake node_modules folder for tests
55
test/node_modules

.eslintrc.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module.exports = {
2-
root: true,
3-
extends: ['@webpack-contrib/eslint-config-webpack'],
4-
rules: {
5-
// Remove strict rule in next major
6-
"strict": "off",
7-
},
2+
root: true,
3+
plugins: ['prettier'],
4+
extends: ['@webpack-contrib/eslint-config-webpack'],
5+
rules: {
6+
// Remove strict rule in next major
7+
strict: 'off',
8+
'prettier/prettier': [
9+
'error',
10+
{ singleQuote: true, trailingComma: 'es5', arrowParens: 'always' },
11+
],
12+
},
813
};

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package-lock.json -diff
2+
* text=auto
3+
bin/* eol=lf

.gitignore

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
lib-cov
2-
*.seed
3-
*.log
4-
*.csv
5-
*.dat
6-
*.out
7-
*.pid
8-
*.gz
9-
10-
pids
111
logs
12-
results
2+
*.log
3+
npm-debug.log*
4+
.eslintcache
135

14-
npm-debug.log
6+
/coverage
7+
/dist
8+
/local
9+
/reports
1510
/node_modules
16-
coverage
11+
12+
.DS_Store
13+
Thumbs.db
1714
.idea
15+
*.iml
16+
.vscode
17+
*.sublime-project
18+
*.sublime-workspace
1819
.nyc_output
1920
test/output

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"arrowParens": "always"
5+
}

lib/formatSassError.js

+39-38
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"use strict";
1+
'use strict';
22

3-
const path = require("path");
4-
const os = require("os");
5-
const fs = require("fs");
3+
const path = require('path');
4+
const os = require('os');
5+
const fs = require('fs');
66

77
// A typical sass error looks like this
88
// const SassError = {
@@ -20,36 +20,37 @@ const fs = require("fs");
2020
* @param {string} resourcePath
2121
*/
2222
function formatSassError(err, resourcePath) {
23-
// Instruct webpack to hide the JS stack from the console
24-
// Usually you're only interested in the SASS stack in this case.
25-
// eslint-disable-next-line no-param-reassign
26-
err.hideStack = true;
27-
28-
// The file property is missing in rare cases.
29-
// No improvement in the error is possible.
30-
if (!err.file) {
31-
return;
32-
}
23+
// Instruct webpack to hide the JS stack from the console
24+
// Usually you're only interested in the SASS stack in this case.
25+
// eslint-disable-next-line no-param-reassign
26+
err.hideStack = true;
3327

34-
let msg = err.message;
28+
// The file property is missing in rare cases.
29+
// No improvement in the error is possible.
30+
if (!err.file) {
31+
return;
32+
}
3533

36-
if (err.file === "stdin") {
37-
// eslint-disable-next-line no-param-reassign
38-
err.file = resourcePath;
39-
}
34+
let msg = err.message;
4035

41-
// node-sass returns UNIX-style paths
36+
if (err.file === 'stdin') {
4237
// eslint-disable-next-line no-param-reassign
43-
err.file = path.normalize(err.file);
38+
err.file = resourcePath;
39+
}
4440

45-
// The 'Current dir' hint of node-sass does not help us, we're providing
46-
// additional information by reading the err.file property
47-
msg = msg.replace(/\s*Current dir:\s*/, "");
41+
// node-sass returns UNIX-style paths
42+
// eslint-disable-next-line no-param-reassign
43+
err.file = path.normalize(err.file);
4844

49-
// eslint-disable-next-line no-param-reassign
50-
err.message = `${getFileExcerptIfPossible(err) +
51-
msg.charAt(0).toUpperCase() + msg.slice(1) + os.EOL
52-
} in ${ err.file } (line ${ err.line }, column ${ err.column })`;
45+
// The 'Current dir' hint of node-sass does not help us, we're providing
46+
// additional information by reading the err.file property
47+
msg = msg.replace(/\s*Current dir:\s*/, '');
48+
49+
// eslint-disable-next-line no-param-reassign
50+
err.message = `${getFileExcerptIfPossible(err) +
51+
msg.charAt(0).toUpperCase() +
52+
msg.slice(1) +
53+
os.EOL} in ${err.file} (line ${err.line}, column ${err.column})`;
5354
}
5455

5556
/**
@@ -62,17 +63,17 @@ function formatSassError(err, resourcePath) {
6263
* @returns {string}
6364
*/
6465
function getFileExcerptIfPossible(err) {
65-
try {
66-
const content = fs.readFileSync(err.file, "utf8");
66+
try {
67+
const content = fs.readFileSync(err.file, 'utf8');
6768

68-
return `${os.EOL +
69-
content.split(os.EOL)[err.line - 1] + os.EOL +
70-
new Array(err.column - 1).join(" ") }^${ os.EOL
71-
} `;
72-
} catch (ignoreErr) {
73-
// If anything goes wrong here, we don't want any errors to be reported to the user
74-
return "";
75-
}
69+
return `${os.EOL +
70+
content.split(os.EOL)[err.line - 1] +
71+
os.EOL +
72+
new Array(err.column - 1).join(' ')}^${os.EOL} `;
73+
} catch (ignoreErr) {
74+
// If anything goes wrong here, we don't want any errors to be reported to the user
75+
return '';
76+
}
7677
}
7778

7879
module.exports = formatSassError;

lib/importsToResolve.js

+44-43
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"use strict";
1+
'use strict';
22

3-
const path = require("path");
3+
const path = require('path');
44

5-
const utils = require("loader-utils");
5+
const utils = require('loader-utils');
66

77
const matchModuleImport = /^~([^/]+|@[^/]+[/][^/]+)$/;
88

@@ -16,46 +16,47 @@ const matchModuleImport = /^~([^/]+|@[^/]+[/][^/]+)$/;
1616
* @returns {Array<string>}
1717
*/
1818
function importsToResolve(url) {
19-
const request = utils.urlToRequest(url);
20-
// Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
21-
// @see https://github.com/webpack-contrib/sass-loader/issues/167
22-
const ext = path.extname(request);
23-
24-
if (matchModuleImport.test(url)) {
25-
return [request, url];
26-
}
27-
28-
// libsass' import algorithm works like this:
29-
30-
// In case there is a file extension...
31-
// - If the file is a CSS-file, do not include it all, but just link it via @import url().
32-
// - The exact file name must match (no auto-resolving of '_'-modules).
33-
if (ext === ".css") {
34-
return [];
35-
}
36-
if (ext === ".scss" || ext === ".sass") {
37-
return [request, url];
38-
}
39-
40-
// In case there is no file extension...
41-
// - Prefer modules starting with '_'.
42-
// - File extension precedence: .scss, .sass, .css.
43-
const basename = path.basename(request);
44-
45-
if (basename.charAt(0) === "_") {
46-
return [
47-
`${ request }.scss`, `${ request }.sass`, `${ request }.css`,
48-
url
49-
];
50-
}
51-
52-
const dirname = path.dirname(request);
53-
54-
return [
55-
`${ dirname }/_${ basename }.scss`, `${ dirname }/_${ basename }.sass`, `${ dirname }/_${ basename }.css`,
56-
`${ request }.scss`, `${ request }.sass`, `${ request }.css`,
57-
url
58-
];
19+
const request = utils.urlToRequest(url);
20+
// Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
21+
// @see https://github.com/webpack-contrib/sass-loader/issues/167
22+
const ext = path.extname(request);
23+
24+
if (matchModuleImport.test(url)) {
25+
return [request, url];
26+
}
27+
28+
// libsass' import algorithm works like this:
29+
30+
// In case there is a file extension...
31+
// - If the file is a CSS-file, do not include it all, but just link it via @import url().
32+
// - The exact file name must match (no auto-resolving of '_'-modules).
33+
if (ext === '.css') {
34+
return [];
35+
}
36+
if (ext === '.scss' || ext === '.sass') {
37+
return [request, url];
38+
}
39+
40+
// In case there is no file extension...
41+
// - Prefer modules starting with '_'.
42+
// - File extension precedence: .scss, .sass, .css.
43+
const basename = path.basename(request);
44+
45+
if (basename.charAt(0) === '_') {
46+
return [`${request}.scss`, `${request}.sass`, `${request}.css`, url];
47+
}
48+
49+
const dirname = path.dirname(request);
50+
51+
return [
52+
`${dirname}/_${basename}.scss`,
53+
`${dirname}/_${basename}.sass`,
54+
`${dirname}/_${basename}.css`,
55+
`${request}.scss`,
56+
`${request}.sass`,
57+
`${request}.css`,
58+
url,
59+
];
5960
}
6061

6162
module.exports = importsToResolve;

0 commit comments

Comments
 (0)