Repository: wemake-services/wemake-python-styleguide

Issue:
Constant condition in comprehension is not reported
Reproduction:

```python
comp = [num for num in range(5) if True]
```

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=h1) Report
> Merging [#1868](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=desc) (7657d19) into [master](https://codecov.io/gh/wemake-services/wemake-python-styleguide/commit/56132c8bba5e752b2d9c41a6fd6a2b28f347bc0c?el=desc) (56132c8) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/graphs/tree.svg?width=650&height=150&src=pr&token=yMZCKw0D02)](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master     #1868   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          115       115           
  Lines         6103      6082   -21     
  Branches      1362      1356    -6     
=========================================
- Hits          6103      6082   -21     
```


| [Impacted Files](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [wemake\_python\_styleguide/visitors/ast/compares.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL3Zpc2l0b3JzL2FzdC9jb21wYXJlcy5weQ==) | `100.00% <100.00%> (ø)` | |
| [wemake\_python\_styleguide/compat/nodes.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL2NvbXBhdC9ub2Rlcy5weQ==) | `100.00% <0.00%> (ø)` | |
| [wemake\_python\_styleguide/logic/walrus.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL2xvZ2ljL3dhbHJ1cy5weQ==) | `100.00% <0.00%> (ø)` | |
| [wemake\_python\_styleguide/compat/routing.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL2NvbXBhdC9yb3V0aW5nLnB5) | `100.00% <0.00%> (ø)` | |
| [wemake\_python\_styleguide/logic/safe\_eval.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL2xvZ2ljL3NhZmVfZXZhbC5weQ==) | `100.00% <0.00%> (ø)` | |
| [wemake\_python\_styleguide/compat/packaging.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL2NvbXBhdC9wYWNrYWdpbmcucHk=) | `100.00% <0.00%> (ø)` | |
| [wemake\_python\_styleguide/visitors/ast/functions.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL3Zpc2l0b3JzL2FzdC9mdW5jdGlvbnMucHk=) | `100.00% <0.00%> (ø)` | |
| [wemake\_python\_styleguide/visitors/ast/operators.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL3Zpc2l0b3JzL2FzdC9vcGVyYXRvcnMucHk=) | `100.00% <0.00%> (ø)` | |
| [...emake\_python\_styleguide/visitors/ast/decorators.py](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868/diff?src=pr&el=tree#diff-d2VtYWtlX3B5dGhvbl9zdHlsZWd1aWRlL3Zpc2l0b3JzL2FzdC9kZWNvcmF0b3JzLnB5) | `100.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=footer). Last update [56132c8...7657d19](https://codecov.io/gh/wemake-services/wemake-python-styleguide/pull/1868?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e5e7ae6d..aaeae191 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,8 @@ Semantic versioning in our case means:
 - Fixes `InconsistentComprehensionViolation` work with `async` comprehensions
 - Fixes nested compehensions support for `InconsistentComprehensionViolation`
 - Fixes multiple `if` support for `InconsistentComprehensionViolation`
+- Fixes that `NestedTernaryViolation` was not reported for a comprehension
+- Fixes that `ConstantConditionViolation` was not reported for a comprehension
 
 ### Misc
 
diff --git a/wemake_python_styleguide/visitors/ast/compares.py b/wemake_python_styleguide/visitors/ast/compares.py
index c114ce3b..379387a9 100644
--- a/wemake_python_styleguide/visitors/ast/compares.py
+++ b/wemake_python_styleguide/visitors/ast/compares.py
@@ -304,6 +304,7 @@ class WrongConditionalVisitor(BaseNodeVisitor):
         ast.BinOp,
         ast.UnaryOp,
         ast.Compare,
+        ast.comprehension,
     )
 
     def visit_any_if(self, node: AnyIf) -> None:
@@ -322,14 +323,17 @@ class WrongConditionalVisitor(BaseNodeVisitor):
             self._check_simplifiable_ifexpr(node)
 
         self._check_nested_ifexpr(node)
-        self._check_constant_condition(node)
+        self._check_constant_condition(node.test)
         self.generic_visit(node)
 
-    def _check_constant_condition(self, node: AnyIf) -> None:
-        real_node = operators.unwrap_unary_node(
-            get_assigned_expr(node.test),
-        )
+    def visit_comprehension(self, node: ast.comprehension) -> None:
+        """Checks all possible comprehensions."""
+        for expr in node.ifs:
+            self._check_constant_condition(expr)
+        self.generic_visit(node)
 
+    def _check_constant_condition(self, node: ast.AST) -> None:
+        real_node = operators.unwrap_unary_node(get_assigned_expr(node))
         if isinstance(real_node, self._forbidden_nodes):
             self.add_violation(ConstantConditionViolation(node))
 


Test patch:
diff --git a/tests/test_visitors/test_ast/test_compares/test_conditionals.py b/tests/test_visitors/test_ast/test_compares/test_conditionals.py
index a09c19a8..ea3987b5 100644
--- a/tests/test_visitors/test_ast/test_compares/test_conditionals.py
+++ b/tests/test_visitors/test_ast/test_compares/test_conditionals.py
@@ -16,16 +16,42 @@ variable = 1
 if_statement = 'if {0}: ...'
 ternary = 'ternary = 0 if {0} else 1'
 
-if_statement_in_comprehension = """
+list_comprehension = """
 def container():
     [x for x in [1, 2, 3] if {0}]
 """
 
+set_comprehension = """
+def container():
+    {{
+        x
+        for x in [1, 2, 3]
+        if {0}
+    }}
+"""
+
+dict_comprehension = """
+def container():
+    {{
+        x: '1'
+        for x in [1, 2, 3]
+        if {0}
+    }}
+"""
+
+gen_comprehension = """
+def container():
+    (x for x in [1, 2, 3] if {0})
+"""
+
 
 @pytest.mark.parametrize('code', [
     if_statement,
     ternary,
-    if_statement_in_comprehension,
+    list_comprehension,
+    set_comprehension,
+    dict_comprehension,
+    gen_comprehension,
 ])
 @pytest.mark.parametrize('comparators', [
     'variable < 3',
@@ -62,6 +88,10 @@ def test_valid_conditional(
 @pytest.mark.parametrize('code', [
     if_statement,
     ternary,
+    # list_comprehension,
+    # set_comprehension,
+    # dict_comprehension,
+    # gen_comprehension,
 ])
 @pytest.mark.parametrize('comparators', [
     'True',
@@ -81,16 +111,23 @@ def test_valid_conditional(
         '(unique := True)',
         marks=pytest.mark.skipif(not PY38, reason='walrus appeared in 3.8'),
     ),
+    pytest.param(
+        '(unique := -1)',
+        marks=pytest.mark.skipif(not PY38, reason='walrus appeared in 3.8'),
+    ),
 ])
-def test_useless(
+def test_constant_condition(
     assert_errors,
     parse_ast_tree,
     code,
     comparators,
     default_options,
+    mode,
 ):
     """Testing that violations are when using invalid conditional."""
-    tree = parse_ast_tree(create_variable.format(code.format(comparators)))
+    tree = parse_ast_tree(
+        mode(create_variable.format(code.format(comparators))),
+    )
 
     visitor = WrongConditionalVisitor(default_options, tree=tree)
     visitor.run()
diff --git a/tests/test_visitors/test_ast/test_compares/test_nested_ternary.py b/tests/test_visitors/test_ast/test_compares/test_nested_ternary.py
index 1e3d8277..2bc9c7ec 100644
--- a/tests/test_visitors/test_ast/test_compares/test_nested_ternary.py
+++ b/tests/test_visitors/test_ast/test_compares/test_nested_ternary.py
@@ -47,6 +47,11 @@ wrong_if2 = 'if call(a if b else c): ...'
 wrong_if3 = 'if attr.call(a if b else c): ...'
 wrong_if4 = 'if x := 1 if True else 2: ...'
 
+wrong_comprehension1 = '[x for x in number if (some if x else other)]'
+wrong_comprehension2 = '(x for x in number if (some if x else other))'
+wrong_comprehension3 = '{{x for x in number if (some if x else other)}}'
+wrong_comprehension4 = '{{x: 1 for x in number if (some if x else other)}}'
+
 # Correct:
 
 correct_if1 = """
@@ -157,6 +162,11 @@ def test_non_nested_ternary(
         wrong_if3,
         marks=pytest.mark.skipif(not PY38, reason='walrus appeared in 3.8'),
     ),
+
+    wrong_comprehension1,
+    wrong_comprehension2,
+    wrong_comprehension3,
+    wrong_comprehension4,
 ])
 def test_nested_ternary(
     assert_errors,
diff --git a/tests/test_visitors/test_tokenize/test_statements/test_inconsistent_comprehension.py b/tests/test_visitors/test_tokenize/test_statements/test_inconsistent_comprehension.py
index 9b914973..b2087cdd 100644
--- a/tests/test_visitors/test_tokenize/test_statements/test_inconsistent_comprehension.py
+++ b/tests/test_visitors/test_tokenize/test_statements/test_inconsistent_comprehension.py
@@ -389,6 +389,17 @@ def wrapper():
     ]
 """
 
+wrong_list_split_multiple_ifs3 = """
+def wrapper():
+    [
+        some(number)
+        for number in matrix
+        if some
+        for other in iterable
+        if number > 0
+    ]
+"""
+
 wrong_list_two_compehensions1 = """
 def wrapper():
     comp = [
@@ -506,6 +517,7 @@ def wrapper():
     wrong_list_split_for_in,
     wrong_list_split_multiple_ifs1,
     wrong_list_split_multiple_ifs2,
+    wrong_list_split_multiple_ifs3,
     wrong_list_two_compehensions1,
     wrong_list_two_compehensions2,
     wrong_dict_almost_one_line,