Skip to content
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

feat: implemented the valid-style-parse rule #1054

Merged
merged 3 commits into from
Feb 9, 2025

Conversation

marekdedic
Copy link
Contributor

Closes #509

Copy link

changeset-bot bot commented Feb 5, 2025

🦋 Changeset detected

Latest commit: 2ee6d7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@marekdedic marekdedic marked this pull request as ready for review February 5, 2025 10:23
@marekdedic
Copy link
Contributor Author

There is some issue in the pkg.pr.new action, I don't think it's related to anything in this PR...

@ota-meshi ota-meshi force-pushed the valid-style-parse branch 2 times, most recently from b225302 to 72e2ad5 Compare February 6, 2025 00:07
Copy link
Contributor

github-actions bot commented Feb 6, 2025

Try the Instant Preview in Online Playground

ESLint Online Playground

Install the Instant Preview to Your Local

npm i https://pkg.pr.new/eslint-plugin-svelte@1054

Published Instant Preview Packages:

View Commit

@ota-meshi
Copy link
Member

The workflow has been fixed 😄
I've rebased this PR so please apply it to your local too.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

Thank you for this PR!
It looks mostly good to me, but I have a few comments.

@marekdedic marekdedic force-pushed the valid-style-parse branch 3 times, most recently from 5f00210 to e5cc901 Compare February 6, 2025 10:02
@marekdedic
Copy link
Contributor Author

@ota-meshi I can't solve the update error - The update script fails on the invalid CSS, which makes sense. I tried wrapping the writeAndFormat function with a try/catch block, but for some reason, the error isn't getting caught there. I suspect it is actually caught somewhere in prettier and printed to stderr directly from there..

BTW, that function can be simplified to:

export async function writeAndFormat(fileName: string, content: string): Promise<void> {
	fs.writeFileSync(fileName, content, 'utf8');
	const prettierrc = await prettier.resolveConfig(fileName);
	const formatted = await prettier.format(content, { filepath: fileName, ...prettierrc });
	fs.writeFileSync(fileName, formatted, 'utf8');

	const eslint = new ESLint({ fix: true });
	const [result] = await eslint.lintText(formatted, { filePath: fileName });
	if (result.output) {
		fs.writeFileSync(fileName, result.output, 'utf8');
	}
}

@ota-meshi
Copy link
Member

It seems that prettier will output a log and continue processing even if it fails to parse the style.
If we want to avoid logging, we will need to write <!-- prettier-ignore --> above the code block. However, prettier works, so it is not necessary for now.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@ota-meshi ota-meshi merged commit c587629 into sveltejs:main Feb 9, 2025
17 checks passed
@marekdedic marekdedic deleted the valid-style-parse branch February 10, 2025 10:38
@marekdedic
Copy link
Contributor Author

Thanks, I tried adding the prettier ignore commands, but I couldn't get it to work either :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule checking for successful style parsing
2 participants