Skip to content

Commit e0bc4e1

Browse files
authored
feat: conform new linting configuration (#1296)
1 parent f810be2 commit e0bc4e1

File tree

206 files changed

+1813
-1328
lines changed

Some content is hidden

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

206 files changed

+1813
-1328
lines changed

.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.idea
2+
node_modules
3+
esm
4+
cjs
5+
coverage
6+
storybook-build
7+
CHANGELOG.md
8+
!.eslintrc.js
9+
!.prettierrc.js

.eslintrc.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,65 @@
11
module.exports = {
22
root: true,
33

4-
ignorePatterns: [
5-
'node_modules',
6-
'coverage',
7-
'storybook-build',
8-
'dist',
9-
'.github/workflows',
10-
'.husky',
11-
'CHANGELOG.md',
12-
],
13-
144
parserOptions: {
155
project: './tsconfig.eslint.json',
16-
tsconfigRootDir: __dirname,
17-
extraFileExtensions: ['.md'],
6+
extraFileExtensions: ['.md', '.mdx'],
187
},
198

209
overrides: [
2110
{
22-
files: ['*.js', '*.ts', '*.jsx', '*.tsx'],
23-
extends: ['@react-hookz/eslint-config/react'],
24-
rules: {
25-
'react/button-has-type': 'off',
26-
'unicorn/prefer-node-protocol': 'off',
27-
'unicorn/prefer-top-level-await': 'off',
28-
},
11+
files: ['*.js'],
12+
extends: ['@react-hookz/eslint-config/base.cjs'],
2913
},
3014
{
31-
files: [
32-
'**/__tests__/**/*.js',
33-
'**/__tests__/**/*.ts',
34-
'**/__tests__/**/*.jsx',
35-
'**/__tests__/**/*.tsx',
15+
files: ['*.jsx'],
16+
extends: ['@react-hookz/eslint-config/base.cjs', '@react-hookz/eslint-config/react.cjs'],
17+
},
18+
{
19+
files: ['*.ts'],
20+
extends: ['@react-hookz/eslint-config/typescript.cjs'],
21+
},
22+
{
23+
files: ['*.tsx'],
24+
extends: [
25+
'@react-hookz/eslint-config/typescript.cjs',
26+
'@react-hookz/eslint-config/react.cjs',
3627
],
37-
extends: ['@react-hookz/eslint-config/react', '@react-hookz/eslint-config/jest'],
3828
},
3929
{
40-
files: ['**/__docs__/**', '**/__tests__/**'],
41-
rules: {
42-
'@typescript-eslint/no-floating-promises': 'off',
43-
'@typescript-eslint/no-explicit-any': 'off',
44-
'@typescript-eslint/no-unsafe-assignment': 'off',
45-
'@typescript-eslint/no-unsafe-member-access': 'off',
46-
'@typescript-eslint/no-unsafe-call': 'off',
47-
'@typescript-eslint/no-unsafe-argument': 'off',
48-
'@typescript-eslint/no-unsafe-return': 'off',
49-
'unicorn/consistent-function-scoping': 'off',
50-
'unicorn/no-this-assignment': 'off',
51-
},
30+
files: ['**/__tests__/**/*.js'],
31+
extends: ['@react-hookz/eslint-config/base.cjs', '@react-hookz/eslint-config/jest.cjs'],
32+
},
33+
{
34+
files: ['**/__tests__/**/*.jsx'],
35+
extends: [
36+
'@react-hookz/eslint-config/base.cjs',
37+
'@react-hookz/eslint-config/react.cjs',
38+
'@react-hookz/eslint-config/jest.cjs',
39+
],
40+
},
41+
{
42+
files: ['**/__tests__/**/*.ts'],
43+
extends: [
44+
'@react-hookz/eslint-config/typescript-unsafe.cjs',
45+
'@react-hookz/eslint-config/jest.cjs',
46+
],
47+
},
48+
{
49+
files: ['**/__tests__/**/*.tsx'],
50+
extends: [
51+
'@react-hookz/eslint-config/typescript-unsafe.cjs',
52+
'@react-hookz/eslint-config/react.cjs',
53+
'@react-hookz/eslint-config/jest.cjs',
54+
],
5255
},
5356
{
5457
files: ['*.md'],
55-
extends: ['@react-hookz/eslint-config/mdx'],
58+
extends: ['@react-hookz/eslint-config/md.cjs'],
59+
},
60+
{
61+
files: ['*.mdx'],
62+
extends: ['@react-hookz/eslint-config/mdx.cjs'],
5663
},
5764
],
5865
};

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const config = require("@react-hookz/eslint-config/.prettierrc.js");
1+
const config = require('@react-hookz/eslint-config/.prettierrc.cjs');
22

33
module.exports = config;

.storybook/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ module.exports = {
1717
fastRefresh: true,
1818
},
1919
staticDirs: ['./public'],
20-
managerWebpack: (config, options) => {
21-
// ToDo: maybe enable cache mack when storybook is fixed
22-
options.cache.set = () => Promise.resolve(); // eslint-disable-line @typescript-eslint/no-unsafe-member-access
20+
managerWebpack(config, options) {
21+
options.cache.set = () => Promise.resolve();
2322

24-
return config; // eslint-disable-line @typescript-eslint/no-unsafe-return
23+
return config;
2524
},
2625
};

jest.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const cfg: Config = {
2121
testMatch: ['<rootDir>/src/**/__tests__/ssr.[jt]s?(x)'],
2222
},
2323

24-
// needed for output bundle testing
24+
// Needed for output bundle testing
2525
{
2626
displayName: 'dom-package',
2727
transformIgnorePatterns: [],
@@ -41,5 +41,4 @@ const cfg: Config = {
4141
collectCoverageFrom: ['./src/**/*.{ts,js,tsx,jsx}', '!**/__tests__/**', '!**/__docs__/**'],
4242
};
4343

44-
// eslint-disable-next-line import/no-default-export
4544
export default cfg;

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"new-hook": "node ./utility/add-new-hook.js",
3939
"test": "jest --selectProjects dom ssr",
4040
"test:coverage": "yarn test --coverage",
41-
"lint": "eslint ./ ./.storybook --ext ts,js,tsx,jsx,md",
41+
"lint": "eslint ./ ./.storybook --ext ts,js,tsx,jsx,md,mdx",
4242
"lint:fix": "yarn lint --fix",
4343
"storybook:watch": "start-storybook -p 6006 --docs --no-manager-cache",
4444
"storybook:build": "build-storybook --docs -o ./storybook-build",
@@ -77,15 +77,15 @@
7777
},
7878
"devDependencies": {
7979
"@babel/core": "^7.22.5",
80-
"@commitlint/cli": "^17.6.0",
80+
"@commitlint/cli": "^17.6.6",
8181
"@commitlint/config-conventional": "^17.6.6",
8282
"@commitlint/cz-commitlint": "^17.5.0",
8383
"@jamesacarr/jest-reporter-github-actions": "^0.0.4",
84-
"@react-hookz/eslint-config": "^1.7.6",
84+
"@react-hookz/eslint-config": "^2.0.0",
8585
"@react-hookz/eslint-formatter-gha": "^1.0.1",
8686
"@semantic-release/changelog": "^6.0.3",
8787
"@semantic-release/git": "^10.0.1",
88-
"@semantic-release/github": "^8.1.0",
88+
"@semantic-release/github": "^9.0.3",
8989
"@storybook/addon-docs": "^6.5.16",
9090
"@storybook/addon-essentials": "^6.5.16",
9191
"@storybook/addon-links": "^6.5.16",
@@ -101,8 +101,8 @@
101101
"@testing-library/react-hooks": "^8.0.1",
102102
"@types/jest": "^29.5.2",
103103
"@types/js-cookie": "^3.0.3",
104-
"@types/react": "^18.0.17",
105-
"@types/react-dom": "^18.0.6",
104+
"@types/react": "^18.2.14",
105+
"@types/react-dom": "^18.2.6",
106106
"babel-loader": "^9.1.2",
107107
"commitizen": "^4.3.0",
108108
"commitlint": "^17.6.6",

src/__docs__/ImportPath.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { DocsContext, Source } from '@storybook/addon-docs';
2-
import React, { FC, useContext } from 'react';
2+
import React, { type FC, useContext } from 'react';
33

4-
export interface ImportPathProps {
5-
root?: boolean;
6-
direct?: boolean;
7-
}
4+
export type ImportPathProps = {
5+
isRoot?: boolean;
6+
isDirect?: boolean;
7+
};
88

9-
export const ImportPath: FC<ImportPathProps> = ({ root = true, direct = true }) => {
9+
export function ImportPath({ isRoot = true, isDirect = true }: ImportPathProps) {
1010
const context = useContext(DocsContext);
11-
// eslint-disable-next-line react/destructuring-assignment
11+
1212
const componentName = context.title?.split('/')[1] || 'UnknownComponent';
1313

1414
const imports: string[] = [];
1515

16-
if (root) {
16+
if (isRoot) {
1717
imports.push(`// root import\nimport { ${componentName} } from '@react-hookz/web';`);
1818
}
1919

20-
if (direct) {
20+
if (isDirect) {
2121
imports.push(
2222
`// direct import\nimport { ${componentName} } from '@react-hookz/web/esm/${componentName}';`
2323
);
2424
}
2525

2626
return <Source language="js" code={imports.join('\n')} />;
27-
};
27+
}

src/__docs__/Introduction.story.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Meta} from '@storybook/addon-docs';
1+
import { Meta } from '@storybook/addon-docs';
22

33
<Meta title="Home" />
44

@@ -42,7 +42,7 @@ transpile your `node-modules` in order to run in IE.
4242
## Usage
4343

4444
> This package distributed with ESNext language level and both, CJS and ES imports.
45-
> It means that depending on your browser target you might need to transpile it. Every major
45+
> It means that depending on your browser target you might need to transpile it. Every major
4646
> bundler provides a way to transpile `node_modules` fully or partially.
4747
> Address your bundler documentation for more details.
4848
@@ -62,7 +62,7 @@ In case, for some reason, you are not able to use ES imports - you should direct
6262

6363
## Migrating from react-use
6464

65-
`@react-hookz/web` was built as a [spiritual successor](https://github.com/streamich/react-use/issues/1974)
65+
`@react-hookz/web` was built as a [spiritual successor](https://github.com/streamich/react-use/issues/1974)
6666
of `react-use` by one of its former maintainers.
6767

6868
Coming from `react-use`? Check out our

src/__tests__/navigator.vibrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const NavigatorVibrateSetup = () => {
1+
export const setupNavigatorVibrate = () => {
22
navigator.vibrate = (() => true) as typeof navigator.vibrate;
33
};

src/__tests__/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* Here goes any setup code that should be performed before actual tests and/or code imports.
33
*/
44

5-
import { NavigatorVibrateSetup } from './navigator.vibrate';
5+
import { setupNavigatorVibrate } from './navigator.vibrate';
66

7-
NavigatorVibrateSetup();
7+
setupNavigatorVibrate();

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export * from './useClickOutside';
7070
export * from './useEventListener';
7171
export * from './useWindowSize';
7272

73-
// utils
73+
// Utils
7474
export { isStrictEqual, truthyAndArrayPredicate, truthyOrArrayPredicate } from './util/const';
75-
export { EffectCallback, EffectHook } from './util/misc';
75+
export type { EffectCallback, EffectHook } from './util/misc';
7676
export { resolveHookState } from './util/resolveHookState';
7777

7878
// Types

src/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { DependencyList } from 'react';
1+
import { type DependencyList } from 'react';
22

33
export type DependenciesComparator<Deps extends DependencyList = DependencyList> = (
44
a: Deps,
55
b: Deps
66
) => boolean;
77

8-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
98
export type Predicate = (prev: any, next: any) => boolean;
109

11-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
12-
export type ConditionsList = ReadonlyArray<any>;
10+
export type ConditionsList = readonly any[];
1311

1412
export type ConditionsPredicate<Cond extends ConditionsList = ConditionsList> = (
1513
conditions: Cond

src/useAsync/__docs__/example.stories.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { useAsync, useMountEffect } from '../..';
33

4-
export const Example: React.FC = () => {
4+
export function Example() {
55
const [state, actions] = useAsync(
66
() =>
77
new Promise<string>((resolve) => {
@@ -25,6 +25,7 @@ export const Example: React.FC = () => {
2525
<br />
2626
<div>
2727
<button
28+
type="button"
2829
onClick={() => {
2930
actions.reset();
3031
// eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -33,6 +34,7 @@ export const Example: React.FC = () => {
3334
reset
3435
</button>{' '}
3536
<button
37+
type="button"
3638
onClick={() => {
3739
// eslint-disable-next-line @typescript-eslint/no-floating-promises
3840
actions.execute();
@@ -42,4 +44,4 @@ export const Example: React.FC = () => {
4244
</div>
4345
</div>
4446
);
45-
};
47+
}

src/useAsync/__docs__/story.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Canvas, Meta, Story} from '@storybook/addon-docs';
2-
import {Example} from './example.stories';
3-
import {ImportPath} from '../../__docs__/ImportPath';
1+
import { Canvas, Meta, Story } from '@storybook/addon-docs';
2+
import { Example } from './example.stories';
3+
import { ImportPath } from '../../__docs__/ImportPath';
44

55
<Meta title="Side-effect/useAsync" component={Example} />
66

@@ -52,7 +52,7 @@ export function useAsync<Result, Args extends unknown[] = unknown[]>(
5252
- **reset** _`() => void`_- Reset state to initial.
5353
- **execute** _`(...args: Args) => Promise<Result>`_- Execute the async function manually.
5454

55-
2. **meta**
55+
3. **meta**
5656

5757
- **promise** _`Promise<Result> | undefined`_- Latest promise returned from the async function.
5858
- **lastArgs** _`Args | undefined`_ - List of arguments applied to the latest async function

src/useAsync/__tests__/dom.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/require-await */
21
import { act, renderHook } from '@testing-library/react-hooks/dom';
32
import { useAsync } from '../..';
43

@@ -56,7 +55,7 @@ describe('useAsync', () => {
5655

5756
it('should have `not-executed` status initially', async () => {
5857
await act(async () => {
59-
const [spy, resolve] = getControllableAsync<undefined | null, []>();
58+
const [spy, resolve] = getControllableAsync<void, []>();
6059
const { result } = renderHook(() => useAsync(spy));
6160

6261
expect(result.current[0]).toStrictEqual({
@@ -66,13 +65,13 @@ describe('useAsync', () => {
6665
});
6766

6867
if (resolve.current) {
69-
resolve.current(null);
68+
resolve.current();
7069
}
7170
});
7271
});
7372

7473
it('should have `loading` status while promise invoked but not resolved', async () => {
75-
const [spy, resolve] = getControllableAsync<undefined | null, []>();
74+
const [spy, resolve] = getControllableAsync<void, []>();
7675
const { result } = renderHook(() => useAsync(spy));
7776

7877
expect(result.current[0]).toStrictEqual({
@@ -94,7 +93,7 @@ describe('useAsync', () => {
9493

9594
await act(async () => {
9695
if (resolve.current) {
97-
resolve.current(null);
96+
resolve.current();
9897
}
9998
});
10099
});

0 commit comments

Comments
 (0)