Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for script to exit with code 0 even if circular dependencies are found #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,18 @@ madge path/src/foo path/src/bar
madge --extensions js,jsx path/src
```

> Finding circular dependencies
> Finding circular dependencies – exits 1 if any are found

```sh
madge --circular path/src/app.js
```

> Finding circular dependencies – exits 0 if any are found

```sh
madge --circular --allow-circular path/src/app.js
```

> Show modules that depends on a given module

```sh
Expand Down
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ program
.option('--stdin', 'read predefined tree from STDIN', false)
.option('--warning', 'show warnings about skipped files', false)
.option('--debug', 'turn on debug output', false)
.option('--allow-circular', 'exit with code 0 when circular dependencies are found', false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.option('--allow-circular', 'exit with code 0 when circular dependencies are found', false)
.option('--allow-circular', 'not exit with code 1 when circular dependencies are found', false)

Describe what's done instead of using its converse. The old description is ambiguous: imagine the case where circular dependencies are found along with other errors. By the old description, madge was meant to exit with 0, which is untrue.

.parse(process.argv);

if (!program.args.length && !program.stdin) {
Expand Down Expand Up @@ -265,7 +266,7 @@ function createOutputFromOptions(program, res) {
json: program.json
});

if (circular.length) {
if (circular.length && !program.allowFailures) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (circular.length && !program.allowFailures) {
if (!program.allowFailures && circular.length) {

Kinda niche-picking but in this way it express better which is more important

exitCode = 1;
}

Expand Down