Skip to content

Commit

Permalink
JS: remove redundant double negations (i.e. if (!!thing))
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
danbeam authored and Commit Bot committed Feb 26, 2019
1 parent 445c099 commit b153665
Show file tree
Hide file tree
Showing 32 changed files with 67 additions and 65 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/bookmarks/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/resources/chromeos/chromevox/common/dom_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1112,7 +1112,7 @@ cvox.DomUtil.computeHasContent_ = function(node) {
}
}

if (!!cvox.DomPredicates.linkPredicate([node])) {
if (cvox.DomPredicates.linkPredicate([node])) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Polymer({
* @private
*/
getNetworkDetails_: function() {
assert(!!this.guid);
assert(this.guid);
this.networkingPrivate.getManagedProperties(
this.guid, this.getPropertiesCallback_.bind(this));
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/hangout_services/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function onProcessCpu(port) {
} else if (process.type == 'gpu') {
gpuProcessCpu = process.cpu;
}
if (!!browserProcessCpu && !!gpuProcessCpu) {
if (browserProcessCpu && gpuProcessCpu) {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/local_ntp/custom_links_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/local_ntp/doodles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/resources/local_ntp/voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -749,7 +749,7 @@ speech.onKeyDown = function(event) {
* @private
*/
speech.onIdleTimeout_ = function() {
if (!!speech.finalResult_) {
if (speech.finalResult_) {
speech.submitFinalResult_();
return;
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ Polymer({
* @private
*/
computeIssueBannerClass_: function(issue) {
return !!issue && !issue.isBlocking ? 'non-blocking' : '';
return issue && !issue.isBlocking ? 'non-blocking' : '';
},

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -1389,7 +1389,7 @@ Polymer({
this.showSinkList_();
}

if (!!this.pendingCreatedRouteId_ && !!issue &&
if (this.pendingCreatedRouteId_ && issue &&
issue.routeId == this.pendingCreatedRouteId_) {
this.resetRouteCreationProperties_(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
18 changes: 9 additions & 9 deletions chrome/browser/resources/print_preview/new/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/print_preview/new/preview_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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_();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,4 +245,4 @@ Polymer({
this.close();
},
});
})();
})();
2 changes: 1 addition & 1 deletion chrome/browser/resources/settings/device_page/stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Polymer({
* @private
*/
toggleLockScreenSupport_: function() {
assert(!!this.selectedApp_);
assert(this.selectedApp_);
if (this.selectedApp_.lockScreenSupport !=
settings.NoteAppLockScreenSupport.ENABLED &&
this.selectedApp_.lockScreenSupport !=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ Polymer({

/**
* @param {!CrOnc.NetworkStateProperties} state The network state.
* @return {boolean}
* @private
*/
isBlockedByPolicy_: function(state) {
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/resources/settings/languages_page/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/settings/people_page/people_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},

/**
Expand Down
Loading

0 comments on commit b153665

Please sign in to comment.