Skip to content

Commit 8385d80

Browse files
authored
chore: run eslint over test files and fix surfaced errors (#374)
* chore: run eslint over test files and fix surfaced errors The `lint` script only scanned `src/`, so the jest config block for `tests/**` in eslint.config.mjs never actually ran. Extend the script to cover `tests/` and fix the 3 errors it surfaces: - domHook.js: setter used `return` for control flow, but a setter's return value is silently discarded (no-setter-return) -> use if/else - scroll.test.js: oversized deltaY literal lost precision (no-loss-of-precision) -> 1e20, same magnitude - drop dead `eslint-disable no-param-reassign` directives in domHook.js and useScrollTo.tsx (the rule isn't enabled) * update
1 parent 167e60c commit 8385d80

5 files changed

Lines changed: 8 additions & 12 deletions

File tree

.github/workflows/react-doctor.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ jobs:
1919
- uses: actions/checkout@v7
2020
with:
2121
persist-credentials: false
22-
- uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3
23-
with:
24-
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
- uses: millionco/react-doctor@964622bf15fa5f8eef7e05196407aa08dc779087 # v2.2.7

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"docs:deploy": "gh-pages -d docs-dist",
3636
"deploy": "npm run gh-pages",
3737
"gh-pages": "npm run compile && cross-env GH_PAGES=1 npm run docs:build && npm run docs:deploy",
38-
"lint": "eslint src/ --ext .tsx,.ts",
38+
"lint": "eslint src/ tests/ --ext .tsx,.ts,.jsx,.js",
3939
"prepublishOnly": "npm run compile && rc-np",
4040
"prettier": "prettier --write --ignore-unknown .",
4141
"start": "dumi dev",

src/hooks/useScrollTo.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-param-reassign */
21
import * as React from 'react';
32
import { raf, useLayoutEffect, warning } from '@rc-component/util';
43
import type { GetKey, GetSize } from '../interface';

tests/scroll.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ describe('List.Scroll', () => {
559559
const holder = container.querySelector('ul');
560560

561561
const event = createEvent.wheel(holder, {
562-
deltaY: 99999999999999999999,
562+
deltaY: 1e20,
563563
});
564564
fireEvent(holder, event);
565565

tests/utils/domHook.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/* eslint-disable no-param-reassign */
21
const NO_EXIST = { __NOT_EXIST: true };
32

43
export function spyElementPrototypes(Element, properties) {
54
const propNames = Object.keys(properties);
65
const originDescriptors = {};
76

8-
propNames.forEach(propName => {
7+
propNames.forEach((propName) => {
98
const originDescriptor = Object.getOwnPropertyDescriptor(Element.prototype, propName);
109
originDescriptors[propName] = originDescriptor || NO_EXIST;
1110

@@ -22,9 +21,10 @@ export function spyElementPrototypes(Element, properties) {
2221
...spyProp,
2322
set(value) {
2423
if (spyProp.set) {
25-
return spyProp.set.call(this, originDescriptor, value);
24+
spyProp.set.call(this, originDescriptor, value);
25+
} else {
26+
originDescriptor.set(value);
2627
}
27-
return originDescriptor.set(value);
2828
},
2929
get() {
3030
if (spyProp.get) {
@@ -39,7 +39,7 @@ export function spyElementPrototypes(Element, properties) {
3939

4040
return {
4141
mockRestore() {
42-
propNames.forEach(propName => {
42+
propNames.forEach((propName) => {
4343
const originDescriptor = originDescriptors[propName];
4444
if (originDescriptor === NO_EXIST) {
4545
delete Element.prototype[propName];
@@ -58,4 +58,3 @@ export function spyElementPrototype(Element, propName, property) {
5858
[propName]: property,
5959
});
6060
}
61-
/* eslint-enable no-param-reassign */

0 commit comments

Comments
 (0)