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 f8b5c6c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Short Name | Description | Code
attribute-deprecated | attribute "%s" deprecated | W8105
attribute-string-redundant | The attribute string is redundant. String parameter equal to name of variable | W8113
bad-builtin-groupby | Used builtin function `itertools.groupby`. Prefer `odoo.tools.groupby` instead. More info about https://github.com/odoo/odoo/issues/105376 | W8155
category-allowed | Category "%s" not allowed in manifest file. | C8114
consider-merging-classes-inherited | Consider merging classes inherited to "%s" from %s. | R8180
context-overridden | Context overridden using dict. Better using kwargs `with_context(**%s)` or `with_context(key=value)` | W8121
deprecated-odoo-model-method | %s has been deprecated by Odoo. Please look for alternatives. | W8160
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
1 change: 1 addition & 0 deletions testing/resources/test_repo/eleven_module/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'name': 'Eleven module for tests',
'license': 'AGPL-3',
'author': u'Jesus, Odoo Community Association (OCA)',
'category': 'Category 01',
'version': '11.0.1.0.0',
'depends': [
'base',
Expand Down
15 changes: 15 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,21 @@ def test_165_no_raises_unlink(self):
extra_params.append("--valid-odoo-versions=14.0")
self.assertFalse(self.run_pylint([test_repo], extra_params).linter.stats.by_msg)

# Test category-allowed with and without error
def test_170_category_allowed(self):
extra_params = ["--disable=all", "--enable=category-allowed", "--category-allowed=Category 00"]
pylint_res = self.run_pylint(self.paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
expected_errors = {
"category-allowed": 1,
}
self.assertDictEqual(real_errors, expected_errors)

extra_params = ["--disable=all", "--enable=category-allowed", "--category-allowed=Category 01"]
pylint_res = self.run_pylint(self.paths_modules, extra_params)
real_errors = pylint_res.linter.stats.by_msg
self.assertFalse(real_errors)

def test_option_odoo_deprecated_model_method(self):
pylint_res = self.run_pylint(
self.paths_modules,
Expand Down

0 comments on commit f8b5c6c

Please sign in to comment.