зеркало из https://github.com/microsoft/boll.git
Fixing incorrect lineNumbers for node_modules_detector
This commit is contained in:
Родитель
2945e49a77
Коммит
f41e485d82
|
@ -49,20 +49,22 @@ export class NodeModulesReferenceDetector implements PackageRule {
|
|||
|
||||
getParsedSourceLines(sourceFile: SourceFile): SourceLineAndLineNumber[] {
|
||||
const parsedSourceLines: SourceLineAndLineNumber[] = [];
|
||||
let lineNumber = 1;
|
||||
sourceFile.forEachChild(n => {
|
||||
const lineNumber = sourceFile.getLineAndCharacterOfPosition(n.pos).line;
|
||||
const totalLines = n.getFullText().split(/\r?\n/).length;
|
||||
lineNumber = lineNumber + totalLines - 1;
|
||||
const trimmedNodeText = n.getFullText().trim();
|
||||
const multiLineCommentsRemovedText = trimmedNodeText
|
||||
.split(MULTI_LINE_COMMENT_REGEXP)
|
||||
.map(n => n && n.trim())
|
||||
.filter(n => n)
|
||||
.join("");
|
||||
.join('\r\n');
|
||||
const singleLineCommentsRemovedText = multiLineCommentsRemovedText
|
||||
.split(SINGLE_LINE_COMMENT_REGEXP)
|
||||
.map(n => n && n.trim())
|
||||
.filter(n => n)
|
||||
.join("");
|
||||
parsedSourceLines.push({ line: singleLineCommentsRemovedText, lineNumber });
|
||||
.join('\r\n');
|
||||
parsedSourceLines.push({ line: singleLineCommentsRemovedText, lineNumber: lineNumber });
|
||||
});
|
||||
return parsedSourceLines;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as assert from "assert";
|
||||
import baretest from "baretest";
|
||||
import { NodeModulesReferenceDetector } from "../node-modules-reference-detector";
|
||||
import { asBollDirectory, getSourceFile, Package, ResultStatus } from "@boll/core";
|
||||
import { asBollDirectory, getSourceFile, Package, ResultStatus, Failure } from "@boll/core";
|
||||
import { inFixtureDir } from "@boll/test-internal";
|
||||
|
||||
export const test: any = baretest("Node modules reference detector");
|
||||
|
@ -23,8 +23,12 @@ test("Should fail if references to node_modules exist in source code", async ()
|
|||
const result = await sut.check(
|
||||
await getSourceFile(asBollDirectory("."), "node-modules-reference.ts", new Package({}, {}))
|
||||
);
|
||||
const failure = result[0] as Failure;
|
||||
const failure1 = result[1] as Failure;
|
||||
assert.strictEqual(2, result.length);
|
||||
assert.strictEqual(ResultStatus.failure, result[0].status);
|
||||
assert.strictEqual(ResultStatus.failure, result[1].status);
|
||||
assert.strictEqual(1, failure.line);
|
||||
assert.strictEqual(5, failure1.line);
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче