Port 1578683 - Turn on ESLint rule prefer-boolean-length-check for toolkit and browser (#5313)
This commit is contained in:
Родитель
60966e5505
Коммит
6f48e802e1
|
@ -307,7 +307,7 @@ function Sections(prevState = INITIAL_STATE.Sections, action) {
|
|||
});
|
||||
// Otherwise, append it
|
||||
if (!hasMatch) {
|
||||
const initialized = !!(action.data.rows && action.data.rows.length > 0);
|
||||
const initialized = !!(action.data.rows && !!action.data.rows.length);
|
||||
const section = Object.assign(
|
||||
{ title: "", rows: [], enabled: false },
|
||||
action.data,
|
||||
|
@ -327,7 +327,7 @@ function Sections(prevState = INITIAL_STATE.Sections, action) {
|
|||
// Disabling a section (SECTION_UPDATE with empty rows) does not retain pinned cards.
|
||||
if (
|
||||
action.data.rows &&
|
||||
action.data.rows.length > 0 &&
|
||||
!!action.data.rows.length &&
|
||||
section.rows.find(card => card.pinned)
|
||||
) {
|
||||
const rows = Array.from(action.data.rows);
|
||||
|
|
|
@ -82,7 +82,7 @@ export class StartupOverlay extends React.PureComponent {
|
|||
*/
|
||||
_getFormInfo() {
|
||||
const value = {
|
||||
has_flow_params: this.props.flowParams.flowId.length > 0,
|
||||
has_flow_params: !!this.props.flowParams.flowId.length,
|
||||
};
|
||||
return { value };
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ export class Trailhead extends React.PureComponent {
|
|||
* Report to telemetry additional information about the form submission.
|
||||
*/
|
||||
_getFormInfo() {
|
||||
const value = { has_flow_params: this.props.flowParams.flowId.length > 0 };
|
||||
const value = { has_flow_params: !!this.props.flowParams.flowId.length };
|
||||
return { value };
|
||||
}
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@ export class _DiscoveryStreamBase extends React.PureComponent {
|
|||
components: [topSites],
|
||||
},
|
||||
])}
|
||||
{layoutRender.length > 0 && (
|
||||
{!!layoutRender.length && (
|
||||
<CollapsibleSection
|
||||
className="ds-layout"
|
||||
collapsed={topStories.pref.collapsed}
|
||||
|
|
|
@ -200,7 +200,7 @@ export class Section extends React.PureComponent {
|
|||
const isPocketLoggedInDefined =
|
||||
isUserLoggedIn === true || isUserLoggedIn === false;
|
||||
|
||||
const hasTopics = topics && topics.length > 0;
|
||||
const hasTopics = topics && !!topics.length;
|
||||
|
||||
const shouldShowPocketCta =
|
||||
id === "topstories" && useCta && isUserLoggedIn === false;
|
||||
|
|
|
@ -96,7 +96,7 @@ function CheckBrowserNeedsUpdate(
|
|||
const now = Date.now();
|
||||
const updateServiceListener = {
|
||||
onCheckComplete(request, updates) {
|
||||
checker._value = updates.length > 0;
|
||||
checker._value = !!updates.length;
|
||||
resolve(checker._value);
|
||||
},
|
||||
onError(request, update) {
|
||||
|
|
|
@ -257,7 +257,7 @@ class PageAction {
|
|||
}
|
||||
|
||||
_clearScheduledStateChanges() {
|
||||
while (this.stateTransitionTimeoutIDs.length > 0) {
|
||||
while (this.stateTransitionTimeoutIDs.length) {
|
||||
// clearTimeout is safe even with invalid/expired IDs
|
||||
this.window.clearTimeout(this.stateTransitionTimeoutIDs.pop());
|
||||
}
|
||||
|
|
|
@ -366,7 +366,7 @@ class PlacesFeed {
|
|||
_getSearchPrefix() {
|
||||
const searchAliases =
|
||||
Services.search.defaultEngine.wrappedJSObject.__internalAliases;
|
||||
if (searchAliases && searchAliases.length > 0) {
|
||||
if (searchAliases && searchAliases.length) {
|
||||
return `${searchAliases[0]} `;
|
||||
}
|
||||
return "";
|
||||
|
|
|
@ -71,7 +71,7 @@ function shortURL({ url }) {
|
|||
|
||||
// Remove the eTLD (e.g., com, net) and the preceding period from the hostname
|
||||
const eTLD = getETLD(hostname);
|
||||
const eTLDExtra = eTLD.length > 0 ? -(eTLD.length + 1) : Infinity;
|
||||
const eTLDExtra = eTLD.length ? -(eTLD.length + 1) : Infinity;
|
||||
|
||||
// Ideally get the short eTLD-less host but fall back to longer url parts
|
||||
return (
|
||||
|
|
|
@ -314,7 +314,7 @@ this.TopStoriesFeed = class TopStoriesFeed {
|
|||
);
|
||||
this.domainAffinitiesLastUpdated = affinities._timestamp;
|
||||
}
|
||||
if (stories && stories.length > 0 && this.storiesLastUpdated === 0) {
|
||||
if (stories && !!stories.length && this.storiesLastUpdated === 0) {
|
||||
this.updateSettings(data.stories.settings);
|
||||
this.stories = this.rotate(this.transform(stories));
|
||||
this.storiesLastUpdated = data.stories._timestamp;
|
||||
|
@ -328,7 +328,7 @@ this.TopStoriesFeed = class TopStoriesFeed {
|
|||
this.cleanUpCampaignImpressionPref();
|
||||
}
|
||||
}
|
||||
if (topics && topics.length > 0 && this.topicsLastUpdated === 0) {
|
||||
if (topics && !!topics.length && this.topicsLastUpdated === 0) {
|
||||
this.topics = topics;
|
||||
this.topicsLastUpdated = data.topics._timestamp;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ describe("CFRMessageProvider", () => {
|
|||
const pinTabMessage = messages.find(m => m.id === "PIN_TAB");
|
||||
|
||||
assert.isTrue(
|
||||
pinTabMessage.trigger.params.filter(host => host.startsWith("www."))
|
||||
.length > 0
|
||||
!!pinTabMessage.trigger.params.filter(host => host.startsWith("www."))
|
||||
.length
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -463,7 +463,7 @@ describe("<TopSiteLink>", () => {
|
|||
it("should have rtl direction automatically set for text", () => {
|
||||
const wrapper = shallow(<TopSiteLink link={link} />);
|
||||
|
||||
assert.isTrue(wrapper.find("[dir='auto']").length > 0);
|
||||
assert.isTrue(!!wrapper.find("[dir='auto']").length);
|
||||
});
|
||||
it("should render a title", () => {
|
||||
const wrapper = shallow(<TopSiteLink link={link} title="foobar" />);
|
||||
|
|
Загрузка…
Ссылка в новой задаче