diff --git a/CHANGELOG.md b/CHANGELOG.md index b34392d..25a5200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,15 @@ # Changelog -## 1.2.1 () -- Moved deprecated rules in documentation into their own section. +## 1.2.1 (2019-01-01) :sparkler: - Added `fix` functionality to `linebreak-style` rule. - Added `linebreak-style` rule configuration to default `.soliumrc.json`. - Added support for tilde for specifying version literals in `pragma` statements. - Added rule `constructor` to warn the user when the deprecated style of constructor declaration is being used. - Added `--fix-dry-run` option to CLI to allow users to see a git-style diff of the changes the `--fix` option will make. - Fixed Hex literal parsing. Incorrect parsing caused the linter to crash in some [cases](https://github.com/duaraghav8/Ethlint/issues/232). -- Changed documentation URL to [ethlint.readthedocs.io](https://ethlint.readthedocs.io). +- Fixed source code util's `getTextOnLine()` to account for both linebreak-styles on both platforms (see [issue](https://github.com/duaraghav8/Ethlint/issues/173)) +- Changed documentation URL to [ethlint.readthedocs.io](https://ethlint.readthedocs.io). `solium.readthedocs.io` is deprecated but will receive updates. +- Moved deprecated rules in documentation into their own section. ## 1.2.0 (2018-12-25) :santa: - Deprecated the npm package `solium`. All updates will be pushed simultaneously to npm packages `solium` and `ethlint`. There is no difference between the software being pushed to these packages, but it is highly recommended that you move to the `ethlint` npm package. diff --git a/README.md b/README.md index e268cd7..61d7a55 100644 --- a/README.md +++ b/README.md @@ -95,15 +95,6 @@ Solium automatically fixes your code to resolve whatever issues it can. solium -d contracts/ --fix ``` -## Trusted by the best -- [Augur](https://augur.net/) -- [Zeppelin](https://zeppelin.solutions/) -- [Consensys](https://consensys.net/) -- [Paritytech](https://paritytech.io/) -- [Aragon](https://aragon.one/) -- [Ethereum Name Service](https://github.com/ensdomains) -- [Melon Project](https://ipfs.io/ipns/melon.fund/) - ## Our supporters
-If Solium helped make your life simpler, please consider donating ETH to `0xacc661A56af9793a4437876a52F4Ad3fc3C443d6` +If Ethlint helped make your life simpler, please consider donating ETH to `0xacc661A56af9793a4437876a52F4Ad3fc3C443d6` #### [IDE and Editor Integrations](http://solium.readthedocs.io/en/latest/user-guide.html#index-9) | [Documentation](https://ethlint.readthedocs.io) | [Demo Video](https://www.youtube.com/watch?v=MlQ6fzwixpI) diff --git a/lib/utils/source-code-utils.js b/lib/utils/source-code-utils.js index 2b58afb..7e30ca6 100644 --- a/lib/utils/source-code-utils.js +++ b/lib/utils/source-code-utils.js @@ -5,7 +5,7 @@ "use strict"; -const { EOL } = require("os"), astUtils = require("./ast-utils"); +const astUtils = require("./ast-utils"); const INHERITABLE_METHODS = [ "isASTNode", "getParent", @@ -120,14 +120,16 @@ SourceCode.prototype = { }, /** - * Get the complete text on line lineNumber (excluding the EOL) - * @param {Integer} lineNumber Line number whose text to get - * @returns {String} code Source code text on the specified line - */ + * Get the complete text on line lineNumber (excluding the EOL) + * @param {Integer} lineNumber Line number whose text to get + * @returns {String} code Source code text on the specified line + */ getTextOnLine: function(lineNumber) { //establish a cache the first time this function is called, so subsequent calls don't have to split the text again if (!this.sourceCodeTextLines) { - this.sourceCodeTextLines = this.text.split(EOL); + // important to account for both types of line endings + // see issue https://github.com/duaraghav8/Ethlint/issues/173 + this.sourceCodeTextLines = this.text.split(/\r?\n/); } if ( diff --git a/test/lib/utils/source-code-utils.js b/test/lib/utils/source-code-utils.js index 929f0b7..d0d823c 100644 --- a/test/lib/utils/source-code-utils.js +++ b/test/lib/utils/source-code-utils.js @@ -5,17 +5,18 @@ "use strict"; -const { EOL } = require("os"), - SourceCode = require("../../../lib/utils/source-code-utils"); +const SourceCode = require("../../../lib/utils/source-code-utils"); describe("Testing SourceCode instance for exposed functionality", function() { - let sourceCodeText = "contract Visual {\n\n\tfunction foo () {\n\t\tvar x = 100;\n\t}\n\n}", + // Linter should account for both windows & unix linebreak styles, + // so use a mix of them. + let sourceCodeText = "contract Visual {\n\r\n\tfunction foo () {\r\n\t\tvar x = 100;\n\t}\n\r\n}\n\r\n", varDeclarator = { type: "VariableDeclarator", - id: { type: "Identifier", name: "x", start: 44, end: 45 }, - init: { type: "Literal", value: 100, start: 48, end: 51 }, - start: 44, - end: 51 + id: { type: "Identifier", name: "x", start: 46, end: 47 }, + init: { type: "Literal", value: 100, start: 50, end: 53 }, + start: 46, + end: 53 }; it("should create instance of SourceCode & expose set of functions (its own & those of astUtils)", function(done) { @@ -167,7 +168,7 @@ describe("Testing SourceCode instance for exposed functionality", function() { sourceCodeObject.getNextChars(varDeclarator).should.equal(""); sourceCodeObject.getNextChars(varDeclarator, 1).should.equal(";"); sourceCodeObject.getNextChars(varDeclarator, -1).should.equal(";"); - sourceCodeObject.getNextChars(varDeclarator, 100).should.equal(";\n\t}\n\n}"); + sourceCodeObject.getNextChars(varDeclarator, 100).should.equal(";\n\t}\n\r\n}\n\r\n"); done(); }); @@ -181,7 +182,7 @@ describe("Testing SourceCode instance for exposed functionality", function() { sourceCodeObject.getPrevChars(varDeclarator, 4).should.equal("var "); sourceCodeObject.getPrevChars(varDeclarator, -4).should.equal("var "); sourceCodeObject.getPrevChars(varDeclarator, 100).should.equal( - "contract Visual {\n\n\tfunction foo () {\n\t\tvar " + "contract Visual {\n\r\n\tfunction foo () {\r\n\t\tvar " ); done(); @@ -274,7 +275,7 @@ describe("Testing SourceCode instance for exposed functionality", function() { it("should behave as expected upon calling getTextOnLine()", function(done) { let sourceCodeObject = new SourceCode(sourceCodeText), - sourceCodeTextLines = sourceCodeText.split(EOL); + sourceCodeTextLines = sourceCodeText.split(/\r?\n/); for (let i = 0; i < sourceCodeTextLines.length; i++) { sourceCodeObject.getTextOnLine(i+1)