Skip to content

Commit b6993a6

Browse files
committed
feat(prettier): make prettier a part of eslint.
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
1 parent 3590a0e commit b6993a6

File tree

128 files changed

+796
-363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+796
-363
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ indent_size = 2
88
indent_style = space
99
insert_final_newline = true
1010
trim_trailing_whitespace = true
11-
max_line_length = 120
11+
max_line_length = 100
1212

1313
[*.{ts, tsx}]
1414
ij_typescript_enforce_trailing_comma = keep
@@ -24,7 +24,7 @@ ij_typescript_catch_on_new_line = false
2424
ij_typescript_spaces_within_interpolation_expressions = false
2525

2626
[*.md]
27-
max_line_length = 120
27+
max_line_length = 100
2828
trim_trailing_whitespace = false
2929

3030
[COMMIT_EDITMSG]

.eslintrc.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
extends: ['prettier/@typescript-eslint', 'react-app', 'plugin:prettier/recommended'],
3+
plugins: ['prettier'],
4+
rules: {
5+
'prettier/prettier': [
6+
'error',
7+
{
8+
singleQuote: true,
9+
trailingComma: 'es5',
10+
tabWidth: 2,
11+
printWidth: 100,
12+
semicolons: true,
13+
quoteProps: 'as-needed',
14+
jsxSingleQuote: false,
15+
bracketSpacing: true,
16+
jsxBracketSameLine: true,
17+
arrowParens: 'always',
18+
endOfLine: 'lf',
19+
},
20+
],
21+
},
22+
};

.eslintrc.json

-3
This file was deleted.

.prettierrc

-6
This file was deleted.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-use",
3-
"version": "17.0.2",
3+
"version": "17.0.0",
44
"description": "Collection of React Hooks",
55
"main": "lib/index.js",
66
"module": "esm/index.js",
@@ -17,10 +17,9 @@
1717
"test:ssr": "jest --maxWorkers 2 --config ./jest.config.node.ts",
1818
"test:watch": "jest --watch",
1919
"test:coverage": "jest --coverage",
20-
"lint": "eslint {src,tests}/**/*.{ts,tsx}",
20+
"lint": "eslint {src,tests,stories}/**/*.{ts,tsx}",
2121
"lint:fix": "yarn lint --fix",
22-
"lint:types": "tsc --noEmit ",
23-
"lint:prettier": "prettier --write src/**/**/*.{ts,tsx}",
22+
"lint:types": "tsc --noEmit",
2423
"build:cjs": "tsc",
2524
"build:es": "tsc -m esNext --outDir esm",
2625
"build": "yarn build:cjs && yarn build:es",
@@ -33,7 +32,7 @@
3332
},
3433
"husky": {
3534
"hooks": {
36-
"pre-commit": "yarn lint:types && lint-staged",
35+
"pre-commit": "lint-staged",
3736
"pre-push": "yarn lint && yarn clean && yarn build && yarn test"
3837
}
3938
},
@@ -93,10 +92,12 @@
9392
"babel-loader": "8.2.2",
9493
"babel-plugin-dynamic-import-node": "2.3.3",
9594
"eslint": "7.19.0",
95+
"eslint-config-prettier": "^7.2.0",
9696
"eslint-config-react-app": "6.0.0",
9797
"eslint-plugin-flowtype": "5.2.0",
9898
"eslint-plugin-import": "2.22.1",
9999
"eslint-plugin-jsx-a11y": "6.4.1",
100+
"eslint-plugin-prettier": "^3.3.1",
100101
"eslint-plugin-react": "7.22.0",
101102
"eslint-plugin-react-hooks": "4.2.0",
102103
"fork-ts-checker-webpack-plugin": "6.1.0",
@@ -107,7 +108,7 @@
107108
"keyboardjs": "2.6.4",
108109
"lint-staged": "10.5.3",
109110
"markdown-loader": "6.0.0",
110-
"prettier": "2.2.1",
111+
"prettier": "^2.2.1",
111112
"raf-stub": "3.0.0",
112113
"react": "17.0.1",
113114
"react-dom": "17.0.1",
@@ -152,7 +153,6 @@
152153
"lint-staged": {
153154
"src/**/**/*.{ts,tsx}": [
154155
"eslint --fix",
155-
"prettier --write",
156156
"git add"
157157
]
158158
},

src/component/UseKey.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import useKey from '../useKey';
22
import createRenderProp from '../factory/createRenderProp';
33

4-
const UseKey = createRenderProp(useKey, ({ filter, fn, deps, ...rest }) => [filter, fn, rest, deps]);
4+
const UseKey = createRenderProp(useKey, ({ filter, fn, deps, ...rest }) => [
5+
filter,
6+
fn,
7+
rest,
8+
deps,
9+
]);
510

611
export default UseKey;

src/factory/createBreakpoint.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const createBreakpoint = (
1616
off(window, 'resize', setSideScreen);
1717
};
1818
});
19-
const sortedBreakpoints = useMemo(() => Object.entries(breakpoints).sort((a, b) => (a[1] >= b[1] ? 1 : -1)), [
20-
breakpoints,
21-
]);
19+
const sortedBreakpoints = useMemo(
20+
() => Object.entries(breakpoints).sort((a, b) => (a[1] >= b[1] ? 1 : -1)),
21+
[breakpoints]
22+
);
2223
const result = sortedBreakpoints.reduce((acc, [name, width]) => {
2324
if (screen >= width) {
2425
return name;

src/factory/createHTMLMediaHook.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { useEffect, useRef } from 'react';
33
import useSetState from '../useSetState';
44
import parseTimeRanges from '../misc/parseTimeRanges';
55

6-
export interface HTMLMediaProps extends React.AudioHTMLAttributes<any>, React.VideoHTMLAttributes<any> {
6+
export interface HTMLMediaProps
7+
extends React.AudioHTMLAttributes<any>,
8+
React.VideoHTMLAttributes<any> {
79
src: string;
810
}
911

@@ -33,7 +35,9 @@ type createHTMLMediaHookReturn = [
3335
];
3436

3537
export default function createHTMLMediaHook(tag: 'audio' | 'video') {
36-
return (elOrProps: HTMLMediaProps | React.ReactElement<HTMLMediaProps>): createHTMLMediaHookReturn => {
38+
return (
39+
elOrProps: HTMLMediaProps | React.ReactElement<HTMLMediaProps>
40+
): createHTMLMediaHookReturn => {
3741
let element: React.ReactElement<any> | undefined;
3842
let props: HTMLMediaProps;
3943

src/factory/createReducer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ interface Store<Action, State> {
88
dispatch: Dispatch<Action>;
99
}
1010

11-
type Middleware<Action, State> = (store: Store<Action, State>) => (next: Dispatch<Action>) => (action: Action) => void;
11+
type Middleware<Action, State> = (
12+
store: Store<Action, State>
13+
) => (next: Dispatch<Action>) => (action: Action) => void;
1214

1315
function composeMiddleware<Action, State>(chain: Middleware<Action, State>[]) {
1416
return (context: Store<Action, State>, dispatch: Dispatch<Action>) => {

src/factory/createReducerContext.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ const createReducerContext = <R extends React.Reducer<any, any>>(
44
reducer: R,
55
defaultInitialState: React.ReducerState<R>
66
) => {
7-
const context = createContext<[React.ReducerState<R>, React.Dispatch<React.ReducerAction<R>>] | undefined>(undefined);
7+
const context = createContext<
8+
[React.ReducerState<R>, React.Dispatch<React.ReducerAction<R>>] | undefined
9+
>(undefined);
810
const providerFactory = (props, children) => createElement(context.Provider, props, children);
911

10-
const ReducerProvider: React.FC<{ initialState?: React.ReducerState<R> }> = ({ children, initialState }) => {
11-
const state = useReducer<R>(reducer, initialState !== undefined ? initialState : defaultInitialState);
12+
const ReducerProvider: React.FC<{ initialState?: React.ReducerState<R> }> = ({
13+
children,
14+
initialState,
15+
}) => {
16+
const state = useReducer<R>(
17+
reducer,
18+
initialState !== undefined ? initialState : defaultInitialState
19+
);
1220
return providerFactory({ value: state }, children);
1321
};
1422

src/factory/createStateContext.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { createContext, createElement, useContext, useState } from 'react';
22

33
const createStateContext = <T>(defaultInitialValue: T) => {
4-
const context = createContext<[T, React.Dispatch<React.SetStateAction<T>>] | undefined>(undefined);
4+
const context = createContext<[T, React.Dispatch<React.SetStateAction<T>>] | undefined>(
5+
undefined
6+
);
57
const providerFactory = (props, children) => createElement(context.Provider, props, children);
68

79
const StateProvider: React.FC<{ initialValue?: T }> = ({ children, initialValue }) => {

src/misc/hookState.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ export type IHookStateSetAction<S> = S | IHookStateSetter<S>;
77
export type IHookStateResolvable<S> = S | IHookStateInitialSetter<S> | IHookStateSetter<S>;
88

99
export function resolveHookState<S>(nextState: IHookStateInitAction<S>): S;
10-
export function resolveHookState<S, C extends S>(nextState: IHookStateSetAction<S>, currentState?: C): S;
11-
export function resolveHookState<S, C extends S>(nextState: IHookStateResolvable<S>, currentState?: C): S;
12-
export function resolveHookState<S, C extends S>(nextState: IHookStateResolvable<S>, currentState?: C): S {
10+
export function resolveHookState<S, C extends S>(
11+
nextState: IHookStateSetAction<S>,
12+
currentState?: C
13+
): S;
14+
export function resolveHookState<S, C extends S>(
15+
nextState: IHookStateResolvable<S>,
16+
currentState?: C
17+
): S;
18+
export function resolveHookState<S, C extends S>(
19+
nextState: IHookStateResolvable<S>,
20+
currentState?: C
21+
): S {
1322
if (typeof nextState === 'function') {
1423
return nextState.length ? (nextState as Function)(currentState) : (nextState as Function)();
1524
}

src/useAsync.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { FunctionReturningPromise } from './misc/types';
44

55
export { AsyncState, AsyncFnReturn } from './useAsyncFn';
66

7-
export default function useAsync<T extends FunctionReturningPromise>(fn: T, deps: DependencyList = []) {
7+
export default function useAsync<T extends FunctionReturningPromise>(
8+
fn: T,
9+
deps: DependencyList = []
10+
) {
811
const [state, callback] = useAsyncFn(fn, deps, {
912
loading: true,
1013
});

src/useAsyncFn.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export type AsyncState<T> =
2424
value: T;
2525
};
2626

27-
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
27+
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<
28+
PromiseType<ReturnType<T>>
29+
>;
2830

2931
export type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
3032
StateFromFunctionReturningPromise<T>,

src/useAsyncRetry.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const useAsyncRetry = <T>(fn: () => Promise<T>, deps: DependencyList = []) => {
1313
const retry = useCallback(() => {
1414
if (stateLoading) {
1515
if (process.env.NODE_ENV === 'development') {
16-
console.log('You are calling useAsyncRetry hook retry() method while loading in progress, this is a no-op.');
16+
console.log(
17+
'You are calling useAsyncRetry hook retry() method while loading in progress, this is a no-op.'
18+
);
1719
}
1820

1921
return;

src/useCopyToClipboard.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const useCopyToClipboard = (): [CopyToClipboardState, (value: string) => void] =
2626
try {
2727
// only strings and numbers casted to strings can be copied to clipboard
2828
if (typeof value !== 'string' && typeof value !== 'number') {
29-
const error = new Error(`Cannot copy typeof ${typeof value} to clipboard, must be a string`);
29+
const error = new Error(
30+
`Cannot copy typeof ${typeof value} to clipboard, must be a string`
31+
);
3032
if (process.env.NODE_ENV === 'development') console.error(error);
3133
setState({
3234
value,

src/useCounter.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default function useCounter(
1717
): [number, CounterActions] {
1818
let init = resolveHookState(initialValue);
1919

20-
typeof init !== 'number' && console.error('initialValue has to be a number, got ' + typeof initialValue);
20+
typeof init !== 'number' &&
21+
console.error('initialValue has to be a number, got ' + typeof initialValue);
2122

2223
if (typeof min === 'number') {
2324
init = Math.max(init, min);
@@ -59,7 +60,9 @@ export default function useCounter(
5960
const rDelta = resolveHookState(delta, get());
6061

6162
if (typeof rDelta !== 'number') {
62-
console.error('delta has to be a number or function returning a number, got ' + typeof rDelta);
63+
console.error(
64+
'delta has to be a number or function returning a number, got ' + typeof rDelta
65+
);
6366
}
6467

6568
set((num: number) => num + rDelta);
@@ -68,7 +71,9 @@ export default function useCounter(
6871
const rDelta = resolveHookState(delta, get());
6972

7073
if (typeof rDelta !== 'number') {
71-
console.error('delta has to be a number or function returning a number, got ' + typeof rDelta);
74+
console.error(
75+
'delta has to be a number or function returning a number, got ' + typeof rDelta
76+
);
7277
}
7378

7479
set((num: number) => num - rDelta);
@@ -77,7 +82,9 @@ export default function useCounter(
7782
const rValue = resolveHookState(value, get());
7883

7984
if (typeof rValue !== 'number') {
80-
console.error('value has to be a number or function returning a number, got ' + typeof rValue);
85+
console.error(
86+
'value has to be a number or function returning a number, got ' + typeof rValue
87+
);
8188
}
8289

8390
// eslint-disable-next-line react-hooks/exhaustive-deps

src/useCustomCompareEffect.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const useCustomCompareEffect = <TDeps extends DependencyList>(
1111
) => {
1212
if (process.env.NODE_ENV !== 'production') {
1313
if (!(deps instanceof Array) || !deps.length) {
14-
console.warn('`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.');
14+
console.warn(
15+
'`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.'
16+
);
1517
}
1618

1719
if (deps.every(isPrimitive)) {
@@ -21,7 +23,9 @@ const useCustomCompareEffect = <TDeps extends DependencyList>(
2123
}
2224

2325
if (typeof depsEqual !== 'function') {
24-
console.warn('`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list');
26+
console.warn(
27+
'`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list'
28+
);
2529
}
2630
}
2731

src/useDebounce.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import useTimeoutFn from './useTimeoutFn';
33

44
export type UseDebounceReturn = [() => boolean | null, () => void];
55

6-
export default function useDebounce(fn: Function, ms: number = 0, deps: DependencyList = []): UseDebounceReturn {
6+
export default function useDebounce(
7+
fn: Function,
8+
ms: number = 0,
9+
deps: DependencyList = []
10+
): UseDebounceReturn {
711
const [isReady, cancel, reset] = useTimeoutFn(fn, ms);
812

913
useEffect(reset, deps);

src/useDeepCompareEffect.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const isPrimitive = (val: any) => val !== Object(val);
77
const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => {
88
if (process.env.NODE_ENV !== 'production') {
99
if (!(deps instanceof Array) || !deps.length) {
10-
console.warn('`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.');
10+
console.warn(
11+
'`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.'
12+
);
1113
}
1214

1315
if (deps.every(isPrimitive)) {

src/useDefault.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { useState } from 'react';
22

3-
const useDefault = <TStateType>(defaultValue: TStateType, initialValue: TStateType | (() => TStateType)) => {
3+
const useDefault = <TStateType>(
4+
defaultValue: TStateType,
5+
initialValue: TStateType | (() => TStateType)
6+
) => {
47
const [value, setValue] = useState<TStateType | undefined | null>(initialValue);
58

69
if (value === undefined || value === null) {

src/useDropArea.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const defaultState: DropAreaState = {
2626
};
2727
*/
2828

29-
const createProcess = (options: DropAreaOptions, mounted: boolean) => (dataTransfer: DataTransfer, event) => {
29+
const createProcess = (options: DropAreaOptions, mounted: boolean) => (
30+
dataTransfer: DataTransfer,
31+
event
32+
) => {
3033
const uri = dataTransfer.getData('text/uri-list');
3134

3235
if (uri) {

src/useEnsuredForwardedRef.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
useRef,
1111
} from 'react';
1212

13-
export default function useEnsuredForwardedRef<T>(forwardedRef: MutableRefObject<T>): MutableRefObject<T> {
13+
export default function useEnsuredForwardedRef<T>(
14+
forwardedRef: MutableRefObject<T>
15+
): MutableRefObject<T> {
1416
const ensuredRef = useRef(forwardedRef && forwardedRef.current);
1517

1618
useEffect(() => {

0 commit comments

Comments
 (0)