Skip to content

Commit 8e5e37d

Browse files
Laura bunsgaearon
authored andcommitted
Replace wrap-warning-with-env-check with an eslint plugin (#17540)
* Replace Babel plugin with an ESLint plugin * Fix ESLint rule violations * Move shared conditions higher * Test formatting nits * Tweak ESLint rule * Bugfix: inside else branch, 'if' tests are not satisfactory * Use a stricter check for exactly if (__DEV__) This makes it easier to see what's going on and matches dominant style in the codebase. * Fix remaining files after stricter check
1 parent af6f895 commit 8e5e37d

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

src/ReactShallowRenderer.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,33 @@ function areHookInputsEqual(
6161
prevDeps: Array<mixed> | null,
6262
) {
6363
if (prevDeps === null) {
64-
warning(
65-
false,
66-
'%s received a final argument during this render, but not during ' +
67-
'the previous render. Even though the final argument is optional, ' +
68-
'its type cannot change between renders.',
69-
currentHookNameInDev,
70-
);
64+
if (__DEV__) {
65+
warning(
66+
false,
67+
'%s received a final argument during this render, but not during ' +
68+
'the previous render. Even though the final argument is optional, ' +
69+
'its type cannot change between renders.',
70+
currentHookNameInDev,
71+
);
72+
}
7173
return false;
7274
}
7375

74-
// Don't bother comparing lengths in prod because these arrays should be
75-
// passed inline.
76-
if (nextDeps.length !== prevDeps.length) {
77-
warning(
78-
false,
79-
'The final argument passed to %s changed size between renders. The ' +
80-
'order and size of this array must remain constant.\n\n' +
81-
'Previous: %s\n' +
82-
'Incoming: %s',
83-
currentHookNameInDev,
84-
`[${nextDeps.join(', ')}]`,
85-
`[${prevDeps.join(', ')}]`,
86-
);
76+
if (__DEV__) {
77+
// Don't bother comparing lengths in prod because these arrays should be
78+
// passed inline.
79+
if (nextDeps.length !== prevDeps.length) {
80+
warning(
81+
false,
82+
'The final argument passed to %s changed size between renders. The ' +
83+
'order and size of this array must remain constant.\n\n' +
84+
'Previous: %s\n' +
85+
'Incoming: %s',
86+
currentHookNameInDev,
87+
`[${nextDeps.join(', ')}]`,
88+
`[${prevDeps.join(', ')}]`,
89+
);
90+
}
8791
}
8892
for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
8993
if (is(nextDeps[i], prevDeps[i])) {

src/ReactTestHostConfig.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,15 @@ export function createTextInstance(
214214
hostContext: Object,
215215
internalInstanceHandle: Object,
216216
): TextInstance {
217-
if (__DEV__ && enableFlareAPI) {
218-
warning(
219-
hostContext !== EVENT_COMPONENT_CONTEXT,
220-
'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
221-
'Wrap the child text "%s" in an element.',
222-
text,
223-
);
217+
if (__DEV__) {
218+
if (enableFlareAPI) {
219+
warning(
220+
hostContext !== EVENT_COMPONENT_CONTEXT,
221+
'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
222+
'Wrap the child text "%s" in an element.',
223+
text,
224+
);
225+
}
224226
}
225227
return {
226228
text,

0 commit comments

Comments
 (0)