chore: Remove console.log left in code and added eslint rule to prevent it happening again

This commit is contained in:
Tom Moor
2023-04-11 22:15:52 -04:00
parent a9800165c1
commit 49d903d6d4
19 changed files with 59 additions and 47 deletions

View File

@@ -25,6 +25,7 @@
"rules": { "rules": {
"eqeqeq": 2, "eqeqeq": 2,
"curly": 2, "curly": 2,
"no-console": "error",
"arrow-body-style": ["error", "as-needed"], "arrow-body-style": ["error", "as-needed"],
"spaced-comment": "error", "spaced-comment": "error",
"object-shorthand": "error", "object-shorthand": "error",

View File

@@ -25,6 +25,7 @@ import Item, { Actions } from "~/components/List/Item";
import Time from "~/components/Time"; import Time from "~/components/Time";
import useStores from "~/hooks/useStores"; import useStores from "~/hooks/useStores";
import RevisionMenu from "~/menus/RevisionMenu"; import RevisionMenu from "~/menus/RevisionMenu";
import Logger from "~/utils/Logger";
import { documentHistoryUrl } from "~/utils/routeHelpers"; import { documentHistoryUrl } from "~/utils/routeHelpers";
type Props = { type Props = {
@@ -109,7 +110,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
break; break;
default: default:
console.warn("Unhandled event: ", event.name); Logger.warn("Unhandled event", { event });
} }
if (!meta) { if (!meta) {

View File

@@ -8,6 +8,7 @@ import useComponentSize from "~/hooks/useComponentSize";
import useEventListener from "~/hooks/useEventListener"; import useEventListener from "~/hooks/useEventListener";
import useMediaQuery from "~/hooks/useMediaQuery"; import useMediaQuery from "~/hooks/useMediaQuery";
import useViewportHeight from "~/hooks/useViewportHeight"; import useViewportHeight from "~/hooks/useViewportHeight";
import Logger from "~/utils/Logger";
import { useEditor } from "./EditorContext"; import { useEditor } from "./EditorContext";
type Props = { type Props = {
@@ -63,7 +64,7 @@ function usePosition({
fromPos = view.coordsAtPos(selection.from); fromPos = view.coordsAtPos(selection.from);
toPos = view.coordsAtPos(selection.to, -1); toPos = view.coordsAtPos(selection.to, -1);
} catch (err) { } catch (err) {
console.warn(err); Logger.warn("Unable to calculate selection position", err);
return defaultPosition; return defaultPosition;
} }

View File

@@ -17,6 +17,7 @@ import { ResizingHeightContainer } from "~/components/ResizingHeightContainer";
import Scrollable from "~/components/Scrollable"; import Scrollable from "~/components/Scrollable";
import { Dictionary } from "~/hooks/useDictionary"; import { Dictionary } from "~/hooks/useDictionary";
import { ToastOptions } from "~/types"; import { ToastOptions } from "~/types";
import Logger from "~/utils/Logger";
import Input from "./Input"; import Input from "./Input";
import LinkSearchResult from "./LinkSearchResult"; import LinkSearchResult from "./LinkSearchResult";
import ToolbarButton from "./ToolbarButton"; import ToolbarButton from "./ToolbarButton";
@@ -223,8 +224,8 @@ class LinkEditor extends React.Component<Props, State> {
}, },
previousValue: trimmedValue, previousValue: trimmedValue,
})); }));
} catch (error) { } catch (err) {
console.error(error); Logger.error("Error searching for link", err);
} }
} }
}; };

View File

@@ -16,6 +16,7 @@ import { Portal } from "~/components/Portal";
import Scrollable from "~/components/Scrollable"; import Scrollable from "~/components/Scrollable";
import useDictionary from "~/hooks/useDictionary"; import useDictionary from "~/hooks/useDictionary";
import useToasts from "~/hooks/useToasts"; import useToasts from "~/hooks/useToasts";
import Logger from "~/utils/Logger";
import { useEditor } from "./EditorContext"; import { useEditor } from "./EditorContext";
import Input from "./Input"; import Input from "./Input";
@@ -99,7 +100,7 @@ function SuggestionsMenu<T extends MenuItem>(props: Props<T>) {
fromPos = view.coordsAtPos(selection.from); fromPos = view.coordsAtPos(selection.from);
toPos = view.coordsAtPos(selection.to, -1); toPos = view.coordsAtPos(selection.to, -1);
} catch (err) { } catch (err) {
console.warn(err); Logger.warn("Unable to calculate caret position", err);
return { return {
top: 0, top: 0,
bottom: 0, bottom: 0,

View File

@@ -1,5 +1,6 @@
import { pick } from "lodash"; import { pick } from "lodash";
import { set, observable } from "mobx"; import { set, observable } from "mobx";
import Logger from "~/utils/Logger";
import { getFieldsForModel } from "./decorators/Field"; import { getFieldsForModel } from "./decorators/Field";
export default abstract class BaseModel { export default abstract class BaseModel {
@@ -126,7 +127,7 @@ export default abstract class BaseModel {
const attributes = this.toAPI(); const attributes = this.toAPI();
if (Object.keys(attributes).length === 0) { if (Object.keys(attributes).length === 0) {
console.warn("Checking dirty on model with no @Field decorators"); Logger.warn("Checking dirty on model with no @Field decorators");
} }
return ( return (

View File

@@ -78,7 +78,6 @@ function AddGroupsToCollection(props: Props) {
toasts.showToast(t("Could not add user"), { toasts.showToast(t("Could not add user"), {
type: "error", type: "error",
}); });
console.error(err);
} }
}; };

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import * as Sentry from "@sentry/react"; import * as Sentry from "@sentry/react";
import env from "~/env"; import env from "~/env";

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-undef */ /* eslint-disable no-undef */
const { exec } = require("child_process"); const { exec } = require("child_process");

View File

@@ -2,6 +2,14 @@
"extends": [ "extends": [
"../.eslintrc" "../.eslintrc"
], ],
"overrides": [
{
"files": ["scripts/*"],
"rules": {
"no-console": "off"
}
}
],
"env": { "env": {
"jest": true, "jest": true,
"node": true "node": true

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { IncomingMessage } from "http"; import { IncomingMessage } from "http";
import chalk from "chalk"; import chalk from "chalk";
import { isEmpty, isArray, isObject, isString } from "lodash"; import { isEmpty, isArray, isObject, isString } from "lodash";

View File

@@ -32,9 +32,6 @@ if (env.SENTRY_DSN) {
export function requestErrorHandler(error: any, ctx: AppContext) { export function requestErrorHandler(error: any, ctx: AppContext) {
// we don't need to report every time a request stops to the bug tracker // we don't need to report every time a request stops to the bug tracker
if (error.code === "EPIPE" || error.code === "ECONNRESET") { if (error.code === "EPIPE" || error.code === "ECONNRESET") {
console.warn("Connection error", {
error,
});
return; return;
} }
@@ -69,6 +66,7 @@ export function requestErrorHandler(error: any, ctx: AppContext) {
Sentry.captureException(error); Sentry.captureException(error);
}); });
} else { } else {
// eslint-disable-next-line no-console
console.error(error); console.error(error);
} }
} }

View File

@@ -1,11 +1,12 @@
/* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/ban-types */
import Logger from "@server/logging/Logger";
const Deprecated = (message?: string) => ( const Deprecated = (message?: string) => (
target: Object, target: Object,
propertyKey: string propertyKey: string
) => { ) => {
if (process.env[propertyKey]) { if (process.env[propertyKey]) {
console.warn( Logger.warn(
`The environment variable ${propertyKey} is deprecated and will be removed in a future release. ${message}` `The environment variable ${propertyKey} is deprecated and will be removed in a future release. ${message}`
); );
} }

View File

@@ -1,5 +1,6 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import Logger from "@server/logging/Logger";
export type Chunk = { export type Chunk = {
file: string; file: string;
@@ -17,7 +18,7 @@ export const readManifestFile = (file = "./build/app/manifest.json") => {
try { try {
manifest = fs.readFileSync(absoluteFilePath, "utf8") as string; manifest = fs.readFileSync(absoluteFilePath, "utf8") as string;
} catch (err) { } catch (err) {
console.warn( Logger.warn(
`Can not find ${absoluteFilePath}. Try executing "yarn vite:build" before running in production mode.` `Can not find ${absoluteFilePath}. Try executing "yarn vite:build" before running in production mode.`
); );
} }

View File

@@ -1,4 +1,5 @@
import * as Sentry from "@sentry/react"; import * as Sentry from "@sentry/react";
import invariant from "invariant";
import { NodeSelection } from "prosemirror-state"; import { NodeSelection } from "prosemirror-state";
import { EditorView } from "prosemirror-view"; import { EditorView } from "prosemirror-view";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
@@ -43,10 +44,10 @@ const insertFiles = function (
onShowToast, onShowToast,
} = options; } = options;
if (!uploadFile) { invariant(
console.warn("uploadFile callback must be defined to handle uploads."); uploadFile,
return; "uploadFile callback must be defined to handle uploads."
} );
// okay, we have some dropped files and a handler lets stop this // okay, we have some dropped files and a handler lets stop this
// event going any further up the stack // event going any further up the stack

View File

@@ -85,7 +85,6 @@ function getNewState({
} }
); );
} catch (error) { } catch (error) {
console.log(error);
const errorNode = document.getElementById( const errorNode = document.getElementById(
"d" + "mermaid-diagram-" + diagramId "d" + "mermaid-diagram-" + diagramId
); );

View File

@@ -12,30 +12,26 @@ export default class Suggestion extends Extension {
return [new SuggestionsMenuPlugin(this.editor, this.options)]; return [new SuggestionsMenuPlugin(this.editor, this.options)];
} }
inputRules = (_options: { type: NodeType; schema: Schema }) => { inputRules = (_options: { type: NodeType; schema: Schema }) => [
console.log(this.name, this.options.openRegex); new InputRule(this.options.openRegex, (state, match) => {
if (
return [ match &&
new InputRule(this.options.openRegex, (state, match) => { state.selection.$from.parent.type.name === "paragraph" &&
if ( (!isInCode(state) || this.options.enabledInCode) &&
match && (!isInTable(state) || this.options.enabledInTable)
state.selection.$from.parent.type.name === "paragraph" && ) {
(!isInCode(state) || this.options.enabledInCode) && this.editor.events.emit(EventType.SuggestionsMenuOpen, {
(!isInTable(state) || this.options.enabledInTable) type: this.options.type,
) { query: match[1],
this.editor.events.emit(EventType.SuggestionsMenuOpen, { });
type: this.options.type, }
query: match[1], return null;
}); }),
} new InputRule(this.options.closeRegex, (state, match) => {
return null; if (match) {
}), this.editor.events.emit(EventType.SuggestionsMenuClose);
new InputRule(this.options.closeRegex, (state, match) => { }
if (match) { return null;
this.editor.events.emit(EventType.SuggestionsMenuClose); }),
} ];
return null;
}),
];
};
} }

View File

@@ -31,8 +31,8 @@ export default abstract class Mark extends Extension {
return []; return [];
} }
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) { toMarkdown(_state: MarkdownSerializerState, _node: ProsemirrorNode) {
console.error("toMarkdown not implemented", state, node); throw new Error("toMarkdown not implemented");
} }
parseMarkdown(): TokenConfig | void { parseMarkdown(): TokenConfig | void {

View File

@@ -37,8 +37,8 @@ export default abstract class Node extends Extension {
return {}; return {};
} }
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode): void { toMarkdown(_state: MarkdownSerializerState, _node: ProsemirrorNode) {
console.error("toMarkdown not implemented", state, node); throw new Error("toMarkdown not implemented");
} }
parseMarkdown(): TokenConfig | void { parseMarkdown(): TokenConfig | void {