Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,46 @@

// This should trigger an error breaking eslint-plugin-react-hooks:
// react-hooks/exhaustive-deps
// react-hooks/rules-of-hooks
// react-hooks/error-boundaries

import { useState, useEffect } from "react";
import { useEffect, useState } from "react";
import { View } from "react-native";

const MyComponent = () => {
const [count, setCount] = useState(0);
// react-hooks/exhaustive-deps
// Missing `count` in the dependency array
const ExhaustiveDepsComponent = () => {
const [count] = useState(0);

useEffect(() => void String(count), []);

return <View />;
};

useEffect(() => {
setCount(count + 1);
}, []);
// react-hooks/rules-of-hooks
// Hooks must not be called conditionally
const RulesOfHooksComponent = ({ isEnabled }: { isEnabled: boolean }) => {
if (isEnabled) {
const [value] = useState("conditional");
return <View testID={value} />;
}

return <></>;
return <View />;
};

export default MyComponent;
// react-hooks/error-boundaries
// Use error boundaries instead of try/catch for child component errors
const ErrorBoundaryComponent = () => {
try {
const result = JSON.parse("{}") as Record<string, string>;
return <View testID={result["id"]} />;
} catch {
return <View testID="fallback" />;
}
};

export {
ErrorBoundaryComponent,
ExhaustiveDepsComponent,
RulesOfHooksComponent,
};
8 changes: 0 additions & 8 deletions packages/eslint-plugin/lib/configs/declarations.d.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si pas nécessaire + on ne sait pas d'où il vient, comment il a été fait et qu'en plus on n'en a pas besoin, autant ne pas le mettre.
Ou creuser ce qui se passe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup j'ai creusé, le fichier sert à typer nos rules, mais il est pertinent uniquement pour celles qui ne le sont pas déjà, du coup je supprime la partie "eslint-plugin-react-hooks" car le package inclut le typage

Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
declare module "eslint-plugin-react-hooks" {
import type { Linter, Rule } from "eslint";
export const rules: {
"rules-of-hooks": Rule.RuleModule;
"exhaustive-deps": Rule.RuleModule;
};
}

declare module "eslint-plugin-react-native" {
export const deprecatedRules: Record<string, any>;
export const rules: Record<string, any>;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/lib/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const recommendedConfig = tseslint.config(
tseslint.configs.recommended,
eslint.configs.recommended,
eslintPluginPrettierRecommended,
reactHookPlugin.configs.flat.recommended,
{
rules: {
"no-var": "error",
Expand Down Expand Up @@ -50,7 +51,6 @@ export const recommendedConfig = tseslint.config(
plugins: {
react,
"react-native": reactNativePlugin,
"react-hooks": reactHookPlugin,
"@bam.tech": {
rules: {
"no-different-displayname": noDifferentDisplaynameRule,
Expand Down
Loading