Skip to content

Commit

Permalink
Merge pull request #13 from loeffel-io/feature/loeffel-io/support-or-…
Browse files Browse the repository at this point in the history
…rules

support or rules, update sync
  • Loading branch information
loeffel-io authored Mar 17, 2020
2 parents 6b3655a + c76ae76 commit f9b1f20
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ An extremely fast file and directory name linter
## Example & How-to ([vue.js](https://github.com/vuejs/vue))

- `.ls-lint.yml` file must be present in your root directory
- Multiple rules supported by `,` - They are logicly *AND* combined
- Multiple rules supported by `|` - They are logicly *OR* combined
- `.dir` set rules for the current directory and their subdirectories
- Rules for subdirectories will overwrite the rules for all their subdirectories
- For Windows you must use backslashs `\` instead of slashs `/`
Expand Down Expand Up @@ -68,19 +68,19 @@ ignore:
### MacOS
```bash
curl -sL -o ls-lint https://github.com/loeffel-io/ls-lint/releases/download/v1.5.1/ls-lint-darwin && chmod +x ls-lint && ./ls-lint
curl -sL -o ls-lint https://github.com/loeffel-io/ls-lint/releases/download/v1.6.0/ls-lint-darwin && chmod +x ls-lint && ./ls-lint
```

### Linux

```bash
curl -sL -o ls-lint https://github.com/loeffel-io/ls-lint/releases/download/v1.5.1/ls-lint-linux && chmod +x ls-lint && ./ls-lint
curl -sL -o ls-lint https://github.com/loeffel-io/ls-lint/releases/download/v1.6.0/ls-lint-linux && chmod +x ls-lint && ./ls-lint
```

### Windows

```bash
# (!) First download the .exe from https://github.com/loeffel-io/ls-lint/releases/download/v1.5.1/ls-lint-windows.exe
# (!) First download the .exe from https://github.com/loeffel-io/ls-lint/releases/download/v1.6.0/ls-lint-windows.exe
ls-lint-windows.exe
```

Expand Down Expand Up @@ -136,6 +136,12 @@ docker run -t -v /path/to/files:/data lslintorg/ls-lint:1
- [x] Npm package
- [x] Add ignore directories and files

## Major changes

**v1.6.x**

- Rules are not longer logicly `AND` combined - Now they are logicly `OR` combined by `|`

## Benchmarks ([hyperfine](https://github.com/sharkdp/hyperfine))

| Package | Mean [s] | File |
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
extSep = "."
root = "."
dir = ".dir"
or = "|"
)

type Config struct {
Expand Down Expand Up @@ -114,7 +115,7 @@ func (config *Config) walkIndex(index index, key string, list ls) error {
continue
}

for _, ruleName := range strings.Split(v.(string), ",") {
for _, ruleName := range strings.Split(v.(string), or) {
ruleName = strings.TrimSpace(ruleName)
ruleSplit := strings.SplitN(ruleName, ":", 2)
ruleName = ruleSplit[0]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/loeffel-io/ls-lint
go 1.13

require (
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
gopkg.in/yaml.v2 v2.2.8
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
Expand Down
45 changes: 28 additions & 17 deletions linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func (linter *Linter) addError(error *Error) {

func (linter *Linter) validateDir(config *Config, index index, path string) error {
var g = new(errgroup.Group)
var errRules = make([]Rule, 0)
var rulesError = 0
var rulesErrorMutex = new(sync.Mutex)

rules := config.getConfig(index, path)
basename := filepath.Base(path)
Expand All @@ -53,7 +54,9 @@ func (linter *Linter) validateDir(config *Config, index index, path string) erro
}

if !valid {
errRules = append(errRules, rule)
rulesErrorMutex.Lock()
rulesError += 1
rulesErrorMutex.Unlock()
}

return nil
Expand All @@ -64,26 +67,30 @@ func (linter *Linter) validateDir(config *Config, index index, path string) erro
return err
}

if len(errRules) > 0 {
linter.addError(&Error{
Path: path,
Rules: errRules,
RWMutex: new(sync.RWMutex),
})
if rulesError == 0 || rulesError != len(rules[dir]) {
return nil
}

linter.addError(&Error{
Path: path,
Rules: rules[dir],
RWMutex: new(sync.RWMutex),
})

return nil
}

func (linter *Linter) validateFile(config *Config, index index, entrypoint string, path string) error {
var ext string
var g = new(errgroup.Group)
var errRules = make([]Rule, 0)
var rulesError = 0
var rulesErrorMutex = new(sync.Mutex)

exts := strings.Split(filepath.Base(path), extSep)
rules := config.getConfig(index, path)

for i := 1; i < len(exts); i++ {
ext := fmt.Sprintf("%s%s", extSep, strings.Join(exts[i:], extSep))
ext = fmt.Sprintf("%s%s", extSep, strings.Join(exts[i:], extSep))
withoutExt := strings.TrimSuffix(filepath.Base(path), ext)

if _, exists := rules[ext]; exists {
Expand All @@ -97,7 +104,9 @@ func (linter *Linter) validateFile(config *Config, index index, entrypoint strin
}

if !valid {
errRules = append(errRules, rule)
rulesErrorMutex.Lock()
rulesError += 1
rulesErrorMutex.Unlock()
}

return nil
Expand All @@ -112,14 +121,16 @@ func (linter *Linter) validateFile(config *Config, index index, entrypoint strin
return err
}

if len(errRules) > 0 {
linter.addError(&Error{
Path: path,
Rules: errRules,
RWMutex: new(sync.RWMutex),
})
if rulesError == 0 || rulesError != len(rules[ext]) {
return nil
}

linter.addError(&Error{
Path: path,
Rules: rules[ext],
RWMutex: new(sync.RWMutex),
})

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
ruleMessages = append(ruleMessages, rule.GetErrorMessage())
}

log.Printf("%s failed for rules: %s", err.getPath(), strings.Join(ruleMessages, ", "))
log.Printf("%s failed for rules: %s", err.getPath(), strings.Join(ruleMessages, fmt.Sprintf(" %s ", or)))
}

os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ls-lint/ls-lint",
"version": "1.5.1",
"version": "1.6.0",
"description": "The 64-bit binary for ls-lint",
"repository": "https://github.com/loeffel-io/ls-lint",
"license": "MIT",
Expand Down

0 comments on commit f9b1f20

Please sign in to comment.