Skip to content

Commit

Permalink
Merge pull request #623 from protofire/fix-minor-typos
Browse files Browse the repository at this point in the history
fix: minor typos
  • Loading branch information
dbale-altoros authored Jan 15, 2025
2 parents 46c9196 + 7fd122b commit 7055c5a
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 27 deletions.
2 changes: 1 addition & 1 deletion conf/rulesets/solhint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ module.exports = Object.freeze({
immutablesAsConstants: true,
},
],
'imports-order': 'warn',
'modifier-name-mixedcase': 'warn',
'named-parameters-mapping': 'warn',
'private-vars-leading-underscore': [
Expand All @@ -62,6 +61,7 @@ module.exports = Object.freeze({
'use-forbidden-name': 'warn',
'var-name-mixedcase': 'warn',
'imports-on-top': 'warn',
'imports-order': 'warn',
ordering: 'warn',
'visibility-modifier-order': 'warn',
'avoid-call-value': 'warn',
Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ title: "Rule Index of Solhint"
| [func-named-parameters](./rules/naming/func-named-parameters.md) | Enforce named parameters for function calls with 4 or more arguments. This rule may have some false positives | | |
| [func-param-name-mixedcase](./rules/naming/func-param-name-mixedcase.md) | Function param name must be in mixedCase. | | |
| [immutable-vars-naming](./rules/naming/immutable-vars-naming.md) | Check Immutable variables. Capitalized SNAKE_CASE or mixedCase depending on configuration. | $~~~~~~~~$✔️ | |
| [imports-order](./rules/naming/imports-order.md) | Order the imports of the contract to follow a certain hierarchy (read "Notes section") | | |
| [modifier-name-mixedcase](./rules/naming/modifier-name-mixedcase.md) | Modifier name must be in mixedCase. | | |
| [named-parameters-mapping](./rules/naming/named-parameters-mapping.md) | Solidity v0.8.18 introduced named parameters on the mappings definition. | | |
| [private-vars-leading-underscore](./rules/naming/private-vars-leading-underscore.md) | Non-external functions and state variables should start with a single underscore. Others, shouldn't | | |
| [use-forbidden-name](./rules/naming/use-forbidden-name.md) | Avoid to use letters 'I', 'l', 'O' as identifiers. | $~~~~~~~~$✔️ | |
| [var-name-mixedcase](./rules/naming/var-name-mixedcase.md) | Variable names must be in mixedCase. (Does not check IMMUTABLES, use immutable-vars-naming) | $~~~~~~~~$✔️ | |
| [func-order](./rules/order/func-order.md) | Function order is incorrect. | | $~~~~~~~$✔️ |
| [imports-on-top](./rules/order/imports-on-top.md) | Import statements must be on top. | $~~~~~~~~$✔️ | |
| [imports-order](./rules/naming/imports-order.md) | Order the imports of the contract to follow a certain hierarchy (read "Notes section") | | |
| [ordering](./rules/order/ordering.md) | Check order of elements in file and inside each contract, according to the style guide. | | |
| [visibility-modifier-order](./rules/order/visibility-modifier-order.md) | Visibility modifier must be first in list of modifiers. | $~~~~~~~~$✔️ | |
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/code-complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ while (d > e) { }
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/code-complexity.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/explicit-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ uint public variableName = uint256(5)
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/explicit-types.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/function-max-lines.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This rule accepts an array of options:
This rule does not have examples.

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/function-max-lines.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/max-line-length.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This rule accepts an array of options:
This rule does not have examples.

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/max-line-length.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/max-states-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ This rule accepts an array of options:
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/max-states-count.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-console.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import "forge-std/consoleN.sol"
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/no-console.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-empty-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ constructor () { }
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/no-empty-blocks.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-global-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import "foo.sol"
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/no-global-import.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-unused-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/no-unused-import.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-unused-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
This rule does not have examples.

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/no-unused-vars.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/one-contract-per-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
This rule does not have examples.

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/one-contract-per-file.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/payable-fallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fallback() {} function g() payable {}
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/payable-fallback.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practices/reason-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ This rule accepts an array of options:
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/reason-string.js)
Expand Down
1 change: 1 addition & 0 deletions docs/rules/gas-consumption/gas-struct-packing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war

### Notes
- This rule assumes all UserDefinedTypeName take a new slot. (beware of Enums inside Structs)
- Simple cases like a struct with three addresses might be reported as false positive. (needs to be fixed)
- [source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing)
- [source 2](https://www.rareskills.io/post/gas-optimization?postId=c9db474a-ff97-4fa3-a51d-fe13ccb8fe3b#viewer-f8m1r) of the rule initiative

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/contract-name-capwords.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
This rule does not have examples.

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/contract-name-capwords.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/event-name-capwords.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
This rule does not have examples.

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/event-name-capwords.js)
Expand Down
8 changes: 4 additions & 4 deletions docs/rules/naming/imports-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
This rule does not have examples.

## Version
This rule was introduced in [Solhint 5.0.2](https://github.com/protofire/solhint/blob/v5.0.2)
This rule is introduced in the latest version.

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/imports-order.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/naming/imports-order.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/naming/imports-order.js)
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/order/imports-order.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/order/imports-order.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/order/imports-order.js)
2 changes: 1 addition & 1 deletion docs/rules/naming/interface-starts-with-i.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface Foo { function foo () external; }
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 5.0.4](https://github.com/protofire/solhint/blob/v5.0.4)

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/best-practices/interface-starts-with-i.js)
Expand Down
2 changes: 1 addition & 1 deletion e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('e2e', function () {
const { code, stderr } = shell.exec(`${NODE}solhint Foo.sol -c ./noconfig/.solhint.json`)

expect(code).to.equal(EXIT_CODES.BAD_OPTIONS)
expect(stderr).to.include('couldnt be found')
expect(stderr).to.include("couldn't be found")
})

it('should create an initial config with --init', function () {
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/gas-consumption/gas-struct-packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const meta = {
{
note: 'This rule assumes all UserDefinedTypeName take a new slot. (beware of Enums inside Structs) ',
},
{
note: 'Simple cases like a struct with three addresses might be reported as false positive. (needs to be fixed)',
},
{
note: '[source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing)',
},
Expand Down
2 changes: 0 additions & 2 deletions lib/rules/naming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const NamedParametersMappingChecker = require('./named-parameters-mapping')
const ImmutableVarsNamingChecker = require('./immutable-vars-naming')
const FunctionNamedParametersChecker = require('./func-named-parameters')
const FoundryTestFunctionsChecker = require('./foundry-test-functions')
const ImportsOrderChecker = require('./imports-order')

module.exports = function checkers(reporter, config) {
return [
Expand All @@ -28,6 +27,5 @@ module.exports = function checkers(reporter, config) {
new ImmutableVarsNamingChecker(reporter, config),
new FunctionNamedParametersChecker(reporter, config),
new FoundryTestFunctionsChecker(reporter, config),
new ImportsOrderChecker(reporter, config),
]
}
File renamed without changes.
2 changes: 2 additions & 0 deletions lib/rules/order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ const FuncOrderChecker = require('./func-order')
const ImportsOnTopChecker = require('./imports-on-top')
const VisibilityModifierOrderChecker = require('./visibility-modifier-order')
const OrderingChecker = require('./ordering')
const ImportsOrderChecker = require('./imports-order')

module.exports = function order(reporter, tokens) {
return [
new FuncOrderChecker(reporter),
new ImportsOnTopChecker(reporter),
new VisibilityModifierOrderChecker(reporter, tokens),
new OrderingChecker(reporter),
new ImportsOrderChecker(reporter),
]
}
3 changes: 2 additions & 1 deletion solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ function executeMainActionLogic() {

const customConfig = program.opts().config
if (customConfig && !fs.existsSync(customConfig)) {
console.error(`Config file "${customConfig}" couldnt be found.`)
console.error(`Config file "${customConfig}" couldn't be found.`)
process.exit(EXIT_CODES.BAD_OPTIONS)
}

let reports
try {
const reportLists = program.args.filter(_.isString).map(processPath)
// console.log('reportLists :>> ', reportLists)
reports = _.flatten(reportLists)
} catch (e) {
console.error(e)
Expand Down
24 changes: 23 additions & 1 deletion test/rules/gas-consumption/gas-struct-packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ const assert = require('assert')
const linter = require('../../../lib/index')
const TEST_CASES = require('../../fixtures/gas-consumption/gas-struct-packing-data')

// const { contractWith, multiLine } = require('../../common/contract-builder')

const replaceErrorMsg = (variableName) => {
const errMsg = `GC: For [ ${variableName} ] struct, packing seems inefficient. Try rearranging to achieve 32bytes slots`
return errMsg
}

describe('Linter - gas-struct-packingone', () => {
describe('Linter - gas-struct-packing', () => {
for (const contract of TEST_CASES.contractStructsInefficient) {
it(`should raise error for ${contract.name}`, () => {
const code = contract.code
Expand All @@ -30,4 +32,24 @@ describe('Linter - gas-struct-packingone', () => {
assert.equal(report.errorCount, 0)
})
}

// it(`should NOT raise error for `, () => {
// const code = contractWith(
// multiLine(
// // // Large Types Followed by Small Types
// 'struct MyStruct2 {',
// ' address addr1;',
// ' address addr2;',
// ' address addr3;',
// '}'
// )
// )
// const report = linter.processStr(code, {
// rules: { 'gas-struct-packing': 'error' },
// })

// console.log(report)

// // assert.equal(report.errorCount, 0)
// })
})

0 comments on commit 7055c5a

Please sign in to comment.