Skip to content

Update plugin code for flake8 v5 compatibility #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ To install with ``conda``:
flake8 codes
--------------

============== ====================================
Code Description
============== ====================================
STRFTIME001 Linux-specific strftime code used
STRFTIME002 Windows-specific strftime code used
========= ====================================
Code Description
========= ====================================
SFT001 Linux-specific strftime code used
SFT002 Windows-specific strftime code used
============== ====================================


Expand Down
4 changes: 2 additions & 2 deletions doc-source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Flake8 codes

.. flake8-codes:: flake8_strftime

STRFTIME001
STRFTIME002
SFT001
SFT002



Expand Down
10 changes: 5 additions & 5 deletions flake8_strftime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
# 3rd party
import flake8_helper

__all__ = ("Visitor", "Plugin", "STRFTIME001", "STRFTIME002")
__all__ = ("Visitor", "Plugin", "SFT001", "SFT002")

__author__ = "Dominic Davis-Foster"
__copyright__ = "2020-2021 Dominic Davis-Foster"
__license__ = "MIT"
__version__ = "0.3.1"
__email__ = "dominic@davis-foster.co.uk"

STRFTIME001 = "STRFTIME001 Linux-specific strftime code used."
STRFTIME002 = "STRFTIME002 Windows-specific strftime code used."
SFT001 = "SFT001 Linux-specific strftime code used."
SFT002 = "SFT002 Windows-specific strftime code used."


class Visitor(flake8_helper.Visitor):
Expand Down Expand Up @@ -102,7 +102,7 @@ def _check_linux(self, node: Union[ast.Str, ast.Constant]) -> None:
self.errors.append((
node.lineno,
node.col_offset + match.span()[0],
STRFTIME001, # pylint: disable=loop-global-usage
SFT001, # pylint: disable=loop-global-usage
))

def _check_windows(self, node: Union[ast.Str, ast.Constant]) -> None:
Expand All @@ -116,7 +116,7 @@ def _check_windows(self, node: Union[ast.Str, ast.Constant]) -> None:
self.errors.append((
node.lineno,
node.col_offset + match.span()[0],
STRFTIME002, # pylint: disable=loop-global-usage
SFT002, # pylint: disable=loop-global-usage
))


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ show_error_codes = true
directives = [ "code-block",]

[project.entry-points."flake8.extension"]
STRFTIME = "flake8_strftime:Plugin"
SFT = "flake8_strftime:Plugin"

[tool.dependency-dash."requirements.txt"]
order = 10
Expand Down
2 changes: 1 addition & 1 deletion repo_helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extra_sphinx_extensions:

entry_points:
flake8.extension:
- STRFTIME=flake8_strftime:Plugin
- SFT=flake8_strftime:Plugin

sphinx_conf_epilogue:
- nitpicky = True
Expand Down
24 changes: 12 additions & 12 deletions tests/flake8_strftime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ def results(s: str) -> Set[str]:


def test_linux_specific():
assert results('print(f"{now:%Y/%-m/%-d %H:%M}")') == { # noqa: STRFTIME001
"1:9: STRFTIME001 Linux-specific strftime code used.",
"1:13: STRFTIME001 Linux-specific strftime code used.",
assert results('print(f"{now:%Y/%-m/%-d %H:%M}")') == { # noqa: SFT001
"1:9: SFT001 Linux-specific strftime code used.",
"1:13: SFT001 Linux-specific strftime code used.",
}

assert results('print(now.strftime("%Y/%-m/%-d %H:%M"))') == { # noqa: STRFTIME001
"1:22: STRFTIME001 Linux-specific strftime code used.",
"1:26: STRFTIME001 Linux-specific strftime code used.",
assert results('print(now.strftime("%Y/%-m/%-d %H:%M"))') == { # noqa: SFT001
"1:22: SFT001 Linux-specific strftime code used.",
"1:26: SFT001 Linux-specific strftime code used.",
}


def test_windows_specific():
assert results('print(f"{now:%Y/%#m/%#d %H:%M}")') == { # noqa: STRFTIME002
"1:9: STRFTIME002 Windows-specific strftime code used.",
"1:13: STRFTIME002 Windows-specific strftime code used.",
assert results('print(f"{now:%Y/%#m/%#d %H:%M}")') == { # noqa: SFT002
"1:9: SFT002 Windows-specific strftime code used.",
"1:13: SFT002 Windows-specific strftime code used.",
}

assert results('print(now.strftime("%Y/%#m/%#d %H:%M"))') == { # noqa: STRFTIME002
"1:22: STRFTIME002 Windows-specific strftime code used.",
"1:26: STRFTIME002 Windows-specific strftime code used.",
assert results('print(now.strftime("%Y/%#m/%#d %H:%M"))') == { # noqa: SFT002
"1:22: SFT002 Windows-specific strftime code used.",
"1:26: SFT002 Windows-specific strftime code used.",
}


Expand Down