Skip to content

Commit dc9b250

Browse files
walauragaearon
authored andcommitted
Remove the condition argument from warning() (#17568)
* prep for codemod * prep warnings * rename lint rules * codemod for ifs * shim www functions * Handle more cases in the transform * Thanks De Morgan * Run the codemod * Delete the transform * Fix up confusing conditions manually * Fix up www shims to match expected API * Also check for low-pri warning in the lint rule
1 parent 8e5e37d commit dc9b250

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/ReactShallowRenderer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ function areHookInputsEqual(
6363
if (prevDeps === null) {
6464
if (__DEV__) {
6565
warning(
66-
false,
6766
'%s received a final argument during this render, but not during ' +
6867
'the previous render. Even though the final argument is optional, ' +
6968
'its type cannot change between renders.',
@@ -78,7 +77,6 @@ function areHookInputsEqual(
7877
// passed inline.
7978
if (nextDeps.length !== prevDeps.length) {
8079
warning(
81-
false,
8280
'The final argument passed to %s changed size between renders. The ' +
8381
'order and size of this array must remain constant.\n\n' +
8482
'Previous: %s\n' +

src/ReactTestHostConfig.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ export function appendChild(
8282
child: Instance | TextInstance,
8383
): void {
8484
if (__DEV__) {
85-
warning(
86-
Array.isArray(parentInstance.children),
87-
'An invalid container has been provided. ' +
88-
'This may indicate that another renderer is being used in addition to the test renderer. ' +
89-
'(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
90-
'This is not supported.',
91-
);
85+
if (!Array.isArray(parentInstance.children)) {
86+
warning(
87+
'An invalid container has been provided. ' +
88+
'This may indicate that another renderer is being used in addition to the test renderer. ' +
89+
'(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
90+
'This is not supported.',
91+
);
92+
}
9293
}
9394
const index = parentInstance.children.indexOf(child);
9495
if (index !== -1) {
@@ -216,12 +217,13 @@ export function createTextInstance(
216217
): TextInstance {
217218
if (__DEV__) {
218219
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-
);
220+
if (hostContext === EVENT_COMPONENT_CONTEXT) {
221+
warning(
222+
'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
223+
'Wrap the child text "%s" in an element.',
224+
text,
225+
);
226+
}
225227
}
226228
}
227229
return {

src/ReactTestRendererAct.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ function act(callback: () => Thenable) {
8484
if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
8585
// if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
8686
warningWithoutStack(
87-
null,
8887
'You seem to have overlapping act() calls, this is not supported. ' +
8988
'Be sure to await previous act() calls before making a new one. ',
9089
);
@@ -117,7 +116,6 @@ function act(callback: () => Thenable) {
117116
.then(() => {
118117
if (called === false) {
119118
warningWithoutStack(
120-
null,
121119
'You called act(async () => ...) without await. ' +
122120
'This could lead to unexpected testing behaviour, interleaving multiple act ' +
123121
'calls and mixing their scopes. You should - await act(async () => ...);',
@@ -164,12 +162,13 @@ function act(callback: () => Thenable) {
164162
};
165163
} else {
166164
if (__DEV__) {
167-
warningWithoutStack(
168-
result === undefined,
169-
'The callback passed to act(...) function ' +
170-
'must return undefined, or a Promise. You returned %s',
171-
result,
172-
);
165+
if (result !== undefined) {
166+
warningWithoutStack(
167+
'The callback passed to act(...) function ' +
168+
'must return undefined, or a Promise. You returned %s',
169+
result,
170+
);
171+
}
173172
}
174173

175174
// flush effects until none remain, and cleanup
@@ -193,7 +192,6 @@ function act(callback: () => Thenable) {
193192
then(resolve: () => void) {
194193
if (__DEV__) {
195194
warningWithoutStack(
196-
false,
197195
'Do not await the result of calling act(...) with sync logic, it is not a Promise.',
198196
);
199197
}

0 commit comments

Comments
 (0)