Skip to content

Conversation

@joshbax189
Copy link
Contributor

@joshbax189 joshbax189 commented Nov 1, 2025

This moves the test for eask analyze from #275 and also matches the command's behavior to what was proposed in the tests.

Changes

Exit codes

  • eask analyze exits with 1 if there are any errors in any of the files checked.
  • it does not exit early, so --allow-error has no effect
  • the --strict flag makes any warnings cause an exit with code 1
    (This does not include lexical binding cookie warnings)

Others

  • when --json is set, but there are no warnings or errors, output {}
  • always print (Checked N files) whether there are errors or not
  • ensure (Checked N files) includes files with and without errors

@jcs090218
Copy link
Member

I remembered why it was outputted to stderr instead of stdout (sorry, it's been a while 😓) since other CLI tools also use stderr for this purpose; therefore, it was designed this way. Other things to consider, like flycheck-eask wouldn't work after switching to stdout. 🤔

I've temporarily added the function eask-stdout to analyze.el. It should probably go in _prepare.el.

Yes, but I guess we don't need it anymore since it should go to stderr. (above statement) 🤔

How would you suggest to integrate that with the other message commands?

The message commands are a bit out of control. This indeed requires some refactoring due to inconsistencies and a lack of standards. 😅 eask-print, eask-println, eask-write, etc. 😨

  • when --json is set, but there are no warnings, output {}
  • always print (Checked N files) whether there are errors or not (prints to stderr)
  • ensure this counts error files as well

👍 Thanks for taking care of this!

  • eask analyze exits with 1 if there are any errors in any of the files checked.
  • it does not exit early, so --allow-error has no effect
  • currently --strict has no effect either (TODO should it?)

Exiting code with 1 sounds good!

There is a conflict between the options --allow-error and --strict, as the program will be interrupted (reporting an error) while analyzing Eask files. This is a temporary workaround by design for now.

@jcs090218 jcs090218 added the enhancement New feature or request label Nov 1, 2025
@joshbax189
Copy link
Contributor Author

Cool! I didn't know about flycheck-eask. If mixed JSON+text output works there, then that's good enough. I'll figure out some way of replicating that in tests.

There is a conflict between the options --allow-error and --strict

I meant that --strict should case it to exit with 1 if there are any warnings. Does that make sense?

@jcs090218
Copy link
Member

jcs090218 commented Nov 5, 2025

FYI, there is also flymake-eask too! :D

I meant that --strict should case it to exit with 1 if there are any warnings. Does that make sense?

Oh, yeah! In that case, yes! 👍

@joshbax189
Copy link
Contributor Author

Ok so I've reverted to use only stderr.

In order to test the JSON output I've made it so all JSON output is on a single line. This matches how flycheck works, and I've tested that flycheck-eask still works in the updated version.

(cond ((eask-json-p) ; JSON format
;; Fill content with result.
(when (or eask-analyze--warnings eask-analyze--errors)
(setq content (json-encode
Copy link
Member

Choose a reason for hiding this comment

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

The pretty print eask-analyze--pretty-json is probably still better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There needs to be a way to separate JSON from plain text in tests. See the function tryJSON in analyze.test.js. It wont work if the JSON is pretty printed.

I'm assuming that the output from analyze --json is just for flycheck/flymake and so it doesn't need to be pretty printed.

The other alternative would be to write something like this https://stackoverflow.com/a/54608716, which is kind of messy and likely fragile.

Copy link
Member

Choose a reason for hiding this comment

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

What if we convert the pretty print result to a single line result in the tryJSON function? 🤔

A printed result is a better UX, since I seldom read the JSON output directly from the terminal. Additionally, it's easier to debug and add new content to the output. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I made a compromise solution that assumes that all non-JSON lines don't begin with whitespace and there is a single JSON object in the output. See the comments in the code. It allows pretty-printing the output, but the test may fail while flycheck still accepts the output.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder why the test may fail. It seems fine and the CI passed! :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, in general, you can change the code in analyze.el so that analyze --json prints output that causes the test to fail while flycheck-eask is still working.

@jcs090218
Copy link
Member

Let me know if this is ready to merge! I'll be happy to merge this! :)

@joshbax189
Copy link
Contributor Author

Yep ready to merge. I've updated the PR description to just show what was actually changed after revisions.

@jcs090218 jcs090218 merged commit c7600fc into emacs-eask:master Nov 7, 2025
200 of 206 checks passed
@jcs090218
Copy link
Member

Awesome! Merged now! Thank you so much for your hard work! 🚀 🥳

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants