linter: Add check that Optional models are tagged with null=True.

Exclude NullBooleanField explicitly.

Amend one line in models.py found from this linter change.
This commit is contained in:
neiljp (Neil Pilgrim)
2018-03-25 22:00:44 +00:00
committed by Tim Abbott
parent 7d93f5726c
commit 07971d3a66
2 changed files with 12 additions and 1 deletions

View File

@@ -494,6 +494,17 @@ def build_custom_checkers(by_lang):
'bad_lines': ['desc = models.CharField(null=True) # type: Text',
'stream = models.ForeignKey(Stream, null=True, on_delete=CASCADE) # type: Stream'],
},
{'pattern': ' = models[.](?!NullBoolean).*\) # type: Optional', # Optional tag, except NullBoolean(Field)
'exclude_pattern': 'null=True',
'include_only': {"zerver/models.py"},
'description': 'Model variable annotated with Optional but variable does not have null=true.',
'good_lines': ['desc = models.TextField(null=True) # type: Optional[Text]',
'stream = models.ForeignKey(Stream, null=True, on_delete=CASCADE) # type: Optional[Stream]',
'desc = models.TextField() # type: Text',
'stream = models.ForeignKey(Stream, on_delete=CASCADE) # type: Stream'],
'bad_lines': ['desc = models.TextField() # type: Optional[Text]',
'stream = models.ForeignKey(Stream, on_delete=CASCADE) # type: Optional[Stream]'],
},
]) + whitespace_rules + comma_whitespace_rule
bash_rules = cast(RuleList, [
{'pattern': '#!.*sh [-xe]',