summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
authorJaehoon Hwang <jaehoonhwang@users.noreply.github.com>2021-10-09 23:18:46 -0700
committerGitHub <noreply@github.com>2021-10-10 08:18:46 +0200
commit220e27dc5bdd6bdd9dbee56d5c7d33a946c8ad17 (patch)
treec3f34d216acce183b92b7007f4a38811169d4c66 /tests/functional
parent661703f3c9f030420d6559433b621abdc27ac7b5 (diff)
downloadpylint-git-220e27dc5bdd6bdd9dbee56d5c7d33a946c8ad17.tar.gz
Rename `len-as-condition` to `use-implicit-booleaness-not-len` (#5132)
Rename `len-as-condition` to be more general for new checker `use-implicit-booleaness-not-comparison` * Refactor `LenChecker` class -> `ImplicitBooleanessChecker`o * Rename test files/`len_checker.py`/`__init__.py` to reflect new name. * Add `len-as-condition` as `old_names` for `use-implicit-booleaness-not-len` Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/l/len_checks.txt25
-rw-r--r--tests/functional/u/use/use_implicit_booleaness_not_len.py (renamed from tests/functional/l/len_checks.py)54
-rw-r--r--tests/functional/u/use/use_implicit_booleaness_not_len.txt25
3 files changed, 54 insertions, 50 deletions
diff --git a/tests/functional/l/len_checks.txt b/tests/functional/l/len_checks.txt
deleted file mode 100644
index f1b96e477..000000000
--- a/tests/functional/l/len_checks.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-len-as-condition:4:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:7:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:11:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:14:11::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:55:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:60:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:63:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:66:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:69:12::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:72:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:95:11:github_issue_1331_v2:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:98:11:github_issue_1331_v3:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:101:17:github_issue_1331_v4:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:103:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:104:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:124:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:125:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:126:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:127:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:128:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:129:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:130:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-len-as-condition:171:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
-undefined-variable:183:11:github_issue_4215:Undefined variable 'undefined_var'
-undefined-variable:185:11:github_issue_4215:Undefined variable 'undefined_var2'
diff --git a/tests/functional/l/len_checks.py b/tests/functional/u/use/use_implicit_booleaness_not_len.py
index ceeedb549..b4107ac2d 100644
--- a/tests/functional/l/len_checks.py
+++ b/tests/functional/u/use/use_implicit_booleaness_not_len.py
@@ -1,17 +1,17 @@
# pylint: disable=too-few-public-methods,import-error, missing-docstring, misplaced-comparison-constant
# pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order, condition-evals-to-constant
-if len('TEST'): # [len-as-condition]
+if len('TEST'): # [use-implicit-booleaness-not-len]
pass
-if not len('TEST'): # [len-as-condition]
+if not len('TEST'): # [use-implicit-booleaness-not-len]
pass
z = []
-if z and len(['T', 'E', 'S', 'T']): # [len-as-condition]
+if z and len(['T', 'E', 'S', 'T']): # [use-implicit-booleaness-not-len]
pass
-if True or len('TEST'): # [len-as-condition]
+if True or len('TEST'): # [use-implicit-booleaness-not-len]
pass
if len('TEST') == 0: # Should be fine
@@ -52,24 +52,24 @@ if z or 10 > len('TEST') != 0: # Should be fine
if z:
pass
-elif len('TEST'): # [len-as-condition]
+elif len('TEST'): # [use-implicit-booleaness-not-len]
pass
if z:
pass
-elif not len('TEST'): # [len-as-condition]
+elif not len('TEST'): # [use-implicit-booleaness-not-len]
pass
-while len('TEST'): # [len-as-condition]
+while len('TEST'): # [use-implicit-booleaness-not-len]
pass
-while not len('TEST'): # [len-as-condition]
+while not len('TEST'): # [use-implicit-booleaness-not-len]
pass
-while z and len('TEST'): # [len-as-condition]
+while z and len('TEST'): # [use-implicit-booleaness-not-len]
pass
-while not len('TEST') and z: # [len-as-condition]
+while not len('TEST') and z: # [use-implicit-booleaness-not-len]
pass
assert len('TEST') > 0 # Should be fine
@@ -92,17 +92,16 @@ def github_issue_1331(*args):
assert False, len(args) # Should be fine
def github_issue_1331_v2(*args):
- assert len(args), args # [len-as-condition]
+ assert len(args), args # [use-implicit-booleaness-not-len]
def github_issue_1331_v3(*args):
- assert len(args) or z, args # [len-as-condition]
+ assert len(args) or z, args # [use-implicit-booleaness-not-len]
def github_issue_1331_v4(*args):
- assert z and len(args), args # [len-as-condition]
-
-b = bool(len(z)) # [len-as-condition]
-c = bool(len('TEST') or 42) # [len-as-condition]
+ assert z and len(args), args # [use-implicit-booleaness-not-len]
+b = bool(len(z)) # [use-implicit-booleaness-not-len]
+c = bool(len('TEST') or 42) # [use-implicit-booleaness-not-len]
def github_issue_1879():
@@ -121,13 +120,13 @@ def github_issue_1879():
assert len(ClassWithBool())
assert len(ChildClassWithBool())
- assert len(ClassWithoutBool()) # [len-as-condition]
- assert len(ChildClassWithoutBool()) # [len-as-condition]
- assert len(range(0)) # [len-as-condition]
- assert len([t + 1 for t in []]) # [len-as-condition]
- assert len(u + 1 for u in []) # [len-as-condition]
- assert len({"1":(v + 1) for v in {}}) # [len-as-condition]
- assert len(set((w + 1) for w in set())) # [len-as-condition]
+ assert len(ClassWithoutBool()) # [use-implicit-booleaness-not-len]
+ assert len(ChildClassWithoutBool()) # [use-implicit-booleaness-not-len]
+ assert len(range(0)) # [use-implicit-booleaness-not-len]
+ assert len([t + 1 for t in []]) # [use-implicit-booleaness-not-len]
+ assert len(u + 1 for u in []) # [use-implicit-booleaness-not-len]
+ assert len({"1":(v + 1) for v in {}}) # [use-implicit-booleaness-not-len]
+ assert len(set((w + 1) for w in set())) # [use-implicit-booleaness-not-len]
# pylint: disable=import-outside-toplevel
import numpy
@@ -168,9 +167,9 @@ def github_issue_1879():
# def function_returning_function(r):
# return function_returning_generator(r)
- assert len(function_returning_list(z)) # [len-as-condition]
+ assert len(function_returning_list(z)) # [use-implicit-booleaness-not-len]
assert len(function_returning_int(z))
- # This should raise a len-as-conditions once astroid can infer it
+ # This should raise a use-implicit-booleaness-not-len once astroid can infer it
# See https://github.com/PyCQA/pylint/pull/3821#issuecomment-743771514
# assert len(function_returning_generator(z))
# assert len(function_returning_comprehension(z))
@@ -184,3 +183,8 @@ def github_issue_4215():
pass
if len(undefined_var2[0]): # [undefined-variable]
pass
+
+# pylint: disable=len-as-condition
+
+if len('TEST'):
+ pass
diff --git a/tests/functional/u/use/use_implicit_booleaness_not_len.txt b/tests/functional/u/use/use_implicit_booleaness_not_len.txt
new file mode 100644
index 000000000..f5020c80e
--- /dev/null
+++ b/tests/functional/u/use/use_implicit_booleaness_not_len.txt
@@ -0,0 +1,25 @@
+use-implicit-booleaness-not-len:4:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:7:3::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:11:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:14:11::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:55:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:60:5::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:63:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:66:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:69:12::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:72:6::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:95:11:github_issue_1331_v2:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:98:11:github_issue_1331_v3:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:101:17:github_issue_1331_v4:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:103:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:104:9::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:123:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:124:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:125:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:126:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:127:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:128:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:129:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+use-implicit-booleaness-not-len:170:11:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty:HIGH
+undefined-variable:182:11:github_issue_4215:Undefined variable 'undefined_var':HIGH
+undefined-variable:184:11:github_issue_4215:Undefined variable 'undefined_var2':HIGH