Skip to content

Commit 99f05a5

Browse files
authored
Merge pull request #74 from nightnoryu/add-ignore-not-found-components-option
Add option to ignore components not found by glob
2 parents aaee6cc + 999e831 commit 99f05a5

File tree

12 files changed

+134
-34
lines changed

12 files changed

+134
-34
lines changed

docs/syntax/README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
# Archfile Syntax
22

3-
| Path | Req? | Type | Description |
4-
|--------------------|------|------------|-------------------------------------------------------------------------------------------------|
5-
| version | `+` | int | schema version (__latest: 3__) |
6-
| workdir | | str | relative directory for analyse |
7-
| allow | | map | global rules |
8-
| . depOnAnyVendor | | bool | allow import any vendor code to any project file |
9-
| . deepScan | | bool | use advanced AST code analyse (default `true`, since v3+). |
10-
| exclude | | []str | list of directories (relative path) for exclude from analyse |
11-
| excludeFiles | | []str | regular expression rules for file names, will exclude this files and it's packages from analyse |
12-
| components | `+` | map | component is abstraction on go packages. One component = one or more go packages |
13-
| . %name% | `+` | str | name of component |
14-
| . . in | `+` | str, []str | one or more relative directory name, support glob masking (src/\*/engine/\*\*) |
15-
| vendors | | map | vendor libs (go.mod) |
16-
| . %name% | `+` | str | name of vendor component |
17-
| . . in | `+` | str, []str | one or more import path of vendor libs, support glob masking (github.com/abc/\*/engine/\*\*) |
18-
| commonComponents | | []str | list of components, allow import them into any code |
19-
| commonVendors | | []str | list of vendors, allow import them into any code |
20-
| deps | `+` | map | dependency rules |
21-
| . %name% | `+` | str | name of component, exactly as defined in "components" section |
22-
| . . anyVendorDeps | | bool | all component code can import any vendor code |
23-
| . . anyProjectDeps | | bool | all component code can import any other project code, useful for DI/main component |
24-
| . . mayDependOn | | []str | list of components that can by imported in %name% |
25-
| . . canUse | | []str | list of vendors that can by imported in %name% |
26-
| . . deepScan | | bool | override of allow.deepScan for this component. Default `nil` = use global settings |
3+
| Path | Req? | Type | Description |
4+
|----------------------------|------|------------|-------------------------------------------------------------------------------------------------|
5+
| version | `+` | int | schema version (__latest: 3__) |
6+
| workdir | | str | relative directory for analyse |
7+
| allow | | map | global rules |
8+
| . depOnAnyVendor | | bool | allow import any vendor code to any project file |
9+
| . deepScan | | bool | use advanced AST code analyse (default `true`, since v3+). |
10+
| . ignoreNotFoundComponents | | bool | ignore not found components (default `false`) |
11+
| exclude | | []str | list of directories (relative path) for exclude from analyse |
12+
| excludeFiles | | []str | regular expression rules for file names, will exclude this files and it's packages from analyse |
13+
| components | `+` | map | component is abstraction on go packages. One component = one or more go packages |
14+
| . %name% | `+` | str | name of component |
15+
| . . in | `+` | str, []str | one or more relative directory name, support glob masking (src/\*/engine/\*\*) |
16+
| vendors | | map | vendor libs (go.mod) |
17+
| . %name% | `+` | str | name of vendor component |
18+
| . . in | `+` | str, []str | one or more import path of vendor libs, support glob masking (github.com/abc/\*/engine/\*\*) |
19+
| commonComponents | | []str | list of components, allow import them into any code |
20+
| commonVendors | | []str | list of vendors, allow import them into any code |
21+
| deps | `+` | map | dependency rules |
22+
| . %name% | `+` | str | name of component, exactly as defined in "components" section |
23+
| . . anyVendorDeps | | bool | all component code can import any vendor code |
24+
| . . anyProjectDeps | | bool | all component code can import any other project code, useful for DI/main component |
25+
| . . mayDependOn | | []str | list of components that can by imported in %name% |
26+
| . . canUse | | []str | list of vendors that can by imported in %name% |
27+
| . . deepScan | | bool | override of allow.deepScan for this component. Default `nil` = use global settings |
2728

2829
Examples:
29-
- [.go-arch-lint.yml](../../.go-arch-lint.yml)
30+
- [.go-arch-lint.yml](../../.go-arch-lint.yml)

internal/models/arch/spec.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ type (
2020
}
2121

2222
Allow struct {
23-
DepOnAnyVendor common.Referable[bool]
24-
DeepScan common.Referable[bool]
23+
DepOnAnyVendor common.Referable[bool]
24+
DeepScan common.Referable[bool]
25+
IgnoreNotFoundComponents common.Referable[bool]
2526
}
2627

2728
Component struct {

internal/services/schema/v3.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
"deepScan": {
4444
"title": "will use new advanced AST linter (this default=true from v3+)",
4545
"type": "boolean"
46+
},
47+
"ignoreNotFoundComponents": {
48+
"title": "skips components that are not found by their glob (disabled by default)",
49+
"type": "boolean"
4650
}
4751
}
4852
},
@@ -173,4 +177,4 @@
173177
"additionalProperties": false
174178
}
175179
}
176-
}
180+
}

internal/services/spec/assembler/assembler_ac_allow.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ func newAllowAssembler() *allowAssembler {
1414

1515
func (efa *allowAssembler) assemble(spec *arch.Spec, document spec.Document) error {
1616
spec.Allow = arch.Allow{
17-
DepOnAnyVendor: document.Options().IsDependOnAnyVendor(),
18-
DeepScan: document.Options().DeepScan(),
17+
DepOnAnyVendor: document.Options().IsDependOnAnyVendor(),
18+
DeepScan: document.Options().DeepScan(),
19+
IgnoreNotFoundComponents: document.Options().IgnoreNotFoundComponents(),
1920
}
2021

2122
return nil

internal/services/spec/decoder/decoder_doc_v1.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func (a ArchV1Allow) DeepScan() common.Referable[bool] {
107107
return common.NewEmptyReferable(false)
108108
}
109109

110+
func (a ArchV1Allow) IgnoreNotFoundComponents() common.Referable[bool] {
111+
return common.NewEmptyReferable(false)
112+
}
113+
110114
// --
111115

112116
func (a ArchV1Vendor) ImportPaths() []models.Glob {

internal/services/spec/decoder/decoder_doc_v2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func (a ArchV2Allow) DeepScan() common.Referable[bool] {
117117
return common.NewEmptyReferable(false)
118118
}
119119

120+
func (a ArchV2Allow) IgnoreNotFoundComponents() common.Referable[bool] {
121+
return common.NewEmptyReferable(false)
122+
}
123+
120124
// --
121125

122126
func (a ArchV2Vendor) ImportPaths() []models.Glob {

internal/services/spec/decoder/decoder_doc_v3.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ type (
2323
}
2424

2525
ArchV3Allow struct {
26-
FDepOnAnyVendor ref[bool] `json:"depOnAnyVendor"`
27-
FDeepScan ref[bool] `json:"deepScan"`
26+
FDepOnAnyVendor ref[bool] `json:"depOnAnyVendor"`
27+
FDeepScan ref[bool] `json:"deepScan"`
28+
FIgnoreNotFoundComponents ref[bool] `json:"ignoreNotFoundComponents"`
2829
}
2930

3031
ArchV3Vendor struct {
@@ -138,6 +139,15 @@ func (a ArchV3Allow) DeepScan() common.Referable[bool] {
138139
return common.NewEmptyReferable(true)
139140
}
140141

142+
func (a ArchV3Allow) IgnoreNotFoundComponents() common.Referable[bool] {
143+
if a.FIgnoreNotFoundComponents.defined {
144+
return a.FIgnoreNotFoundComponents.ref
145+
}
146+
147+
// disabled by default
148+
return common.NewEmptyReferable(false)
149+
}
150+
141151
// --
142152

143153
func (a ArchV3Vendor) ImportPaths() []models.Glob {

internal/services/spec/document.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ type (
7171
// DeepScan turn on usage of advanced AST linter
7272
// this is default behavior since v3+ configs
7373
DeepScan() common.Referable[bool]
74+
75+
// IgnoreNotFoundComponents skips components that are not found by their glob
76+
// disabled by default
77+
IgnoreNotFoundComponents() common.Referable[bool]
7478
}
7579

7680
Vendor interface {

internal/services/spec/validator/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (u *utils) assertGlobPathValid(localGlobPath string) error {
3535
return fmt.Errorf("failed to resolv path: %w", err)
3636
}
3737

38-
if len(resolved) == 0 {
38+
if len(resolved) == 0 && !u.document.Options().IgnoreNotFoundComponents().Value {
3939
return fmt.Errorf("not found directories for '%s' in '%s'", localGlobPath, absPath)
4040
}
4141

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$ go-arch-lint check --project-path ${PWD}/test/check/project --arch-file arch3_ignore_not_found_components.yml --output-color=false
2+
module: github.com/fe3dback/go-arch-lint/test/check/project
3+
linters:
4+
On | Base: component imports # always on
5+
On | Advanced: vendor imports # switch 'allow.depOnAnyVendor = false' (or delete) to on
6+
On | Advanced: method calls and dependency injections # switch 'allow.deepScan = true' (or delete) to on
7+
8+
OK - No warnings found

0 commit comments

Comments
 (0)