Skip to content

Commit

Permalink
Merge pull request #509 from protofire/i508-export-to-file
Browse files Browse the repository at this point in the history
I508 export to file
  • Loading branch information
dbale-altoros authored Oct 18, 2023
2 parents d686cde + 5298a75 commit 23833d5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ convertLib.sol
antlr4.jar
/docs/.sass-cache/
_temp/
*solhintReport*.*

30 changes: 25 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## [4.0] - 2023-10-01

### Updated
- Enhance explicit types sensitivity [493](https://github.com/protofire/solhint/pull/493) (Thanks to @vladyan18)
- Docs on `private-vars-leading-underscore` rule to clarify its functionality
- Changelog and docs for `no-empty-blocks` rule to clarify its functionality

### Added
- `fixShow` option to show report. `fix` option skips showing report on screen
- `save` option to store report on disk with the standard or the specified format
- Check for updates on Solhint version to keep users with the last versin available. There's an option to disable this check (`--disc`)
- Autofix for `explicit-types` rule [504](https://github.com/protofire/solhint/pull/504)

### Fixed
- Generate docs script on Windows OS [494](https://github.com/protofire/solhint/pull/494) (Thanks to @vladyan18)




## [3.6.2] - 2023-08-17
### Added
- New Rule: `one-contract-per-file` - Enforces the use of ONE contract per file [#487](https://github.com/protofire/solhint/pull/487)
Expand Down Expand Up @@ -31,22 +50,24 @@ If not explicitly added, this rule will not be executed.
### SPECIAL ATTENTION
- RULE: `compiler-version` default was updated from ^0.5.2 to ^0.8.0


### Updated
- Rule: `check-send-result` added config clarification in the new `Notes` section [#482](https://github.com/protofire/solhint/pull/482)
- Rule: `compiler-version` default was updated from ^0.5.2 to ^0.8.0 [#483](https://github.com/protofire/solhint/pull/483)

### Added
- New Rule: Enforces the use of Custom Errors over Require and Revert statements [#475](https://github.com/protofire/solhint/pull/475)
- New Rule: Enforces the test_ prefix on a file for Foundry users [#476](https://github.com/protofire/solhint/pull/476)
- New Rule: Enforces the naming of function return values [#478](https://github.com/protofire/solhint/pull/478)
- `Notes` option on docs to add more information of each rule. See `foundry-test-functions`. [#476](https://github.com/protofire/solhint/pull/476)

### Fixed
- `func-named-parameters` - false positives on builtin functions [#472](https://github.com/protofire/solhint/pull/472)
- `ordering` - treat initializer weight same as constructor [#474](https://github.com/protofire/solhint/pull/474)
- `check-send-result` - false positive on `erc777.send()`` function [#477](https://github.com/protofire/solhint/pull/477)
- `explicit-types` - default value is now taking into account when no value is specified in config [#481](https://github.com/protofire/solhint/pull/481)
- `compiler-version` - default value is now taking into account when no value is specified in config [#483](https://github.com/protofire/solhint/pull/483)

### Updates
- Rule: `check-send-result` added config clarification in the new `Notes` section [#482](https://github.com/protofire/solhint/pull/482)
- Rule: `compiler-version` default was updated from ^0.5.2 to ^0.8.0 [#483](https://github.com/protofire/solhint/pull/483)



Expand All @@ -64,7 +85,6 @@ If not explicitly added, this rule will not be executed.
- Removed runtime dependencies on load-rules [#462](https://github.com/protofire/solhint/pull/462)
- Allowed $ symbol as part of naming [#465](https://github.com/protofire/solhint/issues/465)
- Disabled `no-empty-blocks` rule for receive() function [#466](https://github.com/protofire/solhint/pull/466)


### Added
- New Rule: No unused imports [#417](https://github.com/protofire/solhint/pull/417)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Options:
--fix automatically fix problems. Skip report
--fixShow automatically fix problems. Show report
--init create configuration file for solhint
do not check for solhint updates
--disc do not check for solhint updates
--save save report to file on current folder
-h, --help output usage information
Commands:
Expand All @@ -76,6 +77,7 @@ Commands:
### 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.
- `--save` option will create a file named as `YYYYMMDDHHMMSS_solhintReport.txt` on current folder with default or specified format
<br><br>
## Configuration

Expand Down
4 changes: 2 additions & 2 deletions e2e/formatters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('e2e', function () {
}
expect(code).to.equal(0)

const finalLine = '3 problem/s (3 warning/s) '
const finalLine = '3 problem/s (3 warning/s)'
expect(reportLines[reportLines.length - 2]).to.equal(finalLine)
})
it('should make the output report with unix formatter for Foo and Foo2 and Foo3', () => {
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('e2e', function () {
}
expect(code).to.equal(0)

const finalLine = '3 problem/s (3 warning/s) '
const finalLine = '3 problem/s (3 warning/s)'
expect(reportLines[reportLines.length - 2]).to.equal(finalLine)
})
it('should make the output report with compact formatter for Foo and Foo2 and Foo3', () => {
Expand Down
51 changes: 30 additions & 21 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function init() {
.option('--fixShow', 'automatically fix problems. Show fixes in report')
.option('--init', 'create configuration file for solhint')
.option('--disc', 'do not check for solhint updates')
.option('--save', 'save report to file on current folder')
.description('Linter for Solidity programming language')
.action(execMainAction)

Expand Down Expand Up @@ -241,12 +242,40 @@ function printReports(reports, formatter) {
}
}

console.log(formatter(reports), finalMessage || '')
const fullReport = formatter(reports) + (finalMessage || '')
console.log(fullReport)

if (program.opts().save) {
writeStringToFile(fullReport)
}

if (exitWithOne) process.exit(1)
return reports
}

function writeStringToFile(data) {
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0') // Months are zero-based
const day = String(now.getDate()).padStart(2, '0')
const hour = String(now.getHours()).padStart(2, '0')
const minute = String(now.getMinutes()).padStart(2, '0')
const second = String(now.getSeconds()).padStart(2, '0')

const fileName = `${year}${month}${day}${hour}${minute}${second}_solhintReport.txt`

// Remove ANSI escape codes from the data
// eslint-disable-next-line no-control-regex
const cleanedData = data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')

try {
fs.writeFileSync(fileName, cleanedData, 'utf-8') // Specify the encoding (UTF-16)
// console.log('File written successfully:', fileName)
} catch (err) {
console.error('Error writing to file:', err)
}
}

function getFormatter(formatter) {
const formatterName = formatter || 'stylish'
try {
Expand Down Expand Up @@ -304,26 +333,6 @@ function exitWithCode(reports) {
process.exit(errorsCount > 0 ? 1 : 0)
}

// async function checkForUpdate() {
// try {
// // Dynamic import of latest-version
// // eslint-disable-next-line import/no-extraneous-dependencies
// const latestVersionModule = await import('latest-version')
// const latestVersion = latestVersionModule.default

// const currentVersion = require('./package.json').version

// const latest = await latestVersion('solhint')

// if (currentVersion !== latest) {
// console.log('\nA new version of Solhint is available:', latest)
// console.log('Please consider updating your Solhint package.')
// }
// } catch (error) {
// console.log('Error checking for updates: ', error.message)
// }
// }

function checkForUpdate() {
// eslint-disable-next-line import/no-extraneous-dependencies
return import('latest-version')
Expand Down

0 comments on commit 23833d5

Please sign in to comment.