Skip to content

Commit ca0607f

Browse files
committed
Tweak code style
1 parent 8f63f03 commit ca0607f

File tree

4 files changed

+437
-437
lines changed

4 files changed

+437
-437
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"lint-staged": {
2222
"*.js": [
2323
"eslint",
24-
"prettier --single-quote --no-semi --write",
24+
"prettier --write",
2525
"git add"
2626
]
2727
},

src/index.js

Lines changed: 105 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,208 +1,208 @@
11
/* eslint-env node */
2-
import postcss from 'postcss'
3-
import Tokenizer from 'css-selector-tokenizer'
2+
import postcss from "postcss";
3+
import Tokenizer from "css-selector-tokenizer";
44

55
function normalizeNodeArray(nodes) {
6-
var array = []
6+
var array = [];
77
nodes.forEach(function(x) {
88
if (Array.isArray(x)) {
99
normalizeNodeArray(x).forEach(function(item) {
10-
array.push(item)
11-
})
10+
array.push(item);
11+
});
1212
} else if (x) {
13-
array.push(x)
13+
array.push(x);
1414
}
15-
})
16-
if (array.length > 0 && array[array.length - 1].type === 'spacing') {
17-
array.pop()
15+
});
16+
if (array.length > 0 && array[array.length - 1].type === "spacing") {
17+
array.pop();
1818
}
19-
return array
19+
return array;
2020
}
2121

2222
function localizeNode(node, context) {
23-
if (context.ignoreNextSpacing && node.type !== 'spacing') {
24-
throw new Error('Missing whitespace after :' + context.ignoreNextSpacing)
23+
if (context.ignoreNextSpacing && node.type !== "spacing") {
24+
throw new Error("Missing whitespace after :" + context.ignoreNextSpacing);
2525
}
26-
if (context.enforceNoSpacing && node.type === 'spacing') {
27-
throw new Error('Missing whitespace before :' + context.enforceNoSpacing)
26+
if (context.enforceNoSpacing && node.type === "spacing") {
27+
throw new Error("Missing whitespace before :" + context.enforceNoSpacing);
2828
}
2929

30-
var newNodes
30+
var newNodes;
3131
switch (node.type) {
32-
case 'selectors':
33-
var resultingGlobal
34-
context.hasPureGlobals = false
32+
case "selectors":
33+
var resultingGlobal;
34+
context.hasPureGlobals = false;
3535
newNodes = node.nodes.map(function(n) {
3636
var nContext = {
3737
global: context.global,
3838
lastWasSpacing: true,
3939
hasLocals: false,
4040
explicit: false
41-
}
42-
n = localizeNode(n, nContext)
43-
if (typeof resultingGlobal === 'undefined') {
44-
resultingGlobal = nContext.global
41+
};
42+
n = localizeNode(n, nContext);
43+
if (typeof resultingGlobal === "undefined") {
44+
resultingGlobal = nContext.global;
4545
} else if (resultingGlobal !== nContext.global) {
4646
throw new Error(
4747
'Inconsistent rule global/local result in rule "' +
4848
Tokenizer.stringify(node) +
4949
'" (multiple selectors must result in the same mode for the rule)'
50-
)
50+
);
5151
}
5252
if (!nContext.hasLocals) {
53-
context.hasPureGlobals = true
53+
context.hasPureGlobals = true;
5454
}
55-
return n
56-
})
57-
context.global = resultingGlobal
58-
node = Object.create(node)
59-
node.nodes = normalizeNodeArray(newNodes)
60-
break
55+
return n;
56+
});
57+
context.global = resultingGlobal;
58+
node = Object.create(node);
59+
node.nodes = normalizeNodeArray(newNodes);
60+
break;
6161

62-
case 'selector':
62+
case "selector":
6363
newNodes = node.nodes.map(function(n) {
64-
return localizeNode(n, context)
65-
})
66-
node = Object.create(node)
67-
node.nodes = normalizeNodeArray(newNodes)
68-
break
64+
return localizeNode(n, context);
65+
});
66+
node = Object.create(node);
67+
node.nodes = normalizeNodeArray(newNodes);
68+
break;
6969

70-
case 'spacing':
70+
case "spacing":
7171
if (context.ignoreNextSpacing) {
72-
context.ignoreNextSpacing = false
73-
context.lastWasSpacing = false
74-
context.enforceNoSpacing = false
75-
return null
72+
context.ignoreNextSpacing = false;
73+
context.lastWasSpacing = false;
74+
context.enforceNoSpacing = false;
75+
return null;
7676
}
77-
context.lastWasSpacing = true
78-
return node
77+
context.lastWasSpacing = true;
78+
return node;
7979

80-
case 'pseudo-class':
81-
if (node.name === 'local' || node.name === 'global') {
80+
case "pseudo-class":
81+
if (node.name === "local" || node.name === "global") {
8282
if (context.inside) {
8383
throw new Error(
84-
'A :' +
84+
"A :" +
8585
node.name +
86-
' is not allowed inside of a :' +
86+
" is not allowed inside of a :" +
8787
context.inside +
88-
'(...)'
89-
)
88+
"(...)"
89+
);
9090
}
91-
context.ignoreNextSpacing = context.lastWasSpacing ? node.name : false
92-
context.enforceNoSpacing = context.lastWasSpacing ? false : node.name
93-
context.global = node.name === 'global'
94-
context.explicit = true
95-
return null
91+
context.ignoreNextSpacing = context.lastWasSpacing ? node.name : false;
92+
context.enforceNoSpacing = context.lastWasSpacing ? false : node.name;
93+
context.global = node.name === "global";
94+
context.explicit = true;
95+
return null;
9696
}
97-
break
97+
break;
9898

99-
case 'nested-pseudo-class':
100-
var subContext
101-
if (node.name === 'local' || node.name === 'global') {
99+
case "nested-pseudo-class":
100+
var subContext;
101+
if (node.name === "local" || node.name === "global") {
102102
if (context.inside) {
103103
throw new Error(
104-
'A :' +
104+
"A :" +
105105
node.name +
106-
'(...) is not allowed inside of a :' +
106+
"(...) is not allowed inside of a :" +
107107
context.inside +
108-
'(...)'
109-
)
108+
"(...)"
109+
);
110110
}
111111
subContext = {
112-
global: node.name === 'global',
112+
global: node.name === "global",
113113
inside: node.name,
114114
hasLocals: false,
115115
explicit: true
116-
}
116+
};
117117
node = node.nodes.map(function(n) {
118-
return localizeNode(n, subContext)
119-
})
118+
return localizeNode(n, subContext);
119+
});
120120
// don't leak spacing
121-
node[0].before = undefined
122-
node[node.length - 1].after = undefined
121+
node[0].before = undefined;
122+
node[node.length - 1].after = undefined;
123123
} else {
124124
subContext = {
125125
global: context.global,
126126
inside: context.inside,
127127
lastWasSpacing: true,
128128
hasLocals: false,
129129
explicit: context.explicit
130-
}
130+
};
131131
newNodes = node.nodes.map(function(n) {
132-
return localizeNode(n, subContext)
133-
})
134-
node = Object.create(node)
135-
node.nodes = normalizeNodeArray(newNodes)
132+
return localizeNode(n, subContext);
133+
});
134+
node = Object.create(node);
135+
node.nodes = normalizeNodeArray(newNodes);
136136
}
137137
if (subContext.hasLocals) {
138-
context.hasLocals = true
138+
context.hasLocals = true;
139139
}
140-
break
140+
break;
141141

142-
case 'id':
143-
case 'class':
142+
case "id":
143+
case "class":
144144
if (!context.global) {
145145
node = {
146-
type: 'nested-pseudo-class',
147-
name: 'local',
146+
type: "nested-pseudo-class",
147+
name: "local",
148148
nodes: [node]
149-
}
150-
context.hasLocals = true
149+
};
150+
context.hasLocals = true;
151151
}
152-
break
152+
break;
153153
}
154154

155155
// reset context
156-
context.lastWasSpacing = false
157-
context.ignoreNextSpacing = false
158-
context.enforceNoSpacing = false
159-
return node
156+
context.lastWasSpacing = false;
157+
context.ignoreNextSpacing = false;
158+
context.enforceNoSpacing = false;
159+
return node;
160160
}
161161

162162
module.exports = postcss.plugin(
163-
'postcss-modules-local-by-default',
163+
"postcss-modules-local-by-default",
164164
(options = {}) => css => {
165165
if (
166166
options.mode &&
167-
options.mode !== 'global' &&
168-
options.mode !== 'local' &&
169-
options.mode !== 'pure'
167+
options.mode !== "global" &&
168+
options.mode !== "local" &&
169+
options.mode !== "pure"
170170
) {
171171
throw Error(
172172
'options.mode must be either "global", "local" or "pure" (default "local")'
173-
)
173+
);
174174
}
175-
var pureMode = options.mode === 'pure'
176-
var globalMode = options.mode === 'global'
175+
var pureMode = options.mode === "pure";
176+
var globalMode = options.mode === "global";
177177
css.walkRules(function(rule) {
178178
if (
179-
rule.parent.type === 'atrule' &&
179+
rule.parent.type === "atrule" &&
180180
/keyframes$/.test(rule.parent.name)
181181
) {
182182
// ignore keyframe rules
183-
return
183+
return;
184184
}
185-
var selector = Tokenizer.parse(rule.selector)
185+
var selector = Tokenizer.parse(rule.selector);
186186
var context = {
187187
options: options,
188188
global: globalMode,
189189
hasPureGlobals: false
190-
}
191-
var newSelector
190+
};
191+
var newSelector;
192192
try {
193-
newSelector = localizeNode(selector, context)
193+
newSelector = localizeNode(selector, context);
194194
} catch (e) {
195-
throw rule.error(e.message)
195+
throw rule.error(e.message);
196196
}
197197
if (pureMode && context.hasPureGlobals) {
198198
throw rule.error(
199199
'Selector "' +
200200
Tokenizer.stringify(selector) +
201201
'" is not pure ' +
202-
'(pure selectors must contain at least one local class or id)'
203-
)
202+
"(pure selectors must contain at least one local class or id)"
203+
);
204204
}
205-
rule.selector = Tokenizer.stringify(newSelector)
206-
})
205+
rule.selector = Tokenizer.stringify(newSelector);
206+
});
207207
}
208-
)
208+
);

0 commit comments

Comments
 (0)