Repository: protofire/solhint (js)

Issue:
Should count CRLF as one character
solhint 1.5.1 counts CRLF as two characters.  Should only be one.

Pull request:
Handle CRLF newlines
Closes #109.

Patch:
diff --git a/lib/rules/best-practises/max-line-length.js b/lib/rules/best-practises/max-line-length.js
index 8cafae0..01bdc4b 100644
--- a/lib/rules/best-practises/max-line-length.js
+++ b/lib/rules/best-practises/max-line-length.js
@@ -1,5 +1,7 @@
 const BaseChecker = require('./../base-checker')
 
+const lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u
+
 const ruleId = 'max-line-length'
 const meta = {
   type: 'best-practises',
@@ -31,7 +33,7 @@ class MaxLineLengthChecker extends BaseChecker {
   }
 
   enterSourceUnit(ctx) {
-    const lines = ctx.parser._input.tokenSource._input.strdata.split('\n')
+    const lines = ctx.parser._input.tokenSource._input.strdata.split(lineBreakPattern)
 
     lines.map(line => line.length).forEach(this.validateLineLength.bind(this))
   }


Test patch:
diff --git a/test/rules/best-practises/max-line-length.js b/test/rules/best-practises/max-line-length.js
index f99acdd..f1ed707 100644
--- a/test/rules/best-practises/max-line-length.js
+++ b/test/rules/best-practises/max-line-length.js
@@ -22,4 +22,36 @@ describe('Linter - max-line-length', () => {
 
     assertNoErrors(report)
   })
+
+  it('should not raise error when line is exactly the max length', () => {
+    const code = ' '.repeat(120)
+
+    const report = linter.processStr(code, {
+      rules: { 'max-line-length': 'error' }
+    })
+
+    assertNoErrors(report)
+  })
+
+  it('should not count newlines', () => {
+    const line = ' '.repeat(120)
+    const code = `${line}\n${line}\n`
+
+    const report = linter.processStr(code, {
+      rules: { 'max-line-length': 'error' }
+    })
+
+    assertNoErrors(report)
+  })
+
+  it('should not count windows newlines', () => {
+    const line = ' '.repeat(120)
+    const code = `${line}\n\r${line}\n\r`
+
+    const report = linter.processStr(code, {
+      rules: { 'max-line-length': 'error' }
+    })
+
+    assertNoErrors(report)
+  })
 })