From ceb5e7096e4edfaff00c395c091c7faaa2ee7a89 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 24 Apr 2024 10:32:29 +0200 Subject: [PATCH 1/9] 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 From 196a4cf0c0166abbd33be6ed7002373ae3105e82 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 24 Apr 2024 10:51:48 +0200 Subject: [PATCH 2/9] Refactor profile name check method in linter CURA-11153 --- printer-linter/src/printerlinter/linters/profile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index a0b3c93836..12e358f0b8 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -23,8 +23,7 @@ class Profile(Linter): 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 """ + """ check the name of profile and where it is found""" name_of_profile, found = self._getprofileName() if len(name_of_profile) > Profile.MAX_SIZE_OF_NAME: yield Diagnostic( From 56aad519ae3aec443a1498232267c424c5f2dc17 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 24 Apr 2024 10:59:36 +0200 Subject: [PATCH 3/9] Changed message CURA-11153 --- printer-linter/src/printerlinter/linters/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index 12e358f0b8..84104aa024 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -29,7 +29,7 @@ class Profile(Linter): 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", + message = f"The profile name exceeds the maximum length limit. For optimal results, please limit it to 20 characters or fewer.", level="Warning", offset = found.span(0)[0] ) From 0ce09d917c30a2cb2f2d87b08abe1d10971b3190 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Wed, 24 Apr 2024 11:01:30 +0200 Subject: [PATCH 4/9] message has profile name in bold CURA-11153 --- printer-linter/src/printerlinter/linters/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index 84104aa024..924e13079a 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -29,7 +29,7 @@ class Profile(Linter): yield Diagnostic( file=self._file, diagnostic_name="diagnostic-long-profile-names", - message = f"The profile name exceeds the maximum length limit. For optimal results, please limit it to 20 characters or fewer.", + message = f"The profile name **{name_of_profile}** exceeds the maximum length limit. For optimal results, please limit it to 20 characters or fewer.", level="Warning", offset = found.span(0)[0] ) From 467801bf9e3b4ebda4709b5c05a3ce0075651aeb Mon Sep 17 00:00:00 2001 From: Saumya Jain <70144862+saumyaj3@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:26:52 +0200 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Casper Lamboo --- printer-linter/src/printerlinter/linters/profile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index 924e13079a..9535e1b454 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -18,7 +18,6 @@ class Profile(Linter): 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]: @@ -35,7 +34,7 @@ class Profile(Linter): ) yield - def _getprofileName(self) -> dict: + def _getprofileName(self) -> Tuple[str, bool]: config = ConfigParser() config.read([self._file]) name_of_profile = config.get("general", "name") From ec6c7f109c9bf1aa3e764192fdd1cbe1d59a379a Mon Sep 17 00:00:00 2001 From: Saumya Jain <70144862+saumyaj3@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:29:42 +0200 Subject: [PATCH 6/9] removed non necessary yield --- printer-linter/src/printerlinter/linters/profile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index 9535e1b454..e8c9da2acd 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -32,7 +32,6 @@ class Profile(Linter): level="Warning", offset = found.span(0)[0] ) - yield def _getprofileName(self) -> Tuple[str, bool]: config = ConfigParser() From d6164fddaec6fa83e6cd39220c927d855c7ec2bc Mon Sep 17 00:00:00 2001 From: HellAholic Date: Fri, 26 Apr 2024 11:36:12 +0200 Subject: [PATCH 7/9] Update printer-linter/src/printerlinter/linters/profile.py --- printer-linter/src/printerlinter/linters/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index e8c9da2acd..ea92c26366 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -33,7 +33,7 @@ class Profile(Linter): offset = found.span(0)[0] ) - def _getprofileName(self) -> Tuple[str, bool]: + def _getprofileName(self) -> tuple[str, bool]: config = ConfigParser() config.read([self._file]) name_of_profile = config.get("general", "name") From 4495f6475357433ae9d27bf036d9ca4820151f8e Mon Sep 17 00:00:00 2001 From: HellAholic Date: Fri, 26 Apr 2024 11:39:39 +0200 Subject: [PATCH 8/9] Revert "Update printer-linter/src/printerlinter/linters/profile.py" This reverts commit d6164fddaec6fa83e6cd39220c927d855c7ec2bc. --- printer-linter/src/printerlinter/linters/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index ea92c26366..e8c9da2acd 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -33,7 +33,7 @@ class Profile(Linter): offset = found.span(0)[0] ) - def _getprofileName(self) -> tuple[str, bool]: + def _getprofileName(self) -> Tuple[str, bool]: config = ConfigParser() config.read([self._file]) name_of_profile = config.get("general", "name") From fdc2688413e6c9074827cbdb5f3d7c95b3be5717 Mon Sep 17 00:00:00 2001 From: HellAholic Date: Fri, 26 Apr 2024 11:49:54 +0200 Subject: [PATCH 9/9] Update printer-linter/src/printerlinter/linters/profile.py --- printer-linter/src/printerlinter/linters/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer-linter/src/printerlinter/linters/profile.py b/printer-linter/src/printerlinter/linters/profile.py index e8c9da2acd..4ca3ded964 100644 --- a/printer-linter/src/printerlinter/linters/profile.py +++ b/printer-linter/src/printerlinter/linters/profile.py @@ -1,5 +1,5 @@ import re -from typing import Iterator +from typing import Iterator, Tuple from ..diagnostic import Diagnostic from .linter import Linter