sass / migrator

Tool for migrating stylesheets to new Sass versions
MIT License
84 stars 10 forks source link

New code at beginning of file should be inserted after BOM #234

Open lwpinion opened 1 year ago

lwpinion commented 1 year ago

Operating System Windows 10

Sass Version 1.55.0 (compiled with dart2js 2.18.1)

Migrator Version 1.7.1 (compiled with dart2js 2.18.0)

After using the migrator on a large number of files, I encountered a bug when it came to the styles on my home page. I dug into it and turns out when the migrator tool inserts the use rule it injected some sort of hidden character along with the line break (see screenshot).

sass-hidden-character

I am on Windows, so perhaps this is due to some sort of discrepancy with the line breaks between operating systems? Visual Studio does notify me on each file that the line endings are inconsistent; however, no matter what option I choose I still get this invisible character.

sass-line-endings

Fwiw, there's no urgency to fix this. I just went through all of my files and deleted that character before each rule.

jathak commented 1 year ago

Can you provide a minimal reproduction with an input file and migrator invocation that causes this error?

Also, is everything entirely running within Windows, or are you using a tool like WSL, or any other intermediate tools that could be messing with the file format?

lwpinion commented 1 year ago

Can you provide a minimal reproduction with an input file and migrator invocation that causes this error?

Are you looking for me to provide something you can use to reproduce the issue? I'm sorry, but I don't fully understand what you are needing.

If it's helpful, I ran sass-migrator --migrate-deps module style.scss on a large centralized stylesheet we use to import all of our partials. It's those partial that ended up with the extra character. The code in each of these files was previously flush at the top, but sass-migrator went through and added the @use statements to the top with the extra line breaks (along with this character) as you can see in my earlier post.

As to your second question, I was using bash inside of Cmder (I prefer bash commands over Windows commands), so I thought there could be something there. However, I tried running sass-migrator with Command Prompt and still got the same issue.

I took my existing files and copied them to a temp folder before running it. Other than that, the only tools I used were Command Prompt and then VS Code to look at the files. Below is a screenshot of how VS Code interprets the invisible character.

image

stof commented 12 months ago

This U+FEFF unicode character is the BOM.

I guess the sass-migrator should ensure that if a file starts with a BOM, it inserts the use statement after it rather than before it. The BOM needs to stay the first thing in the file.