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

Ignore directive adds newline #2137

Open
jonrosner opened this issue Mar 3, 2023 · 1 comment
Open

Ignore directive adds newline #2137

jonrosner opened this issue Mar 3, 2023 · 1 comment

Comments

@jonrosner
Copy link

Description

I have a special JSON syntax allowing interpolations using ${env} notation. Without the directive, beautify would split the interpolation apart across several lines. To mitigate this I add ignore directives around the interpolations before beautification. Unfortunately it still does not provide the expected result.

Input

The code looked like this before beautification:

{
    "hello": /* beautify ignore:start */${world}/* beautify ignore:end */
}

Expected Output

The code should have looked like this after beautification:

{
    "hello": /* beautify ignore:start */${world}/* beautify ignore:end */
}

Actual Output

The code actually looked like this after beautification:

{
    "hello":
    /* beautify ignore:start */${world}/* beautify ignore:end */
}

Steps to Reproduce

const body = `
    {
      "hello": /* beautify ignore:start */${world}/* beautify ignore:end */
    }
`;
const result = beautify(body, { format: 'json' });
console.log(result)

Settings

all default settings

@bitwiseman
Copy link
Member

This correct behavior in the current design. The ignore expects to start on it's own line. The ignore annotation is not designed to handle the level of fine-grained control.

PRs to change this are welcome, but will require a broad set of tests to ensure they behave well.

Instead of trying to ignore parts of a line, perhaps try ignoring the whole line:

{
    /* beautify ignore:start */
    "hello": ${world}
    /* beautify ignore:end */
}

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

No branches or pull requests

2 participants