Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solium

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solium - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

lib/rules/constructor.js

11

CHANGELOG.md
# Changelog
## 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).
- 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:

@@ -4,0 +15,0 @@ - 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.

1

config/rulesets/solium-all.js

@@ -42,2 +42,3 @@ /**

"visibility-first": "warning",
"constructor": "warning",

@@ -44,0 +45,0 @@ // Turn OFF all deprecated rules

4

config/rulesets/solium-recommended.js

@@ -32,2 +32,5 @@ /**

"error-reason": "warning",
"constructor": "warning",
"visibility-first": "warning",
"lbrace": "off",

@@ -42,3 +45,2 @@ "mixedcase": "off",

"no-experimental": "off",
"visibility-first": "warning",

@@ -45,0 +47,0 @@ // Disable deprecated rules

@@ -28,3 +28,3 @@ /**

},
"options": { "autofix": true, "returnInternalIssues": true }
"options": { "autofix": true, "autofixDryrun": true, "returnInternalIssues": true }
}

@@ -80,2 +80,3 @@ */

autofix: { type: "boolean" },
autofixDryrun: { type: "boolean" },
debug: { type: "boolean" },

@@ -93,2 +94,2 @@ returnInternalIssues: { type: "boolean" }

module.exports = Schema;
module.exports = Schema;

@@ -214,2 +214,9 @@ {

"constructor": {
"enabled": true,
"recommended": true,
"type": "warning",
"description": "Suggest replacing deprecated contract name with 'constructor' for constructor function"
},
"visibility-first": {

@@ -227,4 +234,4 @@ "enabled": true,

"description": "Ensure consistent linebreak style"
}
}
}
}

@@ -24,7 +24,7 @@ /**

/**
* Apply fixes to source code depending on whichever errors can be fixed.
* @param {String} sourceCode Code to fix
* @param {Array} errorMessages Error objects that describe the error and possibly how to fix it.
* @returns {Object} fixed Contains fixed code and information about fixes applied & remaining un-fixed errors.
*/
* Apply fixes to source code depending on whichever errors can be fixed.
* @param {String} sourceCode Code to fix
* @param {Array} errorMessages Error objects that describe the error and possibly how to fix it.
* @returns {Object} fixed Contains fixed code and information about fixes applied & remaining un-fixed errors.
*/
applyFixes: function(sourceCode, errorMessages) {

@@ -31,0 +31,0 @@ let fixedSourceCode = "", fixes = [], fixesApplied = [], remainingMessages = [];

@@ -6,4 +6,5 @@ {

"quotes": ["error", "double"],
"indentation": ["error", 4]
"indentation": ["error", 4],
"linebreak-style": ["error", "unix"]
}
}

@@ -93,8 +93,13 @@ /**

try {
if (userConfig.options.autofix) {
if (userConfig.options.autofix || userConfig.options.autofixDryrun) {
let result = solium.lintAndFix(sourceCode, userConfig);
lintErrors = result.errorMessages;
result.fixesApplied.length && fs.writeFileSync(fileName, result.fixedSourceCode);
fixesApplied = result.fixesApplied;
if (userConfig.options.autofix) {
applyFixes(fileName, result);
fixesApplied = result.fixesApplied;
} else {
errorReporter.reportDiff(fileName,
sourceCode, result.fixedSourceCode, result.fixesApplied.length);
}
} else {

@@ -107,3 +112,3 @@ lintErrors = solium.lint(sourceCode, userConfig);

const messageOrStackrace = userConfig.options.debug ? e.stack : e.message;
errorReporter.reportFatal(`An error occured while linting over ${fileName}:\n${messageOrStackrace}`);
errorReporter.reportFatal(`An error occured while linting over ${fileName}:${EOL}${messageOrStackrace}`);
process.exit(errorCodes.ERRORS_FOUND);

@@ -130,2 +135,6 @@ }

function applyFixes(fileName, lintResult) {
lintResult.fixesApplied.length && fs.writeFileSync(fileName, lintResult.fixedSourceCode);
}
/**

@@ -219,6 +228,7 @@ * Lint a file based on user settings

.option("-d, --dir [dirpath::String]", "Directory containing Solidity files to lint")
.option("-R, --reporter [name::String]", "Format to report lint issues in (pretty | gcc)")
.option("-R, --reporter [name::String]", "Format to report lint issues in (pretty | gcc)", "pretty")
.option("-c, --config [filepath::String]", "Path to the .soliumrc configuration file")
.option("-, --stdin", "Read input file from stdin")
.option("--fix", "Fix Lint issues where possible")
.option("--fix-dry-run", "Output fix diff without applying it")
.option("--debug", "Display debug information")

@@ -249,4 +259,2 @@ .option("--watch", "Watch for file changes")

function getErrorReporter(name) {
name = name || "pretty";
try {

@@ -279,3 +287,3 @@ return require("./reporters/" + name);

} catch (e) {
console.error(`[Fatal error] ${e.message}`);
process.stderr.write(`[Fatal error] ${e.message}${EOL}`);
process.exit(errorCodes.INVALID_PARAMS);

@@ -326,5 +334,15 @@ }

autofix: Boolean(cli.fix),
autofixDryrun: Boolean(cli.fixDryRun),
debug: Boolean(cli.debug)
};
if (userConfig.options.autofixDryrun) {
if (userConfig.options.autofix) {
return errorReporter.reportFatal("Cannot use both --fix and --fix-dry-run");
}
if (cli.reporter != "pretty") {
return errorReporter.reportFatal("Option --fix-dry-run is only supported with pretty reporter");
}
}
userConfig.plugins = userConfig.plugins || [];

@@ -331,0 +349,0 @@ userConfig.rules = userConfig.rules || {};

@@ -8,4 +8,4 @@ /**

const path = require("path"),
sort = require("lodash/sortBy"), Table = require("text-table");
const path = require("path"), jsdiff = require("diff"),
sort = require("lodash/sortBy"), Table = require("text-table"), {EOL} = require("os");
require("colors");

@@ -24,3 +24,13 @@

function getDiffLine(diffPart) {
if (diffPart.startsWith("+")) {
return diffPart.green;
} else if (diffPart.startsWith("-")) {
return diffPart.red;
}
return diffPart;
}
module.exports = {

@@ -79,3 +89,19 @@

reportDiff(fileName, sourceCode, fixedSourceCode, issuesFixed) {
let diff = jsdiff.structuredPatch(fileName,
fileName, sourceCode, fixedSourceCode, "old-header", "new-header");
if (diff.hunks.length == 0) {
return;
}
process.stdout.write((`Diff for: ${fileName}${EOL}`).cyan);
diff.hunks.forEach(function(hunk){
process.stdout.write(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@${EOL}`.cyan);
hunk.lines.forEach(line => { process.stdout.write(getDiffLine(line) + EOL); });
});
process.stdout.write(`${EOL}${issuesFixed} lint issue(s) can be fixed.${EOL}`.green);
},
finalize() {

@@ -82,0 +108,0 @@

@@ -0,1 +1,6 @@

/**
* @fileoverview Ensure consistent linebreak style across codebase
* @author Arjun Nemani <nemaniarjun@gmail.com>
*/
"use strict";

@@ -10,3 +15,3 @@

type: "error",
description: "This rule changes the EOL of the codebase as per config"
description: "Ensure consistent linebreak style across codebase"
},

@@ -37,8 +42,10 @@ schema: [{

// TODO: Report the exact row and column position at which the linebreak
// violation occured. Still need to investigate the best way to calculate
// the positions where LB is different from the expected.
context.report({
node: node,
// TODO: solve issue #221
// fix(fixer) {
// return fixer.replaceText(node, convertedTxt);
// },
node,
fix(fixer) {
return fixer.replaceTextRange([0, txt.length], convertedTxt);
},
message: "Inconsistent line-break style"

@@ -45,0 +52,0 @@ });

@@ -8,3 +8,3 @@ /**

const { EOL } = require("os"), astUtils = require("./ast-utils");
const astUtils = require("./ast-utils");
const INHERITABLE_METHODS = [

@@ -124,10 +124,12 @@ "isASTNode",

/**
* 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/);
}

@@ -134,0 +136,0 @@

{
"name": "solium",
"version": "1.2.0",
"version": "1.2.1",
"description": "Linter to identify and fix Style & Security issues in Solidity",

@@ -41,2 +41,3 @@ "main": "./lib/solium.js",

"commander": "^2.9.0",
"diff": "^3.5.0",
"eol": "^0.9.1",

@@ -48,3 +49,3 @@ "js-string-escape": "^1.0.1",

"solium-plugin-security": "0.1.1",
"solparse": "2.2.6",
"solparse": "2.2.7",
"text-table": "^0.2.0"

@@ -51,0 +52,0 @@ },

@@ -13,3 +13,3 @@ <p align="center">

Standardize Smart Contract practices across your organisation. Integrate with your build system. Deploy with confidence.
See [Documentation](https://ethlint.readthedocs.io/) and [Changelog](./CHANGELOG.md)

@@ -99,11 +99,2 @@ ## Install

## 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

@@ -123,4 +114,4 @@ <p align="left">

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) | [Complete Documentation](http://solium.readthedocs.io/) | [Demo Video](https://www.youtube.com/watch?v=MlQ6fzwixpI)
#### [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)

@@ -215,3 +215,3 @@ /**

// The below count will keep changing with every change in the number of core rules that exist in solium.
Object.keys(ruleDescriptions).length.should.equal(28);
Object.keys(ruleDescriptions).length.should.equal(29);

@@ -218,0 +218,0 @@ done();

@@ -51,20 +51,20 @@ /**

// TODO: solve issue #221
// describe("[RULE] linebreak-style: Fixes for Unix Line breaks", function() {
// it("should change to Unix Line Breaks when receiving Windows Line breaks", function(done) {
// const unfixedCode = fs
// .readFileSync(path.join(__dirname, "./windows-endings"))
// .toString();
// const fixedCode = fs
// .readFileSync(path.join(__dirname, "./unix-endings"))
// .toString();
// const newCode = Solium.lintAndFix(unfixedCode, userConfigUnix);
// newCode.fixedSourceCode.should.equal(fixedCode);
describe("[RULE] linebreak-style: Fixes for Unix Line breaks", function() {
it("should change to Unix Line Breaks when receiving Windows Line breaks", function(done) {
const unfixedCode = fs
.readFileSync(path.join(__dirname, "./windows-endings"))
.toString();
const fixedCode = fs
.readFileSync(path.join(__dirname, "./unix-endings"))
.toString();
const newCode = Solium.lintAndFix(unfixedCode, userConfigUnix);
// Solium.reset();
// done();
// });
// });
newCode.fixedSourceCode.should.equal(fixedCode);
Solium.reset();
done();
});
});
const userConfigWindows = {

@@ -108,18 +108,17 @@ rules: {

// TODO: solve issue #221
// describe("[RULE] linebreak-style: Fixes for Windows Line breaks", function() {
// it("should change to Windows Line breaks when receiving Unix Line breaks", function(done) {
// const unfixedCode = fs
// .readFileSync(path.join(__dirname, "./unix-endings"))
// .toString();
// const fixedCode = fs
// .readFileSync(path.join(__dirname, "./windows-endings"))
// .toString();
// const newCode = Solium.lintAndFix(unfixedCode, userConfigWindows);
describe("[RULE] linebreak-style: Fixes for Windows Line breaks", function() {
it("should change to Windows Line breaks when receiving Unix Line breaks", function(done) {
const unfixedCode = fs
.readFileSync(path.join(__dirname, "./unix-endings"))
.toString();
const fixedCode = fs
.readFileSync(path.join(__dirname, "./windows-endings"))
.toString();
// newCode.fixedSourceCode.should.equal(fixedCode);
const newCode = Solium.lintAndFix(unfixedCode, userConfigWindows);
newCode.fixedSourceCode.should.equal(fixedCode);
// Solium.reset();
// done();
// });
// });
Solium.reset();
done();
});
});

@@ -8,13 +8,14 @@ /**

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
};

@@ -171,3 +172,3 @@

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");

@@ -186,3 +187,3 @@ done();

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 "
);

@@ -280,3 +281,3 @@

let sourceCodeObject = new SourceCode(sourceCodeText),
sourceCodeTextLines = sourceCodeText.split(EOL);
sourceCodeTextLines = sourceCodeText.split(/\r?\n/);

@@ -283,0 +284,0 @@ for (let i = 0; i < sourceCodeTextLines.length; i++) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc