summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-04-26 21:50:45 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2023-05-02 20:01:39 +0200
commit918f4624d76197bec7cc54467f0281ff63c19c5a (patch)
tree1a7ca06809bff250669d6ca7faa04ab30acd0668
parent26686d544eab7236a92e56cc90c34b6e3a37f473 (diff)
downloadpylint-git-918f4624d76197bec7cc54467f0281ff63c19c5a.tar.gz
Merge the empty-string extensions to 'implicit_booleaness_checker'
-rw-r--r--doc/data/messages/c/compare-to-empty-string/bad.py8
-rw-r--r--doc/data/messages/c/compare-to-empty-string/good.py8
-rw-r--r--doc/data/messages/c/compare-to-empty-string/pylintrc2
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py6
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst3
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py6
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc2
-rw-r--r--doc/user_guide/checkers/extensions.rst15
-rw-r--r--doc/user_guide/checkers/features.rst4
-rw-r--r--doc/user_guide/configuration/all-options.rst2
-rw-r--r--doc/user_guide/messages/messages_overview.rst3
-rw-r--r--doc/whatsnew/fragments/6871.user_action10
-rw-r--r--examples/pylintrc4
-rw-r--r--examples/pyproject.toml4
-rw-r--r--pylint/checkers/refactoring/implicit_booleaness_checker.py58
-rw-r--r--pylint/extensions/emptystring.py78
-rw-r--r--script/.contributors_aliases.json4
-rw-r--r--tests/functional/ext/emptystring/empty_string_comparison.py22
-rw-r--r--tests/functional/ext/emptystring/empty_string_comparison.rc2
-rw-r--r--tests/functional/ext/emptystring/empty_string_comparison.txt6
-rw-r--r--tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.py22
-rw-r--r--tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.rc2
-rw-r--r--tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.txt6
23 files changed, 124 insertions, 153 deletions
diff --git a/doc/data/messages/c/compare-to-empty-string/bad.py b/doc/data/messages/c/compare-to-empty-string/bad.py
deleted file mode 100644
index 1ab940de7..000000000
--- a/doc/data/messages/c/compare-to-empty-string/bad.py
+++ /dev/null
@@ -1,8 +0,0 @@
-x = ""
-y = "hello"
-
-if x == "": # [compare-to-empty-string]
- print("x is an empty string")
-
-if y != "": # [compare-to-empty-string]
- print("y is not an empty string")
diff --git a/doc/data/messages/c/compare-to-empty-string/good.py b/doc/data/messages/c/compare-to-empty-string/good.py
deleted file mode 100644
index 6c4c67e36..000000000
--- a/doc/data/messages/c/compare-to-empty-string/good.py
+++ /dev/null
@@ -1,8 +0,0 @@
-x = ""
-y = "hello"
-
-if not x:
- print("x is an empty string")
-
-if y:
- print("y is not an empty string")
diff --git a/doc/data/messages/c/compare-to-empty-string/pylintrc b/doc/data/messages/c/compare-to-empty-string/pylintrc
deleted file mode 100644
index 13b9afd7e..000000000
--- a/doc/data/messages/c/compare-to-empty-string/pylintrc
+++ /dev/null
@@ -1,2 +0,0 @@
-[main]
-load-plugins=pylint.extensions.emptystring
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py
new file mode 100644
index 000000000..119fd8b43
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py
@@ -0,0 +1,6 @@
+def important_string_manipulation(x: str, y: str) -> None:
+ if x == "": # [use-implicit-booleaness-not-comparison-to-string]
+ print("x is an empty string")
+
+ if y != "": # [use-implicit-booleaness-not-comparison-to-string]
+ print("y is not an empty string")
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst
new file mode 100644
index 000000000..257fb92bc
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst
@@ -0,0 +1,3 @@
+Following this check blindly in weakly typed code base can create hard to debug issues. If the value
+can be something else that is falsey but not a string (for example ``None``, or ``0``), the code will
+not be equivalent.
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py
new file mode 100644
index 000000000..21f222e9b
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py
@@ -0,0 +1,6 @@
+def important_string_manipulation(x: str, y: str) -> None:
+ if not x:
+ print("x is an empty string")
+
+ if y:
+ print("y is not an empty string")
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc
new file mode 100644
index 000000000..aa53d9346
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc
@@ -0,0 +1,2 @@
+[main]
+enable=use-implicit-booleaness-not-comparison-to-string
diff --git a/doc/user_guide/checkers/extensions.rst b/doc/user_guide/checkers/extensions.rst
index f3823d715..79a797a7c 100644
--- a/doc/user_guide/checkers/extensions.rst
+++ b/doc/user_guide/checkers/extensions.rst
@@ -19,7 +19,6 @@ Pylint provides the following optional plugins:
- :ref:`pylint.extensions.docstyle`
- :ref:`pylint.extensions.dunder`
- :ref:`pylint.extensions.empty_comment`
-- :ref:`pylint.extensions.emptystring`
- :ref:`pylint.extensions.eq_without_hash`
- :ref:`pylint.extensions.for_any_all`
- :ref:`pylint.extensions.magic_value`
@@ -87,20 +86,6 @@ Code Style checker Messages
to. This can be changed to be an augmented assign. Disabled by default!
-.. _pylint.extensions.emptystring:
-
-Compare-To-Empty-String checker
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-This checker is provided by ``pylint.extensions.emptystring``.
-Verbatim name of the checker is ``compare-to-empty-string``.
-
-Compare-To-Empty-String checker Messages
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-:compare-to-empty-string (C1901): *"%s" can be simplified to "%s" as an empty string is falsey*
- Used when Pylint detects comparison to an empty string constant.
-
-
.. _pylint.extensions.comparison_placement:
Comparison-Placement checker
diff --git a/doc/user_guide/checkers/features.rst b/doc/user_guide/checkers/features.rst
index e30aff544..789d59b8b 100644
--- a/doc/user_guide/checkers/features.rst
+++ b/doc/user_guide/checkers/features.rst
@@ -893,8 +893,10 @@ Refactoring checker Messages
Emitted when a single "return" or "return None" statement is found at the end
of function or method definition. This statement can safely be removed
because Python will implicitly return None
-:use-implicit-booleaness-not-comparison-to-zero (C1804): *"%s" can be simplified to "%s" as 0 is falsey*
+:use-implicit-booleaness-not-comparison-to-zero (C1805): *"%s" can be simplified to "%s" as 0 is falsey*
Used when Pylint detects comparison to a 0 constant.
+:use-implicit-booleaness-not-comparison-to-string (C1804): *"%s" can be simplified to "%s" as an empty string is falsey*
+ Used when Pylint detects comparison to an empty string constant.
:use-implicit-booleaness-not-comparison (C1803): *'%s' can be simplified to '%s' as an empty %s is falsey*
Used when Pylint detects that collection literal comparison is being used to
check for emptiness; Use implicit booleaness instead of a collection classes;
diff --git a/doc/user_guide/configuration/all-options.rst b/doc/user_guide/configuration/all-options.rst
index 8ddafa104..8b68ab7dd 100644
--- a/doc/user_guide/configuration/all-options.rst
+++ b/doc/user_guide/configuration/all-options.rst
@@ -233,7 +233,7 @@ Standard Checkers
confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"]
- disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead", "consider-using-augmented-assign"]
+ disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-implicit-booleaness-not-comparison-to-string", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead", "consider-using-augmented-assign"]
enable = []
diff --git a/doc/user_guide/messages/messages_overview.rst b/doc/user_guide/messages/messages_overview.rst
index 50f77d35e..9515fecb4 100644
--- a/doc/user_guide/messages/messages_overview.rst
+++ b/doc/user_guide/messages/messages_overview.rst
@@ -390,7 +390,6 @@ All messages in the convention category:
convention/bad-file-encoding
convention/bad-mcs-classmethod-argument
convention/bad-mcs-method-argument
- convention/compare-to-empty-string
convention/consider-iterating-dictionary
convention/consider-using-any-or-all
convention/consider-using-dict-items
@@ -432,6 +431,7 @@ All messages in the convention category:
convention/unnecessary-lambda-assignment
convention/unneeded-not
convention/use-implicit-booleaness-not-comparison
+ convention/use-implicit-booleaness-not-comparison-to-string
convention/use-implicit-booleaness-not-comparison-to-zero
convention/use-implicit-booleaness-not-len
convention/use-maxsplit-arg
@@ -449,6 +449,7 @@ All renamed messages in the convention category:
:titlesonly:
convention/blacklisted-name
+ convention/compare-to-empty-string
convention/compare-to-zero
convention/len-as-condition
convention/missing-docstring
diff --git a/doc/whatsnew/fragments/6871.user_action b/doc/whatsnew/fragments/6871.user_action
index 9aceab4c1..e20983171 100644
--- a/doc/whatsnew/fragments/6871.user_action
+++ b/doc/whatsnew/fragments/6871.user_action
@@ -1,12 +1,14 @@
-* The compare to empty string checker (``pylint.extensions.emptystring``) has been removed and its checks are
+* The compare to empty string checker (``pylint.extensions.emptystring``) and the compare to
+ zero checker (``pylint.extensions.compare-to-zero``) have been removed and their checks are
now part of the implicit booleaness checker:
- ``compare-to-zero`` was renamed ``use-implicit-booleaness-not-comparison-to-zero``
- and it now need to be enabled explicitly.
- - The ``pylint.extensions.compare-to-zero`` extension no longer exists and
+ and ``compare-to-empty-string`` was renamed ``use-implicit-booleaness-not-comparison-to-string``
+ and they now need to be enabled explicitly.
+ - The `pylint.extensions.emptystring`` and ``pylint.extensions.compare-to-zero`` extensions no longer exists and
needs to be removed from the ``load-plugins`` option.
-This permits to make the likeness explicit and will provide better performance as they share most of their
+This permits to make their likeness explicit and will provide better performance as they share most of their
conditions to be raised.
Refs #6871
diff --git a/examples/pylintrc b/examples/pylintrc
index 16284083e..d496b6b90 100644
--- a/examples/pylintrc
+++ b/examples/pylintrc
@@ -428,13 +428,15 @@ disable=raw-checker-failed,
suppressed-message,
useless-suppression,
deprecated-pragma,
+ use-implicit-booleaness-not-comparison-to-string,
+ use-implicit-booleaness-not-comparison-to-zero,
use-symbolic-message-instead
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
-enable=c-extension-no-member
+enable=
[METHOD_ARGS]
diff --git a/examples/pyproject.toml b/examples/pyproject.toml
index f9a493c89..6aba10140 100644
--- a/examples/pyproject.toml
+++ b/examples/pyproject.toml
@@ -365,13 +365,13 @@ confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFIN
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
-disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-symbolic-message-instead"]
+disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-implicit-booleaness-not-comparison-to-string", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead"]
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where it
# should appear only once). See also the "--disable" option for examples.
-enable = ["c-extension-no-member"]
+# enable =
[tool.pylint.method_args]
# List of qualified names (i.e., library.method) which require a timeout
diff --git a/pylint/checkers/refactoring/implicit_booleaness_checker.py b/pylint/checkers/refactoring/implicit_booleaness_checker.py
index ff1a36205..93ac44269 100644
--- a/pylint/checkers/refactoring/implicit_booleaness_checker.py
+++ b/pylint/checkers/refactoring/implicit_booleaness_checker.py
@@ -81,6 +81,15 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
"of a collection classes; empty collections are considered as false",
),
"C1804": (
+ '"%s" can be simplified to "%s" as an empty string is falsey',
+ "use-implicit-booleaness-not-comparison-to-string",
+ "Used when Pylint detects comparison to an empty string constant.",
+ {
+ "default_enabled": False,
+ "old_names": [("C1901", "compare-to-empty-string")],
+ },
+ ),
+ "C1805": (
'"%s" can be simplified to "%s" as 0 is falsey',
"use-implicit-booleaness-not-comparison-to-zero",
"Used when Pylint detects comparison to a 0 constant.",
@@ -162,12 +171,16 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
"use-implicit-booleaness-not-len", node=node, confidence=HIGH
)
- @utils.only_required_for_messages("use-implicit-booleaness-not-comparison")
+ @utils.only_required_for_messages(
+ "use-implicit-booleaness-not-comparison",
+ "use-implicit-booleaness-not-comparison-to-string",
+ "use-implicit-booleaness-not-comparison-to-zero",
+ )
def visit_compare(self, node: nodes.Compare) -> None:
self._check_use_implicit_booleaness_not_comparison(node)
self._check_compare_to_zero(node)
+ self._check_compare_to_string(node)
- @utils.only_required_for_messages("compare-to-zero")
def _check_compare_to_zero(self, node: nodes.Compare) -> None:
# pylint: disable=duplicate-code
_operators = ["!=", "==", "is not", "is"]
@@ -209,6 +222,47 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
confidence=HIGH,
)
+ def _check_compare_to_string(self, node: nodes.Compare) -> None:
+ """Checks for comparisons to empty string.
+
+ Most of the time you should use the fact that empty strings are false.
+ An exception to this rule is when an empty string value is allowed in the program
+ and has a different meaning than None!
+ """
+ _operators = {"!=", "==", "is not", "is"}
+ # note: astroid.Compare has the left most operand in node.left while the rest
+ # are a list of tuples in node.ops the format of the tuple is
+ # ('compare operator sign', node) here we squash everything into `ops`
+ # to make it easier for processing later
+ ops: list[tuple[str, nodes.NodeNG | None]] = [("", node.left)]
+ ops.extend(node.ops)
+ iter_ops = iter(ops)
+ ops = list(itertools.chain(*iter_ops)) # type: ignore[arg-type]
+ for ops_idx in range(len(ops) - 2):
+ op_1: nodes.NodeNG | None = ops[ops_idx]
+ op_2: str = ops[ops_idx + 1] # type: ignore[assignment]
+ op_3: nodes.NodeNG | None = ops[ops_idx + 2]
+ error_detected = False
+ if op_1 is None or op_3 is None or op_2 not in _operators:
+ continue
+ node_name = ""
+ # x ?? ""
+ if utils.is_empty_str_literal(op_1):
+ error_detected = True
+ node_name = op_3.as_string()
+ # '' ?? X
+ elif utils.is_empty_str_literal(op_3):
+ error_detected = True
+ node_name = op_1.as_string()
+ if error_detected:
+ suggestion = f"not {node_name}" if op_2 in {"==", "is"} else node_name
+ self.add_message(
+ "compare-to-empty-string",
+ args=(node.as_string(), suggestion),
+ node=node,
+ confidence=HIGH,
+ )
+
def _check_use_implicit_booleaness_not_comparison(
self, node: nodes.Compare
) -> None:
diff --git a/pylint/extensions/emptystring.py b/pylint/extensions/emptystring.py
deleted file mode 100644
index 7053187b8..000000000
--- a/pylint/extensions/emptystring.py
+++ /dev/null
@@ -1,78 +0,0 @@
-# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
-# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
-
-"""Looks for comparisons to empty string."""
-
-from __future__ import annotations
-
-import itertools
-from typing import TYPE_CHECKING
-
-from astroid import nodes
-
-from pylint import checkers
-from pylint.checkers import utils
-from pylint.interfaces import HIGH
-
-if TYPE_CHECKING:
- from pylint.lint import PyLinter
-
-
-class CompareToEmptyStringChecker(checkers.BaseChecker):
- name = "compare-to-empty-string"
- msgs = {
- "C1901": (
- '"%s" can be simplified to "%s" as an empty string is falsey',
- "compare-to-empty-string",
- "Used when Pylint detects comparison to an empty string constant.",
- )
- }
-
- options = ()
-
- @utils.only_required_for_messages("compare-to-empty-string")
- def visit_compare(self, node: nodes.Compare) -> None:
- """Checks for comparisons to empty string.
-
- Most of the time you should use the fact that empty strings are false.
- An exception to this rule is when an empty string value is allowed in the program
- and has a different meaning than None!
- """
- _operators = {"!=", "==", "is not", "is"}
- # note: astroid.Compare has the left most operand in node.left while the rest
- # are a list of tuples in node.ops the format of the tuple is
- # ('compare operator sign', node) here we squash everything into `ops`
- # to make it easier for processing later
- ops: list[tuple[str, nodes.NodeNG | None]] = [("", node.left)]
- ops.extend(node.ops)
- iter_ops = iter(ops)
- ops = list(itertools.chain(*iter_ops)) # type: ignore[arg-type]
- for ops_idx in range(len(ops) - 2):
- op_1: nodes.NodeNG | None = ops[ops_idx]
- op_2: str = ops[ops_idx + 1] # type: ignore[assignment]
- op_3: nodes.NodeNG | None = ops[ops_idx + 2]
- error_detected = False
- if op_1 is None or op_3 is None or op_2 not in _operators:
- continue
- node_name = ""
- # x ?? ""
- if utils.is_empty_str_literal(op_1):
- error_detected = True
- node_name = op_3.as_string()
- # '' ?? X
- elif utils.is_empty_str_literal(op_3):
- error_detected = True
- node_name = op_1.as_string()
- if error_detected:
- suggestion = f"not {node_name}" if op_2 in {"==", "is"} else node_name
- self.add_message(
- "compare-to-empty-string",
- args=(node.as_string(), suggestion),
- node=node,
- confidence=HIGH,
- )
-
-
-def register(linter: PyLinter) -> None:
- linter.register_checker(CompareToEmptyStringChecker(linter))
diff --git a/script/.contributors_aliases.json b/script/.contributors_aliases.json
index 7a3c4e04b..f77b993a7 100644
--- a/script/.contributors_aliases.json
+++ b/script/.contributors_aliases.json
@@ -634,6 +634,10 @@
"mails": ["lothiraldan@gmail.com"],
"name": "Boris Feld"
},
+ "lucas.cimon@gmail.com": {
+ "mails": ["lucas.cimon@gmail.com", "925560+Lucas-C@users.noreply.github.com"],
+ "name": "Lucas Cimon"
+ },
"lucristofolini@gmail.com": {
"comment": " (luigibertaco)",
"mails": ["luigi.cristofolini@q-ctrl.com", "lucristofolini@gmail.com"],
diff --git a/tests/functional/ext/emptystring/empty_string_comparison.py b/tests/functional/ext/emptystring/empty_string_comparison.py
deleted file mode 100644
index b61caeff6..000000000
--- a/tests/functional/ext/emptystring/empty_string_comparison.py
+++ /dev/null
@@ -1,22 +0,0 @@
-# pylint: disable=literal-comparison,missing-docstring
-
-X = ''
-Y = 'test'
-
-if X is '': # [compare-to-empty-string]
- pass
-
-if Y is not "": # [compare-to-empty-string]
- pass
-
-if X == "": # [compare-to-empty-string]
- pass
-
-if Y != '': # [compare-to-empty-string]
- pass
-
-if "" == Y: # [compare-to-empty-string]
- pass
-
-if '' != X: # [compare-to-empty-string]
- pass
diff --git a/tests/functional/ext/emptystring/empty_string_comparison.rc b/tests/functional/ext/emptystring/empty_string_comparison.rc
deleted file mode 100644
index d2826befa..000000000
--- a/tests/functional/ext/emptystring/empty_string_comparison.rc
+++ /dev/null
@@ -1,2 +0,0 @@
-[MAIN]
-load-plugins=pylint.extensions.emptystring,
diff --git a/tests/functional/ext/emptystring/empty_string_comparison.txt b/tests/functional/ext/emptystring/empty_string_comparison.txt
deleted file mode 100644
index be9c91bc5..000000000
--- a/tests/functional/ext/emptystring/empty_string_comparison.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-compare-to-empty-string:6:3:6:10::"""X is ''"" can be simplified to ""not X"" as an empty string is falsey":HIGH
-compare-to-empty-string:9:3:9:14::"""Y is not ''"" can be simplified to ""Y"" as an empty string is falsey":HIGH
-compare-to-empty-string:12:3:12:10::"""X == ''"" can be simplified to ""not X"" as an empty string is falsey":HIGH
-compare-to-empty-string:15:3:15:10::"""Y != ''"" can be simplified to ""Y"" as an empty string is falsey":HIGH
-compare-to-empty-string:18:3:18:10::"""'' == Y"" can be simplified to ""not Y"" as an empty string is falsey":HIGH
-compare-to-empty-string:21:3:21:10::"""'' != X"" can be simplified to ""X"" as an empty string is falsey":HIGH
diff --git a/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.py b/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.py
new file mode 100644
index 000000000..4fbf0fc1d
--- /dev/null
+++ b/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.py
@@ -0,0 +1,22 @@
+# pylint: disable=literal-comparison,missing-docstring
+
+X = ''
+Y = 'test'
+
+if X is '': # [use-implicit-booleaness-not-comparison-to-string]
+ pass
+
+if Y is not "": # [use-implicit-booleaness-not-comparison-to-string]
+ pass
+
+if X == "": # [use-implicit-booleaness-not-comparison-to-string]
+ pass
+
+if Y != '': # [use-implicit-booleaness-not-comparison-to-string]
+ pass
+
+if "" == Y: # [use-implicit-booleaness-not-comparison-to-string]
+ pass
+
+if '' != X: # [use-implicit-booleaness-not-comparison-to-string]
+ pass
diff --git a/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.rc b/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.rc
new file mode 100644
index 000000000..14648884d
--- /dev/null
+++ b/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.rc
@@ -0,0 +1,2 @@
+[MAIN]
+enable=use-implicit-booleaness-not-comparison-to-string
diff --git a/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.txt b/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.txt
new file mode 100644
index 000000000..c1f31f27f
--- /dev/null
+++ b/tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.txt
@@ -0,0 +1,6 @@
+use-implicit-booleaness-not-comparison-to-string:6:3:6:10::"""X is ''"" can be simplified to ""not X"" as an empty string is falsey":HIGH
+use-implicit-booleaness-not-comparison-to-string:9:3:9:14::"""Y is not ''"" can be simplified to ""Y"" as an empty string is falsey":HIGH
+use-implicit-booleaness-not-comparison-to-string:12:3:12:10::"""X == ''"" can be simplified to ""not X"" as an empty string is falsey":HIGH
+use-implicit-booleaness-not-comparison-to-string:15:3:15:10::"""Y != ''"" can be simplified to ""Y"" as an empty string is falsey":HIGH
+use-implicit-booleaness-not-comparison-to-string:18:3:18:10::"""'' == Y"" can be simplified to ""not Y"" as an empty string is falsey":HIGH
+use-implicit-booleaness-not-comparison-to-string:21:3:21:10::"""'' != X"" can be simplified to ""X"" as an empty string is falsey":HIGH