Skip to content

Commit

Permalink
Add compatibility with VS Code October 2023
Browse files Browse the repository at this point in the history
The October 2023 version of VS Code deprecates built-in linting and
formatting features that were shipped with the Python extension. This
means linters and formatters will have to run through dedicated
extensions. There are currently extensions for Black, Pylint and Flake8,
but there are no extensions for Bandit and Pydocstyle. This means they
must be run in another way. Luckily there are Flake8 plugins for both
Bandit and Pydocstyle. With the changes in this commit, Voight-Kampff
now expects the user to use the plugins if they want to run Bandit and
Pydocstyle, and consequently the standalone linters are disabled by
default when running `vk`. It is still possible to run the linters by
explicitly specifying their names as arguments to the `vk` command.

Unfortunately, the Bandit Flake8 plugin expects a config file in INI
format while Voight-Kampff originally expected a YAML config file for
Bandit. For compatibility with the plugin, this commit updates
Voight-Kampff to expect an INI file. This breaks backwards compatibility.

Further, the functionality for disabling rules are different between the
standalone Bandit and the Flake8-plugin. Consequently if, say, the rule
that detects for hardcoded passwords is to be disabled inline, it must
be done in one way to work with the standalone linter, and in another
way to work with the Flake8 plugin. This means any code that disables
Bandit rules inline should be updated. Pydocstyle does not suffer from
this problem.

The Voight-Kampff code itself has been updated to expect both plugins to
be installed.
  • Loading branch information
sorenlind committed Nov 2, 2023
1 parent a8560be commit daa0acd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .bandit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
skips:
- B101 # assert_used
[bandit]
skips = B101
12 changes: 3 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ jobs:
command: pip3 install --upgrade pip
- run:
name: Install linters
command: pip3 install bandit black flake8 pydocstyle pyenchant pylint
command: pip3 install black flake8 pyenchant pylint
- run:
name: Install Voight-Kampff
command: pip3 install ."[test]"
- run:
name: Bandit
command: vk bandit
command: pip3 install ."[dev]"
- run:
name: Black
command: vk black
Expand All @@ -92,9 +89,6 @@ jobs:
- run:
name: Markdownlint
command: vk markdownlint
- run:
name: Pydocstyle
command: vk pydocstyle
- run:
name: Pyright
command: vk pyright
Expand All @@ -120,7 +114,7 @@ jobs:
command: pip3 install --upgrade pip
- run:
name: Install Voight-Kampff
command: pip3 install ."[test]"
command: pip3 install ."[dev]"
- run:
name: Install pyenchant and pylint
command: pip3 install pyenchant pylint
Expand Down
43 changes: 18 additions & 25 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"autoDocstring.startOnNewLine": true,
"coverage-gutters.coverageFileNames": [
"test-results/voight_kampff/cov-py38.xml"
],
"coverage-gutters.coverageReportFileName": "test-results/voight_kampff/html/index.html",
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.rulers": [88],

"files.exclude": {
"**/.git": true,
"**/.mypy_cache": true,
Expand All @@ -13,42 +21,27 @@
"**/.pytest_cache": true,
"**/.ipynb_checkpoints": true
},

"autoDocstring.startOnNewLine": true,

"notebook.formatOnSave.enabled": true,
"python.analysis.typeCheckingMode": "basic",

"python.formatting.provider": "black",

"python.linting.enabled": true,
"python.linting.ignorePatterns": [".vscode/*.py", "**/site-packages/**/*.py"],
"python.linting.banditEnabled": true,
"python.linting.banditArgs": ["-c=.bandit"],
"python.linting.flake8Enabled": true,
"python.linting.flake8Path": "flake8",
"python.linting.pycodestyleEnabled": false,
"python.linting.pydocstyleEnabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintCategorySeverity.convention": "Warning",
"python.linting.pylintCategorySeverity.refactor": "Information",

"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--exitfirst",
"--verbose",
"--cov=./voight_kampff",
"--cov-report=xml:test-results/voight_kampff/cov-py38.xml",
"--cov-report=html:test-results/voight_kampff/html"
"--cov-report=xml:test-results/cov.xml",
"--cov-report=html:test-results/html"
],
"rewrap.autoWrap.enabled": true,
"[git-commit]": { "editor.rulers": [50, 72] },
"[markdown]": {
"editor.wordWrap": "off",
"editor.renderWhitespace": "all",
"editor.acceptSuggestionOnEnter": "off",
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"coverage-gutters.coverageFileNames": [
"test-results/voight_kampff/cov-py38.xml"
],
"coverage-gutters.coverageReportFileName": "test-results/voight_kampff/html/index.html"
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnType": true
}
}
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ def _validate_version(tag: str | None, version: str) -> bool:
keywords="",
packages=find_packages(),
install_requires=[
"bandit",
"black",
"flake8",
"isort",
"pydocstyle",
"pyenchant",
"pylint",
],
extras_require={
"dev": [
"coverage",
"flake8-annotations",
"flake8-bandit",
"flake8-docstrings",
"flake8-plus",
"flake8-pytest-style",
"pytest-cov",
Expand Down
14 changes: 12 additions & 2 deletions voight_kampff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bandit": Task(
"Bandit",
"bandit",
["-c=.bandit"],
["--ini", ".bandit"],
glob_file_type="py",
),
"black": Task(
Expand Down Expand Up @@ -60,6 +60,16 @@
}

LINTER_NAMES = list(LINTER_TASKS.keys())
DEFAULT_LINTER_NAMES = [
"black",
"cspell",
"flake8",
"isort",
"markdownlint",
"pylint",
"pylint-spelling",
"pyright",
]


def main():
Expand Down Expand Up @@ -111,7 +121,7 @@ def __call__(
)
unique_values.append(value)
if not values:
values = LINTER_NAMES
values = DEFAULT_LINTER_NAMES
setattr(namespace, self.dest, values)


Expand Down
4 changes: 2 additions & 2 deletions voight_kampff/task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Task specification."""
import subprocess # nosec
import subprocess # noqa: S404
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -51,7 +51,7 @@ def run(self) -> int:
"""
print(f"🐍 {self.title}{' ' * (30-len(self.title))}", end="", flush=True)
files = self._list_files()
process = subprocess.run( # nosec
process = subprocess.run( # noqa: S603
[self._command, *self._args, *files],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down

0 comments on commit daa0acd

Please sign in to comment.