handlebars를 린트할 수 있는 방법이 있나요?

Discourse에서 Handlebars 파일을 린트할 방법을 찾고 있었습니다. 명령어는 실행되는 것 같지만, 변경 사항이 없거나 문제가 목록으로 표시되지 않습니다.

yarn ember-template-lint --fix path/to/files

이 시점에서 이 명령어가 실제로 동작해야 하는지조차 확신이 서지 않습니다.

yarn ember-template-lint <dir>가 올바른 명령어여야 합니다.

감사합니다. 하지만 아무것도 보고되지 않는 것 같아요. 손상된 파일에서 실행해 봤는데, 오류를 표시하거나 수정하지 않아요.

@cvx 방금 플러그인 워크플로우에서 이 기능을 구현하셨네요. 이 기능을 사용하려면 특별히 해야 할 일이 있나요?

마법이 필요하지 않아요 :slightly_smiling_face: 하지만 Discourse 루트 디렉터리에서 명령을 실행하는지 꼭 확인하세요. 이 문제로 이미 몇 번이나 발목을 잡혔거든요.

비교해 보세요:

# in [discourse]/app/assets/javascripts
$ yarn ember-template-lint .
✨  Done in 2.57s.
# in [discourse]
$ yarn ember-template-lint app/assets/javascripts
app/assets/javascripts/discourse/app/templates/tags.hbs
  4:0  error  Unexpected {{debugger}} usage.  no-debugger
  4:0  error  Usage of triple curly brackets is unsafe  no-triple-curlies
  3:15  error  Incorrect indentation for `d-section` beginning at L1:C0. Expected `{{/d-section}}` ending at L3:C15 to be at an indentation of 0 but was found at 1.  block-indentation
  2:4  error  Incorrect indentation for `{{outlet}}` beginning at L2:C4. Expected `{{outlet}}` to be at an indentation of 2 but was found at 4.  block-indentation
  1:23  error  you must use double quotes in templates  quotes

✖ 5 problems (5 errors, 0 warnings)
error Command failed with exit code 1.

또한, 이 도구가 우리의 설정(.template-lintrc.js)을 사용하므로 일부 규칙이 현재 비활성화되어 있어 예상되는 모든 문제를 보고하지 않을 수 있다는 점도 염두에 두세요.


@justin 방금 깨달았는데, 현재 플러그인 GitHub Actions 워크플로우에서 이 설정을 공유하지 않고 있네요. 언젠가 이 부분을 변경해야 할 것 같습니다. :smiley:

plugins/에서 실행되나요? @fzngagan님이 이 기능을 여기에 사용하길 원하실 것 같습니다.

플러그인이 plugins 디렉토리에 있는 경우, 당연히 됩니다! :smiley:

$ yarn ember-template-lint plugins
plugins/poll/assets/javascripts/discourse/templates/modal/poll-breakdown.hbs
  1:22  error  you must use double quotes in templates  quotes

제가 같은 일을 하고 있는 것 같긴 한데, 한 번 더 시도해서 알려드릴게요.

ember template lint는 모든 문제를 수정할 수 없으며, eslint와도 같습니다. 실제로 eslint와 달리 ember template lint는 매우 제한적인 것만 수정할 수 있습니다.

대부분은 오류를 보고할 뿐, 직접 수정해야 합니다.

지금까지 시도해 본 내용은 다음과 같습니다.

discourse 자체의 규칙을 위반하여 시도했습니다. 동작합니다

discourse 디렉토리에 심볼릭 링크로 존재하는 discourse-custom-wizard 플러그인의 규칙을 위반하여 시도했습니다. 동작하지 않습니다

discourse 저장소의 일부인 poll 플러그인에서도 동일하게 시도했습니다. 또한 discourse에 기본으로 포함된 다른 플러그인에서도 시도했습니다. 동작합니다

discourse-custom-wizard 플러그인의 규칙을 위반하여 다시 시도했는데, 이번에는 플러그인을 discourse의 플러그인 폴더로 복사했습니다. 동작하지 않습니다

discourse-assign 플러그인의 폴더를 plugins에 배치하고 규칙을 위반하여 시도했습니다. 동작하지 않습니다

제 경우에는:

동작하는 경우

yarn ember-template-lint plugins/discourse-pfaffmanager/assets/javascripts/discourse/templates/user/servers/show.hbs 

동작하지 않는 경우

yarn ember-template-lint plugins/discourse-pfaffmanager/assets/javascripts/discourse/templates/user/servers/

그리고 제 assets는 app 안에 있어야 하나요?

아, 그렇군요. 문제는 ember-template-lint가 .gitignore를 자동으로 고려한다는 점입니다. 그리고 번들링되지 않은 플러그인은 무시됩니다.

따라서 모든 플러그인에 대한 템플릿 린팅을 실행하려면:

yarn ember-template-lint --no-ignore-pattern plugins

# 또는 기타 디렉터리, 예: 단일 플러그인:
yarn ember-template-lint --no-ignore-pattern plugins/discourse-calendar

고마워요. 완벽하게 작동해요.

감사합니다! 그런데 자동으로 수정되게 하는 방법이 있을까요? --fix를 추가해 봤는데 효과가 없었어요.

동작은 하지만:

  1. 자동 수정이 가능한 규칙은 일부뿐입니다 (참고: GitHub - ember-template-lint/ember-template-lint: Linter for Ember or Handlebars templates · GitHub)
  2. 그중에서도 “권장” 규칙 세트에 포함된 것은 단 두 가지뿐입니다 (link-rel-noopener 및 require-button-type)