Skip to content

Commit

Permalink
chore(eslint): add recommended rules and etc (pmndrs#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Nov 25, 2021
1 parent bb26cd0 commit 30f5505
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended",
"plugin:react-hooks/recommended",
Expand All @@ -29,6 +31,9 @@
}
},
"rules": {
"eqeqeq": "error",
"no-var": "error",
"prefer-const": "error",
"curly": ["warn", "multi-line", "consistent"],
"no-console": "off",
"import/no-unresolved": ["error", { "commonjs": true, "amd": true }],
Expand Down Expand Up @@ -108,6 +113,18 @@
"parserOptions": {
"project": "./tsconfig.json"
}
},
{
"files": ["tests/**/*.tsx"],
"env": {
"jest/globals": true
}
},
{
"files": ["./*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
4 changes: 3 additions & 1 deletion src/middleware/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export const devtools =
extension =
(window as any).__REDUX_DEVTOOLS_EXTENSION__ ||
(window as any).top.__REDUX_DEVTOOLS_EXTENSION__
} catch {}
} catch {
// ignored
}

if (!extension) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/persist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetState, SetState, State, StoreApi } from '../vanilla'

type DeepPartial<T extends Object> = {
type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>
}

Expand Down
15 changes: 11 additions & 4 deletions tests/basic.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Component as ClassComponent,
ReactNode,
useEffect,
useLayoutEffect,
useState,
Expand Down Expand Up @@ -289,8 +290,11 @@ it('can throw an error in selector', async () => {
// @ts-expect-error This function is supposed to throw an error
s.value.toUpperCase()

class ErrorBoundary extends ClassComponent<{}, { hasError: boolean }> {
constructor(props: {}) {
class ErrorBoundary extends ClassComponent<
{ children?: ReactNode | undefined },
{ hasError: boolean }
> {
constructor(props: { children?: ReactNode | undefined }) {
super(props)
this.state = { hasError: false }
}
Expand Down Expand Up @@ -332,8 +336,11 @@ it('can throw an error in equality checker', async () => {
// @ts-expect-error This function is supposed to throw an error
a.value.trim() === b.value.trim()

class ErrorBoundary extends ClassComponent<{}, { hasError: boolean }> {
constructor(props: {}) {
class ErrorBoundary extends ClassComponent<
{ children?: ReactNode | undefined },
{ hasError: boolean }
> {
constructor(props: { children?: ReactNode | undefined }) {
super(props)
this.state = { hasError: false }
}
Expand Down
14 changes: 11 additions & 3 deletions tests/context.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Component as ClassComponent, useEffect, useState } from 'react'
import {
Component as ClassComponent,
ReactNode,
useEffect,
useState,
} from 'react'
import { render } from '@testing-library/react'
import create, { GetState, SetState } from 'zustand'
import createContext from 'zustand/context'
Expand Down Expand Up @@ -118,8 +123,11 @@ it('uses context store api', async () => {
it('throws error when not using provider', async () => {
console.error = jest.fn()

class ErrorBoundary extends ClassComponent<{}, { hasError: boolean }> {
constructor(props: {}) {
class ErrorBoundary extends ClassComponent<
{ children?: ReactNode | undefined },
{ hasError: boolean }
> {
constructor(props: { children?: ReactNode | undefined }) {
super(props)
this.state = { hasError: false }
}
Expand Down

0 comments on commit 30f5505

Please sign in to comment.