Skip to content

Commit

Permalink
Bug 1800319 - Change newtab code so that the ESLint rule no-console i…
Browse files Browse the repository at this point in the history
…s an error, except for console.error calls. r=Mardak

Differential Revision: https://phabricator.services.mozilla.com/D161942
  • Loading branch information
Standard8 committed Nov 13, 2022
1 parent c9db87c commit a37d1cd
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion browser/components/newtab/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
"no-bitwise": 0,
"no-buffer-constructor": 2,
"no-catch-shadow": 2,
"no-console": 1,
"no-console": ["error", { allow: ["error"] }],
"no-continue": 0,
"no-div-regex": 2,
"no-duplicate-imports": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const AboutWelcomeUtils = {
flowBeginTime
};
} else {
console.error("Non-200 response", response); // eslint-disable-line no-console
console.error("Non-200 response", response);
}
} catch (e) {
flowParams = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ASRouterUISurface extends React.PureComponent {
if (!fxaEndpoint) {
const err =
"Tried to fetch flow params before fxaEndpoint pref was ready";
console.error(err); // eslint-disable-line no-console
console.error(err);
}

try {
Expand All @@ -64,10 +64,10 @@ export class ASRouterUISurface extends React.PureComponent {
const { deviceId, flowId, flowBeginTime } = await response.json();
result = { deviceId, flowId, flowBeginTime };
} else {
console.error("Non-200 response", response); // eslint-disable-line no-console
console.error("Non-200 response", response);
}
} catch (error) {
console.error(error); // eslint-disable-line no-console
console.error(error);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function safeURI(url) {
"chrome:",
].includes(protocol);
if (!isAllowed) {
console.warn(`The protocol ${protocol} is not allowed for template URLs.`); // eslint-disable-line no-console
// eslint-disable-next-line no-console
console.warn(`The protocol ${protocol} is not allowed for template URLs.`);
}
return isAllowed ? url : "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SubmitFormSnippet extends React.PureComponent {
const response = await fetch(fetchRequest); // eslint-disable-line fetch-options/no-fetch-credentials
json = await response.json();
} catch (err) {
console.log(err); // eslint-disable-line no-console
console.error(err);
}

if (json && json.status === "ok") {
Expand All @@ -83,7 +83,6 @@ export class SubmitFormSnippet extends React.PureComponent {
id: "NEWTAB_FOOTER_BAR_CONTENT",
});
} else {
// eslint-disable-next-line no-console
console.error(
"There was a problem submitting the form",
json || "[No JSON response]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ export class ASRouterAdminInner extends React.PureComponent {
try {
JSON.parse(value);
} catch (e) {
console.log(`Error parsing value of parameter ${name}`); // eslint-disable-line no-console
console.error(`Error parsing value of parameter ${name}`);
targetingParametersError = { id: name };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class _DiscoveryStreamBase extends React.PureComponent {
[...rule.style].forEach(property => {
const value = rule.style[property];
if (!isAllowedCSS(property, value)) {
console.error(`Bad CSS declaration ${property}: ${value}`); // eslint-disable-line no-console
console.error(`Bad CSS declaration ${property}: ${value}`);
rule.style.removeProperty(property);
}
});
Expand All @@ -102,7 +102,7 @@ export class _DiscoveryStreamBase extends React.PureComponent {

// CSSOM silently ignores bad selectors, so we'll be noisy instead
if (rule.selectorText === DUMMY_CSS_SELECTOR) {
console.error(`Bad CSS selector ${selectors}`); // eslint-disable-line no-console
console.error(`Bad CSS selector ${selectors}`);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const AboutWelcomeUtils = {
const { deviceId, flowId, flowBeginTime } = await response.json();
flowParams = { deviceId, flowId, flowBeginTime };
} else {
console.error("Non-200 response", response); // eslint-disable-line no-console
console.error("Non-200 response", response);
}
} catch (e) {
flowParams = null;
Expand Down
2 changes: 1 addition & 1 deletion browser/components/newtab/content-src/lib/init-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function initStore(reducers, initialState) {
try {
store.dispatch(msg.data);
} catch (ex) {
console.error("Content msg:", msg, "Dispatch error: ", ex); // eslint-disable-line no-console
console.error("Content msg:", msg, "Dispatch error: ", ex);
dump(
`Content msg: ${JSON.stringify(msg)}\nDispatch error: ${ex}\n${
ex.stack
Expand Down
23 changes: 10 additions & 13 deletions browser/components/newtab/data/content/activity-stream.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,7 @@ class ASRouterAdminInner extends (external_React_default()).PureComponent {
try {
JSON.parse(value);
} catch (e) {
console.log(`Error parsing value of parameter ${name}`); // eslint-disable-line no-console

console.error(`Error parsing value of parameter ${name}`);
targetingParametersError = {
id: name
};
Expand Down Expand Up @@ -4348,7 +4347,8 @@ function safeURI(url) {
const isAllowed = ["http:", "https:", "data:", "resource:", "chrome:"].includes(protocol);

if (!isAllowed) {
console.warn(`The protocol ${protocol} is not allowed for template URLs.`); // eslint-disable-line no-console
// eslint-disable-next-line no-console
console.warn(`The protocol ${protocol} is not allowed for template URLs.`);
}

return isAllowed ? url : "";
Expand Down Expand Up @@ -4967,7 +4967,7 @@ class SubmitFormSnippet extends (external_React_default()).PureComponent {

json = await response.json();
} catch (err) {
console.log(err); // eslint-disable-line no-console
console.error(err);
}

if (json && json.status === "ok") {
Expand All @@ -4988,7 +4988,6 @@ class SubmitFormSnippet extends (external_React_default()).PureComponent {
id: "NEWTAB_FOOTER_BAR_CONTENT"
});
} else {
// eslint-disable-next-line no-console
console.error("There was a problem submitting the form", json || "[No JSON response]");
this.setState({
signupSuccess: false,
Expand Down Expand Up @@ -5662,7 +5661,7 @@ class ASRouterUISurface extends (external_React_default()).PureComponent {

if (!fxaEndpoint) {
const err = "Tried to fetch flow params before fxaEndpoint pref was ready";
console.error(err); // eslint-disable-line no-console
console.error(err);
}

try {
Expand All @@ -5687,10 +5686,10 @@ class ASRouterUISurface extends (external_React_default()).PureComponent {
flowBeginTime
};
} else {
console.error("Non-200 response", response); // eslint-disable-line no-console
console.error("Non-200 response", response);
}
} catch (error) {
console.error(error); // eslint-disable-line no-console
console.error(error);
}

return result;
Expand Down Expand Up @@ -13774,8 +13773,7 @@ class _DiscoveryStreamBase extends (external_React_default()).PureComponent {
const value = rule.style[property];

if (!isAllowedCSS(property, value)) {
console.error(`Bad CSS declaration ${property}: ${value}`); // eslint-disable-line no-console

console.error(`Bad CSS declaration ${property}: ${value}`);
rule.style.removeProperty(property);
}
}); // Set the actual desired selectors scoped to the component
Expand All @@ -13787,7 +13785,7 @@ class _DiscoveryStreamBase extends (external_React_default()).PureComponent {
selector[0] === ":" ? "" : " ") + selector).join(","); // CSSOM silently ignores bad selectors, so we'll be noisy instead

if (rule.selectorText === DUMMY_CSS_SELECTOR) {
console.error(`Bad CSS selector ${selectors}`); // eslint-disable-line no-console
console.error(`Bad CSS selector ${selectors}`);
}
});
});
Expand Down Expand Up @@ -15098,8 +15096,7 @@ function initStore(reducers, initialState) {
try {
store.dispatch(msg.data);
} catch (ex) {
console.error("Content msg:", msg, "Dispatch error: ", ex); // eslint-disable-line no-console

console.error("Content msg:", msg, "Dispatch error: ", ex);
dump(`Content msg: ${JSON.stringify(msg)}\nDispatch error: ${ex}\n${ex.stack}`);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe("<HelpText>", () => {
}}
/>
);
console.log(shallowWrapper.find("p.helptext").text());
assert.equal(shallowWrapper.find("p.helptext").text(), "Sample help text");
assert.lengthOf(shallowWrapper.find("img.helptext-img"), 1);
});
Expand Down
4 changes: 1 addition & 3 deletions browser/components/newtab/test/unit/unit-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import FxMSCommonSchema from "../../content-src/asrouter/schemas/FxMSCommon.sche
enzyme.configure({ adapter: new Adapter() });

// Cause React warnings to make tests that trigger them fail
const origConsoleError = console.error; // eslint-disable-line no-console
// eslint-disable-next-line no-console
const origConsoleError = console.error;
console.error = function(msg, ...args) {
// eslint-disable-next-line no-console
origConsoleError.apply(console, [msg, ...args]);

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");

function getOnboardingScreenById(screens, screenId) {
return screens.find(screen => {
console.log(screen?.id);
return screen?.id === screenId;
});
}
Expand Down

0 comments on commit a37d1cd

Please sign in to comment.