Skip to content

Commit

Permalink
husky hook to generate docs and ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
llllvvuu committed Jul 31, 2023
1 parent be2aa1c commit 1538f1e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

sh ./scripts/generate-changed.sh
1 change: 1 addition & 0 deletions 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 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)
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"test": "mocha --recursive",
"lint": "eslint .",
"generate-rulesets": "node scripts/generate-rulesets.js && prettier --write conf/rulesets",
"docs": "node scripts/generate-rule-docs.js"
"docs": "node scripts/generate-rule-docs.js",
"prepare": "husky install",
"prepublishOnly": "npm run lint && npm run test && npm run generate-rulesets"
},
"bin": {
"solhint": "solhint.js"
Expand Down Expand Up @@ -61,6 +63,7 @@
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.4",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"markdown-table": "^2.0.0",
"mocha": "^10.2.0",
"mocha-lcov-reporter": "^1.3.0",
Expand Down
11 changes: 11 additions & 0 deletions scripts/generate-changed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

changed() {
git diff-index --name-only -B -R -M -C HEAD lib/rules
git ls-files -t -o -m lib/rules
}

if [ "$(changed)" != "" ]; then
npm run generate-rulesets
npm run docs
fi

0 comments on commit 1538f1e

Please sign in to comment.