Skip to content

Commit

Permalink
DQA-10277: Toolkit add command for cspell (#788)
Browse files Browse the repository at this point in the history
Co-authored-by: J. João Santos <[email protected]>
  • Loading branch information
joaocsilva and jonhy81 authored Oct 22, 2024
1 parent 2c00843 commit 1639139
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ pipeline:
environment: *env
commands:
- ./run toolkit:lint-php

lint-cspell:
group: test
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION=8.1}-ci
secrets: [ github_api_token, composer_auth ]
environment: *env
commands:
- ./run toolkit:lint-cspell --files=src --config=resources/cspell/.cspell.json
5 changes: 5 additions & 0 deletions config/commands/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ command:
options:
config: ${toolkit.lint.css.config}
files: ${toolkit.lint.css.files}
lint-cspell:
options:
config: ${toolkit.lint.cspell.config}
files: ${toolkit.lint.cspell.files}
options: ${toolkit.lint.cspell.options}
4 changes: 4 additions & 0 deletions config/runner/toolkit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ toolkit:
css:
config: .stylelintrc.json
files: '"${toolkit.build.custom-code-folder}/themes/*/css/*.css" "!${toolkit.build.custom-code-folder}/themes/*/css/*.min.css"'
cspell:
config: '.cspell.json'
files: '${toolkit.build.custom-code-folder}/'
options: '--dot --gitignore'
axe-scan:
config: axe-scan.config.json
urls:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
web:
image: registry.fpfis.eu/fpfis/httpd-php:8.1-ci
image: registry.fpfis.eu/fpfis/httpd-php:8.3-ci
working_dir: /test/toolkit
ports:
# Use port "8080:8080" to access the mock in the browser OR to use xdebug.
Expand Down
20 changes: 20 additions & 0 deletions docs/guide/testing-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,26 @@ To run the ESLint YAML tests you can make use of the ``toolkit:lint-yaml`` comma
docker-compose exec web ./vendor/bin/run toolkit:lint-yaml
CSpell testing
^^^^^^^^^^^^^^^^^^^

To run the CSpell tests you can make use of the ``toolkit:lint-cspell`` command:

.. code-block::
docker-compose exec web ./vendor/bin/run toolkit:lint-cspell
These are the default configurations in the ``runner.yml`` file.

.. code-block:: yaml
toolkit:
lint:
cspell:
config: '.cspell.json'
files: 'lib/'
options: '--dot --gitignore'
Testing in CI
-------------

Expand Down
62 changes: 62 additions & 0 deletions resources/cspell/.cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version": "0.2",
"language": "en-US",
"allowCompoundWords": false,
"globRoot": ".",
"ignorePaths": [
"**/.*.json",
".*ignore",
"composer.lock",
"assets/vendor/**",
"**/LICENSE.txt",
"../**/LICENSE.txt",
"node_modules/*",
"tests/fixtures/*",
"CHANGELOG.md",
"COPYRIGHT.txt",
"MAINTAINERS.txt",
"package.json",
"yarn.lock",
".yarnrc.yml",
".yarn/*",
"phpstan*",
".git/**",
"docs/*"
],
"ignoreRegExpList": [
"^msgstr .*",
"!!binary .*",
"%[0-9][0-9A-F]",
"\\Wi18n",
"\\x{[0-9A-F]{4,5}}",
"CURLOPT_[A-Z]+",
"CURLAUTH_[A-Z]+",
"tk-[a-z]+"
],
"dictionaries": [
"companies",
"css",
"toolkit",
"en-gb",
"filetypes",
"fonts",
"html",
"misc",
"php",
"git",
"softwareTerms"
],
"dictionaryDefinitions": [
{
"name": "toolkit",
"path": "./dictionary.txt"
}
],
"flagWords": [
"e-mail",
"grey",
"hte",
"ist",
"queuing"
]
}
77 changes: 77 additions & 0 deletions resources/cspell/.project-cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"version": "0.2",
"language": "en-US",
"allowCompoundWords": false,
"globRoot": ".",
"ignorePaths": [
"**/.*.json",
".*ignore",
"composer.lock",
"assets/vendor/**",
"**/LICENSE.txt",
"../**/LICENSE.txt",
"node_modules/*",
"tests/fixtures/*",
"CHANGELOG.md",
"COPYRIGHT.txt",
"MAINTAINERS.txt",
"package.json",
"yarn.lock",
".yarnrc.yml",
".yarn/*",
"phpstan*",
".git/**",
"docs/*"
],
"ignoreRegExpList": [
"^msgstr .*",
"!!binary .*",
"%[0-9][0-9A-F]",
"\\Wi18n",
"\\x{[0-9A-F]{4,5}}",
"CURLOPT_[A-Z]+",
"tk-[a-z]+"
],
"dictionaries": [
"companies",
"css",
"drupal-dictionary",
"drupal-dictionary-extra",
"en-gb",
"filetypes",
"fonts",
"git",
"html",
"misc",
"php",
"softwareTerms",
"toolkit"
],
"dictionaryDefinitions": [
{
"name": "drupal-dictionary",
"path": "./web/core/misc/cspell/drupal-dictionary.txt"
},
{
"name": "drupal-dictionary-extra",
"path": "./web/core/misc/cspell/dictionary.txt"
},
{
"name": "toolkit",
"path": "./vendor/ec-europa/toolkit/resources/cspell/dictionary.txt"
}
],
"flagWords": [
"e-mail",
"grey",
"hte",
"ist",
"queuing"
],
"overrides": [
{
"filename": "**/{*.engine,*.inc,*.install,*.module,*.profile,*.theme}",
"languageId": "php"
}
]
}
48 changes: 48 additions & 0 deletions resources/cspell/dictionary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Toolkit command names and aliases.
complock-check
tdus
tljs

# Misc.
asda
authmap
behat
blackfire
cicd
commandfile
cweagans
dcweb
devel
dflydev
diffy
Documentor
dropsolid
drush
Dtoolkit
endcode
eulogin
eulogin
ewcms
ewpp
ewppa
EXITCODE
expirable
fpfis
grasmash
grumphp
gulpfile
mailhog
metapackage
mydumper
myloader
nextcloud
nexteuropa
openeuropa
opensocial
phpcbf
phpro
reqs
robo
ruleset
webform
xmlsitemap
3 changes: 3 additions & 0 deletions src/TaskRunner/Commands/AxeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AxeCommands extends AbstractCommands
* @var array|string[]
*/
private array $dependencies = [
// cspell:disable
'libnss3-tools',
'libatk1.0-0',
'libatk-bridge2.0-0',
Expand All @@ -41,6 +42,7 @@ class AxeCommands extends AbstractCommands
'libx11-xcb1',
'libxcursor1',
'xdg-utils',
// cspell:enable
];

/**
Expand Down Expand Up @@ -150,6 +152,7 @@ public function toolkitSetupAxeScan()
'node_modules/axe-scan/build/src/commands/summary.js',
];
$from = 'const browser = await puppeteer.launch();';
// cspell:ignore setuid
$args = '["--no-sandbox", "--disable-setuid-sandbox", "--single-process", "--disable-impl-side-painting", "--disable-gpu-sandbox", "--disable-accelerated-2d-canvas", "--disable-accelerated-jpeg-decoding", "--disable-dev-shm-usage"]';
$to = 'const browser = await puppeteer.launch({args: ' . $args . '});';
foreach ($files as $file) {
Expand Down
1 change: 1 addition & 0 deletions src/TaskRunner/Commands/BlackfireCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function toolkitRunBlackfire(ConsoleIO $io, array $options = [
'field_blackfire_ci_cd_url' => [['value' => $ciUrl]],
'field_blackfire_graph_url' => [['value' => $data['graph']]],
'field_blackfire_timeline_url' => [['value' => $data['timeline']]],
// cspell:ignore recomendations
'field_blackfire_recomendations' => [['value' => $data['recommendation']]],
'field_blackfire_memory' => [['value' => $data['memory']]],
'field_blackfire_wall_time' => [['value' => $data['wall_time']]],
Expand Down
8 changes: 4 additions & 4 deletions src/TaskRunner/Commands/ComponentCheckCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ public function componentEvaluation(ConsoleIO $io)
return 1;
}
// Get vendor list.
$dataTkReqsEndpoint = Website::requirements();
$vendorList = $dataTkReqsEndpoint['vendor_list'] ?? [];
$toolkitRequirements = Website::requirements();
$vendorList = $toolkitRequirements['vendor_list'] ?? [];

// Proceed with 'blocker' option. Loop over the packages.
$groupComponents = [];
Expand Down Expand Up @@ -687,8 +687,8 @@ protected function validateEnvironmentVariables()
$fileNames = [DockerCommands::DC_YML_FILE, '.env', '.env.dist'];
$envVarsSet = [];
// Get forbidden/obsolete vars from config.
$toolkitReqs = Website::requirements();
$forbiddenVars = $toolkitReqs['forbidden_variables'] ?? [];
$toolkitRequirements = Website::requirements();
$forbiddenVars = $toolkitRequirements['forbidden_variables'] ?? [];
if (!empty($forbiddenVars)) {
// Parse files that contain env variables into sets.
foreach ($fileNames as $filename) {
Expand Down
43 changes: 43 additions & 0 deletions src/TaskRunner/Commands/LintCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,47 @@ public function toolkitLintCss(array $options = [
return $this->collectionBuilder()->addTaskList($tasks);
}

/**
* Run lint CSpell.
*
* @command toolkit:lint-cspell
*
* @option config The path to the config file.
* @option files The files to check.
* @option options Extra options for the command.
*
* @aliases tk-cspell
*
* @usage --files='lib' --config='web/core/.cspell.json' --options='--gitignore'
*/
public function toolkitLintCsPell(array $options = [
'config' => InputOption::VALUE_REQUIRED,
'files' => InputOption::VALUE_REQUIRED,
'options' => InputOption::VALUE_OPTIONAL,
])
{
$tasks = [];
$bin = $this->getNodeBinPath('cspell');

// Install dependencies if the bin is not present.
if (!file_exists($bin)) {
$tasks[] = $this->taskExecStack()
->exec('npm -v || npm i npm')
->exec('[ -f package.json ] || npm init -y --scope')
->exec('npm list cspell && npm update cspell || npm install cspell -y');
}

// Ensure the config file exists.
if (!file_exists($options['config'])) {
$tasks[] = $this->taskFilesystemStack()->copy(
Toolkit::getToolkitRoot() . '/resources/cspell/.project-cspell.json',
'.cspell.json'
);
}

$command = $bin . ' ' . $options['files'] . ' --config=' . $options['config'];
$tasks[] = $this->taskExec($command . ' ' . $options['options']);
return $this->collectionBuilder()->addTaskList($tasks);
}

}
4 changes: 2 additions & 2 deletions src/TaskRunner/Commands/ToolCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public function toolkitRequirements(ConsoleIO $io, array $options = [
}

// Handle NEXTCLOUD.
$ncUser = Toolkit::getNExtcloudUser();
$ncPass = Toolkit::getNExtcloudPass();
$ncUser = Toolkit::getNextcloudUser();
$ncPass = Toolkit::getNextcloudPass();
if (!empty($ncUser) && !empty($ncPass)) {
$nextcloudCheck = 'OK';
} else {
Expand Down

0 comments on commit 1639139

Please sign in to comment.