gochan-org / gochan

No default cases in switch statements JS-0047
Anti-pattern
Minor
2 months ago2 years old
Expected a default case
120	if(!idArr) return;
121	const postID = Number.parseInt(idArr[4]);
122	const board = currentBoard();
123	switch(action) {124	case "Watch thread":125		watchThread(postID, board);126		break;127	case "Unwatch thread":128		unwatchThread(postID, board);129		break;130	case "Show thread":131		setThreadVisibility(postID, true);132		break;133	case "Hide thread":134		setThreadVisibility(postID, false);135		break;136	case "Move thread":137		moveThread(postID, board);138		break;139	case "Show post":140		setPostVisibility(postID, true);141		break;142	case "Hide post":143		setPostVisibility(postID, false);144		break;145	case "Edit post":146		editPost(postID, board);147		break;148	case "Report post":149		reportPost(postID, board);150		break;151	case "Delete file":152		deletePost(postID, board, true);153		break;154	case "Delete thread":155	case "Delete post":156		deletePost(postID, board, false);157		break;158	// manage stuff159	case "Lock thread":160		console.log(`Locking /${board}/${postID}`);161		updateThreadLock(board, postID, true);162		break;163	case "Unlock thread":164		console.log(`Unlocking /${board}/${postID}`);165		updateThreadLock(board, postID, false);166		break;167	case "Posts from this IP":168		getPostInfo(postID).then((info: any) => {169			window.open(`${webroot}manage/ipsearch?limit=100&ip=${info.post.IP}`);170		}).catch((reason: JQuery.jqXHR) => {171			alertLightbox(`Failed getting post IP: ${reason.statusText}`, "Error");172		});173		break;174	case "Ban IP address":175		window.open(`${webroot}manage/bans?dir=${board}&postid=${postID}`);176		break;177	case "Ban filename":178	case "Ban file checksum": {179		const banType = (action === "Ban filename")?"filename":"checksum";180		getPostInfo(postID).then((info) => banFile(181			banType, info.originalFilename, info.checksum,182			`Added from post dropdown for post /${board}/${postID} (filename: ${info.originalFilename})`183		)).then((result: any) => {184			if(result.error !== undefined && result.error !== "") {185				if(result.message !== undefined)186					alertLightbox(`Failed applying ${banType} ban: ${result.message}`, "Error");187				else188					alertLightbox(`Failed applying ${banType} ban: ${result.error}`, "Error");189			} else {190				alertLightbox(`Successfully applied ${banType} ban`, "Success");191			}192		}).catch((reason: any) => {193			let messageDetail = "";194			try {195				const responseJSON = JSON.parse(reason.responseText);196				if((typeof responseJSON.message) === "string" && responseJSON.message !== "") {197					messageDetail = responseJSON.message;198				} else {199					messageDetail = reason.statusText;200				}201			} catch(e) {202				messageDetail = reason.statusText;203			}204			alertLightbox(`Failed banning file: ${messageDetail}`, "Error");205		});206		break;207	}208	case "Ban fingerprint":209		getPostInfo(postID).then((info) => banFileFingerprint(210			info.fingerprint, false).then(() => alertLightbox(211			"Successfully applied fingerprint ban", "Success"212		)));213		break;214	case "Ban fingerprint (IP ban)":215		getPostInfo(postID).then((info) => {216			promptLightbox("", false, (_, val) => banFileFingerprint(217				info.fingerprint, true, val,218				`Added from post /${board}/${postID} (filename: ${info.originalFilename})`219			).then(() => alertLightbox(220				"Successfully applied fingerprint ban", "Success"221			)));222		});223		break;224	}225}
226
227export function addPostDropdown($post: JQuery<HTMLElement>) {
Expected a default case
15
16export function applyBBCode(e: JQuery.KeyDownEvent) {
17	let tag = "";
18	switch(e.key) {19	case "Enter":20		// trigger the form submit event, whether the QR post box or the static post box is currently21		$(e.target).parents("form#postform,form#qrpostform").trigger("submit");22		break;23	case "b":24		tag = "b"; // bold25		break;26	case "i":27		tag = "i"; // italics28		break;29	case "r":30		tag = "s"; // strikethrough31		break;32	case "s":33		tag = "?";34		break;35	case "u":36		tag = "u"; // underline37		break;38	}39	if(tag === "") return;
40
41	e.preventDefault();