Skip to content

Commit

Permalink
add: automatic update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Oct 11, 2023
1 parent 38245b3 commit 9d96de0
Show file tree
Hide file tree
Showing 6 changed files with 721 additions and 45 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
By <a href="https://protofire.io/">Protofire</a>
</p>

[![Join Discord](https://img.shields.io/badge/join-Discord-red)](https://discord.gg/4TYGq3zpjs)
[![Donate with Ethereum](https://img.shields.io/badge/Donate-ETH-blue)](https://etherscan.io/address/0xA81705c8C247C413a19A244938ae7f4A0393944e)
[![NPM version](https://badge.fury.io/js/solhint.svg)](https://npmjs.org/package/solhint)
[![Coverage Status](https://coveralls.io/repos/github/protofire/solhint/badge.svg?branch=master)](
Expand All @@ -14,6 +15,7 @@ https://coveralls.io/github/protofire/solhint?branch=master)
This is an open source project for linting [Solidity](http://solidity.readthedocs.io/en/develop/) code. This project
provides both **Security** and **Style Guide** validations.

[JOIN OUR DISCORD SERVER](https://discord.gg/4TYGq3zpjs)
## Installation

You can install Solhint using **npm**:
Expand Down Expand Up @@ -63,15 +65,17 @@ Options:
--fix automatically fix problems. Skip report
--fixShow automatically fix problems. Show report
--init create configuration file for solhint
--disc do not check for solhint updates
-h, --help output usage information
Commands:
stdin [options] linting of source code data provided to STDIN
list-rules display covered rules of current .solhint.json
```
### Note
The `--fix` option currently works only on "avoid-throw" and "avoid-sha3" rules
### Notes
- Solhint checks if there are newer versions. The `--disc` option avoids that check.
- `--fix` option currently works only on "avoid-throw" and "avoid-sha3" rules.
<br><br>
## Configuration

Expand Down
38 changes: 19 additions & 19 deletions e2e/formatters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ describe('e2e', function () {

it('should fail when wrong formatter is specify', () => {
const formatterType = 'wrongOne'
const { code } = shell.exec(`solhint ${PATH}contracts/Foo2.sol -f ${formatterType}`)
const { code } = shell.exec(`solhint --disc ${PATH}contracts/Foo2.sol -f ${formatterType}`)
expect(code).to.equal(1)
})

describe('unix formatter tests', () => {
const formatterType = 'unix'

it('should return nothing when file does not exist and unix is the formatter', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo1.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})

it('should return nothing when file exists and there is no error/warning', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo3.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})
it('should make the output report with unix formatter for Foo2', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo2.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo2.sol -f ${formatterType}`)

const reportLines = stdout.split('\n')
let expectedLine
Expand Down Expand Up @@ -91,17 +91,17 @@ describe('e2e', function () {
const formatterType = 'json'

it('should return nothing when file does not exist and json is the formatter', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo1.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})
it('should return nothing when file exists and there is no error/warning', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo3.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})
it('should make the output report with json formatter for Foo2', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo2.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo2.sol -f ${formatterType}`)

const expectedFinalOutput = foo2Output.concat([{ conclusion: '3 problem/s (3 warning/s)' }])

Expand Down Expand Up @@ -135,18 +135,18 @@ describe('e2e', function () {
const formatterType = 'compact'

it('should return nothing when file does not exist and compact is the formatter', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo1.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})

it('should return nothing when file exists and there is no error/warning', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo3.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})
it('should make the output report with compact formatter for Foo2', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo2.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo2.sol -f ${formatterType}`)

const reportLines = stdout.split('\n')
let expectedLine
Expand Down Expand Up @@ -185,18 +185,18 @@ describe('e2e', function () {
const formatterType = 'stylish'

it('should return nothing when file does not exist and stylish is the formatter', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo1.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})

it('should return nothing when file exists and there is no error/warning', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo3.sol -f ${formatterType}`)
expect(code).to.equal(0)
expect(stdout.trim()).to.be.empty
})
it('should make the output report with stylish formatter for Foo2', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo2.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo2.sol -f ${formatterType}`)

const reportLines = stdout.split('\n')
let expectedLine = foo2Output[0].filePath
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('e2e', function () {
const formatterType = 'tap'

it('should return TAP header when file does not exist and tap is the formatter', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo1.sol -f ${formatterType}`)

const reportLines = stdout.split('\n')
expect(reportLines[0]).to.eq('TAP version 13')
Expand All @@ -260,7 +260,7 @@ describe('e2e', function () {
})

it('should return TAP header [ok 1] when file exists and there is no error/warning', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const reportLines = stdout.split('\n')
expect(reportLines[0]).to.eq('TAP version 13')
expect(reportLines[1]).to.eq('1..1')
Expand All @@ -269,7 +269,7 @@ describe('e2e', function () {
expect(code).to.equal(0)
})
it('should make the output report with tap formatter for Foo2', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo2.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo2.sol -f ${formatterType}`)

const reportLines = stdout.split('\n')
expect(reportLines[0]).to.eq('TAP version 13')
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('e2e', function () {
'╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢'

it('should return TABLE Footer when file does not exist and table is the formatter', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo1.sol -f ${formatterType}`)
const reportLines = stdout.split('\n')
expect(reportLines[1]).to.eq(tableFooter1)
expect(reportLines[2]).to.eq(tableFooter2)
Expand All @@ -314,7 +314,7 @@ describe('e2e', function () {
})

it('should return TABLE Footer when file exists and there is no error/warning', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo3.sol -f ${formatterType}`)
const reportLines = stdout.split('\n')
expect(reportLines[1]).to.eq(tableFooter1)
expect(reportLines[2]).to.eq(tableFooter2)
Expand All @@ -325,7 +325,7 @@ describe('e2e', function () {
expect(code).to.equal(0)
})
it('should make the output report with table formatter for Foo', () => {
const { code, stdout } = shell.exec(`solhint ${PATH}contracts/Foo.sol -f ${formatterType}`)
const { code, stdout } = shell.exec(`solhint --disc ${PATH}contracts/Foo.sol -f ${formatterType}`)
const reportLines = stdout.split('\n')

expect(reportLines[1]).to.eq(foo1Output[0].filePath)
Expand Down
28 changes: 14 additions & 14 deletions e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ describe('e2e', function () {
useFixture('01-no-config')

it('should fail', function () {
const { code } = shell.exec('solhint Foo.sol')
const { code } = shell.exec('solhint --disc Foo.sol')

expect(code).to.equal(1)
})

it('should create an initial config with --init', function () {
const { code } = shell.exec('solhint --init')
const { code } = shell.exec('solhint --disc --init')

expect(code).to.equal(0)

Expand All @@ -43,7 +43,7 @@ describe('e2e', function () {
})

it('should print usage if called without arguments', function () {
const { code, stdout } = shell.exec('solhint')
const { code, stdout } = shell.exec('solhint --disc ')

expect(code).to.equal(0)
expect(stdout).to.include('Usage: solhint [options]')
Expand All @@ -56,14 +56,14 @@ describe('e2e', function () {
useFixture('02-empty-solhint-json')

it('should print nothing', function () {
const { code, stdout } = shell.exec('solhint Foo.sol')
const { code, stdout } = shell.exec('solhint --disc Foo.sol')

expect(code).to.equal(0)
expect(stdout.trim()).to.equal('')
})

it('should show warning when using --init', function () {
const { code, stdout } = shell.exec('solhint --init')
const { code, stdout } = shell.exec('solhint --disc --init')

expect(code).to.equal(0)
expect(stdout.trim()).to.equal('Configuration file already exists')
Expand All @@ -74,14 +74,14 @@ describe('e2e', function () {
useFixture('03-no-empty-blocks')

it('should exit with 1', function () {
const { code, stdout } = shell.exec('solhint Foo.sol')
const { code, stdout } = shell.exec('solhint --disc Foo.sol')

expect(code).to.equal(1)
expect(stdout.trim()).to.contain('Code contains empty blocks')
})

it('should work with stdin', async function () {
const child = cp.exec('solhint stdin')
const child = cp.exec('solhint --disc stdin')

const stdoutPromise = getStream(child.stdout)

Expand All @@ -108,7 +108,7 @@ describe('e2e', function () {
useFixture('04-dotSol-on-path')

it('should handle directory names that end with .sol', function () {
const { code } = shell.exec('solhint contracts/**/*.sol')
const { code } = shell.exec('solhint --disc contracts/**/*.sol')
expect(code).to.equal(0)
})
})
Expand All @@ -122,27 +122,27 @@ describe('e2e', function () {
'Error/s found on rules! [max-warnings] param is ignored. Fixing errors enables max-warnings'

it('should not display [warnings exceeded] for max 7 warnings', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo.sol --max-warnings 7')
const { code, stdout } = shell.exec('solhint --disc contracts/Foo.sol --max-warnings 7')
expect(code).to.equal(0)
expect(stdout.trim()).to.not.contain(warningExceededMsg)
})

it('should display [warnings exceeded] for max 3 warnings and exit error 1', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo.sol --max-warnings 3')
const { code, stdout } = shell.exec('solhint --disc contracts/Foo.sol --max-warnings 3')

expect(code).to.equal(1)
expect(stdout.trim()).to.contain(warningExceededMsg)
})

it('should return error for Compiler version rule, ignoring 3 --max-warnings', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 3')
const { code, stdout } = shell.exec('solhint --disc contracts/Foo2.sol --max-warnings 3')

expect(code).to.equal(1)
expect(stdout.trim()).to.contain(errorFound)
})

it('should return error for Compiler version rule. No message for max-warnings', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 27')
const { code, stdout } = shell.exec('solhint --disc contracts/Foo2.sol --max-warnings 27')
expect(code).to.equal(1)
expect(stdout.trim()).to.not.contain(errorFound)
})
Expand All @@ -154,14 +154,14 @@ describe('e2e', function () {
useFixture('07-foundry-test')

it(`should raise error for empty blocks only`, () => {
const { code, stdout } = shell.exec('solhint contracts/Foo.sol')
const { code, stdout } = shell.exec('solhint --disc contracts/Foo.sol')

expect(code).to.equal(0)
expect(stdout.trim()).to.contain('Code contains empty blocks')
})

it(`should raise error for wrongFunctionDefinitionName() only`, () => {
const { code, stdout } = shell.exec('solhint -c test/.solhint.json test/FooTest.sol')
const { code, stdout } = shell.exec('solhint --disc -c test/.solhint.json test/FooTest.sol')

expect(code).to.equal(1)
expect(stdout.trim()).to.contain(
Expand Down
Loading

0 comments on commit 9d96de0

Please sign in to comment.