프로젝트 규칙
내장 KScript 스타일은 CLI와 편집기의 기본값을 설정해요. kscript.json 옆에 kscript.rules.kscript을 두세요. 명령줄과 편집기 모두 프로젝트 파일을 검사하거나 서식을 지정할 때 이 파일을 읽어요.
<Style indent_size="4" print_width="100" />
<Lint code="KS9001" element="img" missing_attribute="alt" message="Give this image alternative text." />
<Format element="img" attributes="one_per_line" />
<Format model="Attachments" options="one_per_line" />Style(indent_size: 4, print_width: 100)
Lint(
code: 'KS9001',
element: 'img',
missing_attribute: 'alt',
message: 'Give this image alternative text.',
)
Format(element: 'img', attributes: 'one_per_line')
Format(model: 'Attachments', options: 'one_per_line')Style은 문서 전체의 서식 기본값을 재정의해요.indent_size,use_tabs,print_width,max_blank_lines,end_of_line및 규칙 끄기에 나열된 스위치를 받아들여요. 서식 지정은 내장 스타일에서 시작한 뒤 편집기 들여쓰기, 프로젝트Style설정, 그리고kscript.json의 명시적format설정을 순서대로 적용해요.Lint은 요소에 대해missing_attribute또는forbidden_attribute을 검사해요. 코드는 고유해야 하며KS9xxx를 사용해야 해요. 기본 심각도는warning예요.severity:를error,warning,info또는hint로 설정하거나,kscript.json에서"lint": { "rules": { "KS9001": "error" } }로 재정의할 수 있어요.Format은 HTML 또는 XML 태그의 속성 배치를one_per_line또는inline로 설정해요. 스크립트 모델의 옵션을 한 줄에 하나씩 나누고 끝에 쉼표를 추가할 수도 있어요. 모든 태그나 모델에 적용하려면'*'를 사용하세요. 이름이 지정된 배치가'*'보다 우선해요.print_width이나use_tabs와 같은 배치 설정에는 숫자나 불리언을 사용하세요. 리터럴 텍스트 설정은 따옴표로 묶으세요.
함수 규칙
규칙이 문서에 따라 달라질 때는 fn(value) => ...을 사용하세요. 이 규칙은 리터럴 alt 속성을 다듬어요. 보간된 속성과 이벤트 또는 바인딩 식은 원래 텍스트를 유지해요.
<Format element="img" attribute="alt" value="fn(text) => $text->trim()" />Format(
element: 'img',
attribute: 'alt',
value: fn(text) => $text->trim(),
)레이아웃 함수는 일반 배치를 사용하도록 'one_per_line', 'inline' 또는 null을 반환해요. 예를 들어, 이 규칙은 빈 블록을 Something(val1, val2) {}로 축약하고, 블록에 내용이 있을 때는 끝에 쉼표를 붙여 인수를 펼쳐요.
<Format statement="Something" arguments="fn(node) => $node.has_body_content ? 'one_per_line' : 'inline'" />Format(
statement: 'Something',
arguments: fn(node) => $node.has_body_content ? 'one_per_line' : 'inline',
)HTML 또는 XML element:와 함께 attributes:을 사용하면 같은 방식으로 배치를 선택할 수 있어요. 함수에 전달되는 노드에는 name, kind, attributes 및 has_body_content가 있어요. 린트 check: 함수는 자체 메시지를 반환하거나, 선언의 메시지를 쓰려면 true를, 진단을 건너뛰려면 false 또는 null을 반환할 수 있어요.
<Lint code="KS9002" element="img" check="fn(node) => $node.attributes->has('alt') ? null : 'An image needs alternative text.'" />Lint(
code: 'KS9002',
element: 'img',
check: fn(node) => $node.attributes->has('alt') ? null : 'An image needs alternative text.',
)함수는 제한된 식 컨텍스트에서 실행되며, 인수, 비교, 조건문, 그리고 trim(), upper(), starts_with() 같은 텍스트 연산에 접근할 수 있어요. 프로젝트 규칙 파일은 선언을 사용하며 패키지를 가져오거나 명령을 호출할 수 없어요.