Commit 212dc1c63b13bf067c1609f85f28abbbc2c94ff7

Michael Schmidt 2021-05-25T12:46:45

ESLint: Added curly rule (#2901)

diff --git a/.eslintrc.js b/.eslintrc.js
index af23f5b..7a758b1 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -8,6 +8,7 @@ module.exports = {
 
 		// stylistic rules
 		'brace-style': ['warn', '1tbs', { allowSingleLine: true }],
+		'curly': ['warn', 'all'],
 		'no-tabs': ['warn', { allowIndentationTabs: true }],
 		'no-var': 'error',
 		'one-var': ['warn', 'never'],
diff --git a/assets/code.js b/assets/code.js
index 5c10d05..162cdb0 100644
--- a/assets/code.js
+++ b/assets/code.js
@@ -119,7 +119,9 @@
 
 // calc()
 (function () {
-	if (!window.PrefixFree) return;
+	if (!window.PrefixFree) {
+		return;
+	}
 
 	if (PrefixFree.functions.indexOf('calc') == -1) {
 		var style = document.createElement('_').style;
diff --git a/assets/download.js b/assets/download.js
index 2d8855c..121bb11 100644
--- a/assets/download.js
+++ b/assets/download.js
@@ -187,13 +187,16 @@
 			}
 
 			function getLanguageTitle(lang) {
-				if (!lang.aliasTitles)
+				if (!lang.aliasTitles) {
 					return lang.title;
+				}
 
 				var titles = [lang.title];
-				for (var alias in lang.aliasTitles)
-					if (lang.aliasTitles.hasOwnProperty(alias))
+				for (var alias in lang.aliasTitles) {
+					if (lang.aliasTitles.hasOwnProperty(alias)) {
 						titles.push(lang.aliasTitles[alias]);
+					}
+				}
 				return titles.join(' + ');
 			}
 
diff --git a/components/prism-markup-templating.js b/components/prism-markup-templating.js
index 1c22f94..2855b7c 100644
--- a/components/prism-markup-templating.js
+++ b/components/prism-markup-templating.js
@@ -39,8 +39,9 @@
 					var placeholder;
 
 					// Check for existing strings
-					while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1)
+					while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1) {
 						++i;
+					}
 
 					// Create a sparse array
 					tokenStack[i] = match;
diff --git a/dangerfile.js b/dangerfile.js
index 36face9..d9eb8c5 100644
--- a/dangerfile.js
+++ b/dangerfile.js
@@ -45,7 +45,9 @@ const getChangedMinifiedFiles = async () => {
 
 // https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
 const formatBytes = (bytes, decimals = 2) => {
-	if (bytes === 0) return '0 Bytes';
+	if (bytes === 0) {
+		return '0 Bytes';
+	}
 
 	const k = 1000;
 	const dm = decimals < 0 ? 0 : decimals;
diff --git a/plugins/normalize-whitespace/prism-normalize-whitespace.js b/plugins/normalize-whitespace/prism-normalize-whitespace.js
index 9701324..f551807 100644
--- a/plugins/normalize-whitespace/prism-normalize-whitespace.js
+++ b/plugins/normalize-whitespace/prism-normalize-whitespace.js
@@ -6,8 +6,9 @@
 
 	var assign = Object.assign || function (obj1, obj2) {
 		for (var name in obj2) {
-			if (obj2.hasOwnProperty(name))
+			if (obj2.hasOwnProperty(name)) {
 				obj1[name] = obj2[name];
+			}
 		}
 		return obj1;
 	};
@@ -25,8 +26,9 @@
 	function tabLen(str) {
 		var res = 0;
 		for (var i = 0; i < str.length; ++i) {
-			if (str.charCodeAt(i) == '\t'.charCodeAt(0))
+			if (str.charCodeAt(i) == '\t'.charCodeAt(0)) {
 				res += 3;
+			}
 		}
 		return str.length + res;
 	}
@@ -76,13 +78,15 @@
 		removeIndent: function (input) {
 			var indents = input.match(/^[^\S\n\r]*(?=\S)/gm);
 
-			if (!indents || !indents[0].length)
+			if (!indents || !indents[0].length) {
 				return input;
+			}
 
 			indents.sort(function (a, b) { return a.length - b.length; });
 
-			if (!indents[0].length)
+			if (!indents[0].length) {
 				return input;
+			}
 
 			return input.replace(RegExp('^' + indents[0], 'gm'), '');
 		},
@@ -94,8 +98,9 @@
 
 			var lines = input.split('\n');
 			for (var i = 0; i < lines.length; ++i) {
-				if (tabLen(lines[i]) <= characters)
+				if (tabLen(lines[i]) <= characters) {
 					continue;
+				}
 
 				var line = lines[i].split(/(\s+)/g);
 				var len = 0;
diff --git a/tests/helper/test-case.js b/tests/helper/test-case.js
index 4879af1..a3c743e 100644
--- a/tests/helper/test-case.js
+++ b/tests/helper/test-case.js
@@ -306,7 +306,9 @@ function translateIndexIgnoreSpaces(spacey, withoutSpaces, withoutSpaceIndex) {
 	let i = 0;
 	let j = 0;
 	while (i < spacey.length && j < withoutSpaces.length) {
-		while (spacey[i] !== withoutSpaces[j]) i++;
+		while (spacey[i] !== withoutSpaces[j]) {
+			i++;
+		}
 		if (j === withoutSpaceIndex) {
 			return i;
 		}