Skip to content

Commit

Permalink
Merge pull request palantir#405 from eonarheim/master
Browse files Browse the repository at this point in the history
Fix issue palantir#324 windows line endings not respected
  • Loading branch information
adidahiya committed May 23, 2015
2 parents b819ad5 + 96e9ca8 commit 10dc607
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rules/jsdocFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class JsdocWalker extends Lint.SkippableTokenAwareRuleWalker {

private findFailuresForJsdocComment(commentText: string, startingPosition: number, sourceFile: ts.SourceFile) {
var currentPosition = startingPosition;
var lines = commentText.split("\n");
// the file may be different depending on the OS it was originally authored on
// can't rely on require('os').EOL or process.platform as that is the execution env
// regex is: split optionally on \r\n, but alwasy split on \n if no \r exists
var lines = commentText.split(/\r?\n/);
var jsdocPosition = currentPosition;
var firstLine = lines[0];

Expand Down
10 changes: 10 additions & 0 deletions test/files/rules/jsdoc-windows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* MyClass
*
* Does classy things and impresses everyone. Quite a debonair class indeed.
*
* This file has all windows line endings "\r\n" and valid jsdoc.
*/
class MyClass {

}
6 changes: 6 additions & 0 deletions test/rules/jsdocFormatRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ describe("<jsdoc-format>", () => {
Lint.Test.assertContainsFailure(actualFailures, expectedFailure7);
assert.lengthOf(actualFailures, 7);
});

it("ensures jsdoc commments can have have windows line endings", () => {
var fileName = "rules/jsdoc-windows.test.ts";
var actualFailures = Lint.Test.applyRuleOnFile(fileName, JsdocFormatRule);
assert.lengthOf(actualFailures, 0);
});
});

0 comments on commit 10dc607

Please sign in to comment.