From e18c827cc12cb1c52e5d0aa993f572cb56238704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Sun, 11 Nov 2018 23:42:45 +0800 Subject: [PATCH] Chore: refactor linter#parseBooleanConfig to improve readability (#11074) --- lib/linter.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/linter.js b/lib/linter.js index b47e6eb1fcf..edcf741069c 100644 --- a/lib/linter.js +++ b/lib/linter.js @@ -76,19 +76,14 @@ function parseBooleanConfig(string, comment) { if (!name) { return; } - const pos = name.indexOf(":"); - if (pos === -1) { - items[name] = { - value: false, - comment - }; - } else { - items[name.slice(0, pos)] = { - value: name.slice(pos + 1) === "true", - comment - }; - } + // value defaults to "false" (if not provided), e.g: "foo" => ["foo", "false"] + const [key, value = "false"] = name.split(":"); + + items[key] = { + value: value === "true", + comment + }; }); return items; }