Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/stylelint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,14 @@ jobs:
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci --include=dev --legacy-peer-deps

- name: Set up WP environment
run: npm run env start

# css/formidableforms.css is a runtime-rendered stylesheet (see
# FrmStyle::save_settings()), not a build artifact, so there's nothing
# on disk for stylelint to check without this.
- name: Generate default stylesheet for lint coverage
run: npx wp-env run cli wp eval 'require FrmAppHelper::plugin_path() . "/bin/generate-default-stylesheet.php";'

- name: Run Stylelint
run: npx stylelint "**/*.{css,scss}"
19 changes: 16 additions & 3 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"**/frm-legacy-paypal.css",
"**/font_icons.css",
"**/frm_testing_mode.css",
"**/welcome-tour.css",
"**/css/formidableforms.css"
"**/welcome-tour.css"
],
"rules": {
"no-descending-specificity": null,
Expand All @@ -32,5 +31,19 @@
"font-family-no-missing-generic-family-keyword": null,
"scss/at-import-no-partial-leading-underscore": null,
"scss/load-no-partial-leading-underscore": null
}
},
"overrides": [
{
"files": ["**/css/formidableforms.css"],
"rules": {
"rule-empty-line-before": null,
"at-rule-empty-line-before": null,
"selector-attribute-quotes": null,
"selector-pseudo-element-colon-notation": null,
"color-hex-length": null,
"font-weight-notation": null,
"length-zero-no-unit": null
}
}
]
}
46 changes: 46 additions & 0 deletions bin/generate-default-stylesheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Writes css/formidableforms.css so stylelint has a real generated file to
* check instead of an ignored one, using the plugin's own static-file
* generator (FrmStyle::save_settings(), the same method a real save of the
* Styles settings triggers) rather than reimplementing its render logic.
*
* Usage: wp eval 'require FrmAppHelper::plugin_path() . "/bin/generate-default-stylesheet.php";'
* (not `wp eval-file` directly - wp-env's cli container's working
* directory is the WordPress root, not this plugin's checkout, and the
* mounted plugin folder name isn't guaranteed.)
*/

if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
return;
}

( new FrmStyle() )->save_settings();

// save_settings() writes wherever add_css_to_uploads_dir() resolves to,
// which can be outside this checkout (wp_upload_dir()) depending on file
// mod permissions - confirm the file actually landed where stylelint
// will look, rather than letting a silent miss pass as a green run.
$target = FrmStyle::get_generated_css_file_path( FrmStyle::add_css_to_uploads_dir() ) . '/' . FrmStylesController::get_file_name();

if ( ! is_file( $target ) || ! filesize( $target ) ) {
WP_CLI::error( "No stylesheet generated at $target" );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to static method error() on an unknown class WP_CLI


Invalid call to a static method. This would lead to a run time error.

}

// Several of the style templates gate a selector's only declarations behind
// a single `! empty( $defaults[...] )` check with no fallback (e.g. a
// font-family rule that only prints when a custom font is set) - under the
// stock defaults that selector renders with nothing between its braces.
// That's inert in real output either way, but stylelint's block-no-empty
// has no way to tell "false setting produced this on purpose" from "typo'd
// selector" without evaluating the template's PHP, so strip empty rules
// (including any block left empty once its only content is removed, e.g. a
// media query whose sole rule was itself emptied) before lint sees the file.
$css = file_get_contents( $target );
do {
$before = $css;
$css = preg_replace( '/[^{}]*\{\}/', '', $css );
} while ( $css !== $before );
file_put_contents( $target, $css );

WP_CLI::success( "Generated $target" );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to static method success() on an unknown class WP_CLI


Invalid call to a static method. This would lead to a run time error.

Loading