Add detection for deleted files in printer linter

This update adds a new check for deleted files in the printer linter. This will alert the user when a file has been deleted that could potentially disrupt upgrade scripts. An argument "--deleted" is also added to terminal.py to facilitate this new check. Additionally, the printer-linter version has been incremented to 0.1.2.

CURA-10903
This commit is contained in:
Saumya Jain 2024-04-05 15:55:30 +02:00
parent 8020b9d97d
commit 38382eeec7
6 changed files with 36 additions and 5 deletions

View File

@ -37,6 +37,10 @@ jobs:
- name: Create results directory
run: mkdir printer-linter-result
- name: Check Deleted Files(s)
if: env.GIT_DIFF
run: python printer-linter/src/terminal.py --deleted --report printer-linter-result/fixes.yml $(echo "$GIT_DIFF" | grep '^D')
- name: Diagnose file(s)
if: env.GIT_DIFF && !env.MATCHED_FILES
run: python printer-linter/src/terminal.py --diagnose --report printer-linter-result/fixes.yml ${{ env.GIT_DIFF_FILTERED }}
@ -56,5 +60,5 @@ jobs:
uses: platisd/clang-tidy-pr-comments@bc0bb7da034a8317d54e7fe1e819159002f4cc40
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clang_tidy_fixes: result.yml
clang_tidy_fixes: printer-linter-pr-post.yml
request_changes: true

View File

@ -3,6 +3,7 @@ checks:
diagnostic-mesh-file-size: true
diagnostic-definition-redundant-override: true
diagnostic-resources-macos-app-directory-name: true
diagnostic-resource-file-deleted: true
fixes:
diagnostic-definition-redundant-override: true
format:

View File

@ -1,7 +1,7 @@
[project]
name = "printerlinter"
description = "Cura UltiMaker printer linting tool"
version = "0.1.1"
version = "0.1.2"
authors = [
{ name = "UltiMaker", email = "cura@ultimaker.com" }
]

View File

@ -11,7 +11,7 @@ from .linters.directory import Directory
def getLinter(file: Path, settings: dict) -> Optional[List[Linter]]:
""" Returns a Linter depending on the file format """
if not file.exists():
return None
return [Directory(file, settings)]
if ".inst" in file.suffixes and ".cfg" in file.suffixes:
return [Directory(file, settings), Profile(file, settings)]

View File

@ -11,9 +11,12 @@ class Directory(Linter):
super().__init__(file, settings)
def check(self) -> Iterator[Diagnostic]:
if self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False):
if self._file.exists() and self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False):
for check in self.checkForDotInDirName():
yield check
if self._settings["checks"].get("diagnostic-resource-file-deleted", False):
for check in self.checkFilesDeleted():
yield check
yield
@ -29,3 +32,14 @@ class Directory(Linter):
)
yield
def checkFilesDeleted(self) -> Iterator[Diagnostic]:
""" Check if there is a file that is deleted, this causes upgrade scripts to not work properly """
yield Diagnostic(
file = self._file,
diagnostic_name = "diagnostic-resource-file-deleted",
message = f"File: {self._file} must not be deleted as it is not allowed. It will create issues upgrading Cura",
level = "Error",
offset = 1
)
yield

View File

@ -19,6 +19,7 @@ def main() -> None:
parser.add_argument("--report", required=False, type=Path, help="Path where the diagnostic report should be stored")
parser.add_argument("--format", action="store_true", help="Format the files")
parser.add_argument("--diagnose", action="store_true", help="Diagnose the files")
parser.add_argument("--deleted", action="store_true", help="Check for deleted files")
parser.add_argument("--fix", action="store_true", help="Attempt to apply the suggested fixes on the files")
parser.add_argument("Files", metavar="F", type=Path, nargs="+", help="Files or directories to format")
@ -47,6 +48,18 @@ def main() -> None:
print(f"Can't find the file: {file}")
return
if args.deleted and files ==[]:
for file in args.Files:
deletedFiles = diagnoseIssuesWithFile(file, settings )
full_body_check["Diagnostics"].extend([d.toDict() for d in deletedFiles])
results = yaml.dump(full_body_check, default_flow_style=False, indent=4, width=240)
if report:
report.write_text(results)
else:
print(results)
if to_fix or to_diagnose:
for file in files:
diagnostics = diagnoseIssuesWithFile(file, settings)
@ -82,7 +95,6 @@ def diagnoseIssuesWithFile(file: Path, settings: dict) -> List[Diagnostic]:
return linter_results
def applyFixesToFile(file, settings, full_body_check) -> None:
if not file.exists():
return