Skip to content

Commit

Permalink
Allow custom rules specific configuration with ansible-lint-config JS…
Browse files Browse the repository at this point in the history
…ON Schema (#3080)

Co-authored-by: Ajinkya Udgirkar <audgirka@redhat.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
3 people committed Mar 2, 2023
1 parent 19cb057 commit 5b070f0
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 53 deletions.
115 changes: 62 additions & 53 deletions src/ansiblelint/schemas/ansible-lint-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,59 +122,68 @@
"$ref": "#/$defs/rule"
},
"propertyNames": {
"enum": [
"command-instead-of-module",
"command-instead-of-shell",
"deprecated-bare-vars",
"deprecated-command-syntax",
"deprecated-local-action",
"deprecated-module",
"empty-string-compare",
"fqcn",
"fqcn[action-core]",
"fqcn[action-redirect]",
"fqcn[action]",
"galaxy",
"galaxy[no-changelog]",
"galaxy[tags]",
"galaxy[version-incorrect]",
"galaxy[version-missing]",
"ignore-errors",
"inline-env-var",
"internal-error",
"jinja",
"key-order",
"latest",
"literal-compare",
"load-failure",
"meta-incorrect",
"meta-no-info",
"meta-no-tags",
"meta-runtime",
"meta-video-links",
"name",
"no-changed-when",
"no-handler",
"no-jinja-when",
"no-log-password",
"loop-var-prefix",
"no-prompting",
"no-relative-paths",
"no-same-owner",
"no-tabs",
"only-builtins",
"package-latest",
"parser-error",
"partial-become",
"playbook-extension",
"risky-file-permissions",
"risky-octal",
"risky-shell-pipe",
"role-name",
"schema",
"syntax-check",
"var-naming",
"yaml"
"oneOf": [
{
"enum": [
"command-instead-of-module",
"command-instead-of-shell",
"deprecated-bare-vars",
"deprecated-command-syntax",
"deprecated-local-action",
"deprecated-module",
"empty-string-compare",
"fqcn",
"fqcn[action-core]",
"fqcn[action-redirect]",
"fqcn[action]",
"galaxy",
"galaxy[no-changelog]",
"galaxy[tags]",
"galaxy[version-incorrect]",
"galaxy[version-missing]",
"ignore-errors",
"inline-env-var",
"internal-error",
"jinja",
"key-order",
"latest",
"literal-compare",
"load-failure",
"meta-incorrect",
"meta-no-info",
"meta-no-tags",
"meta-runtime",
"meta-video-links",
"name",
"no-changed-when",
"no-handler",
"no-jinja-when",
"no-log-password",
"loop-var-prefix",
"no-prompting",
"no-relative-paths",
"no-same-owner",
"no-tabs",
"only-builtins",
"package-latest",
"parser-error",
"partial-become",
"playbook-extension",
"risky-file-permissions",
"risky-octal",
"risky-shell-pipe",
"role-name",
"schema",
"syntax-check",
"var-naming",
"yaml"
],
"type": "string"
},
{
"pattern": "^[a-z0-9-\\[\\]]+$",
"type": "string"
}
]
},
"title": "Rules specific configuration.",
Expand Down
4 changes: 4 additions & 0 deletions test/schemas/negative_test/.ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# .ansible-lint
rules:
Wrong_Rule_name:
51 changes: 51 additions & 0 deletions test/schemas/negative_test/.ansible-lint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ajv errors

```json
[
{
"instancePath": "/rules",
"keyword": "pattern",
"message": "must match pattern \"^[a-z0-9-\\[\\]]+$\"",
"params": {
"pattern": "^[a-z0-9-\\[\\]]+$"
},
"propertyName": "Wrong_Rule_name",
"schemaPath": "#/properties/rules/propertyNames/pattern"
},
{
"instancePath": "/rules",
"keyword": "propertyNames",
"message": "property name must be valid",
"params": {
"propertyName": "Wrong_Rule_name"
},
"schemaPath": "#/properties/rules/propertyNames"
},
{
"instancePath": "/rules/Wrong_Rule_name",
"keyword": "type",
"message": "must be object",
"params": {
"type": "object"
},
"schemaPath": "#/$defs/rule/type"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [],
"parse_errors": [
{
"filename": "negative_test/.ansible-lint",
"message": "Failed to parse negative_test/.ansible-lint"
}
]
}
```
3 changes: 3 additions & 0 deletions test/schemas/negative_test/.config/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# .ansible-lint
profile: invalid_profile
42 changes: 42 additions & 0 deletions test/schemas/negative_test/.config/ansible-lint.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ajv errors

```json
[
{
"instancePath": "/profile",
"keyword": "enum",
"message": "must be equal to one of the allowed values",
"params": {
"allowedValues": [
"min",
"basic",
"moderate",
"safety",
"shared",
"production",
null
]
},
"schemaPath": "#/properties/profile/enum"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [
{
"filename": "negative_test/.config/ansible-lint.yml",
"path": "$.profile",
"message": "'invalid_profile' is not one of ['min', 'basic', 'moderate', 'safety', 'shared', 'production', None]",
"has_sub_errors": false
}
],
"parse_errors": []
}
```
9 changes: 9 additions & 0 deletions test/schemas/test/.config/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# .ansible-lint
profile: basic
rules:
name[missing]:
exclude_paths: []
custom-inc-rule:
exclude_paths:
- "tests/*.yml"

0 comments on commit 5b070f0

Please sign in to comment.