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 3.3.1 to 3.3.2

4

lib/rules/best-practises/max-states-count.js

@@ -58,3 +58,5 @@ const _ = require('lodash')

.filter(({ type }) => type === 'StateVariableDeclaration')
.flatMap(subNode => subNode.variables.filter(variable => !variable.isDeclaredConst))
.flatMap(({ variables }) =>
variables.filter(({ isDeclaredConst, isImmutable }) => !isDeclaredConst && !isImmutable)
)
.value().length

@@ -61,0 +63,0 @@

@@ -39,10 +39,24 @@ const BaseChecker = require('./../base-checker')

getTokensWithoutFunctionParams(node) {
const parametersCount = node.parameters.length
const nodeStart = parametersCount
? node.parameters[parametersCount - 1].loc.end
: node.loc.start
const lastParamIndex = this.tokens.findIndex(
token =>
token.loc.start.line === nodeStart.line && token.loc.start.column === nodeStart.column
)
// discard parameters
return this.tokens.slice(lastParamIndex + 1)
}
FunctionDefinition(node) {
if (node.visibility !== 'default' && (node.stateMutability || node.modifiers.length)) {
const functionTokens = []
const nodeStart = node.loc.start.line
const nodeEnd = node.loc.end.line
const nodeEnd = node.loc.end
const tokens = this.getTokensWithoutFunctionParams(node)
for (let i = 0, n = this.tokens.length; i < n; ++i) {
const token = this.tokens[i]
for (let i = 0, n = tokens.length; i < n; ++i) {
const token = tokens[i]

@@ -56,13 +70,12 @@ if (functionTokens.length && token.value === '{') break

if (
nodeStart <= start.line &&
start.line <= nodeEnd &&
['Keyword', 'Identifier'].includes(type)
) {
if (start.line <= nodeEnd.line && ['Keyword', 'Identifier'].includes(type)) {
functionTokens.push(token)
}
}
const visibilityIndex = functionTokens.findIndex(t => t.value === node.visibility)
const stateMutabilityIndex = functionTokens.findIndex(t => t.value === node.stateMutability)
const modifierIndex = functionTokens.findIndex(t => t.value === node.modifiers[0].name)
const modifierIndex = node.modifiers.length
? functionTokens.findIndex(t => t.value === node.modifiers[0].name)
: -1

@@ -69,0 +82,0 @@ if (

{
"name": "solhint",
"version": "3.3.1",
"version": "3.3.2",
"description": "Solidity Code Linter",

@@ -38,3 +38,3 @@ "main": "lib/index.js",

"dependencies": {
"@solidity-parser/parser": "^0.8.1",
"@solidity-parser/parser": "^0.8.2",
"ajv": "^6.6.1",

@@ -41,0 +41,0 @@ "antlr4": "4.7.1",

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

```sh
solhint "contracts/**/*.sol"
solhint 'contracts/**/*.sol'
```

@@ -47,0 +47,0 @@

@@ -48,2 +48,16 @@ const { assertErrorCount, assertNoErrors, assertErrorMessage } = require('./../../common/asserts')

})
it('should not count immutable variables', () => {
const code = contractWith(`
uint public immutable a;
uint public b;
uint public c;
function f() {}
`)
const report = linter.processStr(code, { rules: { 'max-states-count': ['error', 2] } })
assertNoErrors(report)
})
})
const assert = require('assert')
const linter = require('./../../../lib/index')
const { contractWith } = require('./../../common/contract-builder')

@@ -13,3 +14,2 @@ describe('Linter - visibility-modifier-order', () => {

assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('Visibility'))
})

@@ -26,2 +26,12 @@

})
it('should not raise error if a payable address is a parameter', () => {
const code = contractWith('function foo(address payable addr) public payable {}')
const report = linter.processStr(code, {
rules: { 'visibility-modifier-order': 'error' }
})
assert.equal(report.errorCount, 0)
})
})
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