Skip to content

[IMP] add manifest-external-assets check #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2025

Conversation

antonag32
Copy link
Contributor

This new check verifies that no external sources are referenced on modules' assets.

Related to: OCA/odoo-pre-commit-hooks#124.

@antonag32 antonag32 force-pushed the manifest-external-assets-anton branch from 948aa7e to 6ed2266 Compare March 4, 2025 03:35
@antonag32
Copy link
Contributor Author

Can you review @moylop260 @luisg123v?

if isinstance(element, nodes.Const):
if is_external_url(element.value):
self.add_message("manifest-external-assets", node=element)
elif isinstance(element, nodes.Tuple):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice it could be a Tuple or a List

See the following example:

Suggested change
elif isinstance(element, nodes.Tuple):
elif isinstance(element, (nodes.Tuple, nodes.List)):

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, Using manifest_get you could get all the isinstance(..., iterable) object if it is not a string and call it recursively

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was checking if it was a tuple because of this use case:

https://github.com/odoo/odoo/blob/032ee36a9556688e2f022ddfb2081800b80efef1/addons/website/__manifest__.py#L241

Odoo docs always show this usage with tuples but I guess in theory you could also use a List although I have not seen it before, I will add it so we cover all possibilities.

if item[0].value == "assets":
assets_node = item[1]

# it is important to use the actual astroid.node instead of manifest_dict, otherwise the
Copy link
Collaborator

@moylop260 moylop260 Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use manifest_dict + args in order to use the string value with the problem

I mean,

Currenly it is good showing the number of line:

twelve_module/__manifest__.py:15:12: {msg}
twelve_module/__manifest__.py:19:12: {msg}

But it could be good too using

twelve_module/__manifest__.py:12:14: {msg} {wrong url}
twelve_module/__manifest__.py:12:14: {msg} {wrong url}

So, the result final could be:

twelve_module/__manifest__.py:12:14: W8162: Assets https://shady.cdn.com/somefile.js should be distributed with module's source code. More info at https://httptoolkit.com/blog/public-cdn-risks/ (manifest-external-assets)
twelve_module/__manifest__.py:12:14: W8162: Assets https://bad.idea.com/cool.css should be distributed with module's source code. More info at https://httptoolkit.com/blog/public-cdn-risks/ (manifest-external-assets)

It should be good since that manifest_dict is more pythonistic than using astroid nodes

So, it is easy to maintain

Only consider a recent fix that I have added for values wrong formed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally tried using manifest_dict but had issues with test_180 which runs parallel jobs. It seems like message were being mangled up because all errors pointed to the same root node (the assets node), also the linenumber was wrong since we were pointing to assets node, instead of the actual offending URL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point for parallels!!!

I didn't know it

I have bypassed a few checks for parallels

Could you check if you can fix them (another PR)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget it

I think it is a different matter

@antonag32 antonag32 force-pushed the manifest-external-assets-anton branch from 6ed2266 to e7e9893 Compare March 7, 2025 22:28
This new check verifies that no external sources are referenced on
modules' assets.

Related to: OCA/odoo-pre-commit-hooks#124.
@antonag32 antonag32 force-pushed the manifest-external-assets-anton branch from e7e9893 to d03a521 Compare March 7, 2025 22:34
@antonag32
Copy link
Contributor Author

@moylop260 I improved the error message by including the actual URL that is offending and also added support for handling lists and not only tuples. I still left the astroid implementation because of the errors I previously found during unit testing, and also because even though I agree that it is uglier than manifest_dict, I think accurate line numbers are important when reporting errors. Otherwise it can be confusing, specially when there are lots of assets.

@moylop260 moylop260 merged commit 58443c4 into OCA:main Mar 8, 2025
22 of 23 checks passed
@moylop260 moylop260 deleted the manifest-external-assets-anton branch March 8, 2025 00:15
moylop260 added a commit to vauxoo-dev/pre-commit-vauxoo that referenced this pull request Apr 27, 2025
Check release notes:
 - https://pypi.org/project/pylint-odoo

v9.3.3
[FIX] prohibited-method-override: Check if caller has a func attribute (OCA/pylint-odoo#524)
[ADD] deprecated-name-get: name_get deprecated since v17 (OCA/pylint-odoo#526)
[ADD] manifest-external-assets: No external sources for assets (OCA/pylint-odoo#525)
moylop260 added a commit to Vauxoo/pre-commit-vauxoo that referenced this pull request Apr 28, 2025
Check release notes:
 - https://pypi.org/project/pylint-odoo/9.3.3

[FIX] prohibited-method-override: Check if caller has a func attribute (OCA/pylint-odoo#524)
[ADD] deprecated-name-get: name_get deprecated since v17 (OCA/pylint-odoo#526)
[ADD] manifest-external-assets: No external sources for assets (OCA/pylint-odoo#525)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants