Skip to content

Commit

Permalink
ENH: disable word wrap if .prettierrc has been removed
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 6, 2023
1 parent d45dc5e commit a3b6ab0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.wordWrap": "off"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.codeActionsOnSave": {
Expand Down
16 changes: 12 additions & 4 deletions src/repoma/check_dev_files/prettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def _remove_configuration() -> None:

def _fix_config_content(no_prettierrc: bool) -> None:
if no_prettierrc:
if CONFIG_PATH.prettier.exists():
os.remove(CONFIG_PATH.prettier)
msg = f"Removed {CONFIG_PATH.prettier} as requested by --no-prettierrc"
raise PrecommitError(msg)
executor = Executor()
executor(__remove_prettierrc)
executor(vscode.remove_setting, {"[markdown]": "editor.wordWrap"})
executor.finalize()
else:
if not CONFIG_PATH.prettier.exists():
existing_content = ""
Expand All @@ -77,6 +77,14 @@ def _fix_config_content(no_prettierrc: bool) -> None:
raise PrecommitError(msg)


def __remove_prettierrc() -> None:
if not CONFIG_PATH.prettier.exists():
return
CONFIG_PATH.prettier.unlink()
msg = f"Removed {CONFIG_PATH.prettier} as requested by --no-prettierrc"
raise PrecommitError(msg)


def _update_prettier_ignore() -> None:
__remove_forbidden_paths()
__insert_expected_paths()
Expand Down
23 changes: 22 additions & 1 deletion src/repoma/utilities/vscode.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
"""Helper functions for modifying a VSCode configuration."""

import json
from copy import deepcopy
from pathlib import Path
from typing import Iterable
from typing import Iterable, Union

from repoma.errors import PrecommitError
from repoma.utilities.executor import Executor

from . import CONFIG_PATH


def remove_setting(key: Union[str, dict]) -> None:
old = __load_config(CONFIG_PATH.vscode_settings, create=True)
new = deepcopy(old)
_recursive_remove_setting(key, new)
_update_settings(old, new)


def _recursive_remove_setting(nested_keys: Union[str, dict], settings: dict) -> None:
if isinstance(nested_keys, str) and nested_keys in settings:
settings.pop(nested_keys)
elif isinstance(nested_keys, dict):
for key, sub_keys in nested_keys.items():
if key not in settings:
continue
if isinstance(sub_keys, str):
sub_keys = [sub_keys]
for sub_key in sub_keys:
_recursive_remove_setting(sub_key, settings[key])


def remove_settings(keys: Iterable[str]) -> None:
removed_keys = set(keys)
settings = __load_config(CONFIG_PATH.vscode_settings, create=True)
Expand Down

0 comments on commit a3b6ab0

Please sign in to comment.