amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.87k stars 543 forks source link

Issue with code formatting / line endings #1163

Closed hansmbakker closed 5 months ago

hansmbakker commented 5 months ago

Hi, I am having issues with source formatting and line endings. I am using Windows.

I tried adding https://github.com/gitattributes/gitattributes/blob/master/Web.gitattributes to ensure consistent file handling across platforms (see https://github.com/amzn/style-dictionary/pull/1162/commits/908c413d6a4285f9c766590fdb15bcc522aaf21a) but every time I try to commit it detects wrong formatting (incorrectly). When I run npm run format, it generates a lot of changed files, which disappear when I stage them.

jorenbroekema commented 5 months ago

I think the solution for this is setting your Git config setting core.autocrlf to either auto or input (I personally use auto, also windows user) https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings

I feel like adding gitattributes is a bit overkill since imo windows and posix users working together isn't really a repository-specific thing but rather a more broad issue which is why I think it's better solved by changing your global git config

hansmbakker commented 5 months ago

I feel like adding gitattributes is a bit overkill

I think having gitattributes is still a helpful thing to have - to ensure files are handled correctly? (I noticed this repo was missing one, and added one that felt like made sense for this repo)

I prefer not to use autocrlf - some files like sh files should always be lf, and some (windows-specific) files should always be crlf.