Skip to content

Setup react hooks linting #3034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc-typescript
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"rules": {
"react/prop-types": 0,
"react/no-find-dom-node": 0,
"react/display-name": 0,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.1",
"jest-environment-jsdom": "^27.5.1",
"lerna": "^5.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const ArrayFieldTemplate = (props: ArrayFieldTemplateProps) => {
className="p-0 m-0"
>
{items &&
items.map((itemProps: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate {...itemProps} />
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
{canAdd && (
<Container className="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const ArrayFieldTemplate = (props: ArrayFieldTemplateProps) => {
<Grid key={`array-item-list-${idSchema.$id}`}>
<GridItem>
{items.length > 0 &&
items.map((itemProps: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate {...itemProps} />
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
</GridItem>
{canAdd && (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/fields/NullField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function NullField<T = any, F = any>(props: FieldProps<T, F>) {
if (formData === undefined) {
onChange(null as unknown as T);
}
}, []);
}, [formData, onChange]);

return null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/templates/ArrayFieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export default function ArrayFieldTemplate<T = any, F = any>(
)}
<div className="row array-item-list">
{items &&
items.map((itemProps: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate {...itemProps} />
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
</div>
{canAdd && (
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/widgets/AltDateWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ function AltDateWidget<T = any, F = any>({
if (value && value !== toDateString(state, time)) {
setState(parseDateString(value, time));
}
}, [value]);
}, [value, state, time]);

useEffect(() => {
if (readyForChange(state)) {
// Only propagate to parent state if we have a complete date{time}
onChange(toDateString(state, time));
}
}, [state, time]);
}, [state, time, onChange]);

const handleChange = (property: keyof DateObject, value: string) => {
setState({ [property]: value });
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/ArrayField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ describe("ArrayField", () => {
set onload(fn) {
fn({ target: { result: "data:text/plain;base64,x=" } });
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
readAsDataUrl() {},
});

Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/StringField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,7 @@ describe("StringField", () => {
set onload(fn) {
fn({ target: { result: "data:text/plain;base64,x=" } });
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
readAsDataUrl() {},
});

Expand Down Expand Up @@ -1899,6 +1900,7 @@ describe("StringField", () => {
set onload(fn) {
fn({ target: { result: "data:text/plain;base64,x=" } });
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
readAsDataUrl() {},
});

Expand Down
5 changes: 3 additions & 2 deletions packages/core/test/setup-jsdom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var { JSDOM } = require("jsdom");
import { JSDOM } from "jsdom";
import html from "html";

// Setup the jsdom environment
// @see https://github.com/facebook/react/issues/5046
Expand All @@ -15,5 +16,5 @@ global.atob = require("atob");

// HTML debugging helper
global.d = function d(node) {
console.log(require("html").prettyPrint(node.outerHTML, { indent_size: 2 }));
console.log(html.prettyPrint(node.outerHTML, { indent_size: 2 }));
};
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const ArrayFieldTemplate = (props: ArrayFieldTemplateProps) => {
/>
)}
{items.length > 0 &&
items.map((itemProps: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate {...itemProps} />
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
{canAdd && (
<span style={rightJustify}>
Expand Down
9 changes: 6 additions & 3 deletions packages/fluent-ui/src/CheckboxWidget/CheckboxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ const CheckboxWidget = (props: WidgetProps) => {
options,
} = props;

const _onChange = React.useCallback((_, checked?: boolean): void => {
onChange(checked);
}, []);
const _onChange = React.useCallback(
(_, checked?: boolean): void => {
onChange(checked);
},
[onChange]
);

const _onBlur = ({
target: { value },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const ArrayFieldTemplate = (props: ArrayFieldTemplateProps) => {
)}
<Grid container={true} key={`array-item-list-${idSchema.$id}`}>
{items &&
items.map((itemProps: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate {...itemProps} />
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
{canAdd && (
<Grid container justifyContent="flex-end">
Expand Down
4 changes: 2 additions & 2 deletions packages/mui/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const ArrayFieldTemplate = (props: ArrayFieldTemplateProps) => {
)}
<Grid container={true} key={`array-item-list-${idSchema.$id}`}>
{items &&
items.map((itemProps: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate {...itemProps} />
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
{canAdd && (
<Grid container justifyContent="flex-end">
Expand Down