0

JS: remove redundant double negations (i.e. if (!!thing))

The changes in this CL should be exactly equivalent and have less
superfluous symbols.

There's precedent for discouraging unnecessary characters when safe,
i.e. https://google.github.io/styleguide/cppguide.html#Return_Values

R=dpapad@chromium.org
BUG=none

Change-Id: I04d7480ebd54a33cfb962a3d2d9e1a58a3d1ea4c
Reviewed-on: https://chromium-review.googlesource.com/c/1450645
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Dan Beam (doing your perf) <dbeam@chromium.org>
Auto-Submit: Dan Beam (doing your perf) <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635427}
This commit is contained in:
Dan Beam
2019-02-26 07:36:25 +00:00
committed by Commit Bot
parent 445c099c64
commit b153665f0f
32 changed files with 67 additions and 65 deletions

@ -15,6 +15,7 @@ module.exports = {
// Enabled checks.
'brace-style': ['error', '1tbs'],
'curly': ['error', 'multi-line', 'consistent'],
'no-extra-boolean-cast': 'error',
'no-extra-semi': 'error',
'no-new-wrappers': 'error',
'no-restricted-properties': [

@ -59,9 +59,9 @@ Polymer({
/** @override */
attached: function() {
this.watch('item_', (store) => store.nodes[this.itemId]);
this.watch('item_', store => store.nodes[this.itemId]);
this.watch(
'isSelectedItem_', (store) => !!store.selection.items.has(this.itemId));
'isSelectedItem_', store => store.selection.items.has(this.itemId));
this.updateFromStore();
},

@ -371,7 +371,7 @@ cvox.DomUtil.isLeafNode = function(node, opt_allowHidden) {
return true;
}
if (!!cvox.DomPredicates.linkPredicate([element])) {
if (cvox.DomPredicates.linkPredicate([element])) {
return !cvox.DomUtil.findNode(element, function(node) {
return !!cvox.DomPredicates.headingPredicate([node]);
});
@ -584,9 +584,9 @@ cvox.DomUtil.getName = function(
* @private
*/
cvox.DomUtil.hasChildrenBasedName_ = function(node, opt_allowHidden) {
if (!!cvox.DomPredicates.linkPredicate([node]) ||
!!cvox.DomPredicates.headingPredicate([node]) ||
node.tagName == 'BUTTON' || cvox.AriaUtil.isControlWidget(node) ||
if (cvox.DomPredicates.linkPredicate([node]) ||
cvox.DomPredicates.headingPredicate([node]) || node.tagName == 'BUTTON' ||
cvox.AriaUtil.isControlWidget(node) ||
!cvox.DomUtil.isLeafNode(node, opt_allowHidden)) {
return true;
} else {
@ -1112,7 +1112,7 @@ cvox.DomUtil.computeHasContent_ = function(node) {
}
}
if (!!cvox.DomPredicates.linkPredicate([node])) {
if (cvox.DomPredicates.linkPredicate([node])) {
return true;
}

@ -440,12 +440,12 @@ AutomationPredicate.shouldIgnoreNode = function(node) {
// Ignore nodes acting as labels for another control, that don't
// have actionable descendants.
if (!!node.labelFor && node.labelFor.length > 0 &&
if (node.labelFor && node.labelFor.length > 0 &&
!hasActionableDescendant(node))
return true;
// Similarly, ignore nodes acting as descriptions.
if (!!node.descriptionFor && node.descriptionFor.length > 0 &&
if (node.descriptionFor && node.descriptionFor.length > 0 &&
!hasActionableDescendant(node))
return true;

@ -126,7 +126,7 @@ Polymer({
* @private
*/
getNetworkDetails_: function() {
assert(!!this.guid);
assert(this.guid);
this.networkingPrivate.getManagedProperties(
this.guid, this.getPropertiesCallback_.bind(this));
},
@ -167,7 +167,7 @@ Polymer({
if (!this.networkPropertiesReceived_)
return;
assert(!!this.guid);
assert(this.guid);
this.networkingPrivate.setProperties(this.guid, onc, () => {
if (chrome.runtime.lastError) {
// An error typically indicates invalid input; request the properties
@ -487,7 +487,7 @@ Polymer({
getInfoFields_: function() {
/** @type {!Array<string>} */ var fields = [];
var type = this.networkProperties.Type;
if (type == CrOnc.Type.CELLULAR && !!this.networkProperties.Cellular) {
if (type == CrOnc.Type.CELLULAR && this.networkProperties.Cellular) {
fields.push(
'Cellular.HomeProvider.Name', 'Cellular.ServingOperator.Name',
'Cellular.ActivationState', 'Cellular.RoamingState',

@ -310,7 +310,7 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
var wpDocument = wallpaperPickerWindow.contentWindow.document;
var messageContainer = wpDocument.querySelector('#message-container');
if (!!appName) {
if (appName) {
chrome.wallpaperPrivate.getStrings(function(strings) {
var message =
strings.currentWallpaperSetByMessage.replace(/\$1/g, appName);

@ -379,7 +379,7 @@ WallpaperManager.prototype.postDownloadDomInit_ = function() {
};
getThirdPartyAppName(function(appName) {
if (!!appName) {
if (appName) {
$('message-container').textContent =
loadTimeData.getStringF('currentWallpaperSetByMessage', appName);
$('message-container').style.visibility = 'visible';

@ -287,7 +287,7 @@ function onProcessCpu(port) {
} else if (process.type == 'gpu') {
gpuProcessCpu = process.cpu;
}
if (!!browserProcessCpu && !!gpuProcessCpu) {
if (browserProcessCpu && gpuProcessCpu) {
break;
}
}

@ -152,7 +152,7 @@ function finishEditLink() {
}
// Update the link only if a field was changed.
if (!!newUrl || !!newTitle) {
if (newUrl || newTitle) {
chrome.embeddedSearch.newTabPage.updateCustomLink(
prepopulatedLink.rid, newUrl, newTitle);
}

@ -396,7 +396,7 @@ doodles.showLogoOrDoodle = function(fromCache) {
.classList.remove(doodles.CLASSES.SHOW_LOGO);
// Log the impression in Chrome metrics.
var isCta = !!doodles.targetDoodle.metadata.animatedUrl;
var isCta = doodles.targetDoodle.metadata.animatedUrl;
var eventType = isCta ?
(fromCache ? doodles.LOG_TYPE.NTP_CTA_LOGO_SHOWN_FROM_CACHE :
doodles.LOG_TYPE.NTP_CTA_LOGO_SHOWN_FRESH) :

@ -538,7 +538,7 @@ speech.handleRecognitionResult_ = function(responseEvent) {
// Force-stop long queries.
if (speech.interimResult_.length > speech.QUERY_LENGTH_LIMIT_) {
if (!!speech.finalResult_) {
if (speech.finalResult_) {
speech.submitFinalResult_();
} else {
speech.onErrorReceived_(RecognitionError.NO_MATCH);
@ -749,7 +749,7 @@ speech.onKeyDown = function(event) {
* @private
*/
speech.onIdleTimeout_ = function() {
if (!!speech.finalResult_) {
if (speech.finalResult_) {
speech.submitFinalResult_();
return;
}
@ -1167,7 +1167,7 @@ text.showErrorMessage = function(error) {
const linkElement = text.getErrorLink_(error);
// Setting textContent removes all children (no need to clear link elements).
if (!!linkElement) {
if (linkElement) {
text.interim_.textContent += ' ';
text.interim_.appendChild(linkElement);
}

@ -799,7 +799,7 @@ Polymer({
* @private
*/
computeIssueBannerClass_: function(issue) {
return !!issue && !issue.isBlocking ? 'non-blocking' : '';
return issue && !issue.isBlocking ? 'non-blocking' : '';
},
/**
@ -1374,7 +1374,7 @@ Polymer({
* @private
*/
maybeShowIssueView_: function(issue) {
if (!!issue) {
if (issue) {
if (issue.isBlocking) {
this.currentView_ = media_router.MediaRouterView.ISSUE;
} else if (this.currentView_ == media_router.MediaRouterView.SINK_LIST) {
@ -1389,7 +1389,7 @@ Polymer({
this.showSinkList_();
}
if (!!this.pendingCreatedRouteId_ && !!issue &&
if (this.pendingCreatedRouteId_ && issue &&
issue.routeId == this.pendingCreatedRouteId_) {
this.resetRouteCreationProperties_(false);
}

@ -214,7 +214,7 @@ Polymer({
'Failed to resolve provisional destination: ' + destination.id);
})
.then(() => {
if (this.$.dialog.open && !!listItem && !listItem.hidden) {
if (this.$.dialog.open && listItem && !listItem.hidden) {
listItem.focus();
}
});

@ -369,7 +369,7 @@ Polymer({
this.lastDestinationCapabilities_ = this.destination.capabilities;
const caps = !!this.destination.capabilities ?
const caps = this.destination.capabilities ?
this.destination.capabilities.printer :
null;
this.updateSettingsAvailabilityFromDestination_(caps);
@ -386,8 +386,8 @@ Polymer({
* @private
*/
updateSettingsAvailabilityFromDestination_: function(caps) {
this.set('settings.copies.available', !!caps && !!(caps.copies));
this.set('settings.collate.available', !!caps && !!(caps.collate));
this.set('settings.copies.available', !!caps && !!caps.copies);
this.set('settings.collate.available', !!caps && !!caps.collate);
this.set('settings.layout.available', this.isLayoutAvailable_(caps));
this.set('settings.color.available', this.destination.hasColorCapability);
@ -424,7 +424,7 @@ Polymer({
'settings.fitToPage.available',
!knownSizeToSaveAsPdf && !this.documentSettings.isModifiable);
this.set('settings.scaling.available', !knownSizeToSaveAsPdf);
const caps = (!!this.destination && !!this.destination.capabilities) ?
const caps = this.destination && this.destination.capabilities ?
this.destination.capabilities.printer :
null;
this.set(
@ -602,17 +602,17 @@ Polymer({
const vendorSettings = {};
for (const item of caps.vendor_capability) {
let defaultValue = null;
if (item.type == 'SELECT' && !!item.select_cap &&
!!item.select_cap.option) {
if (item.type == 'SELECT' && item.select_cap &&
item.select_cap.option) {
const defaultOption =
item.select_cap.option.find(o => !!o.is_default);
defaultValue = !!defaultOption ? defaultOption.value : null;
defaultValue = defaultOption ? defaultOption.value : null;
} else if (item.type == 'RANGE') {
if (!!item.range_cap) {
if (item.range_cap) {
defaultValue = item.range_cap.default || null;
}
} else if (item.type == 'TYPED_VALUE') {
if (!!item.typed_value_cap) {
if (item.typed_value_cap) {
defaultValue = item.typed_value_cap.default || null;
}
}

@ -570,7 +570,7 @@ Polymer({
const newValue =
/** @type {!print_preview.MarginsSetting} */ (
this.getSettingValue('customMargins'));
if (!!this.lastCustomMargins_ &&
if (this.lastCustomMargins_ &&
this.lastCustomMargins_.marginTop !== undefined &&
this.getSettingValue('margins') ==
print_preview.ticket_items.MarginsTypeValue.CUSTOM &&
@ -588,7 +588,7 @@ Polymer({
const newValue =
/** @type {!print_preview_new.MediaSizeValue} */ (
this.getSettingValue('mediaSize'));
if (!!this.lastMediaSize_ &&
if (this.lastMediaSize_ &&
(newValue.height_microns != this.lastMediaSize_.height_microns ||
newValue.width_microns != this.lastMediaSize_.width_microns)) {
this.onSettingsChanged_();

@ -60,7 +60,7 @@ const SettingsBehavior = {
getSetting: function(settingName) {
const setting = /** @type {print_preview_new.Setting} */ (
this.get(settingName, this.settings));
assert(!!setting, 'Setting is missing: ' + settingName);
assert(setting, 'Setting is missing: ' + settingName);
return setting;
},

@ -125,7 +125,7 @@ Polymer({
// time (|delayedCompletionToken_| is not null) progress should be cached
// for consumption when the blocking time ends.
const progressBlocked =
!this.progressTaskToken_ && !!this.delayedCompletionToken_;
!this.progressTaskToken_ && this.delayedCompletionToken_;
if (!progressBlocked) {
clearTimeout(this.progressTaskToken_);
this.progressTaskToken_ = null;
@ -245,4 +245,4 @@ Polymer({
this.close();
},
});
})();
})();

@ -141,7 +141,7 @@ Polymer({
* @private
*/
toggleLockScreenSupport_: function() {
assert(!!this.selectedApp_);
assert(this.selectedApp_);
if (this.selectedApp_.lockScreenSupport !=
settings.NoteAppLockScreenSupport.ENABLED &&
this.selectedApp_.lockScreenSupport !=

@ -350,7 +350,7 @@ Polymer({
* @private
*/
getNetworkDetails_: function() {
assert(!!this.guid);
assert(this.guid);
if (this.isSecondaryUser_) {
this.networkingPrivate.getState(
this.guid, this.getStateCallback_.bind(this));
@ -434,7 +434,7 @@ Polymer({
return;
}
assert(!!this.guid);
assert(this.guid);
this.networkingPrivate.setProperties(this.guid, onc, () => {
if (chrome.runtime.lastError) {
// An error typically indicates invalid input; request the properties

@ -394,7 +394,7 @@ Polymer({
onDeviceStatesChanged_: function(newValue, oldValue) {
const wifiDeviceState = this.getDeviceState_(CrOnc.Type.WI_FI, newValue);
let managedNetworkAvailable = false;
if (!!wifiDeviceState) {
if (wifiDeviceState) {
managedNetworkAvailable = !!wifiDeviceState.ManagedNetworkAvailable;
}

@ -545,6 +545,7 @@ Polymer({
/**
* @param {!CrOnc.NetworkStateProperties} state The network state.
* @return {boolean}
* @private
*/
isBlockedByPolicy_: function(state) {

@ -348,10 +348,10 @@ Polymer({
const languageState = this.languages.enabled[i];
this.set(
`languages.enabled.${i}.spellCheckEnabled`,
!!spellCheckSet.has(languageState.language.code));
spellCheckSet.has(languageState.language.code));
this.set(
`languages.enabled.${i}.isManaged`,
!!spellCheckForcedSet.has(languageState.language.code));
spellCheckForcedSet.has(languageState.language.code));
}
this.set(
@ -547,11 +547,11 @@ Polymer({
}
const languageState = /** @type {LanguageState} */ ({});
languageState.language = language;
languageState.spellCheckEnabled = !!spellCheckSet.has(code);
languageState.spellCheckEnabled = spellCheckSet.has(code);
languageState.translateEnabled = this.isTranslateEnabled_(
code, !!language.supportsTranslate, translateBlockedSet,
translateTarget, prospectiveUILanguage);
languageState.isManaged = !!spellCheckForcedSet.has(code);
languageState.isManaged = spellCheckForcedSet.has(code);
languageState.downloadDictionaryFailureCount = 0;
enabledLanguageStates.push(languageState);
}

@ -494,8 +494,8 @@ Polymer({
* @return {Element|null}
*/
getAdvancedSyncSettingsAssociatedControl_: function() {
return !!this.unifiedConsentEnabled_ ? this.$$('#sync-setup') :
this.$$('#sync-status');
return this.unifiedConsentEnabled_ ? this.$$('#sync-setup') :
this.$$('#sync-status');
},
/**

@ -190,7 +190,7 @@ Polymer({
* @private
*/
getPromoHeaderClass_: function() {
return !!this.subLabel_ ? 'two-line': '';
return this.subLabel_ ? 'two-line' : '';
},
/**
@ -210,7 +210,7 @@ Polymer({
* @private
*/
getAccountLabel_: function(label, account) {
if(!!this.unifiedConsentEnabled && !!this.syncStatus.setupInProgress) {
if (this.unifiedConsentEnabled && this.syncStatus.setupInProgress) {
return this.syncStatus.statusText || account;
}
return this.syncStatus.signedIn && !this.syncStatus.hasError &&
@ -235,16 +235,16 @@ Polymer({
* @private
*/
getSyncIconStyle_: function() {
if (!!this.syncStatus.hasUnrecoverableError) {
if (this.syncStatus.hasUnrecoverableError) {
return 'sync-problem';
}
if (!!this.syncStatus.hasError) {
if (this.syncStatus.hasError) {
return this.syncStatus.statusAction ==
settings.StatusAction.REAUTHENTICATE ?
'sync-paused' :
'sync-problem';
}
if (!!this.syncStatus.disabled) {
if (this.syncStatus.disabled) {
return 'sync-disabled';
}
return 'sync';

@ -171,8 +171,8 @@ Polymer({
// Navigate to main sync page when the sync controls page should *not* be
// available.
if (!syncStatus.signedIn || !!syncStatus.disabled ||
(!!syncStatus.hasError &&
if (!syncStatus.signedIn || syncStatus.disabled ||
(syncStatus.hasError &&
syncStatus.statusAction !== settings.StatusAction.ENTER_PASSPHRASE)) {
settings.navigateTo(settings.routes.SYNC);
}

@ -295,7 +295,7 @@ Polymer({
// When the user is about to cancel the sync setup, but hasn't confirmed
// the cancellation, navigate back and show the 'Cancel sync?' dialog.
if (this.unifiedConsentEnabled && this.syncStatus &&
!!this.syncStatus.setupInProgress && this.didAbort_ &&
this.syncStatus.setupInProgress && this.didAbort_ &&
!this.setupCancelConfirmed_) {
chrome.metricsPrivate.recordUserAction(
'Signin_Signin_BackOnAdvancedSyncSettings');
@ -346,7 +346,7 @@ Polymer({
// When the user tries to leave the sync setup, show the 'Leave site'
// dialog.
if (this.unifiedConsentEnabled && this.syncStatus &&
!!this.syncStatus.setupInProgress) {
this.syncStatus.setupInProgress) {
event.preventDefault();
event.returnValue = '';

@ -528,7 +528,7 @@ cr.define('settings', function() {
Object.keys(this.routes_)
.find((key) => this.routes_[key].path == canonicalPath);
return !!matchingKey ? this.routes_[matchingKey] : null;
return matchingKey ? this.routes_[matchingKey] : null;
}
/**

@ -61,9 +61,9 @@ Polymer({
// 1) Not a direct navigation (such that the search box stays focused), and
// 2) Not a "back" navigation, in which case the anchor element should be
// focused (further below in this function).
if (!!this.previousRoute_ && !settings.lastRouteChangeWasPopstate()) {
if (this.previousRoute_ && !settings.lastRouteChangeWasPopstate()) {
const subpage = this.querySelector('settings-subpage.iron-selected');
if (!!subpage) {
if (subpage) {
subpage.initialFocus();
return;
}

@ -64,7 +64,7 @@ Polymer({
/** @override */
attached: function() {
if (!!this.searchLabel) {
if (this.searchLabel) {
// |searchLabel| should not change dynamically.
this.listen(this, 'clear-subpage-search', 'onClearSubpageSearch_');
}
@ -72,7 +72,7 @@ Polymer({
/** @override */
detached: function() {
if (!!this.searchLabel) {
if (this.searchLabel) {
// |searchLabel| should not change dynamically.
this.unlisten(this, 'clear-subpage-search', 'onClearSubpageSearch_');
}

@ -95,7 +95,7 @@ cr.define('print_preview', function() {
this.initialized_ = true;
}
}
if (!!printer) {
if (printer) {
printer.capabilities =
print_preview_test_utils.getCddTemplate(printerId);
this.eventTarget_.dispatchEvent(new CustomEvent(

@ -125,7 +125,7 @@ cr.define('cr.ui', function() {
Polymer.RenderStatus.afterNextRender(this, function() {
const rowContainer = this.root.querySelector('[focus-row-container]');
assert(!!rowContainer);
assert(rowContainer);
this.row_ = new VirtualFocusRow(
rowContainer, new FocusRowBehaviorDelegate(this));
this.ironListTabIndexChanged_();

@ -199,7 +199,7 @@ cr.define('cr.ui', function() {
if (menuItem.hidden) {
return false;
}
if (!!menuItem.offsetParent) {
if (menuItem.offsetParent) {
return true;
}
// A "position: fixed" element won't have an offsetParent, so we have to