Cura/printer-linter
Saumya Jain db0e46b252 Improve formula checks and error messages in printer-linter
This update enhances the checking of formula correctness in printer settings and provides clearer error messages when formulas appear incorrect. By getting a list of Cura setting variables and typical formula names, it uses these to match and replace incorrect segments in formulas, if any. Related code for error handling and message reporting are also revised to give more useful feedback to users for necessary corrections.

CURA-10901
2024-04-10 10:42:17 +02:00
..
src Improve formula checks and error messages in printer-linter 2024-04-10 10:42:17 +02:00
pyproject.toml Add MacOS directory naming linting 2023-09-22 01:29:22 +02:00
README.md Clarify linter steps for running locally 2022-12-04 19:33:48 -03:00
setup.cfg Create a proper Pyhton packages for printer-linter 2022-11-20 12:16:37 +01:00
setup.py Create a proper Pyhton packages for printer-linter 2022-11-20 12:16:37 +01:00

Printer Linter

Printer linter is a python package that does linting on Cura definitions files. Running this on your definition files will get them ready for a pull request.

Running Locally

From the Cura root folder and pointing to the relative paths of the wanted definition files:

python3 printer-linter/src/terminal.py "resources/definitions/flashforge_dreamer_nx.def.json" "resources/definitions/flashforge_base.def.json" --fix --format

Developing

Printer Linter Rules

Inside .printer-linter you can find a list of rules. These are seperated into roughly three categories.

  1. Checks
    1. These rules are about checking if a file meets some requirements that can't be fixed by replacing its content.
    2. An example of a check is diagnostic-mesh-file-extension this checks if a mesh file extension is acceptable.
  2. Format
    1. These rules are purely about how a file is structured, not content.
    2. An example of a format rule is format-definition-bracket-newline This rule says that when assigning a dict value the bracket should go on a new line.
  3. Fixes
    1. These are about the content of the file.
    2. An example of a fix is diagnostic-definition-redundant-override This removes settings that have already been defined by a parent definition

Linters

Linters find issues within a file. There are separate linters for each type of file. The linter that is used is decided by the create function in factory.py. All linters implement the abstract class Linter.

A Linter class returns an iterator of Diagnostics, each diagnostic is an issue with the file. The diagnostics can also contain suggested fixes.

Formatters

Formatters load a file reformat it and write it to disk. There are separate formatters for each file type. All formatters implement the abstract class Formatter.

Formatters should format based on the Format rules in .printer-linter