This is Exercism's Lines of Code (LoC) Counter. It takes a solution and counts its lines of code.
By default, we'll only count the LoC of files submitted by the student.
If the student submitted a test file (which we identify via the files.test
array in the exercise's .meta/config.json
file), we'll ignore those.
While this works well for most submissions, it doesn't work if the submission's exercise has test files with a different naming scheme than the files listed in the .meta/config.json
file.
This can only really occur for submission that are linked to older exercises which didn't have a .meta/config.json
file at the time.
To ignore additional files (like the above test files) from being included in the LoC count, each track can define a <slug>.ignore
file inside the tracks
directory (e.g. tracks/csharp.ignore
).
Inside this file, you can define rules to exclude certain file paths from the LoC count.
The rules are matched using File.fnmatch, which uses standard globbing syntax.
As an example, the C# track excludes old *Test.cs
files (renamed since to *Tests.cs
) using the following ignore file:
*Test.cs
To count the lines of code of an arbitrary solution, do the following:
- Open a terminal in the project's root
- Run
./bin/run.sh <track-slug> <submission-dir>
Once the test runner has finished, its results will be written to <submission-dir>/response.json
.
This script is provided for testing purposes, as it mimics how the Lines of Code Counter runs in Exercism's production environment.
To count the lines of code of an arbitrary solution using the Docker image, do the following:
- Open a terminal in the project's root
- Run
./bin/run-in-docker.sh <track-slug> <submission-dir>
Once the test runner has finished, its results will be written to <submission-dir>/response.json
.
To run the tests to verify the behavior of the Lines of Code Counter, do the following:
- Open a terminal in the project's root
- Run
./bin/run-tests.sh
These are golden tests that compare the response.json
generated by running the current state of the code against the "known good" tests/<test-name>/response.json
. All files created during the test run itself are discarded.
When you've made modifications to the code that will result in a new "golden" state, you'll need to generate and commit a new tests/<test-name>/response.json
file.
This script is provided for testing purposes, as it mimics how the Lines of Code Counter runs in Exercism's production environment.
To run the tests to verify the behavior of the test runner using the Docker image, do the following:
- Open a terminal in the project's root
- Run
./bin/run-tests-in-docker.sh
These are golden tests that compare the response.json
generated by running the current state of the code against the "known good" tests/<test-name>/response.json
. All files created during the test run itself are discarded.
When you've made modifications to the code that will result in a new "golden" state, you'll need to generate and commit a new tests/<test-name>/response.json
file.
This repo is built and maintained by Exercism.
Contributions are welcome!
The actual counting of the LoC is done using the tokei tool, which is both extremely fast and supports many languages.