solhint
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -5,4 +5,2 @@ --- | ||
title: "Rule Index of Solhint" | ||
date: "Fri, 01 May 2020 22:04:11 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -21,3 +19,3 @@ | ||
| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable you will not be able to receive ethers. | ✔️ | | ||
| [reason-string](./rules/best-practises/reason-string.md) | Require or revert statement must have a reason string and check that each reason string is at most N characters long. | | | ||
| [reason-string](./rules/best-practises/reason-string.md) | Require or revert statement must have a reason string and check that each reason string is at most N characters long. | ✔️ | | ||
| [constructor-syntax](./rules/best-practises/constructor-syntax.md) | Constructors should use the new constructor keyword. | | | ||
@@ -24,0 +22,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "code-complexity | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:47 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "constructor-syntax | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:48 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "function-max-lines | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:47 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "max-line-length | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:47 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "max-states-count | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:48 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "no-empty-blocks | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:48 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "no-unused-vars | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:48 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "payable-fallback | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:48 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,10 +5,11 @@ --- | ||
title: "reason-string | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:48 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
# reason-string | ||
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen) | ||
![Category Badge](https://img.shields.io/badge/-Best%20Practise%20Rules-informational) | ||
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow) | ||
> The {"extends": "solhint:recommended"} property in a configuration file enables this rule. | ||
## Description | ||
@@ -15,0 +16,0 @@ Require or revert statement must have a reason string and check that each reason string is at most N characters long. |
@@ -5,4 +5,2 @@ --- | ||
title: "quotes | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:49 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "const-name-snakecase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:49 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "contract-name-camelcase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:49 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "event-name-camelcase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:49 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "func-name-mixedcase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:49 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "func-param-name-mixedcase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:49 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "modifier-name-mixedcase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:50 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "private-vars-leading-underscore | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:50 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -18,4 +16,10 @@ | ||
## Options | ||
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn. | ||
This rule accepts an array of options: | ||
| Index | Description | Default Value | | ||
| ----- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | | ||
| 0 | Rule severity. Must be one of "error", "warn", "off". | warn | | ||
| 1 | A JSON object with a single property "strict" specifying if the rule should apply to non state variables. Default: { strict: false }. | {"strict":false} | | ||
### Example Config | ||
@@ -25,3 +29,3 @@ ```json | ||
"rules": { | ||
"private-vars-leading-underscore": "warn" | ||
"private-vars-leading-underscore": ["warn",{"strict":false}] | ||
} | ||
@@ -28,0 +32,0 @@ } |
@@ -5,4 +5,2 @@ --- | ||
title: "use-forbidden-name | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:50 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "var-name-mixedcase | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:50 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "func-order | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:50 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "imports-on-top | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "visibility-modifier-order | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "avoid-call-value | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "avoid-low-level-calls | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "avoid-sha3 | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "avoid-suicide | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "avoid-throw | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:51 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "avoid-tx-origin | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:52 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "check-send-result | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:52 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "compiler-version | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:52 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "func-visibility | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:52 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,10 +5,11 @@ --- | ||
title: "mark-callable-contracts | Solhint" | ||
date: "Fri, 01 May 2020 22:04:10 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
# mark-callable-contracts | ||
![Deprecated Badge](https://img.shields.io/badge/-Deprecated-yellow) | ||
![Category Badge](https://img.shields.io/badge/-Security%20Rules-informational) | ||
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow) | ||
> This rule is **deprecated** | ||
## Description | ||
@@ -15,0 +16,0 @@ Explicitly mark all external contracts as trusted or untrusted. |
@@ -5,4 +5,2 @@ --- | ||
title: "multiple-sends | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:53 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "no-complex-fallback | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:53 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "no-inline-assembly | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:53 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "not-rely-on-block-hash | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:53 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "not-rely-on-time | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:53 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "reentrancy | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:53 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -5,4 +5,2 @@ --- | ||
title: "state-visibility | Solhint" | ||
date: "Thu, 23 Apr 2020 20:59:54 GMT" | ||
author: "Franco Victorio <victorio.franco@gmail.com>" | ||
--- | ||
@@ -9,0 +7,0 @@ |
@@ -48,2 +48,19 @@ class TreeTraversing { | ||
/** | ||
* Traverses the tree up and checks `predicate` in each node. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
someParent(node, predicate) { | ||
let parent = node.parent | ||
while (parent) { | ||
if (predicate(parent)) { | ||
return true | ||
} | ||
parent = parent.parent | ||
} | ||
return false | ||
} | ||
*findIdentifier(ctx) { | ||
@@ -50,0 +67,0 @@ const children = ctx.children |
@@ -13,2 +13,7 @@ const _ = require('lodash') | ||
getBooleanByPath(path, defaultValue) { | ||
const configVal = _.get(this, path) | ||
return _.isBoolean(configVal) ? configVal : defaultValue | ||
}, | ||
getStringByPath(path, defaultValue) { | ||
@@ -27,2 +32,6 @@ const configVal = _.get(this, path) | ||
getObjectPropertyBoolean(ruleName, ruleProperty, defaultValue) { | ||
return this.getBooleanByPath(`rules["${ruleName}"][1][${ruleProperty}]`, defaultValue) | ||
}, | ||
getString(ruleName, defaultValue) { | ||
@@ -29,0 +38,0 @@ return this.getStringByPath(`rules["${ruleName}"][1]`, defaultValue) |
@@ -45,3 +45,3 @@ const _ = require('lodash') | ||
isDefault: false, | ||
recommended: false, | ||
recommended: true, | ||
defaultSetup: [DEFAULT_SEVERITY, DEFAULT_OPTION], | ||
@@ -48,0 +48,0 @@ |
@@ -61,3 +61,3 @@ const chalk = require('chalk') | ||
...miscellaneous(reporter, config, tokens), | ||
...naming(reporter), | ||
...naming(reporter, config), | ||
...order(reporter, tokens), | ||
@@ -64,0 +64,0 @@ ...security(reporter, config, inputSrc) |
@@ -11,3 +11,3 @@ const ConstNameSnakecaseChecker = require('./const-name-snakecase') | ||
module.exports = function checkers(reporter) { | ||
module.exports = function checkers(reporter, config) { | ||
return [ | ||
@@ -20,3 +20,3 @@ new ConstNameSnakecaseChecker(reporter), | ||
new ModifierNameMixedcaseChecker(reporter), | ||
new PrivateVarsLeadingUnderscore(reporter), | ||
new PrivateVarsLeadingUnderscore(reporter, config), | ||
new UseForbiddenNameChecker(reporter), | ||
@@ -23,0 +23,0 @@ new VarNameMixedcaseChecker(reporter) |
const BaseChecker = require('./../base-checker') | ||
const naming = require('./../../common/identifier-naming') | ||
const { severityDescription } = require('../../doc/utils') | ||
const DEFAULT_SEVERITY = 'warn' | ||
const DEFAULT_STRICTNESS = false | ||
const DEFAULT_OPTION = { strict: DEFAULT_STRICTNESS } | ||
const ruleId = 'private-vars-leading-underscore' | ||
@@ -10,3 +15,14 @@ const meta = { | ||
description: 'Private and internal names must start with a single underscore.', | ||
category: 'Style Guide Rules' | ||
category: 'Style Guide Rules', | ||
options: [ | ||
{ | ||
description: severityDescription, | ||
default: DEFAULT_SEVERITY | ||
}, | ||
{ | ||
description: | ||
'A JSON object with a single property "strict" specifying if the rule should apply to non state variables. Default: { strict: false }.', | ||
default: JSON.stringify(DEFAULT_OPTION) | ||
} | ||
] | ||
}, | ||
@@ -16,10 +32,19 @@ | ||
recommended: false, | ||
defaultSetup: 'warn', | ||
defaultSetup: [DEFAULT_SEVERITY, DEFAULT_OPTION], | ||
schema: null | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
strict: { | ||
type: 'boolean' | ||
} | ||
} | ||
} | ||
} | ||
class PrivateVarsLeadingUnderscoreChecker extends BaseChecker { | ||
constructor(reporter) { | ||
constructor(reporter, config) { | ||
super(reporter, ruleId, meta) | ||
this.isStrict = config && config.getObjectPropertyBoolean(ruleId, 'strict', DEFAULT_STRICTNESS) | ||
} | ||
@@ -58,2 +83,6 @@ | ||
if (!this.inStateVariableDeclaration) { | ||
// if strict is enabled, non-state vars should not start with leading underscore | ||
if (this.isStrict) { | ||
this.validateName(node, false) | ||
} | ||
return | ||
@@ -69,2 +98,6 @@ } | ||
validateName(node, shouldHaveLeadingUnderscore) { | ||
if (node.name === null) { | ||
return | ||
} | ||
if (naming.hasLeadingUnderscore(node.name) !== shouldHaveLeadingUnderscore) { | ||
@@ -71,0 +104,0 @@ this._error(node, node.name, shouldHaveLeadingUnderscore) |
@@ -49,4 +49,6 @@ const BaseChecker = require('./../base-checker') | ||
const hasIfStatement = traversing.statementNotContains(node, 'IfStatement') | ||
const hasRequire = traversing.someParent(node, this.isRequire) | ||
const hasAssert = traversing.someParent(node, this.isAssert) | ||
if (!hasIfStatement && !hasVarDeclaration) { | ||
if (!hasIfStatement && !hasVarDeclaration && !hasRequire && !hasAssert) { | ||
this.error(node, 'Check result of "send" call') | ||
@@ -56,4 +58,12 @@ } | ||
} | ||
isRequire(node) { | ||
return node.type === 'FunctionCall' && node.expression.name === 'require' | ||
} | ||
isAssert(node) { | ||
return node.type === 'FunctionCall' && node.expression.name === 'assert' | ||
} | ||
} | ||
module.exports = CheckSendResultChecker |
@@ -33,2 +33,3 @@ const TreeTraversing = require('./../../common/tree-traversing') | ||
defaultSetup: 'warn', | ||
deprecated: true, | ||
@@ -35,0 +36,0 @@ schema: null |
{ | ||
"name": "solhint", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Solidity Code Linter", | ||
@@ -20,4 +20,4 @@ "main": "lib/index.js", | ||
"exec-tests": "nyc mocha --recursive && nyc report --reporter=text-lcov | coveralls", | ||
"test": "npm run exec-tests", | ||
"test-only": "mocha --recursive", | ||
"test:coverage": "npm run exec-tests", | ||
"test": "mocha --recursive", | ||
"test-mutation": "stryker run", | ||
@@ -59,5 +59,5 @@ "lint": "eslint .", | ||
"markdown-table": "^1.1.3", | ||
"mocha": "^5.2.0", | ||
"mocha": "^7.1.2", | ||
"mocha-lcov-reporter": "1.3.0", | ||
"nyc": "^13.0.1", | ||
"nyc": "^15.0.1", | ||
"shelljs": "^0.8.3" | ||
@@ -64,0 +64,0 @@ }, |
@@ -33,10 +33,2 @@ <p align="center"> | ||
### Solhint 3.0 | ||
Solhint 3.0 is under development and will be released soon. You can try it out by doing: | ||
```sh | ||
npm install -g solhint@next | ||
``` | ||
## Usage | ||
@@ -47,3 +39,3 @@ | ||
```sh | ||
solhint init-config | ||
solhint --init | ||
``` | ||
@@ -79,2 +71,3 @@ | ||
--fix automatically fix problems | ||
--init create configuration file for solhint | ||
-h, --help output usage information | ||
@@ -85,3 +78,3 @@ | ||
stdin [options] linting of source code data provided to STDIN | ||
init-config create in current directory configuration file for solhint | ||
init-config create configuration file for solhint | ||
``` | ||
@@ -123,2 +116,11 @@ | ||
### Extendable rulesets | ||
The default rulesets provided by solhint are the following: | ||
+ solhint:default | ||
+ solhint:recommended | ||
Use one of these as the value for the "extends" property in your configuration file. | ||
### Configure the linter with comments | ||
@@ -125,0 +127,0 @@ |
@@ -14,10 +14,2 @@ #!env node | ||
class GitHelper { | ||
static getAuthorName() { | ||
return GitHelper.execSilent('git config user.name').trim(); | ||
} | ||
static getAuthorEmail() { | ||
return GitHelper.execSilent('git config user.email').trim(); | ||
} | ||
/** | ||
@@ -75,5 +67,2 @@ * Gets the tag name where a given file was introduced first. | ||
function generateRuleDoc(rule) { | ||
const date = new Date().toUTCString(); | ||
const authorName = GitHelper.getAuthorName(); | ||
const authorEmail = GitHelper.getAuthorEmail(); | ||
const isDefault = !rule.meta.deprecated && rule.meta.isDefault; | ||
@@ -89,4 +78,2 @@ const isRecommended = !rule.meta.deprecated && rule.meta.recommended; | ||
title: "${rule.ruleId} | Solhint" | ||
date: "${date}" | ||
author: "${authorName} <${authorEmail}>" | ||
--- | ||
@@ -236,6 +223,2 @@ | ||
function generateRuleIndex(rulesIndexed) { | ||
const date = new Date().toUTCString(); | ||
const authorName = GitHelper.getAuthorName(); | ||
const authorEmail = GitHelper.getAuthorEmail(); | ||
const contents = Object.keys(rulesIndexed).map(category => { | ||
@@ -254,4 +237,2 @@ const rows = [["Rule Id", "Error", "Recommended"]]; | ||
title: "Rule Index of Solhint" | ||
date: "${date}" | ||
author: "${authorName} <${authorEmail}>" | ||
--- | ||
@@ -258,0 +239,0 @@ |
@@ -27,2 +27,3 @@ #!/usr/bin/env node | ||
.option('--fix', 'automatically fix problems') | ||
.option('--init', 'create configuration file for solhint') | ||
.description('Linter for Solidity programming language') | ||
@@ -39,3 +40,3 @@ .action(execMainAction) | ||
.command('init-config') | ||
.description('create in current directory configuration file for solhint') | ||
.description('create configuration file for solhint') | ||
.action(writeSampleConfigFile) | ||
@@ -45,2 +46,6 @@ | ||
if (program.init) { | ||
writeSampleConfigFile() | ||
} | ||
if (program.args.length < 1) { | ||
@@ -52,2 +57,6 @@ program.help() | ||
function execMainAction() { | ||
if (program.init) { | ||
writeSampleConfigFile() | ||
} | ||
let formatterFn | ||
@@ -127,2 +136,4 @@ | ||
} | ||
process.exit(0) | ||
} | ||
@@ -129,0 +140,0 @@ |
@@ -24,2 +24,9 @@ const assert = require('assert') | ||
] | ||
const SHOULD_WARN_STRICT_CASES = [ | ||
contractWith('function foo() { uint _bar; }'), | ||
contractWith('function foo(uint _bar) {}'), | ||
contractWith('function foo() returns (uint256 _bar) {}'), | ||
libraryWith('function foo() returns (uint256 _bar) {}'), | ||
libraryWith('function foo(uint _bar) {}') | ||
] | ||
const SHOULD_NOT_WARN_CASES = [ | ||
@@ -48,15 +55,9 @@ // don't warn when private/internal names start with _ | ||
contractWith('function foo(uint bar) {}'), | ||
contractWith('function foo(uint _bar) {}'), | ||
contractWith('function foo() { uint bar; }'), | ||
contractWith('function foo() { uint _bar; }'), | ||
contractWith('function foo() returns (uint256) {}'), | ||
contractWith('function foo() returns (uint256 bar) {}'), | ||
contractWith('function foo() returns (uint256 _bar) {}'), | ||
libraryWith('function foo(uint bar) {}'), | ||
libraryWith('function foo(uint _bar) {}'), | ||
libraryWith('function foo() { uint bar; }'), | ||
libraryWith('function foo() { uint _bar; }'), | ||
libraryWith('function foo() returns (uint256) {}'), | ||
libraryWith('function foo() returns (uint256 bar) {}'), | ||
libraryWith('function foo() returns (uint256 _bar) {}') | ||
libraryWith('function foo() returns (uint256 bar) {}') | ||
] | ||
@@ -74,6 +75,16 @@ | ||
SHOULD_WARN_STRICT_CASES.concat(SHOULD_NOT_WARN_CASES).forEach((code, index) => { | ||
it(`should not emit a warning (strict) (${index})`, () => { | ||
const report = linter.processStr(code, { | ||
rules: { 'private-vars-leading-underscore': 'error' } | ||
}) | ||
assert.equal(report.errorCount, 0) | ||
}) | ||
}) | ||
SHOULD_NOT_WARN_CASES.forEach((code, index) => { | ||
it(`should not emit a warning (${index})`, () => { | ||
const report = linter.processStr(code, { | ||
rules: { 'private-vars-leading-underscore': 'error' } | ||
rules: { 'private-vars-leading-underscore': ['error', { strict: true }] } | ||
}) | ||
@@ -84,2 +95,12 @@ | ||
}) | ||
SHOULD_WARN_STRICT_CASES.forEach((code, index) => { | ||
it(`should not emit a warning (strict) (${index})`, () => { | ||
const report = linter.processStr(code, { | ||
rules: { 'private-vars-leading-underscore': ['error', { strict: true }] } | ||
}) | ||
assert.equal(report.errorCount, 1) | ||
}) | ||
}) | ||
}) |
@@ -26,2 +26,52 @@ const assert = require('assert') | ||
}) | ||
it('do not emit error when a require is used', () => { | ||
const code = funcWith('require(x.send(1));') | ||
const report = linter.processStr(code, { | ||
rules: { 'check-send-result': 'error' } | ||
}) | ||
assert.equal(report.errorCount, 0) | ||
}) | ||
it('do not emit error when a require is used upper in the tree', () => { | ||
const code = funcWith('require(!x.send(1));') | ||
const report = linter.processStr(code, { | ||
rules: { 'check-send-result': 'error' } | ||
}) | ||
assert.equal(report.errorCount, 0) | ||
}) | ||
it('do not emit error when an assert is used', () => { | ||
const code = funcWith('assert(x.send(1));') | ||
const report = linter.processStr(code, { | ||
rules: { 'check-send-result': 'error' } | ||
}) | ||
assert.equal(report.errorCount, 0) | ||
}) | ||
it('do not emit error when an assert is used upper in the tree', () => { | ||
const code = funcWith('assert(x.send(1) || something);') | ||
const report = linter.processStr(code, { | ||
rules: { 'check-send-result': 'error' } | ||
}) | ||
assert.equal(report.errorCount, 0) | ||
}) | ||
it('emit error when an arbitrary function surrounds the expression', () => { | ||
const code = funcWith('f(x.send(1));') | ||
const report = linter.processStr(code, { | ||
rules: { 'check-send-result': 'error' } | ||
}) | ||
assert.equal(report.errorCount, 1) | ||
}) | ||
}) |
1372206
28238
240