|
40 | 40 | uses: insightsengineering/r-spellcheck-action@v2
|
41 | 41 | with:
|
42 | 42 | exclude: inst/extdata/*
|
| 43 | + |
| 44 | + grammar: |
| 45 | + name: Check grammar 🔡 |
| 46 | + runs-on: ubuntu-latest |
| 47 | + if: > |
| 48 | + !contains(github.event.commits[0].message, '[skip spelling]') |
| 49 | + && github.event.pull_request.draft == false |
| 50 | +
|
| 51 | + steps: |
| 52 | + - name: Checkout Code 🛎 |
| 53 | + uses: actions/checkout@v3 |
| 54 | + |
| 55 | + - name: Restore npm cache 💰 |
| 56 | + uses: actions/cache@v3 |
| 57 | + with: |
| 58 | + key: npm-${{ runner.os }}-${{ github.job }} |
| 59 | + restore-keys: | |
| 60 | + npm-${{ runner.os }}- |
| 61 | + path: node_modules |
| 62 | + |
| 63 | + - name: Setup NodeJS ☊ |
| 64 | + uses: actions/setup-node@v3 |
| 65 | + with: |
| 66 | + node-version: 18 |
| 67 | + |
| 68 | + - name: Install write-good ⏬ |
| 69 | + run: npm install write-good glob fs |
| 70 | + |
| 71 | + - name: Run write-good 🏃♀️ |
| 72 | + uses: actions/github-script@v6 |
| 73 | + with: |
| 74 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + script: | |
| 76 | + const globber = require('glob'); |
| 77 | + const writeGood = require('write-good'); |
| 78 | + const path = require('path'); |
| 79 | + const fs = require('fs'); |
| 80 | + let files = globber.sync('**/*.@(Rd|Rmd|qmd|md)'); |
| 81 | + let allSuggestions = []; |
| 82 | + files.forEach((file) => { |
| 83 | + if (fs.lstatSync(file).isFile() && |
| 84 | + !path.dirname(file).startsWith("node_modules")) { |
| 85 | + const contents = fs.readFileSync(file, 'utf8'); |
| 86 | + const suggestions = writeGood(contents); |
| 87 | + const annotations = writeGood.annotate(contents, suggestions, true); |
| 88 | + if (annotations.length) { |
| 89 | + for (var i=0; i < annotations.length; i++) { |
| 90 | + let ann = annotations[i]; |
| 91 | + ann['message'] = ann['reason']; |
| 92 | + ann['start_column'] = ann['col']; |
| 93 | + ann['end_column'] = ann['col']; |
| 94 | + ann['start_line'] = ann['line']; |
| 95 | + ann['end_line'] = ann['line']; |
| 96 | + ann['annotation_level'] = 'notice'; |
| 97 | + ann['path'] = file; |
| 98 | + delete ann['reason']; |
| 99 | + delete ann['col']; |
| 100 | + delete ann['line']; |
| 101 | + allSuggestions.push(ann); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + }); |
| 106 | + fs.writeFileSync('./annotations.json', JSON.stringify(allSuggestions, null, 2) , 'utf-8'); |
| 107 | +
|
| 108 | + - name: Annotate files for grammar suggestions ✍️ |
| 109 | + |
| 110 | + with: |
| 111 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + json-file-path: ./annotations.json |
0 commit comments