Skip to content

Commit 4f42876

Browse files
author
Kenji Shimizu
committed
updates
1 parent e56a858 commit 4f42876

File tree

2 files changed

+27
-97
lines changed

2 files changed

+27
-97
lines changed

CSS-SASS.md

+24-8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ A good example is a simple card:
6969
</div>
7070
```
7171

72+
### Do not use SASS `&__` or `&--`
73+
74+
That will make it much harder to debug and find the line of code.
75+
76+
```scss
77+
// Wrong
78+
.product {
79+
color: black;
80+
81+
&__image {
82+
opacity: 1;
83+
}
84+
}
85+
86+
// Right
87+
.product {
88+
color: black;
89+
}
90+
91+
.product__image {
92+
opacity: 1;
93+
}
94+
```
95+
7296
### Avoid over-qualified selectors by (unnecessary) nesting
7397

7498
That means the following code should be avoided. Not only because it produces more code, it also makes it harder to keep track of the parent-children chain, and harder to debug in some cases. The longer the rules, the harder it gets to keep track of the parent when deep nesting is used.
@@ -147,14 +171,6 @@ In slightly more complex situations, blocks can also be elements of other blocks
147171
}
148172
```
149173

150-
### Use `rem()` when defining custom pixel dimensions
151-
152-
```scss
153-
.block {
154-
font-size: rem(16px);
155-
}
156-
```
157-
158174
### Use `media-min` and `media-max` mixins for breakpoints
159175

160176
```scss

JAVASCRIPT.md

+3-89
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,7 @@ if (a !== '') {
147147
}
148148
```
149149

150-
### Ternary operator (???)
151-
152-
> Should this be a hard rule?
153-
154-
Use single-line ternary operators for short expressions only. Split it up into multiple lines otherwise.
155-
156-
```js
157-
// Wrong
158-
var bar = (a === b) ? anIncrediblyLong.map((expression) => expression.whichWillTake === aHugeSpace) : false;
159-
160-
// Right
161-
var foo = (a === b) ? 1 : 2;
162-
var bar = (a === b)
163-
? anIncrediblyLong.map((expression) => expression.whichWillTake === aHugeSpace)
164-
: false;
165-
```
166-
167-
### Do not extend built-in prototypes (???)
168-
169-
> Should this even be here? Who does this nowadays?
150+
### Do not extend built-in prototypes
170151

171152
```js
172153
// Wrong
@@ -259,11 +240,9 @@ req.on('end', function onEnd() {
259240
});
260241
```
261242

262-
### No nested closures (???)
243+
### Avoid nested closures
263244

264-
> Are are keeping this? I don't remember seeing any of our code using this rule.
265-
266-
Use closures, but don't nest them. Otherwise your code will become a mess.
245+
Use closures, but avoid nesting them whenever possible.
267246

268247
```js
269248
// Wrong
@@ -283,71 +262,6 @@ setTimeout(() => {
283262
}, 1000);
284263
```
285264

286-
### Use slashes for comments (???)
287-
288-
> Is this how we want comments?
289-
> This can be moved to a "general principles" doc.
290-
291-
Use slashes for both single line and multi line comments. Try to write
292-
comments that explain higher level mechanisms or clarify difficult
293-
segments of your code. Don't use comments to restate trivial things.
294-
295-
```js
296-
// Wrong
297-
298-
/* Execute a regex */
299-
var matches = item.match(/ID_([^\n]+)=([^\n]+)/));
300-
301-
// Usage: loadUser(5, function() { ... })
302-
function loadUser(id, cb) {
303-
// ...
304-
}
305-
306-
// Check if the session is valid
307-
var isSessionValid = (session.expires < Date.now());
308-
// If the session is valid
309-
if (isSessionValid) {
310-
// ...
311-
}
312-
313-
314-
// Right
315-
316-
// 'ID_SOMETHING=VALUE' -> ['ID_SOMETHING=VALUE'', 'SOMETHING', 'VALUE']
317-
var matches = item.match(/ID_([^\n]+)=([^\n]+)/));
318-
319-
// This function has a nasty side effect where a failure to increment a
320-
// redis counter used for statistics will cause an exception. This needs
321-
// to be fixed in a later iteration.
322-
function loadUser(id, cb) {
323-
// ...
324-
}
325-
326-
var isSessionValid = (session.expires < Date.now());
327-
if (isSessionValid) {
328-
// ...
329-
}
330-
331-
```
332-
333-
### `Object.freeze`, `Object.preventExtensions`, `Object.seal`, `with`, `eval` (???)
334-
335-
> Apart from eval, is this still a good idea in 2023? Eg: Functional Programming make use of `Object.freeze`
336-
337-
Crazy shit that you will probably never need. Stay away from it.
338-
339-
### Getters and setters (???)
340-
341-
> Is this still a good idea in 2023?
342-
343-
Do not use setters, they cause more problems for people who try to use your
344-
software than they can solve.
345-
346-
Feel free to use getters that are free from [side effects][sideeffect], like
347-
providing a length property for a collection class.
348-
349-
[sideeffect]: http://en.wikipedia.org/wiki/Side_effect_(computer_science)
350-
351265
<br>
352266
<br>
353267

0 commit comments

Comments
 (0)