Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !10095

Mustache linting

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/NathanBaulch/mustache-linting into master Aug 05, 2021
  • Overview 0
  • Commits 6
  • Pipelines 0
  • Changes 1000+

Created by: NathanBaulch

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.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/NathanBaulch/mustache-linting