From e05b9746ea2fee503c4e8eb2598443aad1edc357 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 17 Jul 2022 17:29:05 +0800 Subject: [PATCH] [R] Add lintr (#12902) * add lintr * update samples --- .../openapitools/codegen/languages/RClientCodegen.java | 1 + .../openapi-generator/src/main/resources/r/lintr.mustache | 6 ++++++ .../src/main/resources/r/r-client.mustache | 8 ++++---- samples/client/petstore/R/.github/workflows/r-client.yaml | 8 ++++---- samples/client/petstore/R/.lintr | 6 ++++++ samples/client/petstore/R/.openapi-generator/FILES | 1 + 6 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/r/lintr.mustache create mode 100644 samples/client/petstore/R/.lintr diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 9fcf0f4a649..37880fee6c5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -251,6 +251,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE")); supportingFiles.add(new SupportingFile("testthat.mustache", File.separator + "tests", "testthat.R")); supportingFiles.add(new SupportingFile("r-client.mustache", File.separator + ".github" + File.separator + "workflows", "r-client.yaml")); + supportingFiles.add(new SupportingFile("lintr.mustache", "", ".lintr")); // add lambda for mustache templates to fix license field additionalProperties.put("lambdaLicense", new Mustache.Lambda() { diff --git a/modules/openapi-generator/src/main/resources/r/lintr.mustache b/modules/openapi-generator/src/main/resources/r/lintr.mustache new file mode 100644 index 00000000000..9d908cd7c74 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/r/lintr.mustache @@ -0,0 +1,6 @@ +linters: linters_with_defaults( + line_length_linter(160), + object_name_linter = NULL + ) +exclusions: list( + ) diff --git a/modules/openapi-generator/src/main/resources/r/r-client.mustache b/modules/openapi-generator/src/main/resources/r/r-client.mustache index b9d883ec4c9..216ebe6c003 100644 --- a/modules/openapi-generator/src/main/resources/r/r-client.mustache +++ b/modules/openapi-generator/src/main/resources/r/r-client.mustache @@ -21,10 +21,10 @@ jobs: use-public-rspm: true - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck - needs: check - - name: Install roxygen2 - run: install.packages("roxygen2") + extra-packages: any::rcmdcheck, any::roxygen2, any::lintr, local::. + needs: check, roxygen2, lint + - name: Lint + run: lintr::lint_package() shell: Rscript {0} - name: Roxygenize run: | diff --git a/samples/client/petstore/R/.github/workflows/r-client.yaml b/samples/client/petstore/R/.github/workflows/r-client.yaml index b9d883ec4c9..216ebe6c003 100644 --- a/samples/client/petstore/R/.github/workflows/r-client.yaml +++ b/samples/client/petstore/R/.github/workflows/r-client.yaml @@ -21,10 +21,10 @@ jobs: use-public-rspm: true - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck - needs: check - - name: Install roxygen2 - run: install.packages("roxygen2") + extra-packages: any::rcmdcheck, any::roxygen2, any::lintr, local::. + needs: check, roxygen2, lint + - name: Lint + run: lintr::lint_package() shell: Rscript {0} - name: Roxygenize run: | diff --git a/samples/client/petstore/R/.lintr b/samples/client/petstore/R/.lintr new file mode 100644 index 00000000000..9d908cd7c74 --- /dev/null +++ b/samples/client/petstore/R/.lintr @@ -0,0 +1,6 @@ +linters: linters_with_defaults( + line_length_linter(160), + object_name_linter = NULL + ) +exclusions: list( + ) diff --git a/samples/client/petstore/R/.openapi-generator/FILES b/samples/client/petstore/R/.openapi-generator/FILES index 3c5469b531d..7a05f5fdda5 100644 --- a/samples/client/petstore/R/.openapi-generator/FILES +++ b/samples/client/petstore/R/.openapi-generator/FILES @@ -1,6 +1,7 @@ .Rbuildignore .github/workflows/r-client.yaml .gitignore +.lintr .travis.yml DESCRIPTION NAMESPACE