-
-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathcode-checker.texy
More file actions
78 lines (54 loc) · 3.05 KB
/
code-checker.texy
File metadata and controls
78 lines (54 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Nette Code Checker
******************
.[perex]
[Code Checker |https://github.com/nette/code-checker] は、目に見えない BOM、制御文字、壊れたエンコーディング、PHP・Latte・NEON・JSON・YAML ファイルの不正な構文といった形式的な欠陥がないかソースファイルをチェックし、自動的に修正できます。
インストール
======
Composer を使ってグローバルにインストールします:
```shell
composer global require nette/code-checker
```
グローバルな Composer の `bin` ディレクトリが [`$PATH` に含まれている |https://getcomposer.org/doc/03-cli.md#global] ことを確認してください。そうすれば `code-checker` コマンドは、どのオペレーティングシステムでも、どこからでも利用できます。
あるいは、スタンドアロンのプロジェクトとしてインストールすることもできます:
```shell
composer create-project nette/code-checker
```
PHP 8.0 以上が必要です。
使い方
===
デフォルトでは、Code Checker は読み取り専用モードで動作し、見つかった問題を報告するだけです:
```shell
code-checker
```
実際にファイルを修復するには `--fix` を追加します。先にファイルをバックアップするか、あとで `git diff` で変更を確認できるよう、クリーンな作業ツリー上で実行してください:
```shell
code-checker --fix
```
スキャンを特定のパスに限定したり、ファイルをスキップしたり、より高速な構文のみのチェックを実行したりできます:
```shell
code-checker -d src --ignore "temp/*"
code-checker --only-syntax
```
読み取り専用モードでは、すべて問題がなければ終了コード `0`、何らかの問題が見つかれば `1` で終了するため、CI パイプラインにうまく組み込めます。
オプションの完全な一覧:
```
Usage: code-checker [options]
Options:
-d <path> Folder or file to scan (default: current directory)
-i | --ignore <mask> Files to ignore
-f | --fix Fix the files
-l | --eol Normalize line endings to the system default
--only-syntax Check syntax only (faster)
--no-progress Do not show progress dots
--version Show version
```
Code Checker の機能
================
- [Latte |latte:] テンプレートおよび `.php`、`.neon`、`.json` ファイルの構文をチェックします
- [BOM |nette:glossary#BOM] を除去します
- ファイルが有効な UTF-8 であることを検証します
- [制御文字 |nette:glossary#制御文字] をチェックします
- 不正な形式の phpDoc コメント(例: `/** @var` ではなく `/* @var`)を検出します
- PHP、CSS、JS、TS ファイルではタブによるインデントを、YAML ではスペースを強制します
- 行末の空白とファイル末尾の空行を除去します
- 行末記号をシステムのデフォルトに正規化します(`-l` パラメータ使用時)