Skip to content

Commit

Permalink
style: rectify linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Jul 21, 2024
1 parent 33bd781 commit 5820dfa
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 116 deletions.
6 changes: 3 additions & 3 deletions notes/ComputerScience/Compilers/CompilersBasicNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ e -> "\0" # basic definition

```ts
// 标识符
const identifier = /[a-zA-Z\_][a-zA-Z\_0-9]*/g
const identifier = /[a-z_]\w*/gi

// decimal integer
const integer = /(+|-)?(0|[1-9][0-9]*)/g
const integer = /(\+|-)?(0|[1-9]\d*)/g

// decimal float
const float = /(+|-)?(0|[1-9][0-9]*|)?\.[0-9]+/g
const float = /(\+|-)?(0|[1-9]\d*)?\.\d+/g
```

### 分析树
Expand Down
4 changes: 2 additions & 2 deletions notes/Web/HTML/HTMLBasicNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1876,8 +1876,8 @@ export default function Field() {
<input
id="userCode"
aria-describedby={
errors.userCode ? 'user-code-error' : 'user-code-help'
}
errors.userCode ? 'user-code-error' : 'user-code-help'
}
/>
<span id="user-code-help" className="user-code-help">
Enter your 4 digit user code
Expand Down
9 changes: 5 additions & 4 deletions notes/Web/JavaScript/JavaScriptAPINotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1708,10 +1708,11 @@ document.addEventListener('readystatechange', (event) => {
if (
document.readyState === 'interactive'
|| document.readyState === 'complete'
)
) {
console.log('Content loaded')
else if (document.readyState === 'loading')
} else if (document.readyState === 'loading') {
console.log('Loading')
}
})
```

Expand Down Expand Up @@ -2903,14 +2904,14 @@ function getJSON(url) {
if (this.status === 200)
resolve(JSON.parse(this.response))
else
reject(Error(`${this.status} ${this.statusText}`))
reject(new Error(`${this.status} ${this.statusText}`))
} catch (e) {
reject(e.message)
}
}

request.onerror = function () {
reject(Error(`${this.status} ${this.statusText}`))
reject(new Error(`${this.status} ${this.statusText}`))
}

request.send()
Expand Down
34 changes: 17 additions & 17 deletions notes/Web/JavaScript/JavaScriptAdvancedNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,14 @@ it.next() // {value: 1, done: false}
// the error will be handled and printed ("Error: Handled!"),
// then the flow will continue, so we will get the
// next yielded value as result.
it.throw(Error('Handled!')) // {value: 2, done: false}
it.throw(new Error('Handled!')) // {value: 2, done: false}

it.next() // {value: 3, done: false}

// now the generator instance is paused on the
// third yield that is not inside a try-catch.
// the error will be re-thrown out
it.throw(Error('Not handled!')) // !!! Uncaught Error: Not handled! !!!
it.throw(new Error('Not handled!')) // !!! Uncaught Error: Not handled! !!!

// now the iterator is exhausted
it.next() // {value: undefined, done: true}
Expand Down Expand Up @@ -1159,12 +1159,12 @@ setTimeout(console.log, 0, p8) // Promise <pending>
setTimeout(console.log, 0, p9) // Promise <rejected>: undefined

const p10 = p1.then(null, () => {
throw 'bar'
throw new Error('bar')
})
// Uncaught (in promise) bar
setTimeout(console.log, 0, p10) // Promise <rejected>: bar

const p11 = p1.then(null, () => Error('bar'))
const p11 = p1.then(null, () => new Error('bar'))
setTimeout(console.log, 0, p11) // Promise <resolved>: Error: bar
```

Expand Down Expand Up @@ -1209,7 +1209,7 @@ const p4 = p1.finally(() => {})
const p5 = p1.finally(() => Promise.resolve())
const p6 = p1.finally(() => 'bar')
const p7 = p1.finally(() => Promise.resolve('bar'))
const p8 = p1.finally(() => Error('bar'))
const p8 = p1.finally(() => new Error('bar'))
setTimeout(console.log, 0, p2) // Promise <resolved>: foo
setTimeout(console.log, 0, p3) // Promise <resolved>: foo
setTimeout(console.log, 0, p4) // Promise <resolved>: foo
Expand All @@ -1226,7 +1226,7 @@ const p10 = p1.finally(() => Promise.reject())
// Uncaught (in promise): undefined
setTimeout(console.log, 0, p10) // Promise <rejected>: undefined
const p11 = p1.finally(() => {
throw 'bar'
throw new Error('bar')
})
// Uncaught (in promise) baz
setTimeout(console.log, 0, p11) // Promise <rejected>: bar
Expand Down Expand Up @@ -1309,19 +1309,19 @@ console.log('bar') // 这一行不会执行
```

```ts
Promise.reject(Error('foo'))
Promise.reject(new Error('foo'))
console.log('bar')
// bar
// Uncaught (in promise) Error: foo

const p1 = new Promise((resolve, reject) => reject(Error('foo'))) // 1.
const p1 = new Promise((resolve, reject) => reject(new Error('foo'))) // 1.
const p2 = new Promise((resolve, reject) => {
throw new Error('foo') // 2.
})
const p3 = Promise.resolve().then(() => {
throw new Error('foo') // 4.
})
const p4 = Promise.reject(Error('foo')) // 3.
const p4 = Promise.reject(new Error('foo')) // 3.
// Uncaught (in promise) Error: foo
// at Promise (test.html:1)
// at new Promise (<anonymous>)
Expand Down Expand Up @@ -2282,7 +2282,7 @@ function usePostLoading() {
if (response.ok)
return response.json()

return Promise.reject(Error('The request failed.'))
return Promise.reject(new Error('The request failed.'))
})
.then((fetchedPost: Post) => {
setPost(fetchedPost)
Expand Down Expand Up @@ -2321,7 +2321,7 @@ function wait(time: number, signal?: AbortSignal) {
}, time)
signal?.addEventListener('abort', () => {
clearTimeout(timeoutId)
reject(Error('Aborted.'))
reject(new Error('Aborted.'))
})
})
}
Expand Down Expand Up @@ -3679,7 +3679,7 @@ setInterval(() => {
## Regular Expression

```ts
const re = /pattern/gim
const re = /pattern/gi
```

### RegExp Flags
Expand Down Expand Up @@ -3768,7 +3768,7 @@ codePointLength(s) // 2

```ts
const string = 'Favorite GitHub Repos: tc39/ecma262 v8/v8.dev'
const regex = /\b(?<owner>[a-z0-9]+)\/(?<repo>[a-z0-9\.]+)\b/g
const regex = /\b(?<owner>[a-z0-9]+)\/(?<repo>[a-z0-9.]+)\b/g

for (const match of string.matchAll(regex)) {
console.log(`${match[0]} at ${match.index} with '${match.input}'`)
Expand Down Expand Up @@ -3825,7 +3825,7 @@ RegExp [functions](https://exploringjs.com/impatient-js/ch_regexps.html#methods-
#### RegExp Test

```ts
;/[a-z|A-Z|0-9]/gim.test(str)
;/[a-z|0-9]/i.test(str)
```

```ts
Expand Down Expand Up @@ -3910,11 +3910,11 @@ assert(
```

```ts
const RE_DATE = /(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})/
const RE_DATE = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
console.log('1999-12-31'.replace(RE_DATE, '$<month>/$<day>/$<year>'))
// 12/31/1999

const RE_DATE = /(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})/
const RE_DATE = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
console.log(
'1999-12-31'.replace(
RE_DATE,
Expand Down Expand Up @@ -4665,7 +4665,7 @@ Immutable data structure:
#### Immutable Array

```ts
const RE_INDEX_PROP_KEY = /^[0-9]+$/
const RE_INDEX_PROP_KEY = /^\d+$/
const ALLOWED_PROPERTIES = new Set(['length', 'constructor', 'slice', 'concat'])

function createImmutableArray(arrayLike, mapFn) {
Expand Down
21 changes: 13 additions & 8 deletions notes/Web/JavaScript/JavaScriptBasicNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ interface RegExpMatchArray extends Array<string> {
- `string.search(string | RegExp): number`.

```ts
'a2b'.search(/[0-9]/)
'a2b'.search(/\d/)
// 1
'a2b'.search('[0-9]')
// 1
Expand Down Expand Up @@ -2104,7 +2104,7 @@ function typeOf(o) {

```ts
function type(item) {
const reTypeOf = /(?:^\[object\s(.*?)\]$)/
const reTypeOf = /^\[object\s(.*?)\]$/

return Object.prototype.toString
.call(item)
Expand Down Expand Up @@ -2375,14 +2375,16 @@ function abstractEqualityComparison(x, y) {
if (
['string', 'number', 'bigint', 'symbol'].includes(TypeOf(x))
&& TypeOf(y) === 'object'
)
) {
return abstractEqualityComparison(x, ToPrimitive(y))
}

if (
TypeOf(x) === 'object'
&& ['string', 'number', 'bigint', 'symbol'].includes(TypeOf(y))
)
) {
return abstractEqualityComparison(ToPrimitive(x), y)
}

// Comparing a bigint with a number
if (
Expand All @@ -2392,8 +2394,9 @@ function abstractEqualityComparison(x, y) {
if (
[Number.NaN, +Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY].includes(x)
|| [Number.NaN, +Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY].includes(y)
)
) {
return false
}

if (isSameMathematicalValue(x, y))
return true
Expand Down Expand Up @@ -3933,8 +3936,9 @@ const classSim = function (Parent, props) {
if (
Child.uber
&& Object.prototype.hasOwnProperty.call(Child.uber, '_construct')
)
) {
Child.uber._construct.apply(this, args)
}

if (Object.prototype.hasOwnProperty.call(Child.prototype, '_construct'))
Child.prototype._construct.apply(this, args)
Expand Down Expand Up @@ -5358,10 +5362,11 @@ const property = 'name'
alert(obj[property])

// Anti-pattern:

// eslint-disable-next-line no-implied-eval
setTimeout('myFunc()', 1000)

// eslint-disable-next-line no-implied-eval
setTimeout('myFunc(1, 2, 3)', 1000)

// Preferred:
setTimeout(myFunc, 1000)
setTimeout(() => {
Expand Down
28 changes: 14 additions & 14 deletions notes/Web/JavaScript/JavaScriptDevOpsNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1058,21 +1058,21 @@ export default function RootLayout() {

const authNav = user
? (
<li>
<form action={signOut}>
<button type="submit">Sign Out</button>
</form>
</li>
)
: (
<>
<li>
<Link href="/sign-up">Sign Up</Link>
<form action={signOut}>
<button type="submit">Sign Out</button>
</form>
</li>
<li>
<Link href="/sign-in">Sign In</Link>
</li>
</>
)
: (
<>
<li>
<Link href="/sign-up">Sign Up</Link>
</li>
<li>
<Link href="/sign-in">Sign In</Link>
</li>
</>
)
}
```
Expand Down Expand Up @@ -2432,7 +2432,7 @@ module.exports = {
module.exports = {
optimization: {
splitChunks: {
chunks: chunk => !/^(polyfills|main|pages\/_app)$/.test(chunk.name),
chunks: chunk => !/^polyfills|main|pages\/_app$/.test(chunk.name),
cacheGroups: {
framework: {
chunks: 'all',
Expand Down
6 changes: 4 additions & 2 deletions notes/Web/JavaScript/JavaScriptTestingNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1316,8 +1316,9 @@ cy.intercept('POST', apiGraphQL, (req) => {
if (
Object.hasOwn(body, 'operationName')
&& body.operationName === 'CreateBankAccount'
)
) {
req.alias = 'gqlCreateBankAccountMutation'
}
})
```

Expand Down Expand Up @@ -1863,8 +1864,9 @@ console.log(c)
if (
window.outerHeight - window.innerHeight > 200
|| window.outerWidth - window.innerWidth > 200
)
) {
document.body.innerHTML = 'Debug detected, please reload page!'
}

setInterval(() => {
;(function () {
Expand Down
10 changes: 5 additions & 5 deletions notes/Web/JavaScript/TypeScriptBasicNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2448,11 +2448,11 @@ const typeSym = Symbol('type')
const valueSym = Symbol('value')

type Brand<B extends string, T> = T extends
| undefined
| null
| number
| boolean
| bigint
| undefined
| null
| number
| boolean
| bigint
? { [typeSym]: B, [valueSym]: T }
: T & { [typeSym]: B }

Expand Down
9 changes: 6 additions & 3 deletions notes/Web/React/ReactAdvancedNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,9 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
if (
nextLane >= wipLane
|| (nextLane === DefaultLane && (wipLane & TransitionLanes) !== NoLanes)
)
) {
return wipLanes
}
}

if (
Expand Down Expand Up @@ -2176,8 +2177,9 @@ function commitRootImpl(
if (
includesSomeLane(pendingPassiveEffectsLanes, SyncLane)
&& root.tag !== LegacyRoot
)
) {
flushPassiveEffects()
}

// If layout work was scheduled, flush it now.
flushSyncCallbacks()
Expand Down Expand Up @@ -2601,8 +2603,9 @@ function commitLayoutEffectOnFiber(
if (
!enableSuspenseLayoutEffectSemantics
|| !offscreenSubtreeWasHidden
)
) {
commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork)
}

break
}
Expand Down
Loading

0 comments on commit 5820dfa

Please sign in to comment.