Skip to content

Commit

Permalink
Merge pull request #474 from GhostManager/hotfix/linting-style-types
Browse files Browse the repository at this point in the history
Added linting checks for style types on code styles
  • Loading branch information
chrismaddalena authored Jul 3, 2024
2 parents 2293484 + 7aa185a commit c0a1172
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions ghostwriter/modules/reportwriter/base/docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ def lint(cls, template_loc: str, p_style: str | None) -> Tuple[List[str], List[s
logger.info("Template loaded for linting")

undeclared_variables = ReportExportError.map_jinja2_render_errors(
lambda: exporter.word_doc.get_undeclared_template_variables(exporter.jinja_env),
"the DOCX template"
lambda: exporter.word_doc.get_undeclared_template_variables(exporter.jinja_env), "the DOCX template"
)
for variable in undeclared_variables:
if variable not in lint_data:
Expand All @@ -279,6 +278,12 @@ def lint(cls, template_loc: str, p_style: str | None) -> Tuple[List[str], List[s
for style in EXPECTED_STYLES:
if style not in document_styles:
warnings.append("Template is missing a recommended style (see documentation): " + style)
if style == "CodeInline":
if document_styles[style].type != WD_STYLE_TYPE.CHARACTER:
warnings.append("CodeInline style is not a character style (see documentation)")
if style == "CodeBlock":
if document_styles[style].type != WD_STYLE_TYPE.PARAGRAPH:
warnings.append("CodeBlock style is not a paragraph style (see documentation)")
if "Table Grid" not in document_styles:
errors.append("Template is missing a required style (see documentation): Table Grid")
if p_style and p_style not in document_styles:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ <h3 class="icon bug-icon">Linting Results</h3>
role="alert">
<h4 style="margin-top: 0;" class="alert-heading">{{ lint_result.result|capfirst }}</h4>
{% if lint_result.result == "success" %}
Template passed all linter checks, but try using it for a report to test it
<p>Template passed all linter checks, but try using it for a report to test it with findings and custom fields.</p>
{% else %}
To correct these issues, make changes and re-upload this template
<p>To correct these issues, make changes and re-upload this template.
See the documentation for more information on how to fix these issues:<br/>
<a class="italic" href="https://www.ghostwriter.wiki/features/reporting/report-templates" target="_blank">
https://www.ghostwriter.wiki/features/reporting/report-templates
</a>
</p>
{% endif %}
</div>

Expand Down Expand Up @@ -57,4 +62,4 @@ <h4 style="margin-top: 0;" class="alert-heading">{{ lint_result.result|capfirst
<h4 style="margin-top: 0;" class="alert-heading">Unknown</h4>
Run the linter on this template to get new results
</div>
{% endif %}
{% endif %}

0 comments on commit c0a1172

Please sign in to comment.