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

Support running linter from CLI separately to build #2811

Closed
johndowns opened this issue May 24, 2021 · 7 comments · Fixed by #10819
Closed

Support running linter from CLI separately to build #2811

johndowns opened this issue May 24, 2021 · 7 comments · Fixed by #10819
Labels
enhancement New feature or request story: linter

Comments

@johndowns
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When I create a CI/CD pipeline to work with my Bicep templates, I want to run linter rules and fail the build if there are any warnings or errors. Currently, the bicep build command executes the linter but shows linter warnings as outputs, and the exit code is 0, so it's not easy to pick up that linter rules failed. Additionally, bicep build emits a JSON template, which I don't need.

Describe the solution you'd like
Please provide a new bicep lint command, which will run the same linter rules as bicep build, but will return a meaningful exit code (perhaps 0 for no linter warnings, 1 for warnings, 2 for errors?) and that doesn't emit a JSON template.

@MarcusFelling
Copy link
Collaborator

@johndowns - would using bicepsettings.json to set all of the rules to error level meet your needs? The error build-time behavior will throw exit code of 1 and should cause the build to fail. bicepsettings.json can sit in source control alongside your templates and the CLI will automatically pick it up.

@johndowns
Copy link
Contributor Author

@MarcusFelling I don't think so. It's a workaround, but I don't think it's the optimal solution.

The key thing to me is that:

  • At development time, warnings might be something I ignore because I'm trying to get something done.
  • At release time (in my CI/CD process), I want to make sure the warnings are treated as errors and fail the build. This is the last chance to catch issues before they potentially hit production.

So to me, it'd be better if I could have a bicep lint command that fails with any linter violations (except those I've disabled). Alternatively, maybe there could be a new bicep build --treat-warnings-as-errors switch that would do the same thing.

@anthony-c-martin
Copy link
Member

anthony-c-martin commented May 28, 2021

@johndowns - does this ask apply purely to linter warnings, or are you looking for any warnings to be treated as errors? For example, the following type validation message is a core compiler warning (not a linter warning):

image

@johndowns
Copy link
Contributor Author

@anthony-c-martin In principle it'd be good to apply it to all warnings, but my concern is that there are still some situations where RPs haven't properly documented their schemas, and so compiler warnings will appear that I have no control over. If the any() function could be used as an escape hatch for all situations, or if there was another way of telling Bicep to ignore a specific warning for a specific line/resource, then I'd be in favour of that. But as of today, I think separating out the linter results would be a better approach.

@jonas-lomholdt
Copy link

I came here because I was looking for this exact thing. Having a bicep lint command that potentially could also output the warnings/errors as json would also be beneficial.

@alex-frankel alex-frankel modified the milestones: v0.5, Committed Backlog Mar 15, 2022
@zhengchang907
Copy link

Any plans of this feature, thought it would be a handy one.

@alex-frankel
Copy link
Collaborator

We agree it would be a useful command to add, but don't have the time to implement it ourselves. It would be great if someone could make an external contribution for this one.

anthony-c-martin added a commit that referenced this issue Aug 10, 2023
# Contributing a Pull Request

If you haven't already, read the full [contribution
guide](https://github.com/Azure/bicep/blob/main/CONTRIBUTING.md). The
guide may have changed since the last time you read it, so please
double-check. Once you are done and ready to submit your PR, run through
the relevant checklist below.

## Contributing a feature

* [x] I have opened a new issue for the proposal, or commented on an
existing one, and ensured that the Bicep maintainers are good with the
design of the feature being implemented
* [x] I have included "Fixes #{issue_number}" in the PR description, so
GitHub can link to the issue and close it when the PR is merged
* [ ] I have appropriate test coverage of my new feature

Fixes #2811

Added new command `lint` that will return an error exit code when there
are any warnings or errors when building the bicep files. The command
has a flag `--ignore-warnings` to only react on errors, not sure if this
is needed though since you could use the `build` command instead.

I also added tests, copied and refactored from `build` command tests, I
could use some feedback if the tests cover enough or there are some
missing tests that should be added (that's why I didn't check the test
checkbox above).

## Checklist/discussion points
- [ ] Do we want the `--ignore-warnings` flag? Does it serve a purpose?
- [ ] Are there any more tests needed?
- [ ] #2811 describes different exit codes depending on warnings/errors,
is this wanted?
- [ ] Are there any additional flags that are needed for the command?

###### Microsoft Reviewers: [Open in
CodeFlow](https://portal.fabricbot.ms/api/codeflow?pullrequest=https://github.com/Azure/bicep/pull/10819)

---------

Co-authored-by: Anthony Martin <38542602+anthony-c-martin@users.noreply.github.com>
StephenWeatherford pushed a commit that referenced this issue Aug 11, 2023
# Contributing a Pull Request

If you haven't already, read the full [contribution
guide](https://github.com/Azure/bicep/blob/main/CONTRIBUTING.md). The
guide may have changed since the last time you read it, so please
double-check. Once you are done and ready to submit your PR, run through
the relevant checklist below.

## Contributing a feature

* [x] I have opened a new issue for the proposal, or commented on an
existing one, and ensured that the Bicep maintainers are good with the
design of the feature being implemented
* [x] I have included "Fixes #{issue_number}" in the PR description, so
GitHub can link to the issue and close it when the PR is merged
* [ ] I have appropriate test coverage of my new feature

Fixes #2811

Added new command `lint` that will return an error exit code when there
are any warnings or errors when building the bicep files. The command
has a flag `--ignore-warnings` to only react on errors, not sure if this
is needed though since you could use the `build` command instead.

I also added tests, copied and refactored from `build` command tests, I
could use some feedback if the tests cover enough or there are some
missing tests that should be added (that's why I didn't check the test
checkbox above).

## Checklist/discussion points
- [ ] Do we want the `--ignore-warnings` flag? Does it serve a purpose?
- [ ] Are there any more tests needed?
- [ ] #2811 describes different exit codes depending on warnings/errors,
is this wanted?
- [ ] Are there any additional flags that are needed for the command?

###### Microsoft Reviewers: [Open in
CodeFlow](https://portal.fabricbot.ms/api/codeflow?pullrequest=https://github.com/Azure/bicep/pull/10819)

---------

Co-authored-by: Anthony Martin <38542602+anthony-c-martin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request story: linter
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants