Skip to content

Commit

Permalink
Remove the condition argument from warning() (#17568)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
walaura authored and gaearon committed Dec 11, 2019
1 parent 7bf40e1 commit 9ac42dd
Show file tree
Hide file tree
Showing 102 changed files with 903 additions and 1,047 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ module.exports = {
// the second argument of warning/invariant should be a literal string
'react-internal/no-primitive-constructors': ERROR,
'react-internal/no-to-warn-dev-within-to-throw': ERROR,
'react-internal/warning-and-invariant-args': ERROR,
'react-internal/invariant-args': ERROR,
'react-internal/warning-args': ERROR,
'react-internal/no-production-logging': ERROR,
},

Expand Down
16 changes: 8 additions & 8 deletions packages/create-subscription/src/createSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export function createSubscription<Property, Value>(
const {getCurrentValue, subscribe} = config;

if (__DEV__) {
warningWithoutStack(
typeof getCurrentValue === 'function',
'Subscription must specify a getCurrentValue function',
);
warningWithoutStack(
typeof subscribe === 'function',
'Subscription must specify a subscribe function',
);
if (typeof getCurrentValue !== 'function') {
warningWithoutStack(
'Subscription must specify a getCurrentValue function',
);
}
if (typeof subscribe !== 'function') {
warningWithoutStack('Subscription must specify a subscribe function');
}
}

type Props = {
Expand Down
18 changes: 9 additions & 9 deletions packages/legacy-events/EventPluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export function setComponentTree(
getInstanceFromNode = getInstanceFromNodeImpl;
getNodeFromInstance = getNodeFromInstanceImpl;
if (__DEV__) {
warningWithoutStack(
getNodeFromInstance && getInstanceFromNode,
'EventPluginUtils.setComponentTree(...): Injected ' +
'module is missing getNodeFromInstance or getInstanceFromNode.',
);
if (!getNodeFromInstance || !getInstanceFromNode) {
warningWithoutStack(
'EventPluginUtils.setComponentTree(...): Injected ' +
'module is missing getNodeFromInstance or getInstanceFromNode.',
);
}
}
}

Expand All @@ -50,10 +51,9 @@ if (__DEV__) {
? 1
: 0;

warningWithoutStack(
instancesIsArr === listenersIsArr && instancesLen === listenersLen,
'EventPluginUtils: Invalid `event`.',
);
if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
warningWithoutStack('EventPluginUtils: Invalid `event`.');
}
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/legacy-events/EventPropagators.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
*/
function accumulateDirectionalDispatches(inst, phase, event) {
if (__DEV__) {
warningWithoutStack(inst, 'Dispatching inst must not be null');
if (!inst) {
warningWithoutStack('Dispatching inst must not be null');
}
}
const listener = listenerAtPhase(inst, event, phase);
if (listener) {
Expand Down
22 changes: 11 additions & 11 deletions packages/legacy-events/ResponderTouchHistoryStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ function resetTouchRecord(touchRecord: TouchRecord, touch: Touch): void {
function getTouchIdentifier({identifier}: Touch): number {
invariant(identifier != null, 'Touch object is missing identifier.');
if (__DEV__) {
warningWithoutStack(
identifier <= MAX_TOUCH_BANK,
'Touch identifier %s is greater than maximum supported %s which causes ' +
'performance issues backfilling array locations for all of the indices.',
identifier,
MAX_TOUCH_BANK,
);
if (identifier > MAX_TOUCH_BANK) {
warningWithoutStack(
'Touch identifier %s is greater than maximum supported %s which causes ' +
'performance issues backfilling array locations for all of the indices.',
identifier,
MAX_TOUCH_BANK,
);
}
}
return identifier;
}
Expand Down Expand Up @@ -200,10 +201,9 @@ const ResponderTouchHistoryStore = {
}
if (__DEV__) {
const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
warningWithoutStack(
activeRecord != null && activeRecord.touchActive,
'Cannot find single active touch.',
);
if (activeRecord == null || !activeRecord.touchActive) {
warningWithoutStack('Cannot find single active touch.');
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/legacy-events/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
function warn(action, result) {
if (__DEV__) {
warningWithoutStack(
false,
"This synthetic event is reused for performance reasons. If you're seeing this, " +
"you're %s `%s` on a released/nullified synthetic event. %s. " +
'If you must keep the original synthetic event around, use event.persist(). ' +
Expand Down
27 changes: 15 additions & 12 deletions packages/react-cache/src/ReactCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ function readContext(Context, observedBits) {

function identityHashFn(input) {
if (__DEV__) {
warningWithoutStack(
typeof input === 'string' ||
typeof input === 'number' ||
typeof input === 'boolean' ||
input === undefined ||
input === null,
'Invalid key type. Expected a string, number, symbol, or boolean, ' +
'but instead received: %s' +
'\n\nTo use non-primitive values as keys, you must pass a hash ' +
'function as the second argument to createResource().',
input,
);
if (
typeof input !== 'string' &&
typeof input !== 'number' &&
typeof input !== 'boolean' &&
input !== undefined &&
input !== null
) {
warningWithoutStack(
'Invalid key type. Expected a string, number, symbol, or boolean, ' +
'but instead received: %s' +
'\n\nTo use non-primitive values as keys, you must pass a hash ' +
'function as the second argument to createResource().',
input,
);
}
}
return input;
}
Expand Down
2 changes: 0 additions & 2 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ if (__DEV__) {
typeof Set.prototype.forEach !== 'function'
) {
warningWithoutStack(
false,
'React depends on Map and Set built-in types. Make sure that you load a ' +
'polyfill in older browsers. https://fb.me/react-polyfills',
);
Expand Down Expand Up @@ -146,7 +145,6 @@ const ReactDOM: Object = {
if (!didWarnAboutUnstableCreatePortal) {
didWarnAboutUnstableCreatePortal = true;
lowPriorityWarningWithoutStack(
false,
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
'and will be removed in React 17+. Update your code to use ' +
'ReactDOM.createPortal() instead. It has the exact same API, ' +
Expand Down
29 changes: 9 additions & 20 deletions packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ if (__DEV__) {
}
didWarnInvalidHydration = true;
warningWithoutStack(
false,
'Text content did not match. Server: "%s" Client: "%s"',
normalizedServerText,
normalizedClientText,
Expand All @@ -211,7 +210,6 @@ if (__DEV__) {
}
didWarnInvalidHydration = true;
warningWithoutStack(
false,
'Prop `%s` did not match. Server: %s Client: %s',
propName,
JSON.stringify(normalizedServerValue),
Expand All @@ -228,13 +226,12 @@ if (__DEV__) {
attributeNames.forEach(function(name) {
names.push(name);
});
warningWithoutStack(false, 'Extra attributes from the server: %s', names);
warningWithoutStack('Extra attributes from the server: %s', names);
};

warnForInvalidEventListener = function(registrationName, listener) {
if (listener === false) {
warning(
false,
'Expected `%s` listener to be a function, instead got `false`.\n\n' +
'If you used to conditionally omit it with %s={condition && value}, ' +
'pass %s={condition ? value : undefined} instead.',
Expand All @@ -244,7 +241,6 @@ if (__DEV__) {
);
} else {
warning(
false,
'Expected `%s` listener to be a function, instead got a value of `%s` type.',
registrationName,
typeof listener,
Expand Down Expand Up @@ -416,13 +412,14 @@ export function createElement(
isCustomComponentTag = isCustomComponent(type, props);
// Should this check be gated by parent namespace? Not sure we want to
// allow <SVG> or <mATH>.
warning(
isCustomComponentTag || type === type.toLowerCase(),
'<%s /> is using incorrect casing. ' +
'Use PascalCase for React components, ' +
'or lowercase for HTML elements.',
type,
);
if (!isCustomComponentTag && type !== type.toLowerCase()) {
warning(
'<%s /> is using incorrect casing. ' +
'Use PascalCase for React components, ' +
'or lowercase for HTML elements.',
type,
);
}
}

if (type === 'script') {
Expand All @@ -432,7 +429,6 @@ export function createElement(
if (__DEV__) {
if (enableTrustedTypesIntegration && !didWarnScriptTags) {
warning(
false,
'Encountered a script tag while rendering React component. ' +
'Scripts inside React components are never executed when rendering ' +
'on the client. Consider using template tag instead ' +
Expand Down Expand Up @@ -488,7 +484,6 @@ export function createElement(
) {
warnedUnknownTags[type] = true;
warning(
false,
'The tag <%s> is unrecognized in this browser. ' +
'If you meant to render a React component, start its name with ' +
'an uppercase letter.',
Expand Down Expand Up @@ -525,7 +520,6 @@ export function setInitialProperties(
(domElement: any).shadyRoot
) {
warning(
false,
'%s is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
Expand Down Expand Up @@ -926,7 +920,6 @@ export function diffHydratedProperties(
(domElement: any).shadyRoot
) {
warning(
false,
'%s is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
Expand Down Expand Up @@ -1219,7 +1212,6 @@ export function warnForDeletedHydratableElement(
}
didWarnInvalidHydration = true;
warningWithoutStack(
false,
'Did not expect server HTML to contain a <%s> in <%s>.',
child.nodeName.toLowerCase(),
parentNode.nodeName.toLowerCase(),
Expand All @@ -1237,7 +1229,6 @@ export function warnForDeletedHydratableText(
}
didWarnInvalidHydration = true;
warningWithoutStack(
false,
'Did not expect server HTML to contain the text node "%s" in <%s>.',
child.nodeValue,
parentNode.nodeName.toLowerCase(),
Expand All @@ -1256,7 +1247,6 @@ export function warnForInsertedHydratedElement(
}
didWarnInvalidHydration = true;
warningWithoutStack(
false,
'Expected server HTML to contain a matching <%s> in <%s>.',
tag,
parentNode.nodeName.toLowerCase(),
Expand All @@ -1281,7 +1271,6 @@ export function warnForInsertedHydratedText(
}
didWarnInvalidHydration = true;
warningWithoutStack(
false,
'Expected server HTML to contain a matching text node for "%s" in <%s>.',
text,
parentNode.nodeName.toLowerCase(),
Expand Down
4 changes: 0 additions & 4 deletions packages/react-dom/src/client/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function initWrapperState(element: Element, props: Object) {
!didWarnCheckedDefaultChecked
) {
warning(
false,
'%s contains an input of type %s with both checked and defaultChecked props. ' +
'Input elements must be either controlled or uncontrolled ' +
'(specify either the checked prop, or the defaultChecked prop, but not ' +
Expand All @@ -98,7 +97,6 @@ export function initWrapperState(element: Element, props: Object) {
!didWarnValueDefaultValue
) {
warning(
false,
'%s contains an input of type %s with both value and defaultValue props. ' +
'Input elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
Expand Down Expand Up @@ -144,7 +142,6 @@ export function updateWrapper(element: Element, props: Object) {
!didWarnUncontrolledToControlled
) {
warning(
false,
'A component is changing an uncontrolled input of type %s to be controlled. ' +
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
'Decide between using a controlled or uncontrolled input ' +
Expand All @@ -159,7 +156,6 @@ export function updateWrapper(element: Element, props: Object) {
!didWarnControlledToUncontrolled
) {
warning(
false,
'A component is changing a controlled input of type %s to be uncontrolled. ' +
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
'Decide between using a controlled or uncontrolled input ' +
Expand Down
Loading

0 comments on commit 9ac42dd

Please sign in to comment.