Skip to content

Commit 8e61fc2

Browse files
committed
Change include path for lines of code counting
Previously, we were always using `**` in the include path. the effect of this was to always count lines in the entire repository unless explicitly added to the paths-ignore. This was incorrect behaviour. Now we only using `**` if the include path is otherwise empty.
1 parent a77f6b0 commit 8e61fc2

6 files changed

Lines changed: 30 additions & 6 deletions

File tree

lib/count-loc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/count-loc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/count-loc.test.js

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/count-loc.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/count-loc.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,23 @@ test("ensure lines of code can handle includes", async (t) => {
6363
);
6464

6565
t.deepEqual(results, {
66-
javascript: 15,
66+
javascript: 12,
67+
});
68+
});
69+
70+
test("ensure lines of code can handle empty includes", async (t) => {
71+
// note that "**" is always included. The includes are for extra
72+
// directories outside the normal structure.
73+
const results = await countLoc(
74+
path.join(__dirname, "../tests/multi-language-repo"),
75+
["idontexist"],
76+
[],
77+
[Language.javascript],
78+
getRunnerLogger(true)
79+
);
80+
81+
t.deepEqual(results, {
82+
// should get no results
6783
});
6884
});
6985

src/count-loc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function countLoc(
6969
): Promise<Partial<Record<Language, number>>> {
7070
const result = await new LocDir({
7171
cwd,
72-
include: ["**"].concat(include || []),
72+
include: Array.isArray(include) && include.length > 0 ? include : ["**"],
7373
exclude,
7474
analysisLanguages: dbLanguages.flatMap((lang) => nameToLinguist[lang]),
7575
}).loadInfo();

0 commit comments

Comments
 (0)