diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c801b..8825eca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.0 + +* Add linting on data migrations that will raise warnings +* Add `--quiet warning` option to suppress warning messages +* Add `--warnings-as-errors` option to handle warnings as errors + ## 1.5.0 * Rework documentation. diff --git a/django_migration_linter/management/commands/lintmigrations.py b/django_migration_linter/management/commands/lintmigrations.py index 9f9eeb9..ef56d6a 100644 --- a/django_migration_linter/management/commands/lintmigrations.py +++ b/django_migration_linter/management/commands/lintmigrations.py @@ -110,7 +110,7 @@ class Command(BaseCommand): help="don't print linting messages to stdout", ) parser.add_argument( - "--warning-as-error", action="store_true", help="handle warnings as errors", + "--warnings-as-errors", action="store_true", help="handle warnings as errors", ) def handle(self, *args, **options): @@ -139,7 +139,7 @@ class Command(BaseCommand): only_unapplied_migrations=options["unapplied_migrations"], exclude_migration_tests=options["exclude_migration_tests"], quiet=options["quiet"], - warning_as_error=options["warning_as_error"], + warnings_as_errors=options["warnings_as_errors"], ) linter.lint_all_migrations( git_commit_id=options["commit_id"], diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 72ff1cf..132ed77 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -52,7 +52,7 @@ class MigrationLinter(object): only_unapplied_migrations=False, exclude_migration_tests=None, quiet=None, - warning_as_error=False, + warnings_as_errors=False, ): # Store parameters and options self.django_path = path @@ -67,7 +67,7 @@ class MigrationLinter(object): self.only_applied_migrations = only_applied_migrations self.only_unapplied_migrations = only_unapplied_migrations self.quiet = quiet or [] - self.warning_as_error = warning_as_error + self.warnings_as_errors = warnings_as_errors # Initialise counters self.nb_valid = 0 @@ -142,7 +142,7 @@ class MigrationLinter(object): if ignored_data: ignored += ignored_data - if self.warning_as_error: + if self.warnings_as_errors: errors += warnings warnings = [] diff --git a/docs/incompatibilities.md b/docs/incompatibilities.md index 256df07..5df319b 100644 --- a/docs/incompatibilities.md +++ b/docs/incompatibilities.md @@ -12,3 +12,10 @@ The linter analyses your migrations and checks the SQL for: Those are the most important and frequent backward incompatible migrations. We are happy to add more if you can specify them to us. + + +## Warnings + +On data migrations, the linter will show a warning when: +* you are missing a reverse migration +* the RunPython arguments do not respect the naming convention `apps, schema_editor` diff --git a/docs/usage.md b/docs/usage.md index bc32b7e..6dbf227 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -25,6 +25,7 @@ Detailed command line options: |`--project-root-path DJANGO_PROJECT_FOLDER` | An absolute or relative path to the django project. | |`--include-migrations-from FILE_PATH` | If specified, only migrations listed in the given file will be considered. | |`--quiet or -q {ok,ignore,warning,error}` | Suppress certain output messages, instead of writing them to stdout. | +|`--warnings-as-errors` | Handle warnings as errors and therefore return an error status code if we should. | ## Ignoring migration tests diff --git a/tests/functional/test_data_migrations.py b/tests/functional/test_data_migrations.py index 1cc1662..b9f1510 100644 --- a/tests/functional/test_data_migrations.py +++ b/tests/functional/test_data_migrations.py @@ -49,11 +49,11 @@ class DataMigrationDetectionTestCase(unittest.TestCase): self.assertEqual(1, self.linter.nb_valid) self.assertFalse(self.linter.has_errors) - def test_warning_as_error(self): + def test_warnings_as_errors(self): self.linter = MigrationLinter( self.test_project_path, include_apps=fixtures.DATA_MIGRATIONS, - warning_as_error=True, + warnings_as_errors=True, ) reverse_migration = self.linter.migration_loader.disk_migrations[