CRLF를 LF로 수정

00_8_3·2022년 7월 11일

LF를 사용해야 하는 이유

다양한 코딩컨벤션 규칙과 개발자들에게 일관적인 코딩 스타일을 유지할 수 있게 도와주는 툴인 Prettier에서는 CRLF대신 LF사용을 권고하고 있다.

LF를 사용하는 이유는 협업때문인데 CRLF와 LF의 바이트 코드가 다르기 때문에 형상관리 툴에서 다른 코드로 인식함으로 Commit할 때 줄바꿈 타입이 다른 경우 변경하지 않은 파일에 대해서도 변경된 것으로 인식하기 때문에 LF로 통일하는 것이다.

수정 방법

1. IDE로 일일이 수정

vsCode 우측 하단의 CRLF를 클릭 후 LF로 수정

2. .editorconfig 사용

  • EditorConfig for VS Code 익스텐션 설치
  • 루트에 .editorconfig 파일 생성
root = true
[*.{ts,js,json}]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 8

3. .gitattributes 사용

  • 루트에 .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

4. dos2unix 사용

윈도우 사용자의 경우 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

http://daplus.net/linux-%EC%A0%84%EC%B2%B4-%EB%94%94%EB%A0%89%ED%86%A0%EB%A6%AC%EC%97%90%EC%84%9C-dos2unix%EB%A5%BC-%EC%96%B4%EB%96%BB%EA%B2%8C-%EC%8B%A4%ED%96%89%ED%95%A0-%EC%88%98-%EC%9E%88%EC%8A%B5%EB%8B%88/

https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command

0개의 댓글