Execute CSPELL in project root folder and make fixing words easier
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3426136. --> Reported by: [jonathan1055](https://www.drupal.org/user/92645) Related to !155 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Due to the CSPELL work-around for copying the projects files into $CI_PROJECT_DIR/gitlabci_cspell/$CI_PROJECT_NAME the paths in the downloadable _cspell_json.txt are not valid any more. </p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Download _cspell_json.txt and save it as .cspell.json to form the basis for the project's own file. The cspell job then fails with</p> <pre>Dictionary Error with (drupal) Error: ENOENT: no such file or directory, open '/builds/project/core/misc/cspell/drupal-dictionary.txt'<br>Dictionary Error with (dictionary) Error: ENOENT: no such file or directory, open '/builds/project/core/misc/cspell/dictionary.txt'<br>CSpell: Files checked: 0, Issues found: 0 in 0 files</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>This MR also contains several other improvements to make the cspell job easier for maintainers to fix and run green. Here is a summary of the changes:</p> <ol> <li>cspell is executed directly in the project root $CI_PROJECT_DIR instead of the copied folder $CI_PROJECT_DIR/gitlabci_cspell/$CI_PROJECT_NAME</li> <li>This eliminates the need to copy everything, so that folder is no longer created</li> <li>/webroot and /vendor are automatically ignored</li> <li>Manipulation of .cspell.json (either the projects own, or the default from /assets) is done in a new script <strong>prepare-cspell.php</strong> not the inline bash in .gitlab-ci.yml job step. This gives more flexibility and imporves readability</li> <li>The two drupal core dictionaries are always added, and that the paths to them are always corrected, regardless of what the maintainer might need for other running of cspell, locally or pre-existing on DrupalCI</li> <li>The input variables _cspell_words and _cspell_ignore_paths no longer require the tedious quoting of each item. This is all done in the php script. This reduces maintauiner effort in support</li> <li>A new variable _cspell_ignore_standard_files allows flexibility for ignoring the common list (composer.json, maintainers.text, etc). The default value is 1, so that these are ignored unless the maintainer specifically sets the value to 0</li> <li>Additional internal dictionaries (already part of cspell) are used to save maintainers adding some extra words</li> </ol> <p>Here is the <a href="https://git.drupalcode.org/issue/gitlab_templates-3426136/-/blob/3426136-cspell-in-root-folder/docs/jobs/cspell.md" title="3426136-cspell-in-root-folder/docs/jobs/cspell.md">latest updated doc page for these changes</a></p> <p>To test this MR use the following in your .gitlab-ci.yml</p> <pre>include:<br>&nbsp; # MR 155 Run cspell in root folder<br>&nbsp; - project: 'issue/gitlab_templates-3426136'<br>&nbsp;&nbsp;&nbsp; ref: 3426136-cspell-in-root-folder<br><br>variables:<br>&nbsp; _CURL_TEMPLATES_REPO: issue/gitlab_templates-3426136<br>&nbsp; _CURL_TEMPLATES_REF: 3426136-cspell-in-root-folder</pre><h3 id="summary-testing">Testing</h3> <p>Tetsing needs to cover the following scenarios:</p> <ol> <li>Project without any cspell related files or variables. Project does have composer.json<br> <strong>Search API</strong><br> Totally un-customised. No .cspell-project-words.txt, no variables, no .cspell.json. The project does have a composer.json file<br> Issue <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/search_api/issues/3427068" title="Status: Closed (fixed)">#3427068: Fix cspell errors in Search API</a></span><br> MR <a href="https://git.drupalcode.org/project/search_api/-/merge_requests/116">https://git.drupalcode.org/project/search_api/-/merge_requests/116</a><br> Test <a href="https://git.drupalcode.org/issue/search_api-3427068/-/pipelines/120292">https://git.drupalcode.org/issue/search_api-3427068/-/pipelines/120292</a><br> <strong>Decoupled Pages </strong><br> Does not have .cspell.json, no .cpell-project-words.txt, no _CSPELL variables. There is currently one unrecognised word in composer.json, but with this MR the cspell job is green.<br> MR <a href="https://git.drupalcode.org/project/decoupled_pages/-/merge_requests/6">https://git.drupalcode.org/project/decoupled_pages/-/merge_requests/6</a><br> Existing <a href="https://git.drupalcode.org/project/decoupled_pages/-/pipelines/121257">https://git.drupalcode.org/project/decoupled_pages/-/pipelines/121257</a><br> Test <a href="https://git.drupalcode.org/issue/decoupled_pages-3422594/-/pipelines/121458">https://git.drupalcode.org/issue/decoupled_pages-3422594/-/pipelines/121458</a> </li> <li>Project without any cspell variables, no .cspell.json. Project does not have composer.json<br> <strong>CDN</strong><br> Issue <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/cdn/issues/3347168" title="Status: Closed (fixed)">#3347168: Match core's code quality checks: cspell</a></span><br> <a href="https://git.drupalcode.org/project/cdn/-/merge_requests/18">https://git.drupalcode.org/project/cdn/-/merge_requests/18</a><br> <a href="https://git.drupalcode.org/issue/cdn-3347168/-/jobs/1076281">https://git.drupalcode.org/issue/cdn-3347168/-/jobs/1076281</a> </li> <li>Project with cspell variables<br> <strong>Module Filter</strong><br> <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/module_filter/issues/3431234" title="Status: Closed (fixed)">#3431234: Fix spelling and unrecognized words</a></span><br> <a href="https://git.drupalcode.org/project/module_filter/-/merge_requests/45">https://git.drupalcode.org/project/module_filter/-/merge_requests/45</a><br> The project does not have any .cspell.json or .cspell-project-words.txt<br> Fixed entirely with additions to <code>_CSPELL_WORDS</code>. The sequence of commits and pipelines demonstrates that the new MR caters for unquoted words in the list, which makes it easier for maintainers.<br> <strong>Able Player</strong><br> <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ableplayer/issues/3427424" title="Status: Closed (fixed)">#3427424: Resolve cspell errors found by gitlab pipeline</a></span><br> <a href="https://git.drupalcode.org/project/ableplayer/-/merge_requests/37">https://git.drupalcode.org/project/ableplayer/-/merge_requests/37</a><br> Testing shows that existing <code>_CSPELL_WORDS</code> and <code>_CSPELL_IGNORE_PATHS</code> work with the new changes. It also shows simplification and reduction in work. See the linked issue for details. </li> <li>Project with existing .cspell-project-words.txt file<br> <strong>Open Telemetry</strong><br> Project has existing .cspell-project-words.txt and _CSPELL_IGNORE_PATHS and the cspell job currently passes green.<br> Issue <a href="https://www.drupal.org/project/opentelemetry/issues/3425641">https://www.drupal.org/project/opentelemetry/issues/3425641</a><br> switch to MR155 - <a href="https://git.drupalcode.org/issue/opentelemetry-3425641/-/jobs/1109939">cspell job still green</a><br> remove variable _CSPELL_IGNORE_PATHS: "\"composer.json\"" - <a href="https://git.drupalcode.org/issue/opentelemetry-3425641/-/jobs/1110158">job remains passing green</a></li> <li>Project with existing .cspell.json file<br> <strong>Automatic Updates</strong><br> This project contains a dictionary.txt file and was running CSPELL on DrupalCI before Gitlab Templates had it.<br> Issue <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-17"><a href="https://www.drupal.org/project/automatic_updates/issues/3426716" title="Status: Closed (outdated)">#3426716: gitlab CI phpunit tests in 3.0.x are now failing</a></span><br> MR <a href="https://git.drupalcode.org/project/automatic_updates/-/merge_requests/1030">1030</a><br> The current <a href="https://git.drupalcode.org/issue/automatic_updates-3426716/-/pipelines/124266">CSPELL job fails</a><br> With MR155 <a href="https://git.drupalcode.org/issue/automatic_updates-3426716/-/pipelines/124282">it passes</a> with no other changes </li> <li>Project with .cspell.json file as provided in artifacts when no file is present<br> <strong>Scheduler</strong><br> First run on main branch (not new MR), with no project .cspell.json, to get a cspell_json.txt artifact that projects may have now<br> <a href="https://git.drupalcode.org/project/scheduler/-/jobs/1120118">https://git.drupalcode.org/project/scheduler/-/jobs/1120118</a><br> The unrecognised words are in <code>copyright.txt</code> and <code>License.md</code>.<br> Downloaded the cspelll_json.txt artifact, saved as .cspell.json with no changes, uploaded and run using MR155<br> <a href="https://git.drupalcode.org/project/scheduler/-/pipelines/125105">https://git.drupalcode.org/project/scheduler/-/pipelines/125105</a><br> The <code>copyright.txt</code> and <code>License.md</code> files are now ignored as expected. Only two unrecognised words - intentionally added to test _CSPELL_WORDS.<br> Add two words to _CSPELL_WORDS - job ends green<br> <a href="https://git.drupalcode.org/project/scheduler/-/pipelines/125164">https://git.drupalcode.org/project/scheduler/-/pipelines/125164</a></li> <li>Project using the new _CSPELL_IGNORE_STANDARD_FILES variable set to 0 to <i>not</i> those files.<br> <strong>Scheduler</strong><br> As above, but with <code>_CSPELL_IGNORE_STANDARD_FILES=0</code><br> <a href="https://git.drupalcode.org/project/scheduler/-/pipelines/125204">https://git.drupalcode.org/project/scheduler/-/pipelines/125204</a> the jobs ends amber.<br> You can see <a href="https://git.drupalcode.org/project/scheduler/-/jobs/1121185#L259">in the log here</a> that cspell_json['ignorePaths'] only contains 'vendor' 'web' 'node_modules' and '.git'. The unrecognised words are now reported in 4 files: composer.json, COPYRIGHT.txt, License.md and src/copyright.txt</li> </ol> > Related issue: [Issue #3425403](https://www.drupal.org/node/3425403)
issue