Skip to content

Commit

Permalink
Update react hooks rules tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsonntag authored and flaviocastro committed Apr 15, 2019
1 parent d7f0a2a commit 2aaeb48
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
31 changes: 25 additions & 6 deletions test/fixtures/correct.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ function noop() {
// Do nothing
}

// Declare `React` and other react-related variables.
const React = null;

// `array-bracket-spacing`, `comma-spacing` and `no-multi-spaces`.
noop(['bar', 'foo']);

Expand Down Expand Up @@ -384,20 +387,36 @@ if (yoda === true) {
yoda = false;
}

// `react-hooks/rules-of-hooks`.
const useEffect = noop;
// `react-hooks/exhaustive-deps`.
const ExhaustiveDeps = ({ foo }) => {
React.useEffect(() => foo());
React.useEffect(() => foo(), [foo]);
React.useMemo(() => foo(), [foo]);
React.useCallback(() => foo(), [foo]);

const [bar, setBar] = React.useState();

React.useEffect(() => setBar(!bar), [bar]);

return null;
};

noop(ExhaustiveDeps);

// `react-hooks/rules-of-hooks`.
const RulesOfHooks = () => {
useEffect(noop);
React.useState();

return null;
};

noop(RulesOfHooks);
function useHook() {
React.useState();
}

// `react/jsx-tag-spacing`.
const React = null;
noop(RulesOfHooks, useHook);

// `react/jsx-tag-spacing`.
const TagSpacing = () => (
<div />
);
Expand Down
36 changes: 29 additions & 7 deletions test/fixtures/incorrect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ function noop() {
// Do nothing
}

// Declare `React` and other react-related variables.
const React = null;

// `array-bracket-spacing`.
noop([ 'bar', 'foo']);

Expand Down Expand Up @@ -381,22 +384,41 @@ if (true === yoda) {
yoda = false;
}

// `react-hooks/exhaustive-deps`.
const ExhaustiveDeps = ({ foo }) => {
React.useEffect(() => foo(), []);
React.useMemo(() => foo);
React.useMemo(() => foo(), []);
React.useCallback(() => foo);
React.useCallback(() => foo(), []);

return null;
};

noop(ExhaustiveDeps);

// `react-hooks/rules-of-hooks`.
const useEffect = noop;
const RulesOfHooks = ({ foo }) => {
if (foo) {
React.useState();
}

const RulesOfHooks = () => {
if (Math.random() > 0.5) {
useEffect(noop);
for (let i = 0; i < 10; i++) {
React.useState();
}

setTimeout(() => React.useState(), 10);

return null;
};

noop(RulesOfHooks);
function notHook() {
React.useState();
}

noop(RulesOfHooks, notHook);

// `react/jsx-tag-spacing`.
const React = null;

const TagSpacingAfterOpening = () => (
< div />
);
Expand Down
14 changes: 11 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ describe('eslint-config-seegno', () => {
'jest/no-disabled-tests',
'jest/no-disabled-tests',
'jest/no-disabled-tests',
'mocha/no-exclusive-tests',
'jest/no-focused-tests',
'jest/no-focused-tests',
'mocha/no-exclusive-tests',
'jest/no-focused-tests',
'mocha/no-exclusive-tests',
'jest/no-focused-tests',
'mocha/no-exclusive-tests',
'jest/no-focused-tests',
'jest/no-focused-tests',
'jest/no-identical-title',
Expand Down Expand Up @@ -123,13 +123,21 @@ describe('eslint-config-seegno', () => {
'spaced-comment',
'sql-template/no-unsafe-query',
'switch-case/newline-between-switch-case',
'no-fallthrough',
'switch-case/newline-between-switch-case',
'no-fallthrough',
'template-curly-spacing',
'template-curly-spacing',
'wrap-iife',
'sort-destructure-keys/sort-destructure-keys',
'yoda',
'react-hooks/exhaustive-deps',
'react-hooks/exhaustive-deps',
'react-hooks/exhaustive-deps',
'react-hooks/exhaustive-deps',
'react-hooks/exhaustive-deps',
'react-hooks/rules-of-hooks',
'react-hooks/rules-of-hooks',
'react-hooks/rules-of-hooks',
'react-hooks/rules-of-hooks',
'react/jsx-tag-spacing',
'react/jsx-tag-spacing',
Expand Down

0 comments on commit 2aaeb48

Please sign in to comment.