-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check for assets, refactor, error indexes (#17)
* refactor flint package * refactor builtins to share value check logic + asset validator * add asset rule * update readme
- Loading branch information
Showing
13 changed files
with
285 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package builtins | ||
|
||
import "fmt" | ||
|
||
// mapAnyToStr maps any slice to string slice and calls f for each string. | ||
// values that don't pass a type assertion to string are ignored. | ||
func mapAnyToStr(vv []any, f func(s string, i int)) { | ||
for i, v := range vv { | ||
s, ok := v.(string) | ||
if !ok { | ||
continue | ||
} | ||
|
||
f(s, i) | ||
} | ||
} | ||
|
||
func fmtKeyCords(x, y int) string { | ||
if x == -1 { | ||
return "0:0" | ||
} | ||
|
||
return fmt.Sprintf("%d:%d", x, y) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package builtins | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
|
||
"github.com/hay-kot/flint/pkgs/set" | ||
) | ||
|
||
func (b BuiltIns) AssetsFunc(fields []string, dirs []string) Checker { | ||
return b.valueCheckerFactory(fields, func(v string) bool { | ||
for _, dir := range dirs { | ||
path := filepath.Join(dir, v) | ||
if _, err := os.Stat(path); err == nil { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
}) | ||
} | ||
|
||
func (b BuiltIns) EnumFunc(values []string, fields []string) Checker { | ||
valuesSet := set.New(values...) | ||
|
||
return b.valueCheckerFactory(fields, func(v string) bool { | ||
return valuesSet.Contains(v) | ||
}) | ||
} | ||
|
||
func (b BuiltIns) MatchFunc(patterns []string, fields []string) Checker { | ||
compiled := make([]*regexp.Regexp, 0, len(patterns)) | ||
for _, r := range patterns { | ||
compiled = append(compiled, regexp.MustCompile(r)) | ||
} | ||
|
||
return b.valueCheckerFactory(fields, func(v string) bool { | ||
for _, r := range compiled { | ||
if r.MatchString(v) { | ||
return true | ||
} | ||
} | ||
return false | ||
}) | ||
} | ||
|
||
func (b BuiltIns) LengthFunc(min, max int, fields []string) Checker { | ||
return b.valueCheckerFactory(fields, func(v string) bool { | ||
return len(v) >= min && len(v) <= max | ||
}) | ||
} |
Oops, something went wrong.