Skip to content

fix: Ensure languageOptions.customSyntax is serializable #212

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented Jul 24, 2025

Prerequisites checklist

What is the purpose of this pull request?

Ensures that languageOptions.customSyntax is serializable by replacing all functions with true. CSSTree allows functions in its config and we need to account for that to allow things like caching in ESLint.

What changes did you make? (Give an overview)

  • Added CSSLanguage#normalizeLanguageOptions() that adds a toJSON method when the customSyntax option is present
  • Updated the CSSLanguage tests to validate the new functionality works.
  • Updated the plugin test to ensure we get the expected results when run through ESLint.

Related Issues

fixes #211

Is there anything you'd like reviewers to focus on?

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jul 24, 2025
@nzakas nzakas requested a review from Copilot July 24, 2025 15:37
@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Jul 24, 2025
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.

Pull Request Overview

This PR addresses a serialization issue with ESLint configuration by ensuring that languageOptions.customSyntax containing functions can be properly serialized to JSON. This is necessary for ESLint features like configuration caching.

  • Added normalizeLanguageOptions() method to handle serialization of customSyntax configurations
  • Enhanced test coverage for both unit and integration scenarios
  • Updated JSDoc documentation for consistency

Reviewed Changes

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

File Description
src/languages/css-language.js Implements serialization logic with normalizeLanguageOptions() method and helper function
tests/languages/css-language.test.js Unit tests for the new normalization functionality
tests/plugin/eslint.test.js Integration tests validating serialization behavior through ESLint

* @param {CSSLanguageOptions} languageOptions The language options to normalize.
* @returns {CSSLanguageOptions} The normalized language options.
*/
normalizeLanguageOptions(languageOptions) {
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The method modifies the input object by adding a toJSON property. Consider returning a new object instead of mutating the input to avoid side effects and make the API more predictable.

Copilot uses AI. Check for mistakes.

@lumirlumir lumirlumir added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jul 25, 2025
@fasttime fasttime moved this from Needs Triage to Triaging in Triage Aug 5, 2025
Comment on lines +168 to +171
Object.defineProperty(languageOptions, "toJSON", {
value() {
// Shallow copy
const result = { ...languageOptions };
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to set the toJSON method on a shallow clone of the argument (results) so that the original object isn't modified?

Suggested change
Object.defineProperty(languageOptions, "toJSON", {
value() {
// Shallow copy
const result = { ...languageOptions };
// Shallow copy
const result = { ...languageOptions };
Object.defineProperty(result, "toJSON", {
value() {

We'd need to change the return value of the function as well and update some unit tests.

Comment on lines +58 to +59
* @param {Record<string,any>} object The object to process.
* @returns {Record<string,any>} A copy of the object with all functions replaced by true.
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this function also returns arrays and non-object values depending on the type of the argument?

@fasttime fasttime moved this from Triaging to Implementing in Triage Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug Something isn't working
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

Bug: provided syntax object is not JSON-serializable, which causes ESLint to crash in certain situations
3 participants