From c87d79005cc31db6ee84f32781a2a4ff0a1579e3 Mon Sep 17 00:00:00 2001 From: Moises Lopez Date: Tue, 18 Aug 2015 17:00:16 +0000 Subject: [PATCH] [REF] pylint: Enable check to validate CamelCase class name for odoo version >= 8.0 --- .travis.yml | 3 ++- travis/cfg/travis_run_pylint_pr.cfg | 15 ++++++++++--- travis/test_pylint | 33 +++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6f3b974b7..8b8a324c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,8 @@ env: - VERSION="7.0" INCLUDE="test_module,second_module" ODOO_REPO="OCA/OCB" # ODOO_REPO usage example - VERSION="6.1" INCLUDE="test_module,second_module" - LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="17" TRAVIS_PULL_REQUEST="false" # Use main pylint config file - - LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="18" TRAVIS_PULL_REQUEST="true" # Use PR pylint config file + - VERSION="master" LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="18" TRAVIS_PULL_REQUEST="true" # Use PR pylint config file + - VERSION="7.0" LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="17" TRAVIS_PULL_REQUEST="true" # Use PR pylint config file but with params changed by odoo version install: - cp -r ../maintainer-quality-tools/ $HOME diff --git a/travis/cfg/travis_run_pylint_pr.cfg b/travis/cfg/travis_run_pylint_pr.cfg index 1f32c3a44..fe68e0580 100644 --- a/travis/cfg/travis_run_pylint_pr.cfg +++ b/travis/cfg/travis_run_pylint_pr.cfg @@ -6,9 +6,7 @@ cache-size=500 [MESSAGES CONTROL] disable=all -# This change don't add new checks. -# Adding one exits check to test the pr-diff feature -enable=W0403 +enable=invalid-name, [REPORTS] msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} @@ -21,6 +19,17 @@ comment=no [FORMAT] indent-string=' ' +[BASIC] +class-rgx=[A-Z_][a-zA-Z0-9]{2,45} +module-rgx=.* +const-rgx=.* +function-rgx=.* +method-rgx=.* +attr-rgx=.* +argument-rgx=.* +variable-rgx=.* +inlinevar-rgx=.* + [SIMILARITIES] ignore-comments=yes ignore-docstrings=yes diff --git a/travis/test_pylint b/travis/test_pylint index 172ad18ae..ef359ee6f 100755 --- a/travis/test_pylint +++ b/travis/test_pylint @@ -11,13 +11,41 @@ import run_pylint from getaddons import get_modules_changed + +def get_extra_params(odoo_version): + ''' + Get extra pylint params by odoo version + :param version: String with name of version of odoo + :return: List of extra pylint params + ''' + params = [] + try: + version_f = float(odoo_version) + except ValueError: + # master case + version_f = -1 + if version_f != -1 and version_f < 8: + # Class name snake_case style to version < 8 + params.append( + '--class-rgx=' + '([a-z_][a-z0-9_]{2,45})|([A-Z_][a-zA-Z0-9]{2,45})$' + ) + return params + +version = os.environ.get('VERSION', False) +extra_params_cmd = [] +if version: + extra_params = get_extra_params(version) + for extra_param in extra_params: + extra_params_cmd.extend([ + '--extra-params', extra_param]) pylint_rcfile = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', "travis_run_pylint.cfg") count_errors = run_pylint.main([ "--config-file=" + pylint_rcfile, -], standalone_mode=False) +] + extra_params_cmd, standalone_mode=False) pylint_rcfile_pr = os.path.join( @@ -41,7 +69,8 @@ if is_pull_request and branch_base and git_work_dir: ]) count_errors += run_pylint.main([ "--config-file=" + pylint_rcfile_pr, - ] + modules_changed_cmd, standalone_mode=False) + ] + modules_changed_cmd + extra_params_cmd, + standalone_mode=False) else: # TODO: Add git hook case in other PR pass