From 266859d461169c6377b06173fe94ae61dc17c186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Mon, 1 Apr 2024 15:18:24 +0200 Subject: [PATCH] fix: raise error when no default export found in config file (#96) Co-authored-by: Eric Cornelissen --- bin/cli.js | 3 +++ test/cli.spec.js | 8 ++++++++ .../with-config-no-default-export/.svglintrc.js | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/projects/with-config-no-default-export/.svglintrc.js diff --git a/bin/cli.js b/bin/cli.js index de3965d..6f1d874 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -86,6 +86,9 @@ process.on("exit", () => { } else { configObj = {}; } + } else if (configObj === undefined) { + logger.error("Default export missing from configuration file (use `export default {...}` or `module.exports = {...}`"); + process.exit(EXIT_CODES.configuration); } } catch (e) { logger.error(`Failed to parse config: ${e.stack}`); diff --git a/test/cli.spec.js b/test/cli.spec.js index 00e90d8..6d8a79c 100644 --- a/test/cli.spec.js +++ b/test/cli.spec.js @@ -83,6 +83,14 @@ describe("Configuration files", function() { expect(exitCode).toBe(4); }); + it("should fail with a configuration file without default export", async function(){ + const { failed, exitCode } = await execCliWith( + ["--config", "./test/projects/with-config-no-default-export/.svglintrc.js"] + ); + expect(failed).toBeTruthy(); + expect(exitCode).toBe(4); + }); + it("should succeed passing an existent file path to --config", async function() { const { failed } = await execCliWith( [VALID_SVG, "--config", "test/projects/esm/foo/custom-svglint-config.js"] diff --git a/test/projects/with-config-no-default-export/.svglintrc.js b/test/projects/with-config-no-default-export/.svglintrc.js new file mode 100644 index 0000000..492b202 --- /dev/null +++ b/test/projects/with-config-no-default-export/.svglintrc.js @@ -0,0 +1,11 @@ +export const config = { + rules: { + attr: { + "rule::selector": "path", + "d": true, + }, + elm: { + "g": true, + } + } +};