Skip to content

Commit 6036877

Browse files
committed
lint the code
1 parent e8ff093 commit 6036877

File tree

5 files changed

+51
-2335
lines changed

5 files changed

+51
-2335
lines changed

lib/index.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const {assign, identity, negate, camelCase: camelCaseFunc, mapKeys} = require('lodash');
3+
const {assign, identity, negate} = require('lodash');
44
const {dirname, relative, resolve} = require('path');
55
const {readFileSync} = require('fs');
66
const {transformTokens} = require('./transformTokens');
@@ -48,16 +48,13 @@ module.exports = function setupHook({
4848
: process.env.NODE_ENV === 'development';
4949

5050
let scopedName;
51-
if (generateScopedName) {
51+
if (generateScopedName)
5252
scopedName = typeof generateScopedName !== 'function'
5353
? genericNames(generateScopedName, {context, hashPrefix}) // for example '[name]__[local]___[hash:base64:5]'
5454
: generateScopedName;
55-
} else {
55+
else
5656
// small fallback
57-
scopedName = (local, filename) => {
58-
return Scope.generateScopedName(local, relative(context, filename));
59-
};
60-
}
57+
scopedName = (local, filename) => Scope.generateScopedName(local, relative(context, filename));
6158

6259
const plugins = (use || [
6360
...prepend,
@@ -83,7 +80,7 @@ module.exports = function setupHook({
8380
*/
8481
function fetch(_to, from) {
8582
// getting absolute path to the processing file
86-
const filename = /[^\\/?%*:|"<>\.]/i.test(_to[0])
83+
const filename = /[^\\/?%*:|"<>.]/i.test(_to[0])
8784
? require.resolve(_to)
8885
: resolve(dirname(from), _to);
8986

@@ -104,23 +101,21 @@ module.exports = function setupHook({
104101

105102
tokens = lazyResult.root.tokens;
106103

107-
if (!debugMode) {
104+
if (!debugMode)
108105
// updating cache
109106
tokensByFile[filename] = tokens;
110-
} else {
107+
else
111108
// clearing cache in development mode
112109
delete require.cache[filename];
113-
}
114110

115-
if (processCss) {
111+
if (processCss)
116112
processCss(lazyResult.css, filename);
117-
}
118113

119114
debugFetch(`${filename} → fs`);
120115
debugFetch(tokens);
121116

122117
return tokens;
123-
};
118+
}
124119

125120
const exts = toArray(extensions);
126121
const isException = buildExceptionChecker(ignore);
@@ -149,13 +144,11 @@ function toArray(option) {
149144
* @return {function}
150145
*/
151146
function buildExceptionChecker(ignore) {
152-
if (ignore instanceof RegExp) {
147+
if (ignore instanceof RegExp)
153148
return filepath => ignore.test(filepath);
154-
}
155149

156-
if (typeof ignore === 'string') {
150+
if (typeof ignore === 'string')
157151
return filepath => globToRegex(ignore).test(filepath);
158-
}
159152

160153
return ignore || negate(identity);
161154
}

lib/transformTokens.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const camelizeDashedKeys = (acc, value, key) => {
1616

1717
const camelizeOnlyKeys = (acc, value, key) => {
1818
const camelizedKey = camelCase(key);
19-
if (camelizedKey !== key) acc[camelizedKey] = value
19+
if (camelizedKey !== key) acc[camelizedKey] = value;
2020
else acc[key] = value;
2121
return acc;
2222
};
2323

2424
const camelizeOnlyDashedKeys = (acc, value, key) => {
2525
const camelizedKey = camelizeDashes(key);
26-
if (camelizedKey !== key) acc[camelizedKey] = value
26+
if (camelizedKey !== key) acc[camelizedKey] = value;
2727
else acc[key] = value;
2828
return acc;
2929
};

lib/validate.js

+22-25
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,43 @@ const {
1414

1515
const rules = {
1616
// hook
17-
camelCase: 'boolean|string',
18-
devMode: 'boolean',
19-
extensions: 'array|string',
20-
ignore: 'function|regex|string',
21-
preprocessCss: 'function',
22-
processCss: 'function',
23-
processorOpts: 'object',
17+
camelCase: 'boolean|string',
18+
devMode: 'boolean',
19+
extensions: 'array|string',
20+
ignore: 'function|regex|string',
21+
preprocessCss: 'function',
22+
processCss: 'function',
23+
processorOpts: 'object',
2424
// plugins
25-
append: 'array',
26-
prepend: 'array',
27-
use: 'array',
25+
append: 'array',
26+
prepend: 'array',
27+
use: 'array',
2828
createImportedName: 'function',
2929
generateScopedName: 'function|string',
30-
hashPrefix: 'string',
31-
mode: 'string',
32-
rootDir: 'string',
30+
hashPrefix: 'string',
31+
mode: 'string',
32+
rootDir: 'string',
3333
};
3434

3535
const tests = {
36-
array: isArray,
37-
boolean: isBoolean,
36+
array: isArray,
37+
boolean: isBoolean,
3838
function: isFunction,
39-
object: isPlainObject,
40-
regex: isRegExp,
41-
string: isString,
39+
object: isPlainObject,
40+
regex: isRegExp,
41+
string: isString,
4242
};
4343

4444
module.exports = function validate(options) {
4545
const unknownOptions = difference(keys(options), keys(rules));
46-
if (unknownOptions.length) {
46+
if (unknownOptions.length)
4747
throw new Error(`unknown arguments: ${unknownOptions.join(', ')}.`);
48-
}
4948

5049
forEach(rules, (types, rule) => {
51-
if (typeof options[rule] === 'undefined') {
50+
if (typeof options[rule] === 'undefined')
5251
return;
53-
}
5452

55-
if (!types.split('|').some(type => tests[type](options[rule]))) {
53+
if (!types.split('|').some(type => tests[type](options[rule])))
5654
throw new TypeError(`should specify ${types} as ${rule}`);
57-
}
5855
});
59-
}
56+
};

0 commit comments

Comments
 (0)