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

Cannot specify --all-warnings-as-errors with no status codes #269

Open
phillipuniverse opened this issue Oct 3, 2023 · 2 comments
Open

Comments

@phillipuniverse
Copy link
Contributor

I would like to turn every warning the linter emits into an error.

From the docs:

Optionally specify migration test codes to handle as errors. When no test code specified, all warnings are handled as errors.

But the implementation does not work when checking the 'when no test code specified' part. The problem is in this code, either this doesn't work or I don't know how to appropriately specify an empty list for this option on the command line:

def extract_warnings_as_errors_option(
warnings_as_errors: list[str] | None,
) -> tuple[list[str] | None, bool]:
if isinstance(warnings_as_errors, list):
warnings_as_errors_tests = warnings_as_errors
# If the option is specified but without any test codes,
# all warnings become errors
all_warnings_as_errors = len(warnings_as_errors) == 0
else:
warnings_as_errors_tests = None
all_warnings_as_errors = False
return warnings_as_errors_tests, all_warnings_as_errors

Here are some examples and what happens in the debugger:

python manage.py lintmigrations --no-cache --warnings-as-error CREATE_INDEX CREATE_INDEX_EXCLUSIVE DROP_INDEX REINDEX

image

python manage.py lintmigrations --no-cache --warnings-as-error

image

python manage.py lintmigrations --no-cache --warnings-as-error= (same result as python manage.py lintmigrations --no-cache --warnings-as-error '')

image

So what's the right way to get the behavior of treating all warnings as errors without passing them all individually?

@lieryan
Copy link
Contributor

lieryan commented Jan 11, 2024

This works for me:

./manage.py lintmigrations --git-commit-id ... --no-cache --warnings-as-errors

Also, specifying this in pyproject.toml, like so:

[tool.django_migration_linter]
warnings_as_errors = []

I think the documentations can be improved since it's rather unclear how to specify multiple warning names in the CLI and for each of the config file formats. Having some examples would be nice.

@johnnymetz
Copy link

I think improving the documentation would be great here. I set warnings_as_errors = True and was confused when it wasn't working.

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

No branches or pull requests

3 participants