다양한 코딩컨벤션 규칙과 개발자들에게 일관적인 코딩 스타일을 유지할 수 있게 도와주는 툴인 Prettier에서는 CRLF대신 LF사용을 권고하고 있다.
LF를 사용하는 이유는 협업때문인데 CRLF와 LF의 바이트 코드가 다르기 때문에 형상관리 툴에서 다른 코드로 인식함으로 Commit할 때 줄바꿈 타입이 다른 경우 변경하지 않은 파일에 대해서도 변경된 것으로 인식하기 때문에 LF로 통일하는 것이다.
vsCode 우측 하단의 CRLF를 클릭 후 LF로 수정
EditorConfig for VS Code 익스텐션 설치.editorconfig 파일 생성root = true
[*.{ts,js,json}]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 8
.gitattributes 생성# Automatically normalize line endings for all text-based files
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
* text=auto
# For the following file types, normalize line endings to LF on
# checkin and prevent conversion to CRLF when they are checked out
# (this is required in order to prevent newline related issues like,
# for example, after the build script is run)
.* text eol=lf
*.css text eol=lf
*.html text eol=lf
*.jade text eol=lf
*.js text eol=lf
*.json text eol=lf
*.less text eol=lf
*.scss text eol=lf
*.md text eol=lf
*.sh text eol=lf
*.txt text eol=lf
*.xml text eol=lf
*.ts text eol=lf
윈도우 사용자의 경우 bash나 wsl을 이용.
기본 명령어
dos2unix test.txt test.txt 파일 하나를 LF로 수정.
응용
find . -path ./node_modules -prune -o -print0 | xargs -0 dos2unix
./node_modules폴더를 제외한 파일들을 LF로 수정.
https://prettier.io/docs/en/options.html#end-of-line
https://sysops.tistory.com/135
https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command