Skip to content

Commit

Permalink
source code util, getTextOnLine(): account for both linebreak styles …
Browse files Browse the repository at this point in the history
…on both platforms (#173)
  • Loading branch information
duaraghav8 committed Jan 1, 2019
1 parent 4f82111 commit 8c7c5ba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<p align="left">
<a href="https://blog.ethereum.org/2018/03/07/announcing-beneficiaries-ethereum-foundation-grants/">
Expand All @@ -118,6 +109,6 @@ solium -d contracts/ --fix
</a>
</p>

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)
14 changes: 8 additions & 6 deletions lib/utils/source-code-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

const { EOL } = require("os"), astUtils = require("./ast-utils");
const astUtils = require("./ast-utils");
const INHERITABLE_METHODS = [
"isASTNode",
"getParent",
Expand Down Expand Up @@ -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 (
Expand Down
21 changes: 11 additions & 10 deletions test/lib/utils/source-code-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8c7c5ba

Please sign in to comment.