Skip to content

Commit

Permalink
[ADD] checkers: category-allowed
Browse files Browse the repository at this point in the history
New check allowing to enforce the allowed Odoo modules categories.
A list of coma-separated categories can be set under the category-allowed setting.
  • Loading branch information
ThomasBinsfeld committed Oct 27, 2023
1 parent ec00a35 commit e41a5cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ except-pass | pass into block except. If you really need to use the pass conside
external-request-timeout | Use of external request method `%s` without timeout. It could wait for a long time | E8106
invalid-commit | Use of cr.commit() directly - More info https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#never-commit-the-transaction | E8102
license-allowed | License "%s" not allowed in manifest file. | C8105
category-allowed | Category "%s" not allowed in manifest file. | C8114
manifest-author-string | The author key in the manifest file must be a string (with comma separated values) | E8101
manifest-data-duplicated | The file "%s" is duplicated in lines %s from manifest key "%s" | W8125
manifest-deprecated-key | Deprecated key "%s" in manifest file | C8103
Expand Down
23 changes: 23 additions & 0 deletions src/pylint_odoo/checkers/odoo_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"no-wizard-in-models",
CHECK_DESCRIPTION,
),
"C8114": ('Category "%s" not allowed in manifest file.', "category-allowed", CHECK_DESCRIPTION),
"E8101": (
"The author key in the manifest file must be a string (with comma separated values)",
"manifest-author-string",
Expand Down Expand Up @@ -284,6 +285,7 @@
"_defaults",
"length",
]
DFTL_CATEGORY_ALLOWED = []
DFTL_METHOD_REQUIRED_SUPER = [
"copy",
"create",
Expand Down Expand Up @@ -534,6 +536,15 @@ class OdooAddons(OdooBaseChecker, BaseChecker):
"help": "Dictionary consisting of versions (keys) and methods that have been marked as deprecated.",
},
),
(
"category-allowed",
{
"type": "csv",
"metavar": "<comma separated values>",
"default": DFTL_CATEGORY_ALLOWED,
"help": "List of categories allowed in manifest file, separated by a comma.",
},
),
)

checks_maxmin_odoo_version = {
Expand Down Expand Up @@ -986,6 +997,7 @@ def visit_call(self, node):
@utils.only_required_for_messages(
"development-status-allowed",
"license-allowed",
"category-allowed",
"manifest-author-string",
"manifest-data-duplicated",
"manifest-deprecated-key",
Expand Down Expand Up @@ -1045,6 +1057,17 @@ def visit_dict(self, node):
if license_str and license_str not in self.linter.config.license_allowed:
self.add_message("license-allowed", node=manifest_keys_nodes.get("license") or node, args=(license_str,))

# Check category allowed
category_str = manifest_dict.get("category")
if (
category_str
and self.linter.config.category_allowed
and category_str not in self.linter.config.category_allowed
):
self.add_message(
"category-allowed", node=manifest_keys_nodes.get("category") or node, args=(category_str,)
)

# Check version format
version_format = manifest_dict.get("version", "")
formatrgx = self.formatversion(version_format)
Expand Down

0 comments on commit e41a5cf

Please sign in to comment.