{"id":51977186,"url":"https://github.com/ddotta/rsonar-examples","last_synced_at":"2026-07-30T07:30:21.397Z","repository":{"id":372644967,"uuid":"1216249227","full_name":"ddotta/rsonar-examples","owner":"ddotta","description":"Examples to illustrate somes features of the `rsonar` package","archived":false,"fork":false,"pushed_at":"2026-07-22T15:23:54.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-22T16:29:35.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ddotta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-20T18:06:43.000Z","updated_at":"2026-07-22T15:28:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ddotta/rsonar-examples","commit_stats":null,"previous_names":["ddotta/rsonar-examples"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ddotta/rsonar-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddotta%2Frsonar-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddotta%2Frsonar-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddotta%2Frsonar-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddotta%2Frsonar-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddotta","download_url":"https://codeload.github.com/ddotta/rsonar-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddotta%2Frsonar-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36067204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-30T02:00:05.956Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-30T07:30:20.841Z","updated_at":"2026-07-30T07:30:21.377Z","avatar_url":"https://github.com/ddotta.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rsonar-examples\r\n\r\n\u003e Practical examples showcasing [rsonar](https://github.com/ddotta/rsonar) — the SonarQube equivalent for R. Includes automatic code formatting with [air](https://github.com/posit-dev/air).\r\n\r\nThis repository is a **demo R package** with intentionally clean and messy code, paired with **9 example scripts** and **6 GitHub Actions workflows** to illustrate every feature of the `rsonar` package.\r\n\r\n## Repository structure\r\n\r\n```\r\nrsonar-examples/\r\n├── R/                          # Demo R package source code\r\n│   ├── clean_code.R            # Well-written functions (greet, fibonacci, bmi)\r\n│   └── messy_code.R            # Intentionally messy code (lint issues, style violations)\r\n├── tests/testthat/             # Unit tests (intentional coverage gaps)\r\n├── examples/                   # Standalone R scripts\r\n│   ├── 01_basic_analysis.R     # Run a full analysis and print results\r\n│   ├── 02_technical_debt.R     # SQALE debt with default and custom costs\r\n│   ├── 03_quality_gate.R       # Quality gate: lenient vs. strict thresholds\r\n│   ├── 04_export_formats.R     # Generate HTML, JSON, JUnit, and SARIF exports\r\n│   ├── 05_selective_analysis.R # Run only lint, style, or coverage individually\r\n│   ├── 06_diff_comparison.R    # Compare two analyses to detect regressions\r\n│   ├── 07_trend_tracking.R     # Persist metrics over time to a JSON history\r\n│   ├── 08_project_setup.R      # Use setup helpers (lintr config, CI templates)\r\n│   └── 09_auto_fix.R           # Auto-format code with air + MR/PR creation\r\n├── .github/workflows/          # GitHub Actions CI examples\r\n│   ├── 01-basic.yml            # Basic analysis + HTML report\r\n│   ├── 02-quality-gate.yml     # Quality gate that blocks the pipeline\r\n│   ├── 03-sarif.yml            # SARIF export → GitHub Code Scanning\r\n│   ├── 04-all-exports.yml      # All export formats in a single job\r\n│   ├── 05-trend.yml            # Trend tracking with auto-commit\r\n│   └── 06-full-pipeline.yml    # Full production pipeline (5 parallel stages)\r\n└── ci-templates/\r\n    └── gitlab-ci.yml           # GitLab CI equivalent pipeline with auto-fix\r\n```\r\n\r\n## What is rsonar?\r\n\r\n`rsonar` brings SonarQube-style code quality analysis to R projects. It combines:\r\n\r\n| Tool | Purpose |\r\n|------|---------|\r\n| [lintr](https://lintr.r-lib.org/) | Static analysis (lint errors, warnings, style) |\r\n| [styler](https://styler.r-lib.org/) | Code formatting checks |\r\n| [covr](https://covr.r-lib.org/) | Test coverage measurement |\r\n| [goodpractice](https://mangothecat.github.io/goodpractice/) | R package best practices |\r\n| [air](https://github.com/posit-dev/air) | Automatic code formatting (auto-fix) |\r\n\r\nAll results are unified into a single analysis object with technical debt estimation (SQALE model), quality gates, and multiple export formats.\r\n\r\n## Quick start\r\n\r\n```r\r\n# Install rsonar\r\nremotes::install_github(\"ddotta/rsonar\")\r\n\r\n# Clone this repo and run an example\r\nlibrary(rsonar)\r\nres \u003c- sonar_analyse(\"path/to/rsonar-examples\")\r\nprint(res)\r\n```\r\n\r\n## Example scripts\r\n\r\n### 1. Basic analysis (`01_basic_analysis.R`)\r\n\r\nRun a full analysis and display the results in the console.\r\n\r\n```r\r\nres \u003c- sonar_analyse(\".\", verbose = TRUE)\r\nprint(res)\r\n```\r\n\r\n### 2. Technical debt (`02_technical_debt.R`)\r\n\r\nCompute SQALE technical debt with default and custom cost models.\r\n\r\n```r\r\ndebt_default \u003c- debt_index(res)\r\ndebt_strict  \u003c- debt_index(res, cost_lint_error = 60, coverage_target = 90)\r\n```\r\n\r\n### 3. Quality gate (`03_quality_gate.R`)\r\n\r\nDefine thresholds and check if the project passes. In CI, use `fail_on_error = TRUE` to exit with code 1.\r\n\r\n```r\r\nquality_gate(res, coverage_min = 80, lint_errors_max = 0, fail_on_error = TRUE)\r\n```\r\n\r\n### 4. Export formats (`04_export_formats.R`)\r\n\r\nGenerate reports for every platform:\r\n\r\n| Function | Format | Target |\r\n|----------|--------|--------|\r\n| `sonar_report()` | HTML | Browser / artifact |\r\n| `export_sonar_json()` | JSON | SonarQube import |\r\n| `export_junit()` | JUnit XML | GitLab CI / GitHub Actions / Jenkins |\r\n| `export_sarif()` | SARIF 2.1.0 | GitHub Code Scanning / VS Code / Azure DevOps |\r\n\r\n### 5. Selective analysis (`05_selective_analysis.R`)\r\n\r\nRun only specific checks for faster feedback:\r\n\r\n```r\r\nres_lint \u003c- sonar_analyse(\".\", include_coverage = FALSE, include_goodpractice = FALSE)\r\n```\r\n\r\n### 6. Diff comparison (`06_diff_comparison.R`)\r\n\r\nCompare a baseline vs. current state:\r\n\r\n```r\r\ndiff \u003c- sonar_diff(current, baseline)\r\nprint(diff)  # Shows IMPROVED or REGRESSED with metric deltas\r\n```\r\n\r\n### 7. Trend tracking (`07_trend_tracking.R`)\r\n\r\nPersist metrics to a JSON history file:\r\n\r\n```r\r\nsonar_trend(res, file = \"rsonar-history.json\")\r\n```\r\n\r\n### 8. Project setup (`08_project_setup.R`)\r\n\r\nInitialize rsonar in a new project:\r\n\r\n```r\r\nuse_rsonar_lintr(\".\")       # Copy reference .lintr config\r\nuse_rsonar_ci(\"github\")     # Copy GitHub Actions workflow\r\nuse_rsonar_ci(\"gitlab\")     # Copy GitLab CI pipeline\r\n```\r\n\r\n### 9. Auto-fix with air (`09_auto_fix.R`)\r\n\r\nAutomatically format R code using Posit's `air` formatter:\r\n\r\n```r\r\nlibrary(rsonar)\r\n\r\n# Install air (once per machine)\r\ninstall_air()\r\n\r\n# Check what would be changed (dry-run)\r\nfix_dry \u003c- sonar_fix(\".\", dry_run = TRUE)\r\nprint(fix_dry)\r\n\r\n# Apply formatting to all R files\r\nfix \u003c- sonar_fix(\".\")\r\n\r\n# In CI: create a Merge Request with the fixes\r\nfix \u003c- sonar_fix(\".\", create_mr = TRUE)\r\n```\r\n\r\nIn CI pipelines (`rsonar-fix` job):\r\n- Installs `air` via `install_air()`\r\n- Formats all R files automatically\r\n- Optionally creates a Merge Request (GitLab) or Pull Request (GitHub)\r\n\r\n## CI workflow examples\r\n\r\n### GitHub Actions\r\n\r\n| Workflow | Description | Key features |\r\n|----------|-------------|--------------|\r\n| `01-basic.yml` | Basic analysis | HTML report as artifact |\r\n| `02-quality-gate.yml` | Quality gate | JUnit report + pipeline blocking |\r\n| `03-sarif.yml` | SARIF upload | Issues in GitHub Security tab |\r\n| `04-all-exports.yml` | All exports | HTML + JSON + JUnit + SARIF |\r\n| `05-trend.yml` | Trend tracking | Auto-commit history file |\r\n| `06-full-pipeline.yml` | Full pipeline | 5 parallel stages (recommended) |\r\n\r\n### GitLab CI\r\n\r\nThe `ci-templates/gitlab-ci.yml` file provides a complete pipeline with:\r\n- Parallel lint/style/coverage jobs\r\n- **Auto-fix with air** (optional, manual trigger)\r\n- Quality gate stage\r\n- HTML report + trend tracking as artifacts\r\n- Cobertura coverage integration\r\n\r\n## The demo package\r\n\r\nThis package contains two files designed to showcase rsonar's detection:\r\n\r\n- **`clean_code.R`** — 3 well-written, documented, and tested functions (`greet`, `fibonacci`, `bmi`)\r\n- **`messy_code.R`** — 2 intentionally messy functions with:\r\n  - Missing spaces around `=` and `{`\r\n  - `T`/`F` instead of `TRUE`/`FALSE`\r\n  - Lines exceeding 80 characters\r\n  - `=` used instead of `\u003c-` for assignment\r\n  - No tests (coverage gap)\r\n\r\nThis mix ensures rsonar always detects issues, making it ideal for demonstrations.\r\n\r\n## License\r\n\r\nMIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddotta%2Frsonar-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddotta%2Frsonar-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddotta%2Frsonar-examples/lists"}