mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-17 17:33:40 -05:00
style: pass additional linters
This commit is contained in:
@@ -91,7 +91,7 @@ class Config:
|
||||
def _load_config(self) -> dict[str, Any]:
|
||||
"""Load the configuration file."""
|
||||
try:
|
||||
with open(self.config_path, encoding="utf-8") as fp:
|
||||
with self.config_path.open(encoding="utf-8") as fp:
|
||||
return tomlkit.load(fp)
|
||||
except tomlkit.exceptions.TOMLKitError as e:
|
||||
alerts.error(f"Could not parse '{self.config_path}'")
|
||||
|
||||
@@ -86,7 +86,7 @@ def dict_values_to_lists_strings(
|
||||
new_dict[key] = sorted([str(item) for item in value if item is not None])
|
||||
elif isinstance(value, dict):
|
||||
new_dict[key] = dict_values_to_lists_strings(value) # type: ignore[assignment]
|
||||
elif value is None or value == "None" or value == "":
|
||||
elif value is None or value == "None" or not value:
|
||||
new_dict[key] = []
|
||||
else:
|
||||
new_dict[key] = [str(value)]
|
||||
@@ -179,7 +179,7 @@ def remove_markdown_sections(
|
||||
if strip_frontmatter:
|
||||
text = re.sub(r"^\s*---.*?---", "", text, flags=re.DOTALL)
|
||||
|
||||
return text # noqa: RET504
|
||||
return text
|
||||
|
||||
|
||||
def version_callback(value: bool) -> None:
|
||||
|
||||
@@ -79,7 +79,7 @@ def main(
|
||||
help="""Set verbosity level (0=WARN, 1=INFO, 2=DEBUG, 3=TRACE)""",
|
||||
count=True,
|
||||
),
|
||||
version: Optional[bool] = typer.Option(
|
||||
version: Optional[bool] = typer.Option( # noqa: ARG001
|
||||
None, "--version", help="Print version and exit", callback=version_callback, is_eager=True
|
||||
),
|
||||
) -> None:
|
||||
|
||||
@@ -183,7 +183,7 @@ class Application:
|
||||
match self.questions.ask_selection(choices=choices, question="Select an action"):
|
||||
case "apply_path_filter":
|
||||
path = self.questions.ask_filter_path()
|
||||
if path is None or path == "": # pragma: no cover
|
||||
if path is None or not path: # pragma: no cover
|
||||
return
|
||||
|
||||
self.filters.append(VaultFilter(path_filter=path))
|
||||
@@ -200,7 +200,7 @@ class Application:
|
||||
)
|
||||
if value is None: # pragma: no cover
|
||||
return
|
||||
if value == "":
|
||||
if not value:
|
||||
self.filters.append(VaultFilter(key_filter=key))
|
||||
else:
|
||||
self.filters.append(VaultFilter(key_filter=key, value_filter=value))
|
||||
@@ -208,7 +208,7 @@ class Application:
|
||||
|
||||
case "apply_tag_filter":
|
||||
tag = self.questions.ask_existing_inline_tag()
|
||||
if tag is None or tag == "":
|
||||
if tag is None or not tag:
|
||||
return
|
||||
|
||||
self.filters.append(VaultFilter(tag_filter=tag))
|
||||
|
||||
@@ -210,7 +210,7 @@ class VaultMetadata:
|
||||
class Frontmatter:
|
||||
"""Representation of frontmatter metadata."""
|
||||
|
||||
def __init__(self, file_content: str):
|
||||
def __init__(self, file_content: str) -> None:
|
||||
self.dict: dict[str, list[str]] = self._grab_note_frontmatter(file_content)
|
||||
self.dict_original: dict[str, list[str]] = copy.deepcopy(self.dict)
|
||||
|
||||
@@ -389,7 +389,7 @@ class Frontmatter:
|
||||
class InlineMetadata:
|
||||
"""Representation of inline metadata in the form of `key:: value`."""
|
||||
|
||||
def __init__(self, file_content: str):
|
||||
def __init__(self, file_content: str) -> None:
|
||||
self.dict: dict[str, list[str]] = self.grab_inline_metadata(file_content)
|
||||
self.dict_original: dict[str, list[str]] = copy.deepcopy(self.dict)
|
||||
|
||||
@@ -535,7 +535,7 @@ class InlineMetadata:
|
||||
class InlineTags:
|
||||
"""Representation of inline tags."""
|
||||
|
||||
def __init__(self, file_content: str):
|
||||
def __init__(self, file_content: str) -> None:
|
||||
self.metadata_key = INLINE_TAG_KEY
|
||||
self.list: list[str] = self._grab_inline_tags(file_content)
|
||||
self.list_original: list[str] = self.list.copy()
|
||||
|
||||
@@ -41,7 +41,7 @@ class Note:
|
||||
inline_metadata (dict): Dictionary of inline metadata in the note.
|
||||
"""
|
||||
|
||||
def __init__(self, note_path: Path, dry_run: bool = False):
|
||||
def __init__(self, note_path: Path, dry_run: bool = False) -> None:
|
||||
log.trace(f"Creating Note object for {note_path}")
|
||||
self.note_path: Path = Path(note_path)
|
||||
self.dry_run: bool = dry_run
|
||||
@@ -146,7 +146,7 @@ class Note:
|
||||
return
|
||||
|
||||
try:
|
||||
with open(p, "w") as f:
|
||||
with p.open(mode="w") as f:
|
||||
log.trace(f"Writing note {p} to disk")
|
||||
f.write(self.file_content)
|
||||
except FileNotFoundError as e:
|
||||
@@ -579,7 +579,7 @@ class Note:
|
||||
except AttributeError:
|
||||
top = ""
|
||||
|
||||
if top == "":
|
||||
if not top:
|
||||
self.file_content = f"{new_string}\n{self.file_content}"
|
||||
return True
|
||||
|
||||
@@ -593,7 +593,7 @@ class Note:
|
||||
except AttributeError:
|
||||
top = ""
|
||||
|
||||
if top == "":
|
||||
if not top:
|
||||
self.file_content = f"{new_string}\n{self.file_content}"
|
||||
return True
|
||||
|
||||
|
||||
@@ -423,7 +423,7 @@ class Questions:
|
||||
|
||||
return self.ask_selection(
|
||||
choices=choices,
|
||||
question="Select the location for the metadata",
|
||||
question=question,
|
||||
)
|
||||
|
||||
def ask_new_key(self, question: str = "New key name") -> str: # pragma: no cover
|
||||
|
||||
@@ -47,7 +47,7 @@ class Vault:
|
||||
config: VaultConfig,
|
||||
dry_run: bool = False,
|
||||
filters: list[VaultFilter] = [],
|
||||
):
|
||||
) -> None:
|
||||
self.config = config.config
|
||||
self.vault_path: Path = config.path
|
||||
self.name = self.vault_path.name
|
||||
@@ -329,7 +329,7 @@ class Vault:
|
||||
|
||||
match export_format:
|
||||
case "csv":
|
||||
with open(export_file, "w", encoding="UTF8") as f:
|
||||
with export_file.open(mode="w", encoding="UTF8") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["Metadata Type", "Key", "Value"])
|
||||
|
||||
@@ -357,7 +357,7 @@ class Vault:
|
||||
"tags": self.metadata.tags,
|
||||
}
|
||||
|
||||
with open(export_file, "w", encoding="UTF8") as f:
|
||||
with export_file.open(mode="w", encoding="UTF8") as f:
|
||||
json.dump(dict_to_dump, f, indent=4, ensure_ascii=False, sort_keys=True)
|
||||
|
||||
def get_changed_notes(self) -> list[Note]:
|
||||
|
||||
Reference in New Issue
Block a user