-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Change Request: (add eslint warnings exit code) #18402
Comments
Just in case, I’ll explain what I want:
In GitLab CI this can be implemented using exit code. |
Thanks for the issue @alSergey. As you may already know, npx eslint . --max-warnings=0 And then any warning will cause There is no way to distinguish between only warnings and errors plus warnings just from the exit code, this can be achieved with a custom formatter. But anyway, talking about GitLab CI, I'm not sure that you can selectively set the status of a job to warning or error from the exit code of the last command: the related issue is closed and I don't see that feature in their documentation, so I would recommend that you solve that problem first, and update the yaml code in your issue to show what you are planning to do. This would help us to understand how we can help you. |
@fasttime hi, I know about the I suggest adding a new feature flag like fe eslint:
script:
- npx eslint . --warnings-exit-code
allow_failure:
exit_codes: 15 # This is the exit code with which eslint will exit in case of warnings |
So, that job will complete as successful if the exit code of the command is 0, with a warning if the exit code is 15, and with an error for any other exit code? I'm just trying to understand how things work, because the docs about allow_failure.exit_codes doesn't explain it. Do you know if GitLab provides other ways to set the status of a job to a warning or error without checking the exit code, maybe an API? That could be simpler to implement for your case, because currently the ESLint CLI does not provide a way for plugins or formatters to control the exit code. |
Yes, everything will be exactly as you said. I wrote a small example where you can see how it works. And this is what the pipeline looks like.
Unfortunately, I don’t know any other options for making a job warning, only checking for exit code. This is a built-in feature in GitLab pipelines that is widely used, so it seems like it should be used. The allow_failure command allows you to select in which cases the job will end with an error, and in which cases with a warning. And this command has an exit_codes setting. Here is an excerpt from the documentation that describes how the command works.
|
Thanks for the useful clarifications @alSergey! The reason why ESLint exits with code zero for warnings is because nonzero exit codes are typically treated as errors, and unlike errors, warnings should not enforce rule compliance or break build commands (see Rule Severities). Now, GitLab seems to have a different idea: in order to report a warning, a command must exit with an error code - if it's true that there are no other options - and that code has to be specially annotated in their job definition. I can see that this makes it difficult to integrate GitLab's Given the popularity of GitLab CI/CD, maybe it would be good to find a solution to improve this situation. I'd like to know what other members of the team think about this. @eslint/eslint-team. |
@fasttime Hi, I understand why the It will work something like this. By default, the Errors and Warnings $ npx eslint .
...
✖ 2 problems (1 error, 1 warning)
$ echo $?
1
$ npx eslint . --warnings-exit-code
...
✖ 2 problems (1 error, 1 warning)
$ echo $?
1 # Old exit code because there are errors Only Warnings $ npx eslint .
...
⚠ 1 problem (0 error, 1 warning)
$ echo $?
0
$ npx eslint . --warnings-exit-code
...
⚠ 1 problem (0 errors, 1 warning)
$ echo $?
3 # New exit code with feature flag !!! All Success $ npx eslint .
...
0 problems (0 error, 0 warning)
$ echo $?
0
$ npx eslint . --warnings-exit-code
...
0 problems (0 error, 0 warning)
$ echo $?
0 # Old exit code because there are no warnings |
I wouldn't be opposed to adding this flag if others are in favor, though you can always pass the output from ESLint to another command or script that can then analyze it and determine the final exit code. Here's an example I found with eslint warnings and https://blog.vasi.li/soft-failing-the-build-in-gitlab-ci-on-eslint-warnings |
Yes, you are right. It really can be done as you wrote. But this introduces additional difficulties. First you need to parse the output and understand whether there is only a warning, or there are also errors. Then you need to print the original output so that it appears in the console. At the very end, you need to enter the exit code yourself. Given the popularity of GitLab CI, I would like to have a more native solution to this problem. |
https://eslint.org/docs/latest/use/command-line-interface#exit-codes
I'm👍 to distinction between the two cases in the exitcode (e.g. 3 for |
I'm not opposed to adding a new flag, but we'd definitely need an RFC for that. |
@nzakas hi, is there anything you need from me? |
@alSergey I think there is agreement that we can add a CLI flag to change the exit code as you suggested, but some reviewers consider this change sufficiently complex that it will require a RFC (request for comments) to discuss the details and formalize the process of finding the best design. To start a RFC, just follow the instructions in this readme file and fill in the design template with the requested information. |
ESLint version
v8.57.0
What problem do you want to solve?
We have a fe eslint job in GitLab CI that runs eslint checks. Currently there is no way to show a warning in a job if eslint ends with a warning.
What do you think is the correct solution?
Add a new exit code, which will be triggered if eslint checks find 0 error and more than 0 warning.
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: