Problem/Motivation
Hi,
I am enabling Gitlab CI on UI Suite Bootstrap theme, see #3417516: Enable Gitlab CI + Update README + Coding standards.
And I would like to be able to ignore some compiled CSS files in the stylelint job.
Proposed resolution
I have been to override the stylelint job scripts to use the "--ignore-path" option to be able to point to a .stylelintignore file but it does not seem to have an effect. While I already use this option in Makefile and GItlab CI on custom projects, scripts can be found in https://gitlab.com/florenttorregrosa-drupal/docker-drupal-project/-/tree... if needed.
See the results in the MR https://git.drupalcode.org/project/ui_suite_bootstrap/-/merge_requests/163.
Remaining tasks
- Find a "fix"
- Discuss how to add this feature by default in Gitlab CI templates.
Thanks for any help.
Comment | File | Size | Author |
---|---|---|---|
#11 | Capture d’écran du 2024-01-30 11-47-26.png | 77.89 KB | Grimreaper |
#11 | Capture d’écran du 2024-01-30 11-47-32.png | 69.46 KB | Grimreaper |
Issue fork gitlab_templates-3417807
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedWould adding a
$STYLELINT_EXTRA
variable help with this?We've done something similar with
$COMPOSER_EXTRA
,$_PARALLEL_LINT_EXTRA
or$PHPUNIT_EXTRA
to allow passing extra parameters to the commands.Comment #3
GrimreaperI think this will be the solution, but before going on this, I would like to ensure that the option will work :)
And currently, it is not working on the MR on the related issue.
Comment #4
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedIt might be related to the path where the file is. I can maybe check it tomorrow.
Comment #5
GrimreaperI think I found the diff in stylelint execution that can explain why in my stack the ignore works.
Drupal.org Gitlab CI:
My Makefile:
My Giltab CI:
In my case I use the bin stylelint directly why on drupal.org it is launched with Yarn.
I will try to launch with Yarn locally too to see if the diff comes from that.
Comment #6
GrimreaperAnd it is a win! The different results comes from that way to launch stylelint.
Searching how to make it work.
Comment #7
GrimreaperIf I place the following line in core/.stylelintrc.json in ignoreFiles, I see that the CSS files are ignored:
"../themes/custom/ui_suite_bootstrap/starterkits/ui_suite_bootstrap_subtheme_example/assets/css/**/*.css"
But in the .stylelintignore, not working. I think the evaluation of the ignore regexes or the path relative to cwd has a bug when used with yarn...
I can't figure out why or where the diff is coming from.
Next step would be to try to put console.log in stylelint codebase but if someone more experienced with stylelint could give feedback, it would be very appreciated.
Comment #8
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedhttps://stylelint.io/user-guide/ignore-code/#files-entirely
So maybe you need to specify
--ignore-path
because CWD is changed to./core
in the yarn command.Comment #9
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedRecommended to put the full path like this:
$CI_PROJECT_DIR/$_WEB_ROOT/...
Comment #10
GrimreaperYes, the
--ignore-path
is already what I tried ^^But its content is resolved differently how stylelint is triggered as mentioned in comment 5 :)
Comment #11
GrimreaperAfter some diving into stylelint codebase, and console.log, after console.log debug.
I think I found the "culprit".
app/core/node_modules/stylelint/lib/utils/filterFilePaths.js
So it is not possible to:
- use the --ignore-path option with a .stylelintignore file (relative or absolute path to this file change nothing)
- use the --ignore-pattern option
when it is for linting a file outside the directory where cwd is, those options will be ignored...
With those options (when scanning files inside the directory of cwd), the list of detected files is filtered out before linting:
While when adding ignore into app/core/.stylelintrc.json:
Then list of detected files is not filtered out but in the results it is mentioned which files had been ignored:
Attaching screenshots too, with color maybe more readable.
So not possible to handle an ignore that way if launching stylelint with yarn and cwd in core folder.
Maybe we can "play" with the path "../modules/custom/**/*.css" to make it variable. or need to launch stylelint differently or from somewhere else...
Comment #12
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedThis other broader issue (#3386841: Reconcile gitlab lint jobs and commit-code-check.sh) is changing the way the lints will be called. Maybe we can take/learn something from there.
MR: https://git.drupalcode.org/project/drupal/-/merge_requests/5498/diffs
--
Or another thought I just had. Maybe we can copy the module's
. stylelintignore
file, if present, to the "./core" folder.I'm not sure if that will work though, it's just a thought.
Comment #13
GrimreaperThanks for the other issue link.
But looking at the MR:
There will be the same problem because stylelint is executed from the core folder and not from the directory just above.
--
The problem is not that stylelint can't find the .stylelintignore file.
The problem is that either with --ignore-path or --ignore-pattern options, a CSS file outside of the folder from which stylelint is executed (so a CSS file with a relative path starting with "..") can't be ignored.
Maybe it is something to change upstream in stylelint.
Or next stuff I will try is to check if there is an option with stylelint like the --resolve-plugins-relative-to option of eslint. That way let's launch stylelint from the app root folder and make it load core config.
Comment #14
GrimreaperRegarding the eslint job, it is executed with
CI_PROJECT_DIR/$_WEB_ROOT/core/node_modules/.bin/eslint
, not with Yarn.Comment #15
Grimreaper\o/ https://git.drupalcode.org/project/ui_suite_bootstrap/-/jobs/716123
Proposing a MR for Gitlab template.
Comment #17
GrimreaperRe-checking one last stuff on the MR on my theme. To ensure last changes are ok and that I fixed back the report in Gitlab UI.
Comment #18
GrimreaperOk for me.
Thanks for the review.
Comment #19
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedGreat stuff! I'll review this tomorrow unless somebody beats me to it.
Comment #20
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commented@Grimreaper - can you link two tests runs, one where the ". stylelintignore" file exists in the module and another one where it doesn't?
Comment #21
GrimreaperHere it is.
Stylelint job from 5.0.x branch: https://git.drupalcode.org/project/ui_suite_bootstrap/-/jobs/716225
Stylelint job from MR https://git.drupalcode.org/project/ui_suite_bootstrap/-/merge_requests/164 where the .stylelintignore file had been deleted: https://git.drupalcode.org/project/ui_suite_bootstrap/-/jobs/724367
Comment #22
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedAwesome. Thanks so much. I've reviewed the code and all the feedback was addressed.
The testing is good as well.
RTBC.
Comment #24
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedMerged and marked this issue as fixed. Thanks!
Comment #25
GrimreaperThanks a lot!