Skip to content

Commit 24517f8

Browse files
authored
Merge pull request #166 from nschonni/typos
chore: Minor typo cleanup
2 parents 8499607 + c347ad1 commit 24517f8

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

docs/rules/array-foreach.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Here's a summary of why `forEach` is disallowed, and why we prefer `for...of` fo
1313

1414
Typically developers will reach for a `forEach` when they want to iterate over a set of items. However not all "iterables" have access to Array methods. So a developer might convert their iterable to an Array by using `Array.from(iter).forEach()`. This code has introduced performance problems, where a `for...of` loop would be more performant.
1515

16-
`forEach` does not do anything special with the Array - it does not create a new array or does not aid in encapsulation (except for introducing a new lexical scope within the callback, which isn't a benefit considering we use `let`/`const`). We don't dissallow `map`/`filter`/`reduce` because they have a tangible effect - they create a new array - which would take _more_ code and be _less_ readable to do with a `for...of` loop, the exception being as more requirements are added, and we start chaining array methods together...
16+
`forEach` does not do anything special with the Array - it does not create a new array or does not aid in encapsulation (except for introducing a new lexical scope within the callback, which isn't a benefit considering we use `let`/`const`). We don't disallow `map`/`filter`/`reduce` because they have a tangible effect - they create a new array - which would take _more_ code and be _less_ readable to do with a `for...of` loop, the exception being as more requirements are added, and we start chaining array methods together...
1717

1818
Often when using a method like `forEach` - when coming back to add new code, let's say to filter certain elements from the Array before operating on them, a developer is implicitly encouraged to use Array's method chaining to achieve this result. For example if we wanted to filter out bad apples from an Array of Apples, if the code already uses `forEach`, then its a simple addition to add `filter()`:
1919

@@ -23,7 +23,7 @@ Often when using a method like `forEach` - when coming back to add new code, let
2323
.forEach(polishApple)
2424
```
2525

26-
The problem we now have is that we're iterating multiple times over the items in a collection. Using `forEach` to begin with is what encouraged the chaining, if this were a `for` loop then the equivalent behaviour would be to use 2 `for` loops, which a developer is far less likely to write, so the `for` loop instead encourages an imperative style `continue`, keeping within a single set of iterations:
26+
The problem we now have is that we're iterating multiple times over the items in a collection. Using `forEach` to begin with is what encouraged the chaining, if this were a `for` loop then the equivalent behavior would be to use 2 `for` loops, which a developer is far less likely to write, so the `for` loop instead encourages an imperative style `continue`, keeping within a single set of iterations:
2727

2828
```diff
2929
for(const apple of apples) {
@@ -32,7 +32,7 @@ The problem we now have is that we're iterating multiple times over the items in
3232
}
3333
```
3434

35-
Chaning isn't always necessarily bad. Chaining can advertise a series of transformations that are independant from one another, and therefore aid readability. Additionally, sometimes the "goto-style" behaviour of `continue` in for loops can hamper readability. For small Arrays, performance is not going to be of concern, but caution should be applied where there is a potentially unbounded Array (such as iterating over a fetched users list) as performance can easily become a bottleneck when unchecked.
35+
Changing isn't always necessarily bad. Chaining can advertise a series of transformations that are independent from one another, and therefore aid readability. Additionally, sometimes the "goto-style" behavior of `continue` in for loops can hamper readability. For small Arrays, performance is not going to be of concern, but caution should be applied where there is a potentially unbounded Array (such as iterating over a fetched users list) as performance can easily become a bottleneck when unchecked.
3636

3737
The `forEach` method passes more than just the current item it is iterating over. The signature of the `forEach` callback method is `(cur: T, i: Number, all: []T) => void` and it can _additionally_ override the `receiver` (`this` value), meaning that often the _intent_ of what the callback does is hidden. To put this another way, there is _no way_ to know what the following code operates on without reading the implementation: `forEach(polishApple)`.
3838

@@ -58,7 +58,7 @@ for (const apple of apples) {
5858
}
5959
```
6060

61-
If `polishApple` needed to do some serial async work, then we'd need to refactor the iteration steps to accomodate for this async work, by `await`ing each call to `polishApple`. We cannot simply pass an `async` function to `forEach`, as it does not understand async functions, instead we'd have to turn the `forEach` into a `reduce` and combine that with a `Promise` returning function. For example:
61+
If `polishApple` needed to do some serial async work, then we'd need to refactor the iteration steps to accommodate for this async work, by `await`ing each call to `polishApple`. We cannot simply pass an `async` function to `forEach`, as it does not understand async functions, instead we'd have to turn the `forEach` into a `reduce` and combine that with a `Promise` returning function. For example:
6262

6363
```diff
6464
- apples.forEach(polishApple)

docs/rules/no-then.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/asy
1111
```js
1212
function getProcessedData(url) {
1313
return downloadData(url).catch(e => {
14-
console.log('Error occured!', e)
14+
console.log('Error occurred!', e)
1515
})
1616
}
1717
```
@@ -24,7 +24,7 @@ async function getProcessedData(url) {
2424
try {
2525
v = await downloadData(url)
2626
} catch (e) {
27-
console.log('Error occured!', e)
27+
console.log('Error occurred!', e)
2828
return
2929
}
3030
return v

lib/rules/unescaped-html-literal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
meta: {
33
type: 'problem',
44
docs: {
5-
description: 'disallow unesaped HTML literals',
5+
description: 'disallow unescaped HTML literals',
66
url: require('../url')(module)
77
},
88
schema: []

tests/no-inner-html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const RuleTester = require('eslint').RuleTester
33

44
const ruleTester = new RuleTester()
55

6-
ruleTester.run('no-innter-html', rule, {
6+
ruleTester.run('no-inner-html', rule, {
77
valid: [
88
{
99
code: 'document.createElement("js-flash-text").textContent = ""'

tests/require-passive-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ruleTester.run('require-passive-events', rule, {
4747
]
4848
},
4949
{
50-
// Intentionally mispelled!
50+
// Intentionally misspelled!
5151
code: 'document.addEventListener("wheel", function(event) {}, { pssive: true })',
5252
errors: [
5353
{

0 commit comments

Comments
 (0)