Skip to content

Commit

Permalink
fix: raise error when no default export found in config file (#96)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Cornelissen <[email protected]>
  • Loading branch information
mondeja and ericcornelissen authored Apr 1, 2024
1 parent 9b3849e commit 266859d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
8 changes: 8 additions & 0 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
11 changes: 11 additions & 0 deletions test/projects/with-config-no-default-export/.svglintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const config = {
rules: {
attr: {
"rule::selector": "path",
"d": true,
},
elm: {
"g": true,
}
}
};

0 comments on commit 266859d

Please sign in to comment.