Upgrade linguist dependency

This version changes how it counts python heredoc. All heredoc is
counted as code.
This commit is contained in:
Andrew Eisenberg 2021-08-25 10:45:44 -07:00
parent a44b61d961
commit b29bf7b05a
32 changed files with 410 additions and 339 deletions

6
node_modules/.package-lock.json generated vendored
View file

@ -2960,9 +2960,9 @@
}
},
"node_modules/github-linguist": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.3.tgz",
"integrity": "sha512-hKWn1QQ+9oUyOIcUhPzi6AxTcAkYHg4OOwK79Pr05SBTFmdNr7GQkMDJabSGCZwu7SDhEb5YeUwUGqrUfyo7PA==",
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.4.tgz",
"integrity": "sha512-QSw/HfSTqA13t7eqNeGLd62ghnTsTQAUrJQKkUG100NZqqzpsKB9c7gH7lFaGU1ZWGmNSWfhG6q1Ok/xotOA/g==",
"dependencies": {
"chalk": "^2.2.0",
"commander": "^2.11.0",

1
node_modules/github-linguist/.eslintcache generated vendored Normal file
View file

@ -0,0 +1 @@
[{"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/cli.ts":"1","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/directory.ts":"2","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/file.ts":"3","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/index.ts":"4","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/languages.ts":"5","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/utils.ts":"6","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/declarations.d.ts":"7"},{"size":1802,"mtime":1629757721099,"results":"8","hashOfConfig":"9"},{"size":4764,"mtime":1629758968321,"results":"10","hashOfConfig":"9"},{"size":4177,"mtime":1629759033403,"results":"11","hashOfConfig":"9"},{"size":751,"mtime":1629758749896,"results":"12","hashOfConfig":"9"},{"size":5651,"mtime":1629759502034,"results":"13","hashOfConfig":"14"},{"size":541,"mtime":1629758671936,"results":"15","hashOfConfig":"9"},{"size":25,"mtime":1629758437358,"results":"16","hashOfConfig":"9"},{"filePath":"17","messages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1ug2nbr",{"filePath":"19","messages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"21","messages":"22","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"23","messages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","errorCount":1,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"1okz2by",{"filePath":"27","messages":"28","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"29","messages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/cli.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/directory.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/file.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/index.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/languages.ts",["31"],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/utils.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/declarations.d.ts",[],{"ruleId":"32","severity":2,"message":"33","line":4,"column":21,"nodeType":"34","messageId":"35","endLine":4,"endColumn":44},"@typescript-eslint/no-var-requires","Require statement not part of import statement.","CallExpression","noVarReqs"]

View file

@ -1,3 +1,38 @@
module.exports = {
extends: [require.resolve('@umijs/fabric/dist/eslint')],
root: true,
extends: [
'eslint-config-airbnb-base',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
env: {
node: true,
es6: true,
jest: true,
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts']
}
}
},
rules: {
'import/extensions': 'off',
'no-await-in-loop': 'off',
'no-console': 'off',
'class-methods-use-this': 'off',
'no-continue': 'off',
'@typescript-eslint/naming-convention': { format: 'camelCase' },
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true },
],
},
};

View file

@ -1,26 +1,34 @@
name: Node CI
on: [push]
on:
- push
- workflow_dispatch
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: [10.x, 12.x]
node_version: [12.x, 14.x]
os: [ubuntu-latest, windows-latest]
steps:
- run: git config --global core.autocrlf false
if: matrix.os == 'windows-latest'
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- run: echo ${{github.ref}}
- run: yarn
- run: yarn run lint
- run: yarn run test
- run: npm ci
- run: npm run lint
- run: npm run test
env:
CI: true
PROGRESS: none
NODE_ENV: test
NODE_OPTIONS: --max_old_space_size=4096

View file

@ -1,5 +1,15 @@
const fabric = require('@umijs/fabric');
module.exports = {
...fabric.prettier,
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
proseWrap: 'never',
endOfLine: 'lf',
overrides: [
{
files: '.prettierrc',
options: {
parser: 'json',
},
},
],
};

View file

@ -6,26 +6,13 @@
"configurations": [
{
"name": "Launch Tests",
"program": "${workspaceFolder}/node_modules/.bin/umi-test",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"args": ["--testNamePattern", "example dir info"]
},
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist/index.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
"args": ["--testNamePattern", "example dir info"]
}
]
}

View file

@ -63,7 +63,7 @@ const dir = new LocDir({
include: // string or string[] containing path patterns to include (default include all)
exclude: // string or string[] containing path patterns to exclude (default exclude none)
});
const { info } = dir.getInfo();
const { info } = dir.loadInfo();
```
## License

View file

@ -15,7 +15,7 @@ commander_1.default
.description('count lines of code in a file')
.action(async (pathPattern) => {
try {
const info = await (new file_1.LocFile(pathPattern).getFileInfo());
const info = await new file_1.LocFile(pathPattern).getFileInfo();
// eslint-disable-next-line no-console
console.log(chalk_1.default.cyan(`
path: \t\t${pathPattern}
@ -42,9 +42,9 @@ const formatInfo = (info, languages) => `
.join('')}`;
commander_1.default.arguments('<cmd> [env]').action(async (cmd) => {
try {
const { info, languages } = await (new directory_1.LocDir({
include: cmd
}).loadInfo());
const { info, languages } = await new directory_1.LocDir({
include: cmd,
}).loadInfo();
// eslint-disable-next-line no-console
console.log(chalk_1.default.cyan(formatInfo(info, languages)));
}

View file

@ -1 +1 @@
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAC1B,0DAAgC;AAEhC,2CAAqC;AACrC,iCAA2C;AAC3C,mCAAqC;AAErC,mBAAO;KACJ,OAAO,CAAC,kBAAU,EAAE,EAAE,IAAI,CAAC;KAC3B,OAAO,CAAC,aAAa,CAAC;KACtB,WAAW,CAAC,+BAA+B,CAAC;KAC5C,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;IAC5B,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,cAAO,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,sCAAsC;QACtC,OA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BAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}

View file

@ -7,7 +7,6 @@ exports.LocDir = void 0;
const globby_1 = __importDefault(require("globby"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const file_1 = require("./file");
const languages_1 = require("./languages");
@ -26,16 +25,16 @@ const defaultExclude = [
'**/*.snap',
// java
'**/target',
"**/*.class",
"**/*.o",
"**/bin",
"**/*.map",
'**/*.class',
'**/*.o',
'**/bin',
'**/*.map',
// python
"**/*.pyc",
"**/*.pyo",
'**/*.pyc',
'**/*.pyo',
// other
"**/*.dil",
"**/*.ra",
'**/*.dil',
'**/*.ra',
// images
'**/*.png',
'**/*.jpg',
@ -97,6 +96,12 @@ const defaultExclude = [
'**/*.tbz',
'**/*.tgz',
];
function ensureArray(arr, dfault) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr) ? arr : [arr];
}
/**
* Collect the info of a directory.
*/
@ -136,12 +141,12 @@ class LocDir {
// that end in .ts because the globstar indicates 0 or more directory paths.
this.exclude = ensureArray(options.exclude)
.concat(defaultExclude)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
// remove all leading './' since this messes up globstar matches in the
// excludes.
this.include = ensureArray(options.include, '**')
.map(item => item.startsWith('./') ? item.substring(2) : item)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.startsWith('./') ? item.substring(2) : item))
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
this.cwd = options.cwd || process.cwd();
this.analysisLanguages = options.analysisLanguages;
}
@ -152,13 +157,14 @@ class LocDir {
const paths = await globby_1.default(this.include, {
cwd: this.cwd,
ignore: this.exclude,
nodir: true
nodir: true,
});
const files = [];
const info = { ...defaultInfo };
let languages = {};
// We _could_ use Promise.all to count the files in parallel, but that
// would lead to out of memory errors when there are many files.
// eslint-disable-next-line no-restricted-syntax
for (const pathItem of paths) {
const fullPath = slash2_1.default(path_1.default.join(this.cwd, pathItem));
if (!pathItem ||
@ -195,16 +201,9 @@ class LocDir {
* and this language is not one of them.
*/
ignoreLanguage(pathItem) {
return this.analysisLanguages && !this.analysisLanguages.includes(this.allLanguages.getType(pathItem));
return (this.analysisLanguages &&
!this.analysisLanguages.includes(this.allLanguages.getType(pathItem)));
}
}
exports.LocDir = LocDir;
function ensureArray(arr, dfault) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr)
? arr
: [arr];
}
//# sourceMappingURL=directory.js.map

View file

@ -1 +1 @@
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,wDAA0B;AAC1B,gDAAwB;AACxB,aAAa;AACb,oDAA2B;AAE3B,iCAA2C;AAC3C,2CAAwC;AAExC,MAAM,WAAW,GAAa;IAC5B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;CACX,CAAC;AAmBF,MAAM,cAAc,GAAG;IACrB,aAAa;IACb,UAAU;IACV,WAAW;IACX,YAAY;IACZ,oBAAoB;IACpB,YAAY;IACZ,WAAW;IAEX,OAAO;IACP,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,UAAU;IAEV,SAAS;IACT,UAAU;IACV,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,SAAS;IAET,SAAS;IACT,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,UAAU;IACV,SAAS;IACT,SAAS;IACT,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,WAAW;IACX,YAAY;IACZ,UAAU;IACV,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IACV,WAAW;IAEX,QAAQ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,CAAC"}
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,wDAA0B;AAC1B,gDAAwB;AACxB,oDAA2B;AAE3B,iCAA2C;AAC3C,2CAAwC;AAExC,MAAM,WAAW,GAAa;IAC5B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;CACX,CAAC;AAmBF,MAAM,cAAc,GAAG;IACrB,aAAa;IACb,UAAU;IACV,WAAW;IACX,YAAY;IACZ,oBAAoB;IACpB,YAAY;IACZ,WAAW;IAEX,OAAO;IACP,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,UAAU;IAEV,SAAS;IACT,UAAU;IACV,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,SAAS;IAET,SAAS;IACT,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,UAAU;IACV,SAAS;IACT,SAAS;IACT,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,WAAW;IACX,YAAY;IACZ,UAAU;IACV,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IACV,WAAW;IAEX,QAAQ;IACR,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IAEV,SAAS;IACT,UAAU;IACV,WAAW;IACX,WAAW;IACX,UAAU;IACV,WAAW;IACX,UAAU;IACV,WAAW;IAEX,YAAY;IACZ,UAAU;IACV,WAAW;IACX,WAAW;IAEX,WAAW;IACX,UAAU;IACV,UAAU;IACV,SAAS;IACT,UAAU;IACV,SAAS;IACT,UAAU;IACV,SAAS;IACT,UAAU;IACV,UAAU;CACX,CAAC;AAEF,SAAS,WAAW,CAAC,GAAuB,EAAE,MA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M,QAAQ,GAAG,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1D,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;YAClD,QAAQ,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACvC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;YAC3D,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;YACrD,SAAS,GAAG;gBACV,GAAG,SAAS;gBACZ,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,QAAQ;aACnC,CAAC;YACF,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACtB;QAED,OAAO;YACL,KAAK;YACL,IAAI;YACJ,SAAS;SACV,CAAC;IACJ,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,QAAgB;QACrC,OAAO,CACL,IAAI,CAAC,iBAAiB;YACtB,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CACtE,CAAC;IACJ,CAAC;CACF;AA7FD,wBA6FC"}

View file

@ -27,8 +27,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocFile = void 0;
const fs = __importStar(require("fs-extra"));
const Path = __importStar(require("path"));
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const languages_1 = require("./languages");
const DefaultLine = {
@ -84,15 +82,16 @@ class LocFile {
let codeLength = lines.length;
const total = codeLength;
let inMultiLineComment = false;
lines.forEach((line) => {
lines.forEach((origLine) => {
var _a, _b, _c, _d, _e, _f;
let lineType = 'code';
line = line.trim();
const line = origLine.trim();
if (inMultiLineComment) {
let noCode = true;
if (regexes.multiLineCommentClose.test(line)) {
if ((_a = regexes.multiLineCommentClose) === null || _a === void 0 ? void 0 : _a.test(line)) {
// line contains the end of a multi-line comment
inMultiLineComment = false;
if (!regexes.multiLineCommentCloseEnd.test(line)) {
if (!((_b = regexes.multiLineCommentCloseEnd) === null || _b === void 0 ? void 0 : _b.test(line))) {
// the multiline comment does not end this line.
// there is real code on it.
noCode = false;
@ -106,21 +105,21 @@ class LocFile {
}
else if (line) {
// non-empty line
if (regexes.multiLineCommentOpen.test(line)) {
if ((_c = regexes.multiLineCommentOpen) === null || _c === void 0 ? void 0 : _c.test(line)) {
// line contains the start of a multi-line comment
// might contain some real code, but we'll let that slide
if (!regexes.multiLineCommentOpenAndClose.test(line)) {
if (!((_d = regexes.multiLineCommentOpenAndClose) === null || _d === void 0 ? void 0 : _d.test(line))) {
// comment is not also closed on this line
inMultiLineComment = true;
}
if (regexes.multiLineCommentOpenStart.test(line)) {
if ((_e = regexes.multiLineCommentOpenStart) === null || _e === void 0 ? void 0 : _e.test(line)) {
// The comment starts the line. There is no other code on this line
commentLength += 1;
codeLength -= 1;
lineType = 'comm';
}
}
else if (regexes.singleLineComment.test(line)) {
else if ((_f = regexes.singleLineComment) === null || _f === void 0 ? void 0 : _f.test(line)) {
// line contains only a single line comment
commentLength += 1;
codeLength -= 1;
@ -155,14 +154,16 @@ class LocFile {
throw new Error(`Error: file ${this.rawPath} does not exist.`);
}
let newData = data;
const info = Object.assign({}, DefaultFileInfo);
const name = this.path.split(Path.sep).pop() || '';
const info = { ...DefaultFileInfo };
// note: do not use Path.sep here since we have already
// translated the path to a posix path using slash(...).
const name = this.path.split('/').pop() || '';
try {
const stat = await fs.stat(this.path);
if (!stat.isFile()) {
return info;
}
newData = data || await fs.readFile(this.path, 'utf-8');
newData = data || (await fs.readFile(this.path, 'utf-8'));
info.name = name;
info.size = (stat && stat.size) || 0;
info.languages = this.languages.getType(this.path);
@ -180,7 +181,7 @@ class LocFile {
return info;
}
getFileInfoByContent(name, data) {
const info = Object.assign({}, DefaultFileInfo);
const info = { ...DefaultFileInfo };
info.name = name;
info.languages = this.languages.getType(name);
info.lines = this.filterData(data, this.languages.getRegexes(info.languages));

View file

@ -1 +1 @@
{"version":3,"file":"file.js","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAC/B,2CAA6B;AAC7B,aAAa;AACb,oDAA2B;AAE3B,2CAAiD;AAejD,MAAM,WAAW,GAAa;IAC5B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,eAAe,GAAa;IAChC,IAAI,EAAE,EAAE;IACR,SAAS,EAAE,EAAE;IACb,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,WAAW;CACnB,CAAC;AAEF;;GAEG;AACH,MAAa,OAAO;IAMlB;;OAEG;IACH,YAAY,OAAe,EAAU,QAAQ,KAAK;;;;;mBAAb;;QARrC;;;;;WAAoB;QACpB;;;;;WAAwB;QAExB;;;;mBAAoB,IAAI,qBAAS,EAAE;WAAC;QAUpC;;;;mBAAqB,CAAC,IAAY,EAAE,OAAgB,EAAY,EAAE;gBAChE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,aAAa,GAAG,CAAC,CAAC;gBACtB,IAAI,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;gBAC9B,MAAM,KAAK,GAAG,UAAU,CAAC;gBAEzB,IAAI,kBAAkB,GAAG,KAAK,CAAC;gBAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBAErB,IAAI,QAAQ,GAAG,MAAM,CAAC;oBACtB,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,C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,MAAM,IAAI,GAAa,EAAE,GAAG,eAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAC9E,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/HD,0BA+HC"}

View file

@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const directory_1 = require("./directory");

View file

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,aAAa;AACb,oDAA2B;AAC3B,wDAA0B;AAE1B,2CAAgD;AAChD,iCAAiC;AAEjC,yCAAoD;AAA3C,mGAAA,MAAM,OAAA;AACf,+BAA2C;AAAlC,+FAAA,OAAO,OAAA;AAEhB,MAAM,GAAG,GAAG,KAAK,EACf,SAAiB,EACG,EAAE;IACtB,MAAM,IAAI,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,gBAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAI,cAAO,CAAC,gBAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,KA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,CAAC,EAAE,GAAG,EAAE,gBAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF,kBAAe,GAAG,CAAC"}

View file

@ -1,4 +1,10 @@
export interface DetectorOptions {
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen?: RegExp;
multiLineCommentOpenStart?: RegExp;
multiLineCommentClose?: RegExp;
multiLineCommentCloseEnd?: RegExp;
multiLineCommentOpenAndClose?: RegExp;
}
/**
* detecte program language through file extension
@ -37,11 +43,3 @@ export declare class Languages {
*/
getType(path: string): string;
}
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen: RegExp;
multiLineCommentOpenStart: RegExp;
multiLineCommentClose: RegExp;
multiLineCommentCloseEnd: RegExp;
multiLineCommentOpenAndClose: RegExp;
}

View file

@ -1,9 +1,11 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Languages = void 0;
const languages_json_1 = __importDefault(require("language-map/languages.json"));
const utils_1 = require("./utils");
// tslint:disable-next-line
const languageMap = require('language-map');
/**
* The extension map can contain multiple languages with the same extension,
* but we only want a single one. For the moment, these clashes are resolved
@ -12,7 +14,70 @@ const languageMap = require('language-map');
* where the extension is ambiguous. The ordering of the list matters and
* languages earlier on will get a higher priority when resolving clashes.
*/
const importantLanguages = ["javascript", "typescript", "ruby", "python", "java", "c", "c++", "c#", "rust", "scala", "perl", "go"];
const importantLanguages = [
'javascript',
'typescript',
'ruby',
'python',
'java',
'c',
'c++',
'c#',
'rust',
'scala',
'perl',
'go',
];
const ALL_REGEXES = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//,
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/,
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/,
},
};
/**
* detecte program language through file extension
*
@ -39,8 +104,8 @@ class Languages {
writable: true,
value: () => {
const extensions = {};
Object.keys(languageMap).forEach((language) => {
const languageMode = languageMap[language];
Object.keys(languages_json_1.default).forEach((language) => {
const languageMode = languages_json_1.default[language];
const languageExtensions = (languageMode && languageMode.extensions) || [];
languageExtensions.forEach((extension) => {
const lowerCaseExtension = extension.toLowerCase();
@ -61,7 +126,7 @@ class Languages {
}
});
});
return Object.assign({}, extensions, utils_1.ExtensionJustify);
return { ...extensions, ...utils_1.ExtensionJustify };
}
});
this.extensionMap = this.loadExtensionMap();
@ -102,66 +167,4 @@ class Languages {
}
}
exports.Languages = Languages;
const ALL_REGEXES = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
// matches when """ starts a line. This is not right, since
// a multiline string is not always a comment, but for the
// sake of simplicity, we will do that here.
multiLineCommentOpen: /"""/,
// matches when """ starts a line
multiLineCommentOpenStart: /^"""/,
// matches when """ exists in a line
multiLineCommentClose: /"""/,
// matches when """ ends a line
multiLineCommentCloseEnd: /"""$/,
// matches """ ... """
multiLineCommentOpenAndClose: /""".*"""/
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/
}
};
//# sourceMappingURL=languages.js.map

View file

@ -1 +1 @@
{"version":3,"file":"languages.js","sourceRoot":"","sources":["../src/languages.ts"],"names":[],"mappings":";;;AAAA,mCAA2C;AAE3C,2BAA2B;AAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAU5C;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAGnI;;;;;GAKG;AACH,MAAa,SAAS;I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AAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;CACF;AAnFD,8BAmFC"}

View file

@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionJustify = exports.getVersion = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const packagePath = slash2_1.default(path_1.default.join(__dirname, '../', 'package.json'));
/**

View file

@ -1 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,aAAa;AACb,oDAA2B;AAE3B,MAAM,WAAW,GAAG,gBAAK,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;AAEvE;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAErE,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC;AACpE,CAAC;AAJD,gCAIC;AAEY,QAAA,gBAAgB,GAAG;IAC9B,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;CACrB,CAAC"}
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,oDAA2B;AAE3B,MAAM,WAAW,GAAG,gBAAK,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;AAEvE;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAErE,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC;AACpE,CAAC;AAJD,gCAIC;AAEY,QAAA,gBAAgB,GAAG;IAC9B,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;CACrB,CAAC"}

14
node_modules/github-linguist/jest.config.ts generated vendored Normal file
View file

@ -0,0 +1,14 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/
export default {
// Automatically clear mock calls and instances between every test
clearMocks: true,
// Indicates whether each individual test should be reported during the run
verbose: undefined,
preset: 'ts-jest',
};

View file

@ -1,12 +1,11 @@
{
"name": "github-linguist",
"version": "2.4.3",
"version": "2.4.4",
"description": "A tool to count lines of code in a repository powered by github-linguist langauge mappings.",
"keywords": [
"loc",
"cloc",
"linguist",
"umijs",
"lines of code"
],
"homepage": "https://github.com/aeisenberg/linguist#readme",
@ -33,10 +32,10 @@
},
"scripts": {
"build": "tsc -d",
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint": "eslint --cache --ext .ts ./src",
"prettier": "prettier -c --write \"**/*\"",
"prepublishOnly": "npm run build",
"test": "umi-test"
"test": "jest"
},
"dependencies": {
"chalk": "^2.2.0",
@ -52,15 +51,22 @@
"@types/commander": "^2.11.0",
"@types/fs-extra": "^4.0.2",
"@types/globby": "^6.1.0",
"@types/jest": "^25.1.5",
"@types/jest": "^27.0.1",
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.45",
"@umijs/fabric": "^2.0.7",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"eslint": "^6.8.0",
"prettier": "^2.0.2",
"typescript": "^3.8.3",
"umi-test": "^1.9.6"
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.1",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^3.9.10"
}
}

View file

@ -13,7 +13,7 @@ program
.description('count lines of code in a file')
.action(async (pathPattern) => {
try {
const info = await (new LocFile(pathPattern).getFileInfo());
const info = await new LocFile(pathPattern).getFileInfo();
// eslint-disable-next-line no-console
console.log(
chalk.cyan(`
@ -52,9 +52,9 @@ const formatInfo = (
program.arguments('<cmd> [env]').action(async (cmd) => {
try {
const { info, languages } = await (new LocDir({
include: cmd
}).loadInfo());
const { info, languages } = await new LocDir({
include: cmd,
}).loadInfo();
// eslint-disable-next-line no-console
console.log(chalk.cyan(formatInfo(info, languages)));
} catch (e) {

2
node_modules/github-linguist/src/declarations.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
declare module 'slash2';
declare module 'language-map/languages.json';

View file

@ -1,7 +1,6 @@
import globby from 'globby';
import fs from 'fs-extra';
import path from 'path';
// @ts-ignore
import slash from 'slash2';
import { LineInfo, LocFile } from './file';
@ -41,18 +40,18 @@ const defaultExclude = [
// java
'**/target',
"**/*.class",
"**/*.o",
"**/bin",
"**/*.map",
'**/*.class',
'**/*.o',
'**/bin',
'**/*.map',
// python
"**/*.pyc",
"**/*.pyo",
'**/*.pyc',
'**/*.pyo',
// other
"**/*.dil",
"**/*.ra",
'**/*.dil',
'**/*.ra',
// images
'**/*.png',
@ -122,29 +121,39 @@ const defaultExclude = [
'**/*.tgz',
];
function ensureArray(arr?: string[] | string, dfault?: string) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr) ? arr : [arr];
}
/**
* Collect the info of a directory.
*/
export class LocDir {
private cwd: string;
private include: string[];
private exclude: string[];
private analysisLanguages?: string[];
private allLanguages = new Languages();
constructor(options: LocDirOptions) {
// ensure all excludes are globstar. Note that '**/*.ts/**' matches files
// that end in .ts because the globstar indicates 0 or more directory paths.
this.exclude = ensureArray(options.exclude)
.concat(defaultExclude)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
// remove all leading './' since this messes up globstar matches in the
// excludes.
this.include = ensureArray(options.include, '**')
.map(item => item.startsWith('./') ? item.substring(2) : item)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.startsWith('./') ? item.substring(2) : item))
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
this.cwd = options.cwd || process.cwd();
this.analysisLanguages = options.analysisLanguages;
}
@ -156,7 +165,7 @@ export class LocDir {
const paths = await globby(this.include, {
cwd: this.cwd,
ignore: this.exclude,
nodir: true
nodir: true,
});
const files: string[] = [];
const info: LineInfo = { ...defaultInfo };
@ -168,6 +177,7 @@ export class LocDir {
// We _could_ use Promise.all to count the files in parallel, but that
// would lead to out of memory errors when there are many files.
// eslint-disable-next-line no-restricted-syntax
for (const pathItem of paths) {
const fullPath = slash(path.join(this.cwd, pathItem));
if (
@ -178,6 +188,7 @@ export class LocDir {
) {
continue;
}
const file = new LocFile(fullPath);
const fileLineInfo = await file.getFileInfo();
const { lines } = fileLineInfo;
@ -208,15 +219,9 @@ export class LocDir {
* and this language is not one of them.
*/
private ignoreLanguage(pathItem: string): boolean {
return this.analysisLanguages && !this.analysisLanguages.includes(this.allLanguages.getType(pathItem));
return (
this.analysisLanguages &&
!this.analysisLanguages.includes(this.allLanguages.getType(pathItem))
);
}
}
function ensureArray(arr?: string[] | string, dfault?: string) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr)
? arr
: [arr];
}

View file

@ -3,8 +3,6 @@
*/
import * as fs from 'fs-extra';
import * as Path from 'path';
// @ts-ignore
import slash from 'slash2';
import { Languages, Regexes } from './languages';
@ -40,6 +38,7 @@ const DefaultFileInfo: FileInfo = {
*/
export class LocFile {
public path: string;
private rawPath: string;
private languages = new Languages();
@ -59,18 +58,16 @@ export class LocFile {
const total = codeLength;
let inMultiLineComment = false;
lines.forEach((line) => {
lines.forEach((origLine) => {
let lineType = 'code';
line = line.trim();
const line = origLine.trim();
if (inMultiLineComment) {
let noCode = true;
if (regexes.multiLineCommentClose.test(line)) {
if (regexes.multiLineCommentClose?.test(line)) {
// line contains the end of a multi-line comment
inMultiLineComment = false;
if (!regexes.multiLineCommentCloseEnd.test(line)) {
if (!regexes.multiLineCommentCloseEnd?.test(line)) {
// the multiline comment does not end this line.
// there is real code on it.
noCode = false;
@ -82,33 +79,29 @@ export class LocFile {
commentLength += 1;
codeLength -= 1;
}
} else if (line) {
// non-empty line
if (regexes.multiLineCommentOpen.test(line)) {
if (regexes.multiLineCommentOpen?.test(line)) {
// line contains the start of a multi-line comment
// might contain some real code, but we'll let that slide
if (!regexes.multiLineCommentOpenAndClose.test(line)) {
if (!regexes.multiLineCommentOpenAndClose?.test(line)) {
// comment is not also closed on this line
inMultiLineComment = true;
}
if (regexes.multiLineCommentOpenStart.test(line)) {
if (regexes.multiLineCommentOpenStart?.test(line)) {
// The comment starts the line. There is no other code on this line
commentLength += 1;
codeLength -= 1;
lineType = 'comm';
}
} else if (regexes.singleLineComment.test(line)) {
} else if (regexes.singleLineComment?.test(line)) {
// line contains only a single line comment
commentLength += 1;
codeLength -= 1;
lineType = 'comm';
}
} else {
// empty line
codeLength -= 1;
@ -116,7 +109,7 @@ export class LocFile {
}
if (this.debug) {
console.log(lineType, line)
console.log(lineType, line);
}
});
@ -137,14 +130,16 @@ export class LocFile {
}
let newData = data;
const info: FileInfo = Object.assign({}, DefaultFileInfo);
const name = this.path.split(Path.sep).pop() || '';
const info: FileInfo = { ...DefaultFileInfo };
// note: do not use Path.sep here since we have already
// translated the path to a posix path using slash(...).
const name = this.path.split('/').pop() || '';
try {
const stat = await fs.stat(this.path);
if (!stat.isFile()) {
return info;
}
newData = data || await fs.readFile(this.path, 'utf-8');
newData = data || (await fs.readFile(this.path, 'utf-8'));
info.name = name;
info.size = (stat && stat.size) || 0;
info.languages = this.languages.getType(this.path);
@ -162,7 +157,7 @@ export class LocFile {
}
public getFileInfoByContent(name: string, data: string): FileInfo {
const info: FileInfo = Object.assign({}, DefaultFileInfo);
const info: FileInfo = { ...DefaultFileInfo };
info.name = name;
info.languages = this.languages.getType(name);
info.lines = this.filterData(data, this.languages.getRegexes(info.languages));

View file

@ -1,4 +1,3 @@
// @ts-ignore
import slash from 'slash2';
import fs from 'fs-extra';
@ -8,9 +7,7 @@ import { LocFile } from './file';
export { LocDir, LocDirOptions } from './directory';
export { LocFile, LineInfo } from './file';
const loc = async (
fileOrDir: string,
): Promise<LocResult> => {
const loc = async (fileOrDir: string): Promise<LocResult> => {
const stat = await fs.stat(slash(fileOrDir));
if (stat.isFile()) {
const locFile = new LocFile(slash(fileOrDir));

View file

@ -1,16 +1,10 @@
import languageMap from 'language-map/languages.json';
import { ExtensionJustify } from './utils';
// tslint:disable-next-line
const languageMap = require('language-map');
// tslint:disable-next-line
// const lang = require('language-classifier');
interface ExtensionsTypes {
[key: string]: string;
}
export interface DetectorOptions {}
/**
* The extension map can contain multiple languages with the same extension,
* but we only want a single one. For the moment, these clashes are resolved
@ -19,8 +13,116 @@ export interface DetectorOptions {}
* where the extension is ambiguous. The ordering of the list matters and
* languages earlier on will get a higher priority when resolving clashes.
*/
const importantLanguages = ["javascript", "typescript", "ruby", "python", "java", "c", "c++", "c#", "rust", "scala", "perl", "go"];
const importantLanguages = [
'javascript',
'typescript',
'ruby',
'python',
'java',
'c',
'c++',
'c#',
'rust',
'scala',
'perl',
'go',
];
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen?: RegExp;
multiLineCommentOpenStart?: RegExp;
multiLineCommentClose?: RegExp;
multiLineCommentCloseEnd?: RegExp;
multiLineCommentOpenAndClose?: RegExp;
}
const ALL_REGEXES: Record<string, Regexes> = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//,
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
// matches when """ starts a line. This is not right, since
// a multiline string is not always a comment, but for the
// sake of simplicity, we will do that here.
// multiLineCommentOpen: /"""/,
// matches when """ starts a line
// multiLineCommentOpenStart: /^"""/,
// matches when """ exists in a line
// multiLineCommentClose: /"""/,
// matches when """ ends a line
// multiLineCommentCloseEnd: /"""$/,
// matches """ ... """
// multiLineCommentOpenAndClose: /""".*"""/,
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/,
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/,
},
};
/**
* detecte program language through file extension
@ -51,11 +153,13 @@ export class Languages {
const languageExtensions = (languageMode && languageMode.extensions) || [];
languageExtensions.forEach((extension: string) => {
const lowerCaseExtension = extension.toLowerCase();
const lowerCaseLanguage = language.toLowerCase()
const lowerCaseLanguage = language.toLowerCase();
if (!extensions[lowerCaseExtension]) {
extensions[lowerCaseExtension] = lowerCaseLanguage;
} else {
const currentLanguagePriority = importantLanguages.indexOf(extensions[lowerCaseExtension]);
const currentLanguagePriority = importantLanguages.indexOf(
extensions[lowerCaseExtension],
);
if (currentLanguagePriority === -1) {
extensions[lowerCaseExtension] = lowerCaseLanguage;
} else {
@ -67,8 +171,8 @@ export class Languages {
});
});
return Object.assign({}, extensions, ExtensionJustify);
}
return { ...extensions, ...ExtensionJustify };
};
/**
* Retrieve the regular expressions for a given language.
@ -78,7 +182,7 @@ export class Languages {
* @param language the language to retrieve regexes for
*/
public getRegexes(language: string): Regexes {
switch(language) {
switch (language) {
case 'html':
case 'xml':
return ALL_REGEXES.html;
@ -105,104 +209,8 @@ export class Languages {
/**
* get file type through a path
*/
public getType(path: string): string {
public getType(path: string): string {
const fileExtension = `.${path.split('.').pop()}`;
return this.extensionMap[fileExtension] || '';
}
}
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen: RegExp;
multiLineCommentOpenStart: RegExp;
multiLineCommentClose: RegExp;
multiLineCommentCloseEnd: RegExp;
multiLineCommentOpenAndClose: RegExp;
}
const ALL_REGEXES: Record<string, Regexes> = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
// matches when """ starts a line. This is not right, since
// a multiline string is not always a comment, but for the
// sake of simplicity, we will do that here.
multiLineCommentOpen: /"""/,
// matches when """ starts a line
multiLineCommentOpenStart: /^"""/,
// matches when """ exists in a line
multiLineCommentClose: /"""/,
// matches when """ ends a line
multiLineCommentCloseEnd: /"""$/,
// matches """ ... """
multiLineCommentOpenAndClose: /""".*"""/
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/
}
};

View file

@ -1,6 +1,5 @@
import fs from 'fs';
import path from 'path';
// @ts-ignore
import slash from 'slash2';
const packagePath = slash(path.join(__dirname, '../', 'package.json'));

View file

@ -13,7 +13,8 @@
"sourceMap": true,
"paths": {
"*": ["node_modules/*", "src/types/*"]
}
},
"resolveJsonModule": true
},
"include": ["src/**/*"]
"include": ["src/**/*", "test/declarations.d.ts"]
}

18
package-lock.json generated
View file

@ -24,7 +24,7 @@
"fast-deep-equal": "^3.1.3",
"file-url": "^3.0.0",
"fs": "0.0.1-security",
"github-linguist": "^2.4.3",
"github-linguist": "^2.4.4",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
"jsonschema": "1.2.6",
@ -1505,6 +1505,7 @@
"dependencies": {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
"fsevents": "~2.1.2",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
@ -3014,9 +3015,9 @@
}
},
"node_modules/github-linguist": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.3.tgz",
"integrity": "sha512-hKWn1QQ+9oUyOIcUhPzi6AxTcAkYHg4OOwK79Pr05SBTFmdNr7GQkMDJabSGCZwu7SDhEb5YeUwUGqrUfyo7PA==",
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.4.tgz",
"integrity": "sha512-QSw/HfSTqA13t7eqNeGLd62ghnTsTQAUrJQKkUG100NZqqzpsKB9c7gH7lFaGU1ZWGmNSWfhG6q1Ok/xotOA/g==",
"dependencies": {
"chalk": "^2.2.0",
"commander": "^2.11.0",
@ -3706,6 +3707,9 @@
"node_modules/jsonfile": {
"version": "4.0.0",
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.1.6"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
@ -8320,9 +8324,9 @@
}
},
"github-linguist": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.3.tgz",
"integrity": "sha512-hKWn1QQ+9oUyOIcUhPzi6AxTcAkYHg4OOwK79Pr05SBTFmdNr7GQkMDJabSGCZwu7SDhEb5YeUwUGqrUfyo7PA==",
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.4.tgz",
"integrity": "sha512-QSw/HfSTqA13t7eqNeGLd62ghnTsTQAUrJQKkUG100NZqqzpsKB9c7gH7lFaGU1ZWGmNSWfhG6q1Ok/xotOA/g==",
"requires": {
"chalk": "^2.2.0",
"commander": "^2.11.0",

View file

@ -37,7 +37,7 @@
"fast-deep-equal": "^3.1.3",
"file-url": "^3.0.0",
"fs": "0.0.1-security",
"github-linguist": "^2.4.3",
"github-linguist": "^2.4.4",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
"jsonschema": "1.2.6",