Skip to content

Mustache linting - #10095

Closed
NathanBaulch wants to merge 6 commits into
OpenAPITools:masterfrom
NathanBaulch:mustache-linting
Closed

Mustache linting#10095
NathanBaulch wants to merge 6 commits into
OpenAPITools:masterfrom
NathanBaulch:mustache-linting

Conversation

@NathanBaulch

Copy link
Copy Markdown
Contributor

I've noticed a lot of inconsistencies and redundancies whilst working on templates across the various languages. This PR uses regex search and replace (via sed) to fix a lot of these minor linting issues. None of the changes here were made by hand and none of them produce any unexpected changes to the generated samples, so they're safe.

Remove redundant sections

Command:

find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
 xargs -0 sed -i -E 's~\{\{[^\w{](([^\Wfi]|f[^\Wn]|i[^\Ws])\w+)\}\}(\{\{\{?)(\.|\1)(\}\}\}?)\{\{/\1\}\}~\3\1\5~g'

Example:

{{#returnType}}{{{returnType}}}{{/returnType}}
->
{{{returnType}}}

Remove empty tags

Command:

find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
 xargs -0 sed -i -E -z 's~\{\{[^\w{](([^\Wri]|r[^\We]|i[^\Ws]|re[^Wq])\w+)\}\}([^{]*)(\{\{\{?)\1(\}\}\}?)([^{]*)\{\{/\1\}\}~{{#\1}}\3\4.\5\6{{/\1}}~g'

Example:

{{^required}}{{/required}}
->

Use dot notation where possible

Command:

find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
 xargs -0 sed -i -E 's~\{\{[#^](\w+)\}\}\{\{/\1\}\}~~g'

Example:

{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
->
{{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}

Reorder tags that handle missing values

Command:

find ./modules/openapi-generator/src/main/resources -type f -name '*.mustache' -print0 |\
 xargs -0 sed -i -E 's~(\{\{\^(([^\Wb]|b[^\Wa])\w+)\}\}.*\{\{/\2\}\})(\{\{\2\}\})~\4\1~g'

Example:

{{^description}}Gets or Sets {{{name}}}{{/description}}{{description}}
->
{{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}

Trim trailing whitespace and extra EOF new lines

Self explanatory.

As with all linting efforts, these cosmetic changes improve code quality but at the cost of potential conflicts in unmerged code.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
  • File the PR against the correct branch: master, 5.3.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@NathanBaulch NathanBaulch changed the title Trim trailing whitespace Mustache linting Aug 5, 2021
@wing328

wing328 commented Aug 7, 2021

Copy link
Copy Markdown
Member

@NathanBaulch thanks for the PR. Can you please resolve the merge conflicts when you've time?

@NathanBaulch

Copy link
Copy Markdown
Contributor Author

Rebased onto latest master. 👍

@wing328

wing328 commented Aug 17, 2021

Copy link
Copy Markdown
Member

cc @OpenAPITools/generator-core-team as it covers pretty much all generators/templates.

@wing328 wing328 added this to the 5.3.0 milestone Aug 17, 2021
@wing328

wing328 commented Aug 17, 2021

Copy link
Copy Markdown
Member

Resolved the merge conflicts and merged via 0204bf4

@wing328 wing328 closed this Aug 17, 2021
@NathanBaulch
NathanBaulch deleted the mustache-linting branch August 17, 2021 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants