Skip to content
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

[ADD] file-not-used: Emit message if there are xml, yml, sql or csv files but It isn't referenced from manifest #53

Merged
merged 5 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Visit module to add odoo checks
"""

import ast
import os

import astroid
Expand Down Expand Up @@ -96,13 +97,22 @@
'dangerous-view-replace-wo-priority',
settings.DESC_DFLT
),
'W%d30' % settings.BASE_OMODULE_ID: (
'%s not used from manifest',
'file-not-used',
settings.DESC_DFLT
),
}


DFTL_README_TMPL_URL = 'https://github.com/OCA/maintainer-tools' + \
'/blob/master/template/module/README.rst'
DFTL_EXTFILES_TO_LINT = ['xml', 'csv', 'po', 'js', 'mako']
DFTL_MIN_PRIORITY = 99
# Files supported from manifest to convert
# Extracted from openerp/tools/convert.py:def convert_file
DFLT_EXTFILES_CONVERT = ['csv', 'sql', 'xml', 'yml']
DFLT_EXTFILES_TO_LINT = DFLT_EXTFILES_CONVERT + [
'po', 'js', 'mako', 'rst', 'md', 'markdown']


class ModuleChecker(misc.WrapperModuleChecker):
Expand All @@ -118,7 +128,7 @@ class ModuleChecker(misc.WrapperModuleChecker):
('extfiles_to_lint', {
'type': 'csv',
'metavar': '<comma separated values>',
'default': DFTL_EXTFILES_TO_LINT,
'default': DFLT_EXTFILES_TO_LINT,
'help': 'List of extension files to check separated by a comma.'
}),
('min-priority', {
Expand All @@ -127,6 +137,13 @@ class ModuleChecker(misc.WrapperModuleChecker):
'default': DFTL_MIN_PRIORITY,
'help': 'Minimum priority number of a view with replace of fields.'
}),
('extfiles_convert', {
'type': 'csv',
'metavar': '<comma separated values>',
'default': DFLT_EXTFILES_CONVERT,
'help': 'List of extension files supported to convert '
'from manifest separated by a comma.'
}),
)

class_inherit_names = []
Expand Down Expand Up @@ -495,3 +512,32 @@ def _check_missing_newline_extrafiles(self):
if self.msg_args:
return False
return True

def _get_manifest_referenced_files(self):
referenced_files = []
data_keys = ['data', 'demo', 'demo_xml', 'init_xml', 'test',
'update_xml']
with open(self.manifest_file) as f_manifest:
manifest_dict = ast.literal_eval(f_manifest.read())
for key in data_keys:
referenced_files.extend(manifest_dict.get(key) or [])
return referenced_files

def _get_module_files(self):
module_files = []
for type_file in self.config.extfiles_convert:
for ext_file_rel in self.filter_files_ext(type_file, relpath=True):
module_files.append(ext_file_rel)
return module_files

def _check_file_not_used(self):
"""Check if a file is not used from manifest"""
self.msg_args = []
module_files = set(self._get_module_files())
referenced_files = set(self._get_manifest_referenced_files())
for no_referenced_file in (module_files - referenced_files):
if not no_referenced_file.startswith('static/'):
self.msg_args.append((no_referenced_file,))
if self.msg_args:
return False
return True
1 change: 1 addition & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'duplicate-id-csv': 2,
'duplicate-xml-fields': 6,
'duplicate-xml-record-id': 2,
'file-not-used': 8,
'incoherent-interpreter-exec-perm': 3,
'invalid-commit': 4,
'javascript-lint': 2,
Expand Down
2 changes: 2 additions & 0 deletions pylint_odoo/test_repo/test_module/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
],
'data': [
'security/ir.model.access.csv',
'res_users.xml',
'model_view.xml',
],
'external_dependencies': {
'bin': [
Expand Down
3 changes: 3 additions & 0 deletions pylint_odoo/test_repo/test_module/static/src/xml/widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
</templates>