プログラムを書いていて、プロジェクト全体の行数がいくつになるかカウントしたいという時がたまにあります。

そんなときにAtomの拡張パッケージであるline-countが手軽に使えたので記録しておきます。

プロジェクト全体の行数カウント

ちょっとした規模のプログラムを作成しその規模を他者に伝えたいということがたまにあります。

そんな時にプロジェクト全体の行数をカウントして伝えるのが手っ取り早いのですが、案外この計上は面倒だったりします。

私はエディターとしてAtomを使用しているので、これに使えそうなパッケージを探してみることにしました。

その結果、line-countというパッケージがこの用途に使えそうということが判明しました。

line-count

line-countというAtomの拡張パッケージが存在します。

プロジェクト内の使用言語をそれぞれ、ファイル毎、ディレクトリ毎、合計のソース本体、コメント、合計の行数をそれぞれカウントしてくれます。

プロジェクト全体の規模を手軽に計上できる便利なパッケージですね。

CryptoMatorでカウントを試してみる

例えば以下はCryptoMator(Java製)の行数カウントです。

実行はAtomメニューのPackage→Line Countから実行可能です。

実行結果を以下に示します。行数のみを抽出して表にしたのが次になります。

言語 ソース本体 コメント 合計
Java 6002 849 8047
CSS 1332 307 1864
XML 778 46 886
合計 8112 1202 10797

実行結果を見ると、ファイル、ディレクトリ、言語をそれぞれ別にカウントしていることが分かります。

Line counts for project C:\xxx\cryptomator-develop.
Generated by the Atom editor package Line-Count on January 15 2019 00:00.
Counts are in order of source, comments, and total.

Files
-----
   38    0   38  main/ant-kit/assembly.xml
   92    3   99  main/ant-kit/pom.xml
   43    4   52  main/ant-kit/src/main/resources/build.xml
   39    3   45  main/commons/pom.xml
   15    5   26  main/commons/src/main/java/org/cryptomator/common/CommonsModule.java
    5    5   13  main/commons/src/main/java/org/cryptomator/common/ConsumerThrowingException.java
   45   24   79  main/commons/src/main/java/org/cryptomator/common/LazyInitializer.java
   10   13   28  main/commons/src/main/java/org/cryptomator/common/Optionals.java
    5    5   13  main/commons/src/main/java/org/cryptomator/common/RunnableThrowingException.java
   54   20   81  main/commons/src/main/java/org/cryptomator/common/SemVerComparator.java
    5    5   13  main/commons/src/main/java/org/cryptomator/common/SupplierThrowingException.java
   72   12  104  main/commons/src/main/java/org/cryptomator/common/settings/Settings.java
   90    5  108  main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java
  116   13  140  main/commons/src/main/java/org/cryptomator/common/settings/SettingsProvider.java
  113    7  148  main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java
   75    6   91  main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java
   20   10   34  main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java
   36   11   58  main/commons/src/test/java/org/cryptomator/common/SemVerComparatorTest.java
   24    9   37  main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java
   22    8   38  main/commons/src/test/java/org/cryptomator/common/settings/SettingsTest.java
   21    5   34  main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java
   13    8   26  main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsTest.java
   38    3   45  main/keychain/pom.xml
    6   20   31  main/keychain/src/main/java/org/cryptomator/keychain/KeychainAccess.java
    4    8   15  main/keychain/src/main/java/org/cryptomator/keychain/KeychainAccessStrategy.java
   30    5   43  main/keychain/src/main/java/org/cryptomator/keychain/KeychainModule.java
   32    5   49  main/keychain/src/main/java/org/cryptomator/keychain/MacSystemKeychainAccess.java
  165    9  194  main/keychain/src/main/java/org/cryptomator/keychain/WindowsProtectedKeychainAccess.java
   14    5   24  main/keychain/src/test/java/org/cryptomator/keychain/KeychainModuleTest.java
   26    5   39  main/keychain/src/test/java/org/cryptomator/keychain/MapKeychainAccess.java
    9    5   20  main/keychain/src/test/java/org/cryptomator/keychain/TestKeychainComponent.java
    9    5   19  main/keychain/src/test/java/org/cryptomator/keychain/TestKeychainModule.java
   51    5   65  main/keychain/src/test/java/org/cryptomator/keychain/WindowsProtectedKeychainAccessTest.java
   20   10   33  main/keychain/src/test/resources/log4j2.xml
   41    3   48  main/launcher/pom.xml
   10    5   20  main/launcher/src/main/java/org/cryptomator/launcher/ApplicationVersion.java
   28    5   40  main/launcher/src/main/java/org/cryptomator/launcher/CleanShutdownPerformer.java
   44    7   63  main/launcher/src/main/java/org/cryptomator/launcher/Cryptomator.java
   42    7   58  main/launcher/src/main/java/org/cryptomator/launcher/FileOpenRequestHandler.java
    4    5   10  main/launcher/src/main/java/org/cryptomator/launcher/InterProcessCommunicationProtocol.java
  202   25  274  main/launcher/src/main/java/org/cryptomator/launcher/InterProcessCommunicator.java
   11    5   23  main/launcher/src/main/java/org/cryptomator/launcher/LauncherComponent.java
   50    5   68  main/launcher/src/main/java/org/cryptomator/launcher/LauncherModule.java
   31    7   45  main/launcher/src/main/java/org/cryptomator/launcher/MainApplication.java
   57    9   81  main/launcher/src/main/java/org/cryptomator/logging/DebugMode.java
   11    8   25  main/launcher/src/main/java/org/cryptomator/logging/LaunchBasedTriggeringPolicy.java
   59    5   76  main/launcher/src/test/java/org/cryptomator/launcher/FileOpenRequestHandlerTest.java
   83    6  100  main/launcher/src/test/java/org/cryptomator/launcher/InterProcessCommunicatorTest.java
   21    8   38  main/launcher/src/test/java/org/cryptomator/logging/LaunchBasedTriggeringPolicyTest.java
   16    1   20  main/launcher/src/test/resources/logback-test.xml
  304   10  335  main/pom.xml
   46    0   48  main/uber-jar/pom.xml
   16    1   20  main/uber-jar/src/main/resources/logback.xml
   85    8  103  main/ui/pom.xml
  175   17  218  main/ui/src/main/java/org/cryptomator/ui/ExitUtil.java
   71    9   91  main/ui/src/main/java/org/cryptomator/ui/UiModule.java
  144   20  199  main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java
  116   16  164  main/ui/src/main/java/org/cryptomator/ui/controllers/InitializeController.java
  464   36  558  main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java
   18    6   31  main/ui/src/main/java/org/cryptomator/ui/controllers/NotFoundController.java
  142   10  184  main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java
  365   45  469  main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java
  215   19  275  main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java
  120   17  162  main/ui/src/main/java/org/cryptomator/ui/controllers/UpgradeController.java
   16    7   31  main/ui/src/main/java/org/cryptomator/ui/controllers/ViewController.java
   14    5   23  main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerKey.java
   38    5   53  main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerLoader.java
   61    5   78  main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerModule.java
  162   14  195  main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java
   80    8  105  main/ui/src/main/java/org/cryptomator/ui/controls/DirectoryListCell.java
  107   11  140  main/ui/src/main/java/org/cryptomator/ui/controls/DraggableListCell.java
   36   23   68  main/ui/src/main/java/org/cryptomator/ui/controls/SecPasswordField.java
   75    6   96  main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java
   77    5   95  main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java
   62    4   78  main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java
  105    5  128  main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java
    3    0    5  main/ui/src/main/java/org/cryptomator/ui/model/InvalidSettingsException.java
   21    5   33  main/ui/src/main/java/org/cryptomator/ui/model/UpgradeStrategies.java
   93   26  137  main/ui/src/main/java/org/cryptomator/ui/model/UpgradeStrategy.java
   65    5   82  main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3DropBundleExtension.java
  138   14  170  main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3to4.java
  138   18  167  main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion4to5.java
   52    6   70  main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion5toX.java
  237   27  302  main/ui/src/main/java/org/cryptomator/ui/model/Vault.java
   13    5   25  main/ui/src/main/java/org/cryptomator/ui/model/VaultComponent.java
   23    8   40  main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java
   99    5  133  main/ui/src/main/java/org/cryptomator/ui/model/VaultList.java
   46    5   63  main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java
   42   17   75  main/ui/src/main/java/org/cryptomator/ui/model/Volume.java
  110    5  131  main/ui/src/main/java/org/cryptomator/ui/model/WebDavVolume.java
   36    5   51  main/ui/src/main/java/org/cryptomator/ui/model/WindowsDriveLetters.java
   40    8   61  main/ui/src/main/java/org/cryptomator/ui/util/DialogBuilderUtil.java
   67    9   90  main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java
  141   11  192  main/ui/src/main/java/org/cryptomator/ui/util/Tasks.java
  402  103  576  main/ui/src/main/resources/css/linux_theme.css
  480  101  656  main/ui/src/main/resources/css/mac_theme.css
  450  103  632  main/ui/src/main/resources/css/win_theme.css
    7    0   10  main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationMock.java
   74   17   94  main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java
  138   10  164  main/ui/src/test/java/org/cryptomator/ui/model/UpgradeVersion3to4Test.java
   16    0   20  main/ui/src/test/java/org/cryptomator/ui/util/PasswordStrengthUtilTest.java

Directories
-----------
  8112  1202  10797  main
   173     7    189  main/ant-kit
    43     4     52  main/ant-kit/src
    43     4     52  main/ant-kit/src/main
    43     4     52  main/ant-kit/src/main/resources
   780   174   1116  main/commons
   741   171   1071  main/commons/src
   625   130    878  main/commons/src/main
   625   130    878  main/commons/src/main/java
   625   130    878  main/commons/src/main/java/org
   625   130    878  main/commons/src/main/java/org/cryptomator
   625   130    878  main/commons/src/main/java/org/cryptomator/common
   486    53    625  main/commons/src/main/java/org/cryptomator/common/settings
   116    41    193  main/commons/src/test
   116    41    193  main/commons/src/test/java
   116    41    193  main/commons/src/test/java/org
   116    41    193  main/commons/src/test/java/org/cryptomator
   116    41    193  main/commons/src/test/java/org/cryptomator/common
    80    30    135  main/commons/src/test/java/org/cryptomator/common/settings
   404    85    577  main/keychain
   366    82    532  main/keychain/src
   237    47    332  main/keychain/src/main
   237    47    332  main/keychain/src/main/java
   237    47    332  main/keychain/src/main/java/org
   237    47    332  main/keychain/src/main/java/org/cryptomator
   237    47    332  main/keychain/src/main/java/org/cryptomator/keychain
   129    35    200  main/keychain/src/test
   109    25    167  main/keychain/src/test/java
   109    25    167  main/keychain/src/test/java/org
   109    25    167  main/keychain/src/test/java/org/cryptomator
   109    25    167  main/keychain/src/test/java/org/cryptomator/keychain
    20    10     33  main/keychain/src/test/resources
   710   111    989  main/launcher
   669   108    941  main/launcher/src
   490    88    707  main/launcher/src/main
   490    88    707  main/launcher/src/main/java
   490    88    707  main/launcher/src/main/java/org
   490    88    707  main/launcher/src/main/java/org/cryptomator
   422    71    601  main/launcher/src/main/java/org/cryptomator/launcher
    68    17    106  main/launcher/src/main/java/org/cryptomator/logging
   179    20    234  main/launcher/src/test
   163    19    214  main/launcher/src/test/java
   163    19    214  main/launcher/src/test/java/org
   163    19    214  main/launcher/src/test/java/org/cryptomator
   142    11    176  main/launcher/src/test/java/org/cryptomator/launcher
    21     8     38  main/launcher/src/test/java/org/cryptomator/logging
    16     1     20  main/launcher/src/test/resources
    62     1     68  main/uber-jar
    16     1     20  main/uber-jar/src
    16     1     20  main/uber-jar/src/main
    16     1     20  main/uber-jar/src/main/resources
  5679   814   7523  main/ui
  5594   806   7420  main/ui/src
  5359   779   7132  main/ui/src/main
  4027   472   5268  main/ui/src/main/java
  4027   472   5268  main/ui/src/main/java/org
  4027   472   5268  main/ui/src/main/java/org/cryptomator
  4027   472   5268  main/ui/src/main/java/org/cryptomator/ui
  1875   205   2422  main/ui/src/main/java/org/cryptomator/ui/controllers
   223    42    313  main/ui/src/main/java/org/cryptomator/ui/controls
    75     6     96  main/ui/src/main/java/org/cryptomator/ui/l10n
  1360   165   1785  main/ui/src/main/java/org/cryptomator/ui/model
   248    28    343  main/ui/src/main/java/org/cryptomator/ui/util
  1332   307   1864  main/ui/src/main/resources
  1332   307   1864  main/ui/src/main/resources/css
   235    27    288  main/ui/src/test
   235    27    288  main/ui/src/test/java
   235    27    288  main/ui/src/test/java/org
   235    27    288  main/ui/src/test/java/org/cryptomator
   235    27    288  main/ui/src/test/java/org/cryptomator/ui
    81    17    104  main/ui/src/test/java/org/cryptomator/ui/l10n
   138    10    164  main/ui/src/test/java/org/cryptomator/ui/model
    16     0     20  main/ui/src/test/java/org/cryptomator/ui/util

Types
-----
  1332  307  1864  css
  6002  849  8047  java
   778   46   886  xml

Total
-----
  8112  1202  10797

line-countの注意点

お手軽なパッケージですが、注意点は以下の2つです。

  • 除外ディレクトリはnode_modulesのみ。個別に指定できない
  • 部分ディレクトリのカウントはできない

パッケージのToDoにフィルタリングの実装が記載されていますが、最終メンテが1年前なので、機能追加は厳しいかもしれません。

まとめ

  • プロジェクト全体の行数カウントを行いたい
  • Atomならline-countが手軽に実行できる
  • フィルタリング機能がないのが注意点