diff --git a/.github/workflows/printer-linter-pr-diagnose.yml b/.github/workflows/printer-linter-pr-diagnose.yml index 57c3732d81..c9c5fb2f60 100644 --- a/.github/workflows/printer-linter-pr-diagnose.yml +++ b/.github/workflows/printer-linter-pr-diagnose.yml @@ -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 diff --git a/.printer-linter b/.printer-linter index 3a42a5c033..e73e4f8ab2 100644 --- a/.printer-linter +++ b/.printer-linter @@ -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: diff --git a/printer-linter/pyproject.toml b/printer-linter/pyproject.toml index c346dc0496..cde196225c 100644 --- a/printer-linter/pyproject.toml +++ b/printer-linter/pyproject.toml @@ -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" } ] diff --git a/printer-linter/src/printerlinter/factory.py b/printer-linter/src/printerlinter/factory.py index 4473fb9a4e..0d706788fc 100644 --- a/printer-linter/src/printerlinter/factory.py +++ b/printer-linter/src/printerlinter/factory.py @@ -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)] diff --git a/printer-linter/src/printerlinter/linters/directory.py b/printer-linter/src/printerlinter/linters/directory.py index 4ca299dad7..616c20af02 100644 --- a/printer-linter/src/printerlinter/linters/directory.py +++ b/printer-linter/src/printerlinter/linters/directory.py @@ -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 \ No newline at end of file diff --git a/printer-linter/src/terminal.py b/printer-linter/src/terminal.py index fb5ee36bd0..fa2212285c 100644 --- a/printer-linter/src/terminal.py +++ b/printer-linter/src/terminal.py @@ -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