https://github.com/dalance/flexlint
A flexible linter with rules defined by regular expression
https://github.com/dalance/flexlint
command-line-tool lint linter rust
Last synced: about 1 year ago
JSON representation
A flexible linter with rules defined by regular expression
- Host: GitHub
- URL: https://github.com/dalance/flexlint
- Owner: dalance
- License: mit
- Created: 2018-10-18T10:02:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-10T20:41:25.000Z (over 1 year ago)
- Last Synced: 2025-04-02T06:07:25.565Z (about 1 year ago)
- Topics: command-line-tool, lint, linter, rust
- Language: Rust
- Homepage:
- Size: 460 KB
- Stars: 29
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# flexlint
**flexlint** is a flexible linter with rules defined by regular expression.
[](https://github.com/dalance/flexlint/actions)
[](https://crates.io/crates/flexlint)
## Install
Download from [release page](https://github.com/dalance/flexlint/releases/latest), and extract to the directory in PATH.
Alternatively you can install by [cargo](https://crates.io).
```
cargo install flexlint
```
## Usage
### Option
```
flexlint 0.1.0
dalance
A flexible linter with rules specified by regular expression
USAGE:
flexlint [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
-s, --simple Show results by simple format
-V, --version Prints version information
-v, --verbose Show verbose message
OPTIONS:
-r, --rule Rule file [default: .flexlint.toml]
```
Rule file is searched to the upper directory until `/`.
So you can put rule file (`.flexlint.toml`) on the repository root like `.gitignore`.
### Rule definition
Rule definition is below:
```toml
[[rules]]
name = "" # name of rule
pattern = "" # check pattern by regexp
required = "" # required pattern by regexp [Optional]
forbidden = "" # forbidden pattern by regexp [Optional]
ignore = "" # ignore pattern by regexp [Optional]
hint = "" # hint message
includes = [""] # include file globs
excludes = [""] # exclude file globs [Optional]
```
If `pattern` is matched, `required` or `forbidden` is tried to match at the `pattern` matched point.
So `required` pattern is not matched, or `forbidden` pattern is matched, then check is failed.
`required` and `forbidden` is optional, but if both of them is not defined, check is skipped.
If the `pattern` matched point is included in the `ignore` matched range, check is skipped.
If files matched `includes` match `excludes` too, the files are skipped.
The example for `if` with brace of C/C++ is below:
```toml
[[rules]]
name = "'if' with brace"
pattern = '(?m)(^|[\t ])if\s'
forbidden = '(?m)(^|[\t ])if\s[^;{]*$'
ignore = '(/\*/?([^/]|[^*]/)*\*/)|(//.*\n)'
hint = "multiline 'if' must have brace"
includes = ["**/*.c", "**/*.cpp"]
excludes = ["external/*.c"]
```
`pattern` is matched `if` keyword and `forbidden` check that `if` must have `;` or `{` until the end of line.
( This example don't support some brace-style, you can modify it )
`ignore` is defined to skip single line comment (`// ...`) and multi-line comment (`/* ... */`).
### Regular expression
The syntax of regular expression follows [Rust regex crate](https://docs.rs/regex/latest/regex/#syntax).
### The example of output
If flexlint is executed in `example` directory of the repository, the output is below:
```console
$ cd example
$ flexlint
Fail: 'if' with brace
--> test.c:4:4
|
4 | if ( hoge )
| ^^^^ hint: multiline 'if' must have brace
Fail: verilog 'always' forbidden
--> test.sv:7:4
|
7 | always @ ( posedge clk ) begin
| ^^^^^^^^ hint: 'always' must be replaced to 'always_comb'/'always_ff'
Fail: 'if' with 'begin'
--> test.sv:13:8
|
13 | if ( rst )
| ^^^^ hint: 'if' statement must have 'begin'
Fail: 'else' with 'begin'
--> test.sv:15:8
|
15 | else
| ^^^^^^ hint: 'else' statement must have 'begin'
```