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

Is there a way to preserve the file as-is and do not autoformat at all? #643

Open
frydj opened this issue Aug 22, 2022 · 5 comments
Open

Comments

@frydj
Copy link

frydj commented Aug 22, 2022

Trying to use this because it's already working, but I need to preserve the line numbers as they actually exist in the file. Is there any recommended way to do this? Using mainly for React JS files.

@panoply
Copy link

panoply commented Aug 22, 2022

In this release, you can leverage ignore comments:

// parse-ignore-start 
function () {}
// parse-ignore-end 

@frydj
Copy link
Author

frydj commented Aug 22, 2022

@panoply thanks for your answer! this seems to get closer, but not quite identical.

I'm comparing 2 files side by side using "diff"; certain things are preventing it from having 100% line match. For example, in my file the closing button tag </button> is on it's own line (formatted using prettier), but in the prettydiff comparison the </button> is not on its own line, and also has an extra space so looks like < /button>.

@panoply
Copy link

panoply commented Aug 22, 2022

Likey a defect pertaining in the markup lexer which happens when handling JSX. Prettier and PrettyDiff handle input in vastly different manners, PrettyDiff generates a data structure whereas Prettier is working with external parsers to product an AST. Sparser is what is producing the structures in PrettyDiff.

Based on the work I have done in Prettify (FYI: Diffing is not available in Prettify), I can say with certainty there are several defects pertaining to JSX processing and resulting output. It's hard to give you a definitive or solution tbh.

You could also try block comments /* parse-ignore-start */.

@frydj
Copy link
Author

frydj commented Aug 22, 2022

@panoply I thought about what you said before ... what I had done previously was wrap my prettydiff() function with the comments. What I changed it to now was to actually inject the string "// parse-ignore-start" (and end) into my diff/source objects.

now I'm really close - the only problem is that it isn't enforcing the line's character limit (120 characters) ... so off by a few lines. trying to find a way to enforce this but not parse anything else. I appreciate your help on this!

@panoply
Copy link

panoply commented Aug 22, 2022

You need to set wrap limit, eg:

prettydiff.options.wrap = 120
prettydiff()

Bare in mind that Prettier might be problem here and not PrettyDiff. Prettier defaults to a 80 character word wrap.

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

No branches or pull requests

2 participants