Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ function getSong() {
}

function singSong(_song) {
if (!_song) throw new Error("song is '' empty, FEED ME A SONG!");
if (!_song) {
throw new Error("song is '' empty, FEED ME A SONG!");
}

console.log(_song);
}

Expand Down Expand Up @@ -128,7 +131,10 @@ function getSong() {
}

function singSong(_song) {
if (!_song) throw new Error("song is '' empty, FEED ME A SONG!");
if (!_song) {
throw new Error("song is '' empty, FEED ME A SONG!");
}

console.log(_song);
}

Expand Down Expand Up @@ -161,7 +167,10 @@ function executeFunctionWithArgs(operation, callback) {
}

function serialProcedure(operation) {
if (!operation) process.exit(0); // finished
if (!operation) {
process.exit(0); // finished
}

executeFunctionWithArgs(operation, function (result) {
// continue AFTER callback
serialProcedure(operations.shift());
Expand Down Expand Up @@ -195,12 +204,20 @@ function dispatch(recipient, callback) {

function sendOneMillionEmailsOnly() {
getListOfTenMillionGreatEmails(function (err, bigList) {
if (err) throw err;
if (err) {
throw err;
}

function serial(recipient) {
if (!recipient || successCount >= 1000000) return final();
if (!recipient || successCount >= 1000000) {
return final();
}

dispatch(recipient, function (_err) {
if (!_err) successCount += 1;
if (!_err) {
successCount += 1;
}

serial(bigList.pop());
});
}
Expand Down Expand Up @@ -241,9 +258,10 @@ function dispatch(recipient, callback) {
function final(result) {
console.log(`Result: ${result.count} attempts \
& ${result.success} succeeded emails`);
if (result.failed.length)
if (result.failed.length) {
console.log(`Failed to send to: \
\n${result.failed.join('\n')}\n`);
}
}

recipients.forEach(function (recipient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ For a simple example, suppose you want to compute the average of the numbers `1`
Example 1: Un-partitioned average, costs `O(n)`

```js
for (let i = 0; i < n; i++) sum += i;
for (let i = 0; i < n; i++) {
sum += i;
}

const avg = sum / n;
console.log('avg: ' + avg);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,12 @@ it doesn't have to be. Take this code snippet for example:

```js
function apiCall(arg, callback) {
if (typeof arg !== 'string')
if (typeof arg !== 'string') {
return process.nextTick(
callback,
new TypeError('argument should be string')
);
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ And here is an equivalent **asynchronous** example:
const fs = require('node:fs');

fs.readFile('/file.md', (err, data) => {
if (err) throw err;
if (err) {
throw err;
}
});
```

Expand All @@ -78,7 +80,10 @@ And here is a similar, but not equivalent asynchronous example:
const fs = require('node:fs');

fs.readFile('/file.md', (err, data) => {
if (err) throw err;
if (err) {
throw err;
}

console.log(data);
});
moreWork(); // will run before console.log
Expand Down Expand Up @@ -117,7 +122,10 @@ at an example:
const fs = require('node:fs');

fs.readFile('/file.md', (err, data) => {
if (err) throw err;
if (err) {
throw err;
}

console.log(data);
});
fs.unlinkSync('/file.md');
Expand All @@ -132,10 +140,16 @@ execute in the correct order is:
const fs = require('node:fs');

fs.readFile('/file.md', (readFileErr, data) => {
if (readFileErr) throw readFileErr;
if (readFileErr) {
throw readFileErr;
}

console.log(data);

fs.unlink('/file.md', unlinkErr => {
if (unlinkErr) throw unlinkErr;
if (unlinkErr) {
throw unlinkErr;
}
});
});
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ async function example() {
console.log(filehandle.fd);
console.log(await filehandle.readFile({ encoding: 'utf8' }));
} finally {
if (filehandle) await filehandle.close();
if (filehandle) {
await filehandle.close();
}
}
}
example();
Expand All @@ -92,7 +94,9 @@ try {
console.log(filehandle.fd);
console.log(await filehandle.readFile({ encoding: 'utf8' }));
} finally {
if (filehandle) await filehandle.close();
if (filehandle) {
await filehandle.close();
}
}
```

Expand Down
16 changes: 12 additions & 4 deletions apps/site/pages/en/learn/modules/backpressuring-in-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,23 @@ However, when we want to use a [`Writable`][] directly, we must respect the
// there is a great chance multiple callbacks will be called.
class MyWritable extends Writable {
_write(chunk, encoding, callback) {
if (chunk.toString().indexOf('a') >= 0) callback();
else if (chunk.toString().indexOf('b') >= 0) callback();
if (chunk.toString().indexOf('a') >= 0) {
callback();
} else if (chunk.toString().indexOf('b') >= 0) {
callback();
}
callback();
}
}

// The proper way to write this would be:
if (chunk.contains('a')) return callback();
if (chunk.contains('b')) return callback();
if (chunk.contains('a')) {
return callback();
}

if (chunk.contains('b')) {
return callback();
}
callback();
```

Expand Down
4 changes: 3 additions & 1 deletion apps/site/pages/en/learn/test-runner/mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ import { db } from 'db';
export function read(key, all = false) {
validate(key, val);

if (all) return db.getAll(key);
if (all) {
return db.getAll(key);
}

return db.getOne(key);
}
Expand Down
4 changes: 3 additions & 1 deletion apps/site/pages/en/learn/typescript/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ import * as fs from 'fs';

fs.readFile('example.txt', 'foo', (err, data) => {
// ^^^ Argument of type '"foo"' is not assignable to parameter of type …
if (err) throw err;
if (err) {
throw err;
}
console.log(data);
});
```
Expand Down
4 changes: 3 additions & 1 deletion docs/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ type MyComponentProps = {
};

const MyComponent: FC<MyComponentProps> = ({ title, isVisible = true }) => {
if (!isVisible) return null;
if (!isVisible) {
return null;
}

return (
<div className={styles.myComponent}>
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default tseslint.config(
],

'object-shorthand': 'error',
curly: ['error', 'all'],
},
}
);
4 changes: 3 additions & 1 deletion packages/remark-lint/src/rules/hashed-self-reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const hashedSelfReference = (tree, vfile) => {
for (const node of getLinksRecursively(tree)) {
const { url } = node;

if (!url || url[0] === '#') continue;
if (!url || url[0] === '#') {
continue;
}

const targetURL = new URL(url, currentFileURL);

Expand Down
4 changes: 3 additions & 1 deletion packages/remark-lint/src/rules/yaml/ordered-yaml-keys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default function orderedYamlKeys(
validKeys = DEFAULT_VALID_KEYS,
prefix = ''
) {
if (!yaml || typeof yaml !== 'object' || Array.isArray(yaml)) return;
if (!yaml || typeof yaml !== 'object' || Array.isArray(yaml)) {
return;
}

const keys = Object.keys(yaml);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const Avatar = forwardRef<
},
ref
) => {
if (!url) Component = 'div';
if (!url) {
Component = 'div';
}

return (
<RadixAvatar.Root
{...props}
Expand Down
Loading