Skip to content

Stylelint: Migrate configuration from JSON to JavaScript format #69590

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

Merged
merged 5 commits into from
Apr 17, 2025

Conversation

im3dabasia
Copy link
Contributor

@im3dabasia im3dabasia commented Mar 17, 2025

What?

Closes #63090

Convert Stylelint configuration from JSON to JavaScript format to enable custom rule messages

Why?

As our Stylelint rules expand, we need more flexible configuration options. The current JSON format is limiting our ability to provide clear, specific messages for each rule violation.

As noted by @mirka in #63048, converting to JavaScript format will allow us to configure the message property as a function, providing different warning messages for each violation type. This requires at least Stylelint version 14.5.0 which supports this feature. (Current Stylelint version is 16.8.2 in GB).

How?

  1. Converts .stylelintrc.json to .stylelintrc.js
  2. Maintains all existing rules while enabling enhanced configuration options

@Mamaduka Mamaduka added [Type] Code Quality Issues or PRs that relate to code quality [Tool] stylelint config /packages/stylelint-config labels Mar 19, 2025
@im3dabasia im3dabasia force-pushed the try/convert-stylelintrc branch 2 times, most recently from e21a88e to 14ed9bc Compare March 27, 2025 06:11
@im3dabasia im3dabasia marked this pull request as ready for review March 27, 2025 07:39
@im3dabasia im3dabasia requested a review from ajitbohra as a code owner March 27, 2025 07:39
Copy link

github-actions bot commented Mar 27, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia force-pushed the try/convert-stylelintrc branch from 14ed9bc to 3c98667 Compare April 15, 2025 08:50
@im3dabasia
Copy link
Contributor Author

im3dabasia commented Apr 15, 2025

Hi @mirka ,

When you have a moment please review my PR.

Looking forward for your feedbacks.

cc: @t-hamano

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

I think this is a great enhancement. It will also be possible to add complex custom rules.

We could make the message more specific as a follow-up:

module.exports = {
	rules: {
		'declaration-property-value-allowed-list': [
			{ 'flex-direction': '/^(?!(row|column)-reverse).*$/' },
			{
				message: ( property, value ) =>
					`Avoid "${ value }" value for the "${ property }" property. For accessibility reasons, visual, reading, and DOM order must match. Only use the reverse values when they do not affect reading order, meaning, and interaction.`,
			},
		],
	},
};

image

Nit: Can you update this too?

├── .stylelintrc.json

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • .stylelintrc.json: Language not supported

@im3dabasia im3dabasia force-pushed the try/convert-stylelintrc branch from 7381047 to 8dbf3f7 Compare April 17, 2025 10:22
@im3dabasia
Copy link
Contributor Author

We could make the message more specific as a follow-up:

Well noted, once this PR is shipped. I will create a follow-up targeting the specific enhancement issue. As suggested earlier in this comment #63048 (comment).

stylelintrc.json

I have fixed this now.

Thanks @t-hamano for the review.

@im3dabasia im3dabasia requested a review from t-hamano April 17, 2025 10:27
@im3dabasia im3dabasia requested a review from t-hamano April 17, 2025 12:51
@t-hamano t-hamano merged commit 3d0dae3 into WordPress:trunk Apr 17, 2025
59 of 61 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.8 milestone Apr 17, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…ordPress#69590)

* feat: Convert stylelint file to .js

* fix: Correct folder structure in docs

* chore: Add changelog entry

* chore: Remove changelog entry

* chore: Remove changelog entry

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] stylelint config /packages/stylelint-config [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stylelint: convert configuration from json to JavaScript format
3 participants