-
Notifications
You must be signed in to change notification settings - Fork 19
Wire up stylelint for CSS/SCSS #1857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: Lint CSS | ||
|
|
||
| on: | ||
| # Run on direct pushes to integration branches and on all pull requests. | ||
| push: | ||
| branches: | ||
| - develop | ||
| - main | ||
| - master | ||
| - trunk | ||
| pull_request: | ||
| # Allow manually triggering the workflow. | ||
| workflow_dispatch: | ||
|
|
||
| # Cancels all previous workflow runs for the same branch that have not yet completed. | ||
| concurrency: | ||
| # The concurrency group contains the workflow name and the branch name. | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| name: "Lint: CSS" | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Cache Node.js modules | ||
| id: cache-node-modules | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: node_modules | ||
| key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-node_modules- | ||
| # The lint stage doesn't run the unit tests or use code style, so no need for PHPUnit, WPCS or phpcompatibility. | ||
| - name: 'Install NPM packages' | ||
| if: steps.cache-node-modules.outputs.cache-hit != 'true' | ||
| run: npm ci --prefer-offline --no-audit --ignore-scripts | ||
|
|
||
| - name: Get only files changed in this PR | ||
| id: changed-files | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| if (!context.payload.pull_request) { | ||
| core.warning("No pull request context available. Skipping changed files retrieval."); | ||
| core.setOutput('files', ''); | ||
| return ''; | ||
| } | ||
|
|
||
| const changedFiles = await github.paginate( | ||
| github.rest.pulls.listFiles, | ||
| { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.payload.pull_request.number, | ||
| } | ||
| ); | ||
| const cssFiles = changedFiles | ||
| .filter(file => file.status !== 'removed') | ||
| .map(file => file.filename) | ||
| .filter(filename => filename.endsWith('.scss') || filename.endsWith('.css')) | ||
| .join(' '); | ||
|
Comment on lines
+63
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win Pass changed filenames as arguments, not shell text. Line 74 interpolates PR-controlled filenames into an unquoted shell command. This both breaks filenames containing spaces and permits shell metacharacters such as Also applies to: 72-74 🤖 Prompt for AI Agents |
||
|
|
||
| core.setOutput('files', cssFiles); | ||
| return cssFiles; | ||
|
|
||
| # If this is a PR then lint only css/scss changed in the PR, if not a PR then lint them all. | ||
| - name: Run stylelint | ||
| run: npx wp-scripts lint-style ${{ steps.changed-files.outputs.files || '' }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "extends": "@wordpress/stylelint-config/scss-stylistic", | ||
| "rules": { | ||
| "selector-class-pattern": null | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,14 @@ | |
| "dist": "npx webpack --mode production && composer install --no-dev && composer dump-autoload --no-dev -o && ./scripts/dist.sh && composer install", | ||
| "dist:dotorg": "npm run dist:keep-build-folder", | ||
| "dist:keep-build-folder": "npx webpack --mode production && composer install --no-dev && composer dump-autoload --no-dev -o && ./scripts/dist.sh --keep-build-folder", | ||
| "lint": "./vendor/bin/phpcs && npm run lint:js", | ||
| "lint": "./vendor/bin/phpcs && npm run lint:js && npm run lint:css", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Do not add full CSS linting to the aggregate command before the baseline is clean. Line 15 makes 🤖 Prompt for AI Agents |
||
| "lint-staged-precommit": "lint-staged", | ||
| "lint:php": "./vendor/bin/phpcs", | ||
| "lint:php:fix": "./vendor/bin/phpcbf", | ||
| "lint:js": "wp-scripts lint-js", | ||
| "lint:js:fix": "wp-scripts lint-js --fix", | ||
| "lint:css": "wp-scripts lint-style", | ||
| "lint:css:fix": "wp-scripts lint-style --fix", | ||
| "test:php": "./scripts/setup-phpunit.sh", | ||
| "test:php:run": "docker compose exec phpunit vendor/bin/phpunit", | ||
| "test:php:coverage": "docker compose exec phpunit vendor/bin/phpunit --coverage-clover=./coverage/clover.xml --coverage-html=./coverage/html", | ||
|
|
@@ -28,7 +30,8 @@ | |
| }, | ||
| "lint-staged": { | ||
| "*.php": "./vendor/bin/phpcs", | ||
| "*.js": "wp-scripts lint-js" | ||
| "*.js": "wp-scripts lint-js", | ||
| "*.scss": "wp-scripts lint-style" | ||
| }, | ||
| "files": [ | ||
| "LICENSE.txt", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Skip linting when a PR has no stylesheet changes.
When the changed-file list is empty, Line 74 still runs
wp-scripts lint-stylewith no paths, which scans the entire repository. This makes unrelated PRs—and every push/manual run—hit the known baseline of approximately 27,000 violations. Skip the step for CSS-free PRs and make full-repository linting an explicit, separately controlled behavior.Also applies to: 49-52, 72-74
🤖 Prompt for AI Agents