Skip to content

Commit 57c71b6

Browse files
committed
Clean up readme
1 parent b8ea96c commit 57c71b6

File tree

5 files changed

+101
-126
lines changed

5 files changed

+101
-126
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./bin/polylint
1+
/bin/polylint

Diff for: Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ test:
1919

2020
test-watch:
2121
watchexec -e go,yml,yaml -- go test -v .
22+
23+
benchmark:
24+
hyperfine --ignore-failure -- "./bin/polylint --config examples/simple.yaml run ~/src/runbook"

Diff for: README.md

+10-82
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,27 @@
22

33
# Features
44

5-
- [ ] Standard linters built using golang functions
6-
- [ ] contains
7-
- [ ] regexp match
8-
- [ ] Ignore mechanisms
9-
- [x] Ignore full file
10-
- [x] polylint disable-for-file=$RULE_ID
11-
- [x] Ignore next line
12-
- [x] polylint disable-next-line=$RULE_ID
13-
- [x] polylint disable=$RULE_ID
14-
- [ ] Ignore from lint runner via cli for file-level ignores
15-
- [ ] Types of rules
16-
- [x] line
17-
- [ ] file content
18-
- [ ] file path
19-
- [ ] Builtin linters configured for use in config file
20-
- [ ] Plugin linters configured for use in config file
21-
- [ ] otto / goja / v8go
22-
- [ ] supports line / file / path types
23-
- [ ] Use cobra for CLI
24-
- [ ] Replace argv[0] option to accept:
25-
- a directory
26-
- many files passed as argv
27-
- a testing config file used as virtual filesystem
28-
- [ ] Ensure that we confirm uniqueness of rule ids at the beginning of run during a pre-flight check
29-
- [ ] Build in a way to source rules from remote locations, via path + sha?
30-
- [ ] ie re-usable plugin infrastructure
31-
- make it an includes that is cached and pulled at runtime w/ SHAs
32-
- [ ] Rename rules to... rules or validations?
33-
- [ ] Add validation that the version of config file is supported
5+
- Simple and fast golang based builtin linting functions
6+
- Extensible embedded javascript based linters
7+
- Linting configurations can be `included` and referenced from external file or via http(s)
8+
- Each rule contains a severity, path match, path exclusions
349

3510
# Configuration
3611

3712
## Configuration Language
3813

39-
```yaml
40-
---
41-
version: 1.0
42-
rules:
43-
- id: no-print
44-
description: "Don't use print()"
45-
recommendation: "Use logging instead."
46-
severity: low
47-
link: https://docs.openstack.org/bandit/latest/plugins/b302_no_print.html
48-
include_paths: '\.py$'
49-
exclude_paths: null
50-
fn:
51-
type: builtin
52-
scope: line
53-
name: contains
54-
args: ['print(']
55-
- id: no-print-js
56-
description: "Don't use print()"
57-
recommendation: "Use logging instead."
58-
severity: low
59-
link: https://docs.openstack.org/bandit/latest/plugins/b302_no_print.html
60-
include_paths: '\.py$'
61-
exclude_paths: null
62-
fn:
63-
type: js
64-
scope: line
65-
name: printRule
66-
body: |
67-
function printRule(path, idx, line) {
68-
return line.contains('print')
69-
}
70-
- id: no-print-js-file-level
71-
description: "Don't use print()"
72-
recommendation: "Use logging instead."
73-
severity: low
74-
link: https://docs.openstack.org/bandit/latest/plugins/b302_no_print.html
75-
include_paths: '\.py$'
76-
exclude_paths: null
77-
fn:
78-
type: js
79-
scope: file
80-
name: printRule
81-
body: |
82-
function printRule(path, idx, file) {
83-
return file.contains('print')
84-
}
85-
```
86-
14+
See [config](examples/simple.yaml)
8715

8816
# Benchmarks
8917

90-
## 2024-04-08
18+
## 2024-04-11
9119

9220
Using test repo https://github.com/zph/runbook
9321
commit f290434f61a2d2b975cdcdcad060c4e01d2cdfc3 (HEAD -> main, tag: 0.3.0, origin/main, origin/HEAD)
9422

9523
```
96-
❯ hyperfine -- "./bin/polylint ~/src/runbook"
97-
Benchmark 1: ./bin/polylint ~/src/runbook
98-
Time (mean ± σ): 281.4 ms ± 1.3 ms [User: 155.5 ms, System: 133.5 ms]
99-
Range (min … max): 279.1 ms … 282.7 ms 10 runs
24+
❯ hyperfine --ignore-failure -- "./bin/polylint --config examples/simple.yaml run ~/src/runbook"
25+
Benchmark 1: ./bin/polylint --config examples/simple.yaml run ~/src/runbook
26+
Time (mean ± σ): 379.2 ms ± 3.7 ms [User: 251.0 ms, System: 142.4 ms]
27+
Range (min … max): 374.4 ms … 384.6 ms 10 runs
10028
```

Diff for: TODO.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# TODO
2+
3+
- [x] Standard linters built using golang functions
4+
- [x] contains
5+
- [x] regexp match
6+
- [x] Ignore mechanisms
7+
- [x] Ignore full file
8+
- [x] polylint disable-for-file=$RULE_ID
9+
- [x] Ignore next line
10+
- [x] polylint disable-next-line=$RULE_ID
11+
- [x] polylint disable=$RULE_ID
12+
- [x] Ignore for path match
13+
- [x] polylint disable-for-path=$RULE_ID,$RULE_ID2
14+
- [x] Types of rules
15+
- [x] line
16+
- [x] file content
17+
- [x] file path
18+
- [ ] Builtin linters configured for use in config file
19+
- [x] Plugin linters configured for use in config file
20+
- [x] otto / goja / v8go
21+
- [x] supports line / file / path types
22+
- [x] Use cobra for CLI
23+
- [x] Build in a way to source rules from remote locations, via path + sha?
24+
- [x] ie re-usable plugin infrastructure
25+
- [x] support include statements
26+
- [x] support SHA hash requirement for includes
27+
- [ ] support caching
28+
- [x] Rename rules to... rules or validations?
29+
- [x] Add validation that the version of config file is supported
30+
- [ ] Ensure that we confirm uniqueness of rule ids at the beginning of run during a pre-flight check
31+
- [x] Replace argv[0] option to accept:
32+
- a directory
33+
- many files passed as argv
34+
- [deferred]a testing config file used as virtual filesystem
35+
- [ ] Set the severity threshold for what constitutes a non-zero exit code
36+
- [ ] Add pluggable output reporters
37+
- [ ] Textual / table based reporter
38+
- [ ] Colored output
39+
- [ ] JSON reporter
40+
- [ ] Configurable logging (log levels for debugging and k/v log values)

Diff for: cmd/run.go

+47-43
Original file line numberDiff line numberDiff line change
@@ -27,66 +27,70 @@ to quickly create a Cobra application.`,
2727
Run: RunCmd,
2828
}
2929

30-
func Run(cmd *cobra.Command, args []string) (int, error) {
30+
func Run(cmd *cobra.Command, args []string) (int, []error) {
3131
var exitCode int
3232
exitCode = 0
33-
if len(args) == 1 {
34-
// We're treating this as a root folder
35-
} else {
36-
// Treat this as individual files
37-
}
38-
root := args[0]
39-
configRaw, err := os.ReadFile(cfgFile)
40-
if err != nil {
41-
panic(err)
42-
}
43-
cfg, err := pl.LoadConfigFile(string(configRaw))
44-
45-
if err != nil {
46-
fmt.Printf("error loading config: %v\n", err)
47-
return exitCode, err
48-
}
49-
50-
err = filepath.Walk(root, func(path string, info fs.FileInfo, err error) error {
33+
var errs []error
34+
for _, root := range args {
35+
configRaw, err := os.ReadFile(cfgFile)
5136
if err != nil {
52-
fmt.Printf("error accessing path %q: %v\n", path, err)
53-
return err
37+
panic(err)
5438
}
39+
cfg, err := pl.LoadConfigFile(string(configRaw))
5540

56-
// Check if the file has the extension
57-
if !info.IsDir() {
58-
content, err := os.ReadFile(path)
41+
if err != nil {
42+
fmt.Printf("error loading config: %v\n", err)
43+
return exitCode, []error{err}
44+
}
5945

46+
err = filepath.Walk(root, func(path string, info fs.FileInfo, err error) error {
6047
if err != nil {
61-
fmt.Printf("error reading file %q: %v\n", path, err)
48+
fmt.Printf("error accessing path %q: %v\n", path, err)
6249
return err
6350
}
6451

65-
result, err2 := pl.ProcessFile(string(content), path, cfg)
66-
if err2 != nil {
67-
return fmt.Errorf("error processing file %q: %v", path, err2)
68-
}
52+
// Check if the file has the extension
53+
if !info.IsDir() {
54+
content, err := os.ReadFile(path)
6955

70-
if len(result.Findings) > 0 {
71-
fmt.Printf("\n%s: violations count %d\n", result.Path, len(result.Findings))
72-
for idx, finding := range result.Findings {
73-
// TODO: figure out why the rule embedded is wrong
74-
fmt.Printf("%d: %s:%d %s %s\n", idx+1, result.Path, finding.LineNo, finding.RuleId, finding.Rule.Description)
56+
if err != nil {
57+
fmt.Printf("error reading file %q: %v\n", path, err)
58+
return err
59+
}
60+
61+
result, err2 := pl.ProcessFile(string(content), path, cfg)
62+
if err2 != nil {
63+
return fmt.Errorf("error processing file %q: %v", path, err2)
7564
}
76-
exitCode = 1
77-
}
78-
}
7965

80-
return nil
81-
})
66+
if len(result.Findings) > 0 {
67+
fmt.Printf("\n%s: violations count %d\n", result.Path, len(result.Findings))
68+
for idx, finding := range result.Findings {
69+
// TODO: figure out why the rule embedded is wrong
70+
fmt.Printf("%d: %s:%d %s %s\n", idx+1, result.Path, finding.LineNo, finding.RuleId, finding.Rule.Description)
71+
}
72+
exitCode = 1
73+
}
74+
}
8275

83-
return exitCode, err
76+
return nil
77+
})
78+
errs = append(errs, err)
79+
}
80+
nonNilErrors := make([]error, 0)
81+
for _, e := range errs {
82+
if e != nil {
83+
nonNilErrors = append(nonNilErrors, e)
84+
}
85+
}
86+
return exitCode, nonNilErrors
8487
}
8588

8689
func RunCmd(cmd *cobra.Command, args []string) {
87-
exitCode, err := Run(cmd, args)
88-
if err != nil {
89-
panic(err)
90+
exitCode, errs := Run(cmd, args)
91+
if len(errs) > 0 {
92+
fmt.Printf("Errors: %+v", errs)
93+
panic(errs)
9094
}
9195
os.Exit(exitCode)
9296
}

0 commit comments

Comments
 (0)