Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jobs:
projectDirectory: resources/app-mpr-v1
modelsource: resources/modelsource-v1
export:
mode: basic
filter: ".*"
raw: false
appstore: false
Expand Down Expand Up @@ -132,7 +131,6 @@ jobs:
projectDirectory: resources/app-mpr-v2
modelsource: resources/modelsource-v2
export:
mode: basic
filter: ".*"
raw: false
appstore: false
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ mxlint-cli export-model [flags]
|------|-------|---------|-------------|
| `--input` | `-i` | `.` | Path to directory or mpr file to export. If it's a directory, all mpr files will be exported |
| `--output` | `-o` | `modelsource` | Path to directory to write the yaml files. If it doesn't exist, it will be created |
| `--mode` | `-m` | `basic` | Export mode. Valid options: `basic`, `advanced` |
| `--filter` | `-f` | | Regex pattern to filter units by name. Only units with names matching the pattern will be exported |
| `--raw` | | `false` | If set, the output yaml will include all attributes as they are in the model |
| `--appstore` | | `false` | If set, appstore modules will be included in the output |
Expand Down Expand Up @@ -107,7 +106,6 @@ lint:
export:
output: modelsource
input: .
mode: basic
filter: "*"
```

Expand Down Expand Up @@ -166,7 +164,6 @@ mxlint-cli serve [flags]
|------|-------|---------|-------------|
| `--input` | `-i` | `.` | Path to directory or mpr file to export. If it's a directory, all mpr files will be exported |
| `--output` | `-o` | `modelsource` | Path to directory to write the yaml files. If it doesn't exist, it will be created |
| `--mode` | `-m` | `basic` | Export mode. Valid options: `basic`, `advanced` |
| `--rules` | `-r` | `.mendix-cache/rules` | Path to directory with rules |
| `--port` | `-p` | `8082` | Port to run the server on |
| `--debounce` | `-d` | `500` | Debounce time in milliseconds for file change events |
Expand Down Expand Up @@ -336,7 +333,6 @@ INFO[0000] Starting server on port 8084
INFO[0000] Watching for changes in /Users/xcheng/project
INFO[0000] Output directory: modelsource
INFO[0000] Rules directory: rules
INFO[0000] Mode: basic
INFO[0000] Debounce time: 500 ms
INFO[0000] HTTP server listening on 127.0.0.1:8084
INFO[0000] Dashboard available at http://localhost:8084
Expand Down Expand Up @@ -374,7 +370,7 @@ INFO[0000] PASS no_allow_2
- Lint Mendix Yaml files for common mistakes and enforces best practices
- Watch for changes and automatically re-lint
- Serve lint results via HTTP for integration with other tools
- Microflow transformation to more readable format (advanced mode)
- Microflow transformation to more readable format
- Support for both Rego and JavaScript rules
- Human readable output

Expand Down
1 change: 0 additions & 1 deletion default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ lint:
modelsource: modelsource
projectDirectory: .
export:
mode: basic
filter: ".*"
raw: false
appstore: false
Expand Down
4 changes: 0 additions & 4 deletions lint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type ConfigRulesSpec struct {
}

type ConfigExportSpec struct {
Mode string `yaml:"mode"`
Filter string `yaml:"filter"`
Raw *bool `yaml:"raw"`
Appstore *bool `yaml:"appstore"`
Expand Down Expand Up @@ -264,9 +263,6 @@ func mergeConfig(base *Config, overlay *Config) {
base.Rules.Rulesets = append([]string{}, overlay.Rules.Rulesets...)
}

if strings.TrimSpace(overlay.Export.Mode) != "" {
base.Export.Mode = strings.TrimSpace(overlay.Export.Mode)
}
if overlay.Export.Filter != "" {
base.Export.Filter = strings.TrimSpace(overlay.Export.Filter)
}
Expand Down
7 changes: 2 additions & 5 deletions lint/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestLoadMergedConfig_ProjectOverridesSystem(t *testing.T) {
modelsource: modelsource-system
projectDirectory: ./system
export:
mode: advanced
filter: system/*
lint:
skip:
Expand All @@ -42,7 +41,6 @@ lint:
modelsource: modelsource
projectDirectory: .
export:
mode: basic
filter: "*"
lint:
skip:
Expand Down Expand Up @@ -78,7 +76,7 @@ lint:
if len(cfg.Rules.Rulesets) != 1 || cfg.Rules.Rulesets[0] != "file://project-rules" {
t.Fatalf("expected project rules.rulesets override, got %#v", cfg.Rules.Rulesets)
}
if cfg.Modelsource != "modelsource" || cfg.ProjectDirectory != "." || cfg.Export.Mode != "basic" || cfg.Export.Filter != "*" {
if cfg.Modelsource != "modelsource" || cfg.ProjectDirectory != "." || cfg.Export.Filter != "*" {
t.Fatalf("expected project config override, got modelsource=%s projectDirectory=%s export=%#v", cfg.Modelsource, cfg.ProjectDirectory, cfg.Export)
}

Expand Down Expand Up @@ -126,7 +124,6 @@ func TestLoadMergedConfig_DefaultConfigBase(t *testing.T) {
modelsource: default-modelsource
projectDirectory: ./default-input
export:
mode: advanced
filter: default/*
`
setDefaultConfigForTest(t, defaultConfig)
Expand All @@ -139,7 +136,7 @@ export:
if cfg.Rules.Path != ".mendix-cache/default-rules" {
t.Fatalf("expected default rules path, got %s", cfg.Rules.Path)
}
if cfg.Modelsource != "default-modelsource" || cfg.ProjectDirectory != "./default-input" || cfg.Export.Mode != "advanced" || cfg.Export.Filter != "default/*" {
if cfg.Modelsource != "default-modelsource" || cfg.ProjectDirectory != "./default-input" || cfg.Export.Filter != "default/*" {
t.Fatalf("expected default values, got modelsource=%s projectDirectory=%s export=%#v", cfg.Modelsource, cfg.ProjectDirectory, cfg.Export)
}
}
Expand Down
24 changes: 19 additions & 5 deletions lint/lint_javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,29 @@ func evalTestcase_Javascript(rulePath string, inputFilePath string, ruleNumber s
}

res, err := ruleFunction(sobek.Undefined(), vm.ToValue(data))

duration := time.Since(startTime)
var failure *Failure = nil

if err != nil {
panic(err)
}
errorMessage := fmt.Sprintf("Error evaluating javascript rule %v for inputfile %v: %v", rulePath, inputFilePath, err)
log.Error(errorMessage)

rs := res.Export().(map[string]interface{})
failure = &Failure{
Message: errorMessage,
Type: "RuntimeError",
}

duration := time.Since(startTime)
testcase := &Testcase{
Name: inputFilePath,
Time: float64(duration.Nanoseconds()) / 1e9, // convert to seconds
Failure: failure,
Skipped: nil,
}
return testcase, nil
}

var failure *Failure = nil
rs := res.Export().(map[string]interface{})

log.Debugf("Result: %v", rs)
result := rs["allow"].(bool)
Expand Down
23 changes: 20 additions & 3 deletions lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,26 @@ function rule(input) {
t.Fatalf("Failed to write yaml file: %v", err)
}

_, err = EvalAllWithResults(tempDir, tempDir, "", "", false, false)
if err == nil {
t.Error("Expected error due to failures")
rule := Rule{
Path: jsPath,
Pattern: ".*\\.yaml",
PackageName: jsPath,
RuleNumber: "099_0099",
Language: LanguageJavascript,
}

result, err := evalTestsuite(rule, tempDir, false, false)
if err != nil {
t.Fatalf("Expected testsuite evaluation to succeed, got: %v", err)
}
if result.Failures != 1 {
t.Fatalf("Expected 1 failure, got %d", result.Failures)
}
if len(result.Testcases) != 1 || result.Testcases[0].Failure == nil {
t.Fatalf("Expected one failing testcase, got %+v", result.Testcases)
}
if !strings.Contains(result.Testcases[0].Failure.Message, "Always fails") {
t.Fatalf("Expected failure message to contain rule error, got: %s", result.Testcases[0].Failure.Message)
}
})
}
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func main() {
inputDirectory,
outputDirectory,
boolValue(config.Export.Raw, false),
config.Export.Mode,
boolValue(config.Export.Appstore, false),
config.Export.Filter,
)
Expand Down
Loading
Loading