Skip to content

Commit

Permalink
Merge pull request #443 from protofire/i429-solhint-default-ruleset
Browse files Browse the repository at this point in the history
fix: I429 added default ruleset description and [quotes] rule fixed
  • Loading branch information
fiction-code authored Jul 7, 2023
2 parents 6f9949a + a18f72e commit c561e53
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parserOptions: {
ecmaVersion: 8,
ecmaVersion: 2020,
},
env: {
browser: false,
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Linter for Solidity programming language
Options:
-V, --version output the version number
-f, --formatter [name] report formatter name (stylish, table, tap, unix)
-f, --formatter [name] report formatter name (stylish, table, tap, unix, json)
-w, --max-warnings [maxWarningsNumber] number of allowed warnings
-c, --config [file_name] file to use as your .solhint.json
-q, --quiet report errors only - default: false
Expand All @@ -68,7 +68,9 @@ Commands:
stdin [options] linting of source code data provided to STDIN
```

### Note
The `--fix` option currently works only on "avoid-throw" and "avoid-sha3" rules
<br><br>
## Configuration

You can use a `.solhint.json` file to configure Solhint for the whole project.
Expand All @@ -86,6 +88,10 @@ This file has the following format:
"extends": "solhint:default"
}
```
### Note
The `solhint:default` configuration contains only two rules: max-line-length & no-console
<br><br>


### Sample
```json
Expand Down
3 changes: 2 additions & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ title: "Rule Index of Solhint"
| [no-console](./rules/best-practises/no-console.md) | No console.log/logInt/logBytesX/logString/etc & No hardhat and forge-std console.sol import statements | ✔️ |
| [no-empty-blocks](./rules/best-practises/no-empty-blocks.md) | Code contains empty block. | ✔️ |
| [no-global-import](./rules/best-practises/no-global-import.md) | Import statement includes an entire file instead of selected symbols | ✔️ |
| [no-unused-import](./rules/best-practises/no-unused-import.md) | Imported name is not used | ✔️ |
| [no-unused-vars](./rules/best-practises/no-unused-vars.md) | Variable "name" is unused. | ✔️ |
| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable you will not be able to receive ethers. | ✔️ |
| [reason-string](./rules/best-practises/reason-string.md) | Require or revert statement must have a reason string and check that each reason string is at most N characters long. | ✔️ |
Expand All @@ -26,13 +27,13 @@ title: "Rule Index of Solhint"
| Rule Id | Error | Recommended |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| [comprehensive-interface](./rules/miscellaneous/comprehensive-interface.md) | Check that all public or external functions are override. This is iseful to make sure that the whole API is extracted in an interface. | |
| [quotes](./rules/miscellaneous/quotes.md) | Use double quotes for string literals. Values must be 'single' or 'double'. | ✔️ |

## Style Guide Rules

| Rule Id | Error | Recommended |
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ----------- |
| [quotes](./rules/miscellaneous/quotes.md) | Use double quotes for string literals. Values must be 'single' or 'double'. | ✔️ |
| [const-name-snakecase](./rules/naming/const-name-snakecase.md) | Constant name must be in capitalized SNAKE_CASE. | ✔️ |
| [contract-name-camelcase](./rules/naming/contract-name-camelcase.md) | Contract name must be in CamelCase. | ✔️ |
| [event-name-camelcase](./rules/naming/event-name-camelcase.md) | Event name must be in CamelCase. | ✔️ |
Expand Down
39 changes: 39 additions & 0 deletions docs/rules/best-practises/no-unused-import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "no-unused-import | Solhint"
---

# no-unused-import
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practise%20Rules-informational)
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)
> The {"extends": "solhint:recommended"} property in a configuration file enables this rule.

## Description
Imported name is not used

## Options
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn.

### Example Config
```json
{
"rules": {
"no-unused-import": "warn"
}
}
```


## Examples
This rule does not have examples.

## Version
This rule is introduced in the latest version.

## Resources
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/best-practises/no-unused-import.js)
- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/best-practises/no-unused-import.md)
- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/best-practises/no-unused-import.js)
2 changes: 1 addition & 1 deletion docs/rules/miscellaneous/quotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "quotes | Solhint"

# quotes
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Style%20Guide%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Miscellaneous-informational)
![Default Severity Badge error](https://img.shields.io/badge/Default%20Severity-error-red)
> The {"extends": "solhint:recommended"} property in a configuration file enables this rule.
Expand Down
2 changes: 1 addition & 1 deletion lib/formatters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ files in this directory are pulled from eslint repository:
- unix.js: eslint v8.32.0 oshi-shinobu
- tap.js: eslint v8.32.0 Jonathan Kingston
- stylish.js: eslint v8.32.0 by Sindre Sorhus

- json.js: eslint v8.32.0 by Artur Lukianov & Diego Bale
42 changes: 42 additions & 0 deletions lib/formatters/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @fileoverview JSON Style formatter
* @author ArturLukianov <Original Idea and base source code> <https://github.com/ArturLukianov>
* @collaborator Diego Bale
*/

//------------------------------------------------------------------------------
// Helper Functions
//------------------------------------------------------------------------------

/**
* Returns a canonical error level string based upon the error message passed in.
* @param {Object} message Individual error message provided by eslint
* @returns {string} Error level string
*/
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return 'Error'
}
return 'Warning'
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

// eslint-disable-next-line func-names
module.exports = function (results) {
const allMessages = []

results.forEach((result) => {
const messages = result.messages

messages.forEach((message) => {
const fullObject = { ...message, filePath: result.filePath }
fullObject.severity = getMessageType(fullObject)
allMessages.push(fullObject)
})
})

return JSON.parse(JSON.stringify(allMessages))
}
5 changes: 3 additions & 2 deletions lib/formatters/stylish.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview Stylish reporter
* @fileoverview Stylish Style formatter
* @author Sindre Sorhus
*/

Expand All @@ -25,7 +25,8 @@ function pluralize(word, count) {
// Public Interface
//------------------------------------------------------------------------------

module.exports = function (results) { // eslint-disable-line
// eslint-disable-next-line func-names
module.exports = function (results) {
let output = '\n'
let errorCount = 0
let warningCount = 0
Expand Down
5 changes: 3 additions & 2 deletions lib/formatters/table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview "table reporter.
* @fileoverview Table Style formatter
* @author Gajus Kuizinas <gajus@gajus.com>
*/

Expand Down Expand Up @@ -108,7 +108,8 @@ function drawReport(results) {
// Public Interface
//------------------------------------------------------------------------------

module.exports = function (report) { // eslint-disable-line
// eslint-disable-next-line func-names
module.exports = function (report) {
let result
let errorCount
let warningCount
Expand Down
5 changes: 3 additions & 2 deletions lib/formatters/tap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview TAP reporter
* @fileoverview TAP Style formatter
* @author Jonathan Kingston
*/

Expand Down Expand Up @@ -39,7 +39,8 @@ function outputDiagnostics(diagnostic) {
// Public Interface
//------------------------------------------------------------------------------

module.exports = function (results) { // eslint-disable-line
// eslint-disable-next-line func-names
module.exports = function (results) {
let output = `TAP version 13\n1..${results.length}\n`

results.forEach((result, id) => {
Expand Down
5 changes: 3 additions & 2 deletions lib/formatters/unix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview unix-style formatter.
* @fileoverview Unix Style formatter
* @author oshi-shinobu
*/

Expand All @@ -23,7 +23,8 @@ function getMessageType(message) {
// Public Interface
//------------------------------------------------------------------------------

module.exports = function (results) { // eslint-disable-line
// eslint-disable-next-line func-names
module.exports = function (results) {
let output = ''
let total = 0

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/miscellaneous/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const meta = {

docs: {
description: `Use double quotes for string literals. Values must be 'single' or 'double'.`,
category: 'Style Guide Rules',
category: 'Miscellaneous',
options: [
{
description: severityDescription,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/security/avoid-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AvoidThrowChecker extends BaseChecker {
// we don't use just `node.range` because ThrowStatement includes the semicolon and the spaces before it
// we know that node.range[0] is the 't' of throw
// we're also pretty sure that 'throw' has 5 letters
fixer.replaceTextRange([node.range[0], node.range[0] + 5], 'revert()')
fixer.replaceTextRange([node.range[0], node.range[0] + 5], 'revert();')
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function init() {
program
.name('solhint')
.usage('[options] <file> [...other_files]')
.option('-f, --formatter [name]', 'report formatter name (stylish, table, tap, unix)')
.option('-f, --formatter [name]', 'report formatter name (stylish, table, tap, unix, json)')
.option('-w, --max-warnings [maxWarningsNumber]', 'number of allowed warnings')
.option('-c, --config [file_name]', 'file to use as your .solhint.json')
.option('-q, --quiet', 'report errors only - default: false')
Expand Down Expand Up @@ -119,6 +119,7 @@ function processStdin(options) {
const report = processStr(stdinBuffer.toString())
report.file = options.filename || 'stdin'
const formatterFn = getFormatter()

printReports([report], formatterFn)

exitWithCode([report])
Expand Down

0 comments on commit c561e53

Please sign in to comment.