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

Add --warnings-as-errors flag for non-zero exit code #1412

Closed
wants to merge 1 commit into from

Conversation

kdawgwilk
Copy link

@kdawgwilk kdawgwilk commented Oct 21, 2021

Closes #1411
Closes #1294

@josevalim
Copy link
Member

Amazing! What if we call it —warnings-as-errors?

@kdawgwilk kdawgwilk changed the title Add strict flag for non-zero exit code Add --warnings-as-errors flag for non-zero exit code Oct 21, 2021
@kdawgwilk
Copy link
Author

kdawgwilk commented Oct 21, 2021

Are we okay with exiting after the first round of warnings are encountered? Or do we want to spit out all of the warnings before we exit? The easier approach would be to exit early but it may be frustrating to:

  • run it
  • see it fail
  • fix warnings
  • run it again
  • see more warnings
  • repeat

But due to this being a new feature having the early exit is still an improvement and could be improved later to show all warnings.

EDIT: Do we also want to support configuring this in mix.exs and not just CLI flag?

@josevalim
Copy link
Member

Ideally we would not fail early. We would have a process in ExDoc's supervision tree (it can be an Agent) which will store if warnings were emitted. If so, you abort at the end of the --warnings-as-errors flag is given. :)

lib/ex_doc/warnings_counter.ex Outdated Show resolved Hide resolved
lib/mix/tasks/docs.ex Outdated Show resolved Hide resolved
lib/ex_doc/cli.ex Outdated Show resolved Hide resolved
lib/ex_doc/warning_counter.ex Outdated Show resolved Hide resolved
Copy link
Member

@wojtekmach wojtekmach left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a couple minor comments!

lib/ex_doc/cli.ex Outdated Show resolved Hide resolved
lib/ex_doc/application.ex Outdated Show resolved Hide resolved
lib/ex_doc/cli.ex Outdated Show resolved Hide resolved
@wojtekmach
Copy link
Member

@kdawgwilk ping! I think this is pretty close, feel free to change from a draft to ready for review so we can merge it soon. (Of course no rush!)

@kdawgwilk
Copy link
Author

Struggling to figure out how to write some good tests for this, other than that I think it is mostly ready to go

@wojtekmach
Copy link
Member

@kdawgwilk ping. :) I think the tests are pretty good as is, no need for more coverage imho.

@kdawgwilk kdawgwilk force-pushed the kaden/strict_flag branch 2 times, most recently from c1f7f2c to 3d0dcc7 Compare February 16, 2022 23:13
@kdawgwilk
Copy link
Author

@wojtekmach I think I have enough tests now just having a hard time getting them to behave with the exit code, have 1 left that is still failing because there are no actual warnings where I am expecting a warning so I can assert it exits as expected. Not sure how to use the fixtures to get a doc warning when I run from the tests. After thats figured out this should be good to go

@kdawgwilk kdawgwilk marked this pull request as ready for review February 16, 2022 23:24
@kdawgwilk
Copy link
Author

Just figured it out now so this should be ready for review!

test/ex_doc/cli_test.exs Outdated Show resolved Hide resolved
test/ex_doc/cli_test.exs Outdated Show resolved Hide resolved
@milmazz
Copy link
Member

milmazz commented Feb 20, 2022

@kdawgwilk This looks good to me. Do you need help with something in particular? or in your opinion, are we good to go?

EDIT: Quick local test seems good too.

diff --git a/README.md b/README.md
index 89cf2ca0..8b59e943 100644
--- a/README.md
+++ b/README.md
@@ -252,3 +252,8 @@ The easiest way to test changes to ExDoc is to locally rebuild the app and its o
 ExDoc source code is released under [Apache 2 License](LICENSE). The generated contents, however, are under different licenses based on projects used to help render HTML, including CSS, JS, and other assets.

 Any documentation generated by ExDoc, or any documentation generated by any "Derivative Works" (as specified in the Apache 2 License), must include a direct, readable, and visible link to the [ExDoc repository](https://github.com/elixir-lang/ex_doc) on each rendered material. For HTML pages, a rendered material represents every single page. For PDF, EPUB and other ebook formats, it means one entry for the whole material.
+
+<pre><code>
+something
+sometjing
+</code></pre>
$ mix docs --warnings-as-errors
Generating docs...
warning: ExDoc.Markdown.Earmark (warning) README.md:256 Failed to find closing <pre>

View "html" docs at "doc/index.html"
Doc generation failed due to warnings while using the --warnings-as-errors option
$ echo $status
1

Copy link
Member

@milmazz milmazz left a comment

Choose a reason for hiding this comment

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

Found a minor bug 🐛 in the unit tests. HTH

@@ -181,4 +181,8 @@ defmodule Mix.Tasks.DocsTest do
] = run([], app: :umbrella, apps_path: "apps/", docs: [ignore_apps: [:foo]])
end)
end

test "accepts warnings_as_errors in :warnings_as_errors" do
assert catch_exit(run([], app: :ex_doc, docs: [warnings_as_errors: true])) == {:shutdown, 1}
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Individually, this test should fail, it's assuming that the state of the WarningCounter is greater than zero when is not the case.

end

test "exits with 1 with warnings" do
ExDoc.WarningCounter.increment()
Copy link
Member

Choose a reason for hiding this comment

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

This test is running in async mode, and you're modifying a global state here that could affect other tests, which is what happening with test/mix/tasks/docs_test.exs

Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the simplest way to solve this?
I have tried some but it requires a large refactoring.

Copy link
Author

Choose a reason for hiding this comment

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

If I do a ExDoc.WarningCounter.reset() on the tests that use this global state would that work?

Copy link
Contributor

@eksperimental eksperimental Apr 25, 2022

Choose a reason for hiding this comment

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

If I do a ExDoc.WarningCounter.reset() on the tests that use this global state would that work?

the issue is that since they are in separate files they could be executed concurrently.
If you execute reset in one file, it will be resetting the ones in the other tests. The only guarantee is that if you use async: false is that the tests within the same file are not going to be running asynchronously.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds like this is going to be more work than I was expecting to get added 😞 I started a new job and am no longer working with elixir day to day so I likely won't be finishing this up anymore. If someone else wants to pick it up feel free.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like this is going to be more work than I was expecting to get added disappointed I started a new job and am no longer working with elixir day to day so I likely won't be finishing this up anymore. If someone else wants to pick it up feel free.

Sure. No worries. I was already working with your PR so I'm familiar with it.
Thanks a lot for the PR, it is almost there.

@warmwaffles
Copy link

Would love to see this feature.

@kdawgwilk
Copy link
Author

No longer working with Elixir day to day 😢 so I won't be able to prioritize this for awhile unfortunately

@kdawgwilk kdawgwilk closed this Apr 25, 2022
@eksperimental
Copy link
Contributor

No longer working with Elixir day to day cry so I won't be able to prioritize this for awhile unfortunately

No worries @kdawgwilk, I can jump in from where you left off.

@eksperimental
Copy link
Contributor

eksperimental commented Apr 25, 2022

So let's define how do we want to deal with the global state of the warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support --strict flag that fails with non-zero exit code for warnings Feature request: Warnings as Errors
7 participants