Enable unicorn/prefer-optional-catch-binding (#9464)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-02-25 18:28:55 +08:00
1 parent feacf82892
commit 64a3906571
14 files changed
+27 -23

No files matched your search

+1
View File
@@ -73,6 +73,7 @@ rules:
unicorn/no-useless-undefined: error
unicorn/prefer-includes: error
unicorn/prefer-number-properties: error
unicorn/prefer-optional-catch-binding: error
unicorn/prefer-regexp-test: error
unicorn/prefer-spread: error
unicorn/prefer-string-slice: error
+1 -1
View File
@@ -127,7 +127,7 @@ async function cacheFiles(cache) {
path.join(".cache", file.replace("dist", "files")),
]);
}
} catch (err) {
} catch {
// Don't fail the build
}
}
+7 -4
View File
@@ -110,10 +110,13 @@ function getBabelConfig(bundle) {
},
],
];
config.plugins.push([
require.resolve("@babel/plugin-proposal-object-rest-spread"),
{ loose: true, useBuiltIns: true },
]);
config.plugins.push(
[
require.resolve("@babel/plugin-proposal-object-rest-spread"),
{ loose: true, useBuiltIns: true },
],
require.resolve("@babel/plugin-proposal-optional-catch-binding")
);
return config;
}
+2 -2
View File
@@ -48,7 +48,7 @@ class Cache {
for (const files of Object.values(this.files)) {
assert.ok(Array.isArray(files));
}
} catch (err) {
} catch {
this.checksums = {};
this.files = {};
}
@@ -97,7 +97,7 @@ class Cache {
async save() {
try {
await fs.writeFile(this.manifest, JSON.stringify(this.updated, null, 2));
} catch (err) {
} catch {
// Don't fail the build
}
}
+1 -1
View File
@@ -165,7 +165,7 @@ function format(context, input, opt) {
let benchmark;
try {
benchmark = eval("require")("benchmark");
} catch (err) {
} catch {
context.logger.debug(
"'--debug-benchmark' requires the 'benchmark' package to be installed."
);
+2 -2
View File
@@ -45,7 +45,7 @@ function load(plugins, pluginSearchDirs) {
try {
// try local files
requirePath = resolve(path.resolve(process.cwd(), pluginName));
} catch (_) {
} catch {
// try node modules
requirePath = resolve(pluginName, { paths: [process.cwd()] });
}
@@ -120,7 +120,7 @@ function findPluginsInNodeModules(nodeModulesDir) {
function isDirectory(dir) {
try {
return fs.statSync(dir).isDirectory();
} catch (e) {
} catch {
return false;
}
}
+3 -3
View File
@@ -213,7 +213,7 @@ function parseValue(value, options) {
try {
result = valueParser(value, { loose: true }).parse();
} catch (e) {
} catch {
return {
type: "value-unknown",
value,
@@ -247,7 +247,7 @@ function parseSelector(selector) {
selectorParser((result_) => {
result = result_;
}).process(selector);
} catch (e) {
} catch {
// Fail silently. It's better to print it as is than to try and parse it
// Note: A common failure is for SCSS nested properties. `background:
// none { color: red; }` is parsed as a NestedDeclaration by
@@ -270,7 +270,7 @@ function parseMediaQuery(params) {
try {
result = mediaParser(params);
} catch (e) {
} catch {
// Ignore bad media queries
/* istanbul ignore next */
return {
+1 -1
View File
@@ -39,7 +39,7 @@ function parseIeConditionalStartEndComment(node, parseHtml, match) {
const [complete, children] = (() => {
try {
return [true, parseHtml(data, contentStartSpan).children];
} catch (e) {
} catch {
const text = {
type: "text",
value: data,
+1 -1
View File
@@ -1172,7 +1172,7 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
"}}",
])
);
} catch (e) {
} catch {
parts.push("{{", replaceEndOfLineWith(part, literalline), "}}");
}
}
+3 -3
View File
@@ -128,7 +128,7 @@ function getInterpreter(filepath) {
let fd;
try {
fd = fs.openSync(filepath, "r");
} catch (err) {
} catch {
// istanbul ignore next
return "";
}
@@ -149,7 +149,7 @@ function getInterpreter(filepath) {
return m2[1];
}
return "";
} catch (err) {
} catch {
// There are some weird cases where paths are missing, causing Jest
// failures. It's unclear what these correspond to in the real world.
/* istanbul ignore next */
@@ -159,7 +159,7 @@ function getInterpreter(filepath) {
// There are some weird cases where paths are missing, causing Jest
// failures. It's unclear what these correspond to in the real world.
fs.closeSync(fd);
} catch (err) {
} catch {
// nop
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ function resolveParser(opts, parsers = getParsers(opts)) {
locStart,
locEnd,
};
} catch (err) {
} catch {
/* istanbul ignore next */
throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
}
+2 -2
View File
@@ -1,7 +1,7 @@
export function get(key) {
try {
return JSON.parse(window.localStorage.getItem(key));
} catch (_) {
} catch {
// noop
}
}
@@ -9,7 +9,7 @@ export function get(key) {
export function set(key, value) {
try {
window.localStorage.setItem(key, JSON.stringify(value));
} catch (_) {
} catch {
// noop
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ export function read() {
try {
return JSON.parse(decode(hash));
} catch (_) {
} catch {
return {};
}
}
+1 -1
View File
@@ -96,7 +96,7 @@ function handleMessage(message) {
if (!errored) {
try {
ast = formatCode(ast, { parser: "json", plugins }).formatted;
} catch (e) {
} catch {
ast = serializeAst(ast);
}
}