Commit cf937f3e authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: Fix pylint false positive errors with Interface Components.

E: 4, 0: Inheriting 'Interface', which is not a class. (inherit-non-class)
E: 5, 2: Method has no argument (no-method-argument)
parent 9c408f22
<tal:block tal:define='site_root python: here.getWebSiteValue() or here.getPortalObject(); <tal:block tal:define='site_root python: here.getWebSiteValue() or here.getPortalObject();
portal_url python: site_root.absolute_url(); portal_url python: site_root.absolute_url();
portal_type python: here.getPortalType();
div_id string:${id}_ace; div_id string:${id}_ace;
mode python: here.Base_getAceEditorMode(); mode python: here.Base_getAceEditorMode();
container_div_id string:${div_id}_container; container_div_id string:${div_id}_container;
...@@ -150,6 +151,7 @@ ...@@ -150,6 +151,7 @@
ace_editor_container_div = null; ace_editor_container_div = null;
ace_editor = null; ace_editor = null;
var mode = '${mode}'; var mode = '${mode}';
var portal_type = '${portal_type}';
var params = '${params}'; var params = '${params}';
function maximizeFullscreenRemoveSaveMessage() { function maximizeFullscreenRemoveSaveMessage() {
...@@ -394,6 +396,7 @@ ...@@ -394,6 +396,7 @@
ace.require('ace/ext/language_tools'); ace.require('ace/ext/language_tools');
ace_editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true }); ace_editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true });
var data_options = {}; var data_options = {};
data_options.portal_type = portal_type;
if (params !== 'None') { if (params !== 'None') {
data_options.bound_names = ['context','container','script','traverse_subpath','printed','same_type','string','sequence','random','DateTime','whrandom','reorder','sets','test','math'], data_options.bound_names = ['context','container','script','traverse_subpath','printed','same_type','string','sequence','random','DateTime','whrandom','reorder','sets','test','math'],
data_options.params = params; data_options.params = params;
......
...@@ -200,7 +200,7 @@ def checkPythonSourceCodeAsJSON(self, data, REQUEST=None): ...@@ -200,7 +200,7 @@ def checkPythonSourceCodeAsJSON(self, data, REQUEST=None):
else: else:
body = data['code'] body = data['code']
message_list = checkPythonSourceCode(body.encode('utf8')) message_list = checkPythonSourceCode(body.encode('utf8'), data.get('portal_type'))
for message_dict in message_list: for message_dict in message_list:
if is_python_script: if is_python_script:
message_dict['row'] = message_dict['row'] - 2 message_dict['row'] = message_dict['row'] - 2
......
...@@ -444,7 +444,8 @@ ...@@ -444,7 +444,8 @@
update_check_running = false; update_check_running = false;
function checkPythonSourceCode(text, updateLinting, options, cm) { function checkPythonSourceCode(text, updateLinting, options, cm) {
update_check_text = text; update_check_text = text;
checker_parameters = {code: text}; checker_parameters = {code: text,
portal_type: '<dtml-var name="portal_type">'};
<dtml-if bound_names> <dtml-if bound_names>
checker_parameters['bound_names'] = <dtml-var name="bound_names">; checker_parameters['bound_names'] = <dtml-var name="bound_names">;
checker_parameters['params'] = $('input[name="params"]').val(); checker_parameters['params'] = $('input[name="params"]').val();
......
...@@ -110,12 +110,14 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -110,12 +110,14 @@ class EditorWidget(Widget.TextAreaWidget):
elif portal_type == "Web Style": elif portal_type == "Web Style":
mode = "css" mode = "css"
site_root = here.getWebSiteValue() or here.getPortalObject() site_root = here.getWebSiteValue() or here.getPortalObject()
portal_type = here.getPortalType()
return code_mirror_support(field=field, return code_mirror_support(field=field,
content=value, content=value,
field_id=key, field_id=key,
portal_url=site_root.absolute_url(), portal_url=site_root.absolute_url(),
mode=mode, mode=mode,
keymap=site_root.portal_preferences.getPreferredSourceCodeEditorKeymap()) keymap=site_root.portal_preferences.getPreferredSourceCodeEditorKeymap(),
portal_type=portal_type)
elif text_editor != 'text_area': elif text_editor != 'text_area':
return here.fckeditor_wysiwyg_support.pt_render( return here.fckeditor_wysiwyg_support.pt_render(
extra_context= { extra_context= {
......
...@@ -423,7 +423,7 @@ def fill_args_from_request(*optional_args): ...@@ -423,7 +423,7 @@ def fill_args_from_request(*optional_args):
_pylint_message_re = re.compile( _pylint_message_re = re.compile(
'^(?P<type>[CRWEF]):\s*(?P<row>\d+),\s*(?P<column>\d+):\s*(?P<message>.*)$') '^(?P<type>[CRWEF]):\s*(?P<row>\d+),\s*(?P<column>\d+):\s*(?P<message>.*)$')
def checkPythonSourceCode(source_code_str): def checkPythonSourceCode(source_code_str, portal_type=None):
""" """
Check source code with pylint or compile() builtin if not available. Check source code with pylint or compile() builtin if not available.
...@@ -511,6 +511,15 @@ def checkPythonSourceCode(source_code_str): ...@@ -511,6 +511,15 @@ def checkPythonSourceCode(source_code_str):
'--disable=W0212', '--disable=W0212',
# string module does not only contain deprecated functions... # string module does not only contain deprecated functions...
'--deprecated-modules=regsub,TERMIOS,Bastion,rexec'] '--deprecated-modules=regsub,TERMIOS,Bastion,rexec']
if portal_type == 'Interface Component':
# Interface inherits from InterfaceClass:
# E: 4, 0: Inheriting 'Interface', which is not a class. (inherit-non-class)
args.append('--disable=E0239')
# Interfaces methods have no arguments:
# E: 5, 2: Method has no argument (no-method-argument)
args.append('--disable=E0211')
try: try:
from pylint.extensions.bad_builtin import __name__ as ext from pylint.extensions.bad_builtin import __name__ as ext
args.append('--load-plugins=' + ext) args.append('--load-plugins=' + ext)
......
...@@ -306,7 +306,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -306,7 +306,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
Check Component source code through Pylint or compile() builtin if not Check Component source code through Pylint or compile() builtin if not
available available
""" """
return checkPythonSourceCode(self.getTextContent()) return checkPythonSourceCode(self.getTextContent(), self.getPortalType())
security.declareProtected(Permissions.ModifyPortalContent, 'PUT') security.declareProtected(Permissions.ModifyPortalContent, 'PUT')
def PUT(self, REQUEST, RESPONSE): def PUT(self, REQUEST, RESPONSE):
......
...@@ -83,6 +83,7 @@ def manage_page_footer(self): ...@@ -83,6 +83,7 @@ def manage_page_footer(self):
if not textarea_selector: if not textarea_selector:
return default return default
portal_type = document.meta_type
if editor == 'codemirror' and getattr(portal, 'code_mirror_support', None) is not None: if editor == 'codemirror' and getattr(portal, 'code_mirror_support', None) is not None:
keymap = portal.portal_preferences.getPreferredSourceCodeEditorKeymap() keymap = portal.portal_preferences.getPreferredSourceCodeEditorKeymap()
return '''<script type="text/javascript" src="%s/jquery/core/jquery.min.js"></script> return '''<script type="text/javascript" src="%s/jquery/core/jquery.min.js"></script>
...@@ -93,7 +94,8 @@ def manage_page_footer(self): ...@@ -93,7 +94,8 @@ def manage_page_footer(self):
portal_url=portal_url, portal_url=portal_url,
bound_names=bound_names, bound_names=bound_names,
mode=mode, mode=mode,
keymap=keymap)) keymap=keymap,
portal_type=portal_type))
else: else:
return ''' return '''
<script type="text/javascript" src="%(portal_url)s/jquery/core/jquery.min.js"></script> <script type="text/javascript" src="%(portal_url)s/jquery/core/jquery.min.js"></script>
...@@ -133,7 +135,8 @@ $(document).ready(function() { ...@@ -133,7 +135,8 @@ $(document).ready(function() {
{'data': JSON.stringify( {'data': JSON.stringify(
{ code: editor.getSession().getValue(), { code: editor.getSession().getValue(),
bound_names: %(bound_names)s, bound_names: %(bound_names)s,
params: $('input[name="params"]').val() })}, params: $('input[name="params"]').val(),
portal_type: %(portal_type)s })},
function(data){ function(data){
editor.getSession().setAnnotations(data.annotations); editor.getSession().setAnnotations(data.annotations);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment