Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/exercism/lines-of-code-counter


https://github.com/exercism/lines-of-code-counter

community-contributions-paused

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Exercism's Lines of Code Counter

![Tests](https://github.com/exercism/lines-of-code-counter/workflows/Test/badge.svg)

This is Exercism's Lines of Code (LoC) Counter.
It takes a solution and counts its lines of code.

## Implementation

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.

### Ignore additional files

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 `.ignore` file inside the `tracks` directory (e.g. [`tracks/csharp.ignore`](./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](https://ruby-doc.org/stdlib-2.6.1/libdoc/pathname/rdoc/Pathname.html#method-i-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:

```gitignore
*Test.cs
```

## Run the Lines of Code Counter

To count the lines of code of an arbitrary solution, do the following:

1. Open a terminal in the project's root
2. Run `./bin/run.sh `

Once the test runner has finished, its results will be written to `/response.json`.

## Run the Lines of Code Counter on a solution using Docker

_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:

1. Open a terminal in the project's root
2. Run `./bin/run-in-docker.sh `

Once the test runner has finished, its results will be written to `/response.json`.

## Run the tests

To run the tests to verify the behavior of the Lines of Code Counter, do the following:

1. Open a terminal in the project's root
2. Run `./bin/run-tests.sh`

These are [golden tests][golden] that compare the `response.json` generated by running the current state of the code against the "known good" `tests//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//response.json` file.

## Run the tests using Docker

_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:

1. Open a terminal in the project's root
2. Run `./bin/run-tests-in-docker.sh`

These are [golden tests][golden] that compare the `response.json` generated by running the current state of the code against the "known good" `tests//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//response.json` file.

## Credit

This repo is built and maintained by Exercism.

Contributions are welcome!

The actual counting of the LoC is done using [our fork][fork] of the [tokei][tokei] tool, which is both extremely fast and [supports many languages](https://github.com/XAMPPRocky/tokei#supported-languages).
Please submit any PRs to both [our fork][fork] _and_ the [tokei repo][tokei].

[test-runners]: https://github.com/exercism/automated-tests/blob/master/docs/introduction.md
[golden]: https://ro-che.info/articles/2017-12-04-golden-tests
[exercism]: https://exercism.io
[fork]: https://github.com/exercism/tokei
[tokei]: https://github.com/XAMPPRocky/tokei