From ceb5e7096e4edfaff00c395c091c7faaa2ee7a89 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 24 Apr 2024 10:32:29 +0200 Subject: [PATCH] Add new linter for long profile names CURA-11153 --- .printer-linter | 1 + .../src/printerlinter/linters/profile.py | 38 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.printer-linter b/.printer-linter index 9724c63300..5715fbdc02 100644 --- a/.printer-linter +++ b/.printer-linter @@ -5,6 +5,7 @@ checks: diagnostic-resources-macos-app-directory-name: true diagnostic-resource-file-deleted: true diagnostic-material-temperature-defined: true + diagnostic-long-profile-names: true fixes: diagnostic-definition-redundant-override: true format: diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index 85cc2d9f0b..a0b3c93836 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -1,9 +1,45 @@ +import re from typing import Iterator from ..diagnostic import Diagnostic from .linter import Linter - +from pathlib import Path +from configparser import ConfigParser class Profile(Linter): + MAX_SIZE_OF_NAME = 20 + def __init__(self, file: Path, settings: dict) -> None: + """ Finds issues in the parent directory""" + super().__init__(file, settings) + self._content = self._file.read_text() + + def check(self) -> Iterator[Diagnostic]: + if self._file.exists() and self._settings["checks"].get("diagnostic-long-profile-names", False): + for check in self.checklengthofProfileName(): + yield check yield + + + def checklengthofProfileName(self) -> Iterator[Diagnostic]: + + data = self._isNameSizeBIggerThanThreshhold() + """ Check if there is a dot in the directory name, MacOS has trouble signing and notarizing otherwise """ + name_of_profile, found = self._getprofileName() + if len(name_of_profile) > Profile.MAX_SIZE_OF_NAME: + yield Diagnostic( + file=self._file, + diagnostic_name="diagnostic-long-profile-names", + message=f"Profile name contained is too long, please make it a bit smaller", + level="Warning", + offset = found.span(0)[0] + ) + yield + + def _getprofileName(self) -> dict: + config = ConfigParser() + config.read([self._file]) + name_of_profile = config.get("general", "name") + redefined = re.compile(name_of_profile) + found = redefined.search(self._content) + return name_of_profile, found