Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid analyzing excluded language files for line counting
This change passes in a list of file types to the line counting
analysis. These are the languages for the databases being analyzed.
Line count analysis is restricted to these files.
Andrew Eisenberg committed Apr 28, 2021
1 parent 5c0a38d commit ee23462
Showing 31 changed files with 436 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.test.js.map
10 changes: 9 additions & 1 deletion lib/count-loc.js
2 changes: 1 addition & 1 deletion lib/count-loc.js.map
51 changes: 51 additions & 0 deletions lib/count-loc.test.js
1 change: 1 addition & 0 deletions lib/count-loc.test.js.map
6 changes: 6 additions & 0 deletions lib/testdata/testFile3.js
1 change: 1 addition & 0 deletions lib/testdata/testFile3.js.map
31 changes: 31 additions & 0 deletions node_modules/github-linguist/.vscode/launch.json
2 changes: 1 addition & 1 deletion node_modules/github-linguist/dist/cli.js.map
8 changes: 8 additions & 0 deletions node_modules/github-linguist/dist/directory.d.ts
94 changes: 93 additions & 1 deletion node_modules/github-linguist/dist/directory.js
2 changes: 1 addition & 1 deletion node_modules/github-linguist/dist/directory.js.map
6 changes: 1 addition & 5 deletions node_modules/github-linguist/dist/file.d.ts
17 changes: 5 additions & 12 deletions node_modules/github-linguist/dist/file.js
2 changes: 1 addition & 1 deletion node_modules/github-linguist/dist/file.js.map
4 changes: 4 additions & 0 deletions node_modules/github-linguist/dist/languages.d.ts
7 changes: 7 additions & 0 deletions node_modules/github-linguist/dist/languages.js
2 changes: 1 addition & 1 deletion node_modules/github-linguist/dist/languages.js.map
2 changes: 1 addition & 1 deletion node_modules/github-linguist/package.json
3 changes: 0 additions & 3 deletions node_modules/github-linguist/src/cli.ts
95 changes: 94 additions & 1 deletion node_modules/github-linguist/src/directory.ts
18 changes: 5 additions & 13 deletions node_modules/github-linguist/src/file.ts
8 changes: 8 additions & 0 deletions node_modules/github-linguist/src/languages.ts
2 changes: 1 addition & 1 deletion src/analyze.test.ts
@@ -20,7 +20,7 @@ setupTests(test);
// paths are set in the database analyze invocation.
test("status report fields and search path setting", async (t) => {
const mockLinesOfCode = Object.entries(Language).reduce((obj, [lang], i) => {
// use a different line count for each languaged
// use a different line count for each language
obj[lang] = i + 1;
return obj;
}, {});
2 changes: 1 addition & 1 deletion src/analyze.ts
@@ -151,7 +151,7 @@ export async function runQueries(
// config.paths specifies external directories. the current
// directory is included in the analysis by default. Replicate
// that here.
["**"].concat(config.paths || []),
config.paths,
config.pathsIgnore,
config.languages,
logger
81 changes: 81 additions & 0 deletions src/count-loc.test.ts
@@ -0,0 +1,81 @@
import * as path from "path";

import test from "ava";

import { countLoc } from "./count-loc";
import { getRunnerLogger } from "./logging";
import { setupTests } from "./testing-utils";

setupTests(test);

test("ensure lines of code works for cpp and js", async (t) => {
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),
[],
[],
["cpp", "js"],
getRunnerLogger(true)
);

t.deepEqual(results, {
cpp: 6,
js: 3,
});
});

test("ensure lines of code can handle undefined language", async (t) => {
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),
[],
[],
["rb", "py", "hucairz"],
getRunnerLogger(true)
);

t.deepEqual(results, {
rb: 6,
py: 5,
});
});

test("ensure lines of code can handle empty languages", async (t) => {
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),
[],
[],
[],
getRunnerLogger(true)
);

t.deepEqual(results, {});
});

test("ensure lines of code can handle includes", async (t) => {
// note that "**" is always included. The includes are for extra
// directories outside the normal structure.
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),
["../../src/testdata"],
[],
["js"],
getRunnerLogger(true)
);

t.deepEqual(results, {
js: 15,
});
});

test("ensure lines of code can handle exclude", async (t) => {
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),
[],
["**/*.py"],
["rb", "py"],
getRunnerLogger(true)
);

t.deepEqual(results, {
rb: 6,
});
});
16 changes: 15 additions & 1 deletion src/count-loc.ts
@@ -15,6 +15,17 @@ const supportedLanguages = {
typescript: "js",
};

const supportedLanguagesReversed = Object.entries(supportedLanguages).reduce(
(obj, [key, value]) => {
if (!obj[value]) {
obj[value] = [];
}
obj[value].push(key);
return obj;
},
{}
);

/**
* Count the lines of code of the specified language using the include
* and exclude glob paths.
@@ -34,8 +45,11 @@ export async function countLoc(
): Promise<Record<string, number>> {
const result = await new LocDir({
cwd,
include,
include: ["**"].concat(include || []),
exclude,
analysisLanguages: dbLanguages.flatMap(
(lang) => supportedLanguagesReversed[lang]
),
}).loadInfo();

// The analysis counts LoC in all languages. We need to
4 changes: 4 additions & 0 deletions src/testdata/testFile3.ts
@@ -0,0 +1,4 @@
var a;
var b;
var c;
var d;

0 comments on commit ee23462

Please sign in to comment.