Socket
Socket
Sign inDemoInstall

solhint

Package Overview
Dependencies
Maintainers
4
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solhint - npm Package Compare versions

Comparing version 2.1.2 to 2.2.0

lib/rules/best-practises/reason-string.js

1

docs/rules.md

@@ -88,1 +88,2 @@ ---

| **max-states-count** | Contract has "some count" states declarations but allowed no more than *maxstates* | [*\<[default](#options)\>*,&nbsp;*\<maxstates\>*] Default *maxstates* is **15**. |
| **reason-string** | Ensure that revert and require statements contains error message but allowed no more than *maxLength* | [*\<[default](#options)\>*,&nbsp;*{ maxLength: 50}*] Default *maxLength* is **32**. |

@@ -22,2 +22,6 @@ const _ = require('lodash')

getObjectPropertyNumber(ruleName, ruleProperty, defaultValue) {
return this.getNumberByPath(`rules["${ruleName}"][1][${ruleProperty}]`, defaultValue)
},
getString(ruleName, defaultValue) {

@@ -24,0 +28,0 @@ return this.getStringByPath(`rules["${ruleName}"][1]`, defaultValue)

@@ -0,1 +1,3 @@

const chalk = require('chalk')
const _ = require('lodash')
const ajv = require('../common/ajv')

@@ -41,2 +43,10 @@ const configSchema = require('./config-schema')

const deprecatedDisableValue = _.once(() => {
console.warn(
chalk.yellow(
'[Solhint] Warning: Disabling rules with `false` or `0` is deprecated. Please use `"off"` instead.'
)
)
})
const validate = config => {

@@ -48,2 +58,14 @@ validateSchema = validateSchema || ajv.compile(configSchema)

}
// show deprecated warning for rules that are configured with `false` or `0`
Object.keys(config.rules || {}).forEach(key => {
let severity = config.rules[key]
if (Array.isArray(severity)) {
severity = severity[0]
}
if (severity === false || severity === 0) {
deprecatedDisableValue()
}
})
}

@@ -50,0 +72,0 @@

4

lib/rules/best-practises/index.js

@@ -8,2 +8,3 @@ const CodeComplexityChecker = require('./code-complexity')

const PayableFallbackChecker = require('./payable-fallback')
const ReasonStringChecker = require('./reason-string')

@@ -18,4 +19,5 @@ module.exports = function checkers(reporter, config) {

new NoUnusedVarsChecker(reporter),
new PayableFallbackChecker(reporter)
new PayableFallbackChecker(reporter),
new ReasonStringChecker(reporter, config)
]
}
const BaseChecker = require('./../base-checker')
const lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u
const ruleId = 'max-line-length'

@@ -34,3 +36,3 @@ const meta = {

enterSourceUnit(ctx) {
const lines = ctx.parser._input.tokenSource._input.strdata.split('\n')
const lines = ctx.parser._input.tokenSource._input.strdata.split(lineBreakPattern)

@@ -37,0 +39,0 @@ lines.map(line => line.length).forEach(this.validateLineLength.bind(this))

@@ -0,1 +1,2 @@

const chalk = require('chalk')
const _ = require('lodash')

@@ -25,3 +26,12 @@ const security = require('./security/index')

return allRules.filter(coreRule => ruleEnabled(coreRule, rules))
const enabledRules = allRules.filter(coreRule => ruleEnabled(coreRule, rules))
// show warnings for deprecated rules
for (const rule of enabledRules) {
if (rule.meta && rule.meta.deprecated) {
console.warn(chalk.yellow(`[solhint] Warning: rule '${rule.ruleId}' is deprecated.`))
}
}
return enabledRules
}

@@ -28,0 +38,0 @@

@@ -16,2 +16,4 @@ const BaseChecker = require('./../base-checker')

deprecated: true,
schema: []

@@ -18,0 +20,0 @@ }

@@ -16,2 +16,4 @@ const BaseChecker = require('./../base-checker')

deprecated: true,
schema: []

@@ -18,0 +20,0 @@ }

@@ -39,2 +39,11 @@ const TreeTraversing = require('./../../common/tree-traversing')

enterEnumDefinition(ctx) {
this.gatherNonContractNames(ctx)
}
enterEnumValue(ctx) {
const enumValue = ctx.getText()
this.nonContractNames.push(enumValue)
}
exitStateVariableDeclaration(ctx) {

@@ -41,0 +50,0 @@ const hasConstModifier = ctx.children.some(i => i.getText() === 'constant')

{
"name": "solhint",
"version": "2.1.2",
"version": "2.2.0",
"description": "Solidity Code Linter",

@@ -33,2 +33,3 @@ "main": "solhint.js",

"antlr4": "4.7.1",
"chalk": "^2.4.2",
"commander": "2.18.0",

@@ -35,0 +36,0 @@ "cosmiconfig": "^5.0.7",

@@ -199,3 +199,3 @@ # Solhint Project

- OpenZeppelin:
- [openzeppelin-solidity](https://github.com/OpenZeppelin/openzeppelin-solidity)
- [openzeppelin-contracts](https://github.com/OpenZeppelin/openzeppelin-contracts)
- POA Network - Public EVM Sidechain:

@@ -202,0 +202,0 @@ - [Proof of Physical Address (PoPA)](https://github.com/poanetwork/poa-popa)

@@ -41,2 +41,8 @@ const assert = require('assert')

})
it('should work with an empty config', () => {
const config = {}
validate(config) // should not throw
})
})

@@ -25,2 +25,34 @@ const assert = require('assert')

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

@@ -90,2 +90,18 @@ const assert = require('assert')

})
it('should not return error for enum', () => {
const code = contractWith(`
enum Status { Initial }
function b() public view returns(Status) {
return Status.Initial;
}
`)
const report = linter.processStr(code, {
rules: { 'mark-callable-contracts': 'warn' }
})
assert.equal(report.warningCount, 0)
})
})

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