mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
updated files names
This commit is contained in:
parent
41f01dd70a
commit
ad0f5863ed
26 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,79 @@
|
|||
This file show how to use loaderon-hooks, showing arguments examples when the corresponding hook needs it.
|
||||
|
||||
Add from here to your project .pre-commit-config.yaml file:
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/Loaderon/pre-commit-hooks
|
||||
rev: v1.0
|
||||
hooks:
|
||||
# Loaderon hooks
|
||||
- id: check-xml-encoding
|
||||
args: [
|
||||
--encoding, '<?xml version="1.0" encoding="utf-8"?>',
|
||||
]
|
||||
- id: check-location
|
||||
args: [
|
||||
--directories, '^[^\/]+$',
|
||||
--directories, '.*\/controllers$',
|
||||
--directories, '.*\/data$',
|
||||
--directories, '.*\/i18n$',
|
||||
--directories, '.*\/models$',
|
||||
--directories, '.*\/report$',
|
||||
--directories, '.*\/security$',
|
||||
--directories, '.*\/static\/img$',
|
||||
--directories, '.*\/static\/lib\/external_lib$',
|
||||
--directories, '.*\/static\/src\/js$',
|
||||
--directories, '.*\/static\/src\/css$',
|
||||
--directories, '.*\/static\/src\/less$',
|
||||
--directories, '.*\/static\/src\/xml$',
|
||||
--directories, '.*\/static\/tests$',
|
||||
--directories, '.*[^\/static]\/tests$',
|
||||
--directories, '.*\/views$',
|
||||
--directories, '.*\/wizard$',
|
||||
|
||||
--files, '__init__.py$ __openerp__.py$',
|
||||
--files, '__init__.py$ .*\.py$ main.py$',
|
||||
--files, '.*_data\.xml$ .*_demo\.xml$',
|
||||
--files, '.*\.po$',
|
||||
--files, '__init__.py$ .*\.py$',
|
||||
--files, '__init__.py$ .*\.py$ .*_views\.xml$ .*_reports\.xml$ .*_templates\.xml$',
|
||||
--files, 'ir.model.access.csv$ .*_security\.xml$',
|
||||
--files, '.*\.png$ .*\.jpg$',
|
||||
--files, '.*\$',
|
||||
--files, '.*\.js$',
|
||||
--files, '.*\.css$',
|
||||
--files, '.*\.less$',
|
||||
--files, '.*\.xml$',
|
||||
--files, '.*\.tour\.js$',
|
||||
--files, '__init__.py$ test_.*\.py',
|
||||
--files, '.*_templates\.xml$ .*_views\.xml$',
|
||||
--files, '.*\.py$ .*_views\.xml$',
|
||||
]
|
||||
- id: check-line
|
||||
args: [
|
||||
--line-to-check, '^(\t| )*<field.+',
|
||||
--line-to-check, '^(\t| )*<record.+',
|
||||
--line-to-check, '.+fields.Many2one.+',
|
||||
--line-to-check, '.+fields.One2many.+',
|
||||
--line-to-check, '.+fields.Many2many.+',
|
||||
--line-to-check, 'class.+',
|
||||
|
||||
--regexp-to-match, '^(\t| )*<field name=".+"',
|
||||
--regexp-to-match, '^(\t| )*<record id=".+"',
|
||||
--regexp-to-match, '^(\t| )*.+_id = fields.Many2one\(',
|
||||
--regexp-to-match, '^(\t| )*.+_ids = fields.One2many\(',
|
||||
--regexp-to-match, '^(\t| )*.+_ids = fields.Many2many\(',
|
||||
--regexp-to-match, 'class ([A-Z]+[a-z0-9]+)+\(.+\):',
|
||||
]
|
||||
- id: check-model-name
|
||||
- id: check-view-name
|
||||
- id: check-view-fields-order
|
||||
- id: check-using-pylint
|
||||
args: [
|
||||
--exclude, '.*(\/)*__openerp__.py$',
|
||||
]
|
||||
- id: check-branch-name
|
||||
args: [
|
||||
--regex, 'develop\..+?\.(DEFECTO|INVES|MEJORA)\.\d+(_\d+)*'
|
||||
]
|
||||
- id: check-class-docstring
|
||||
|
|
@ -0,0 +1,554 @@
|
|||
This file holds an out of the box configuration for pylint, to be used by check_using_pylint hook. You can modify this configuration for your project as best suits you. Bea in mind that check_using_pylint will prevent commit whenever any of pylint not ignored warnings or errors are raised.
|
||||
|
||||
Copy from here into a .pylintrc file in your project root folder:
|
||||
|
||||
[MASTER]
|
||||
|
||||
# A comma-separated list of package or module names from where C extensions may
|
||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
||||
# run arbitrary code
|
||||
extension-pkg-whitelist=
|
||||
|
||||
# Add files or directories to the blacklist. They should be base names, not
|
||||
# paths.
|
||||
ignore=CVS
|
||||
|
||||
# Add files or directories matching the regex patterns to the blacklist. The
|
||||
# regex matches against base names, not paths.
|
||||
ignore-patterns=
|
||||
|
||||
# Python code to execute, usually for sys.path manipulation such as
|
||||
# pygtk.require().
|
||||
#init-hook=
|
||||
|
||||
# Use multiple processes to speed up Pylint.
|
||||
jobs=1
|
||||
|
||||
# List of plugins (as comma separated values of python modules names) to load,
|
||||
# usually to register additional checkers.
|
||||
load-plugins=
|
||||
|
||||
# Pickle collected data for later comparisons.
|
||||
persistent=yes
|
||||
|
||||
# Specify a configuration file.
|
||||
#rcfile=
|
||||
|
||||
# When enabled, pylint would attempt to guess common misconfiguration and emit
|
||||
# user-friendly hints instead of false-positive error messages
|
||||
suggestion-mode=yes
|
||||
|
||||
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
||||
# active Python interpreter and may run arbitrary code.
|
||||
unsafe-load-any-extension=no
|
||||
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
|
||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
|
||||
confidence=
|
||||
|
||||
# Disable the message, report, category or checker with the given id(s). You
|
||||
# can either give multiple identifiers separated by comma (,) or put this
|
||||
# option multiple times (only on the command line, not in the configuration
|
||||
# file where it should appear only once).You can also use "--disable=all" to
|
||||
# disable everything first and then reenable specific checks. For example, if
|
||||
# you want to run only the similarities checker, you can use "--disable=all
|
||||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
disable=print-statement,
|
||||
parameter-unpacking,
|
||||
unpacking-in-except,
|
||||
old-raise-syntax,
|
||||
backtick,
|
||||
long-suffix,
|
||||
old-ne-operator,
|
||||
old-octal-literal,
|
||||
import-star-module-level,
|
||||
non-ascii-bytes-literal,
|
||||
invalid-unicode-literal,
|
||||
raw-checker-failed,
|
||||
bad-inline-option,
|
||||
locally-disabled,
|
||||
locally-enabled,
|
||||
file-ignored,
|
||||
suppressed-message,
|
||||
useless-suppression,
|
||||
deprecated-pragma,
|
||||
apply-builtin,
|
||||
basestring-builtin,
|
||||
buffer-builtin,
|
||||
cmp-builtin,
|
||||
coerce-builtin,
|
||||
execfile-builtin,
|
||||
file-builtin,
|
||||
long-builtin,
|
||||
raw_input-builtin,
|
||||
reduce-builtin,
|
||||
standarderror-builtin,
|
||||
unicode-builtin,
|
||||
xrange-builtin,
|
||||
coerce-method,
|
||||
delslice-method,
|
||||
getslice-method,
|
||||
setslice-method,
|
||||
no-absolute-import,
|
||||
old-division,
|
||||
dict-iter-method,
|
||||
dict-view-method,
|
||||
next-method-called,
|
||||
metaclass-assignment,
|
||||
indexing-exception,
|
||||
raising-string,
|
||||
reload-builtin,
|
||||
oct-method,
|
||||
hex-method,
|
||||
nonzero-method,
|
||||
cmp-method,
|
||||
input-builtin,
|
||||
round-builtin,
|
||||
intern-builtin,
|
||||
unichr-builtin,
|
||||
map-builtin-not-iterating,
|
||||
zip-builtin-not-iterating,
|
||||
range-builtin-not-iterating,
|
||||
filter-builtin-not-iterating,
|
||||
using-cmp-argument,
|
||||
eq-without-hash,
|
||||
div-method,
|
||||
idiv-method,
|
||||
rdiv-method,
|
||||
exception-message-attribute,
|
||||
invalid-str-codec,
|
||||
sys-max-int,
|
||||
bad-python3-import,
|
||||
deprecated-string-function,
|
||||
deprecated-str-translate-call,
|
||||
deprecated-itertools-function,
|
||||
deprecated-types-field,
|
||||
next-method-defined,
|
||||
dict-items-not-iterating,
|
||||
dict-keys-not-iterating,
|
||||
dict-values-not-iterating,
|
||||
deprecated-operator-function,
|
||||
deprecated-urllib-function,
|
||||
xreadlines-attribute,
|
||||
deprecated-sys-function,
|
||||
exception-escape,
|
||||
comprehension-escape,
|
||||
too-few-public-methods,
|
||||
import-error,
|
||||
invalid-name,
|
||||
missing-docstring
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
# multiple time (only on the command line, not in the configuration file where
|
||||
# it should appear only once). See also the "--disable" option for examples.
|
||||
enable=c-extension-no-member
|
||||
|
||||
|
||||
[REPORTS]
|
||||
|
||||
# Python expression which should return a note less than 10 (10 is the highest
|
||||
# note). You have access to the variables errors warning, statement which
|
||||
# respectively contain the number of errors / warnings messages and the total
|
||||
# number of statements analyzed. This is used by the global evaluation report
|
||||
# (RP0004).
|
||||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
||||
|
||||
# Template used to display messages. This is a python new-style format string
|
||||
# used to format the message information. See doc for all details
|
||||
#msg-template=
|
||||
|
||||
# Set the output format. Available formats are text, parseable, colorized, json
|
||||
# and msvs (visual studio).You can also give a reporter class, eg
|
||||
# mypackage.mymodule.MyReporterClass.
|
||||
output-format=text
|
||||
|
||||
# Tells whether to display a full report or only the messages
|
||||
reports=no
|
||||
|
||||
# Activate the evaluation score.
|
||||
score=yes
|
||||
|
||||
|
||||
[REFACTORING]
|
||||
|
||||
# Maximum number of nested blocks for function / method body
|
||||
max-nested-blocks=5
|
||||
|
||||
# Complete name of functions that never returns. When checking for
|
||||
# inconsistent-return-statements if a never returning function is called then
|
||||
# it will be considered as an explicit return statement and no message will be
|
||||
# printed.
|
||||
never-returning-functions=optparse.Values,sys.exit
|
||||
|
||||
|
||||
[VARIABLES]
|
||||
|
||||
# List of additional names supposed to be defined in builtins. Remember that
|
||||
# you should avoid to define new builtins when possible.
|
||||
additional-builtins=
|
||||
|
||||
# Tells whether unused global variables should be treated as a violation.
|
||||
allow-global-unused-variables=yes
|
||||
|
||||
# List of strings which can identify a callback function by name. A callback
|
||||
# name must start or end with one of those strings.
|
||||
callbacks=cb_,
|
||||
_cb
|
||||
|
||||
# A regular expression matching the name of dummy variables (i.e. expectedly
|
||||
# not used).
|
||||
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
|
||||
|
||||
# Argument names that match this expression will be ignored. Default to name
|
||||
# with leading underscore
|
||||
ignored-argument-names=_.*|^ignored_|^unused_
|
||||
|
||||
# Tells whether we should check for unused import in __init__ files.
|
||||
init-import=no
|
||||
|
||||
# List of qualified module names which can have objects that can redefine
|
||||
# builtins.
|
||||
redefining-builtins-modules=six.moves,past.builtins,future.builtins,io,builtins
|
||||
|
||||
|
||||
[TYPECHECK]
|
||||
|
||||
# List of decorators that produce context managers, such as
|
||||
# contextlib.contextmanager. Add to this list to register other decorators that
|
||||
# produce valid context managers.
|
||||
contextmanager-decorators=contextlib.contextmanager
|
||||
|
||||
# List of members which are set dynamically and missed by pylint inference
|
||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||
# expressions are accepted.
|
||||
generated-members=
|
||||
|
||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
||||
ignore-mixin-members=yes
|
||||
|
||||
# This flag controls whether pylint should warn about no-member and similar
|
||||
# checks whenever an opaque object is returned when inferring. The inference
|
||||
# can return multiple potential results while evaluating a Python object, but
|
||||
# some branches might not be evaluated, which results in partial inference. In
|
||||
# that case, it might be useful to still emit no-member and other checks for
|
||||
# the rest of the inferred objects.
|
||||
ignore-on-opaque-inference=yes
|
||||
|
||||
# List of class names for which member attributes should not be checked (useful
|
||||
# for classes with dynamically set attributes). This supports the use of
|
||||
# qualified names.
|
||||
ignored-classes=optparse.Values,thread._local,_thread._local
|
||||
|
||||
# List of module names for which member attributes should not be checked
|
||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
||||
# supports qualified module names, as well as Unix pattern matching.
|
||||
ignored-modules=
|
||||
|
||||
# Show a hint with possible names when a member name was not found. The aspect
|
||||
# of finding the hint is based on edit distance.
|
||||
missing-member-hint=yes
|
||||
|
||||
# The minimum edit distance a name should have in order to be considered a
|
||||
# similar match for a missing member name.
|
||||
missing-member-hint-distance=1
|
||||
|
||||
# The total number of similar names that should be taken in consideration when
|
||||
# showing a hint for a missing member.
|
||||
missing-member-max-choices=1
|
||||
|
||||
|
||||
[MISCELLANEOUS]
|
||||
|
||||
# List of note tags to take in consideration, separated by a comma.
|
||||
notes=FIXME,
|
||||
XXX
|
||||
|
||||
|
||||
[BASIC]
|
||||
|
||||
# Naming style matching correct argument names
|
||||
argument-naming-style=snake_case
|
||||
|
||||
# Regular expression matching correct argument names. Overrides argument-
|
||||
# naming-style
|
||||
#argument-rgx=
|
||||
|
||||
# Naming style matching correct attribute names
|
||||
attr-naming-style=snake_case
|
||||
|
||||
# Regular expression matching correct attribute names. Overrides attr-naming-
|
||||
# style
|
||||
#attr-rgx=
|
||||
|
||||
# Bad variable names which should always be refused, separated by a comma
|
||||
bad-names=foo,
|
||||
bar,
|
||||
baz,
|
||||
toto,
|
||||
tutu,
|
||||
tata
|
||||
|
||||
# Naming style matching correct class attribute names
|
||||
class-attribute-naming-style=any
|
||||
|
||||
# Regular expression matching correct class attribute names. Overrides class-
|
||||
# attribute-naming-style
|
||||
#class-attribute-rgx=
|
||||
|
||||
# Naming style matching correct class names
|
||||
class-naming-style=PascalCase
|
||||
|
||||
# Regular expression matching correct class names. Overrides class-naming-style
|
||||
#class-rgx=
|
||||
|
||||
# Naming style matching correct constant names
|
||||
const-naming-style=UPPER_CASE
|
||||
|
||||
# Regular expression matching correct constant names. Overrides const-naming-
|
||||
# style
|
||||
#const-rgx=
|
||||
|
||||
# Minimum line length for functions/classes that require docstrings, shorter
|
||||
# ones are exempt.
|
||||
docstring-min-length=-1
|
||||
|
||||
# Naming style matching correct function names
|
||||
function-naming-style=snake_case
|
||||
|
||||
# Regular expression matching correct function names. Overrides function-
|
||||
# naming-style
|
||||
#function-rgx=
|
||||
|
||||
# Good variable names which should always be accepted, separated by a comma
|
||||
good-names=i,
|
||||
j,
|
||||
k,
|
||||
ex,
|
||||
Run,
|
||||
_
|
||||
|
||||
# Naming style matching correct inline iteration names
|
||||
inlinevar-naming-style=any
|
||||
|
||||
# Regular expression matching correct inline iteration names. Overrides
|
||||
# inlinevar-naming-style
|
||||
#inlinevar-rgx=
|
||||
|
||||
# Naming style matching correct method names
|
||||
method-naming-style=snake_case
|
||||
|
||||
# Regular expression matching correct method names. Overrides method-naming-
|
||||
# style
|
||||
#method-rgx=
|
||||
|
||||
# Naming style matching correct module names
|
||||
module-naming-style=snake_case
|
||||
|
||||
# Regular expression matching correct module names. Overrides module-naming-
|
||||
# style
|
||||
#module-rgx=
|
||||
|
||||
# Colon-delimited sets of names that determine each other's naming style when
|
||||
# the name regexes allow several styles.
|
||||
name-group=
|
||||
|
||||
# Regular expression which should only match function or class names that do
|
||||
# not require a docstring.
|
||||
no-docstring-rgx=^_
|
||||
|
||||
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
||||
# to this list to register other decorators that produce valid properties.
|
||||
property-classes=abc.abstractproperty
|
||||
|
||||
# Naming style matching correct variable names
|
||||
variable-naming-style=snake_case
|
||||
|
||||
# Regular expression matching correct variable names. Overrides variable-
|
||||
# naming-style
|
||||
#variable-rgx=
|
||||
|
||||
|
||||
[SPELLING]
|
||||
|
||||
# Limits count of emitted suggestions for spelling mistakes
|
||||
max-spelling-suggestions=4
|
||||
|
||||
# Spelling dictionary name. Available dictionaries: none. To make it working
|
||||
# install python-enchant package.
|
||||
spelling-dict=
|
||||
|
||||
# List of comma separated words that should not be checked.
|
||||
spelling-ignore-words=
|
||||
|
||||
# A path to a file that contains private dictionary; one word per line.
|
||||
spelling-private-dict-file=
|
||||
|
||||
# Tells whether to store unknown words to indicated private dictionary in
|
||||
# --spelling-private-dict-file option instead of raising a message.
|
||||
spelling-store-unknown-words=no
|
||||
|
||||
|
||||
[LOGGING]
|
||||
|
||||
# Logging modules to check that the string format arguments are in logging
|
||||
# function parameter format
|
||||
logging-modules=logging
|
||||
|
||||
|
||||
[FORMAT]
|
||||
|
||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
||||
expected-line-ending-format=
|
||||
|
||||
# Regexp for a line that is allowed to be longer than the limit.
|
||||
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
||||
|
||||
# Number of spaces of indent required inside a hanging or continued line.
|
||||
indent-after-paren=4
|
||||
|
||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||
# tab).
|
||||
indent-string=' '
|
||||
|
||||
# Maximum number of characters on a single line.
|
||||
max-line-length=120
|
||||
|
||||
# Maximum number of lines in a module
|
||||
max-module-lines=1000
|
||||
|
||||
# List of optional constructs for which whitespace checking is disabled. `dict-
|
||||
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
|
||||
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
|
||||
# `empty-line` allows space-only lines.
|
||||
no-space-check=trailing-comma,
|
||||
dict-separator
|
||||
|
||||
# Allow the body of a class to be on the same line as the declaration if body
|
||||
# contains single statement.
|
||||
single-line-class-stmt=no
|
||||
|
||||
# Allow the body of an if to be on the same line as the test if there is no
|
||||
# else.
|
||||
single-line-if-stmt=no
|
||||
|
||||
|
||||
[SIMILARITIES]
|
||||
|
||||
# Ignore comments when computing similarities.
|
||||
ignore-comments=yes
|
||||
|
||||
# Ignore docstrings when computing similarities.
|
||||
ignore-docstrings=yes
|
||||
|
||||
# Ignore imports when computing similarities.
|
||||
ignore-imports=no
|
||||
|
||||
# Minimum lines number of a similarity.
|
||||
min-similarity-lines=4
|
||||
|
||||
|
||||
[CLASSES]
|
||||
|
||||
# List of method names used to declare (i.e. assign) instance attributes.
|
||||
defining-attr-methods=__init__,
|
||||
__new__,
|
||||
setUp
|
||||
|
||||
# List of member names, which should be excluded from the protected access
|
||||
# warning.
|
||||
exclude-protected=_asdict,
|
||||
_fields,
|
||||
_replace,
|
||||
_source,
|
||||
_make
|
||||
|
||||
# List of valid names for the first argument in a class method.
|
||||
valid-classmethod-first-arg=cls
|
||||
|
||||
# List of valid names for the first argument in a metaclass class method.
|
||||
valid-metaclass-classmethod-first-arg=mcs
|
||||
|
||||
|
||||
[DESIGN]
|
||||
|
||||
# Maximum number of arguments for function / method
|
||||
max-args=5
|
||||
|
||||
# Maximum number of attributes for a class (see R0902).
|
||||
max-attributes=7
|
||||
|
||||
# Maximum number of boolean expressions in a if statement
|
||||
max-bool-expr=5
|
||||
|
||||
# Maximum number of branch for function / method body
|
||||
max-branches=12
|
||||
|
||||
# Maximum number of locals for function / method body
|
||||
max-locals=15
|
||||
|
||||
# Maximum number of parents for a class (see R0901).
|
||||
max-parents=7
|
||||
|
||||
# Maximum number of public methods for a class (see R0904).
|
||||
max-public-methods=20
|
||||
|
||||
# Maximum number of return / yield for function / method body
|
||||
max-returns=6
|
||||
|
||||
# Maximum number of statements in function / method body
|
||||
max-statements=50
|
||||
|
||||
# Minimum number of public methods for a class (see R0903).
|
||||
min-public-methods=2
|
||||
|
||||
|
||||
[IMPORTS]
|
||||
|
||||
# Allow wildcard imports from modules that define __all__.
|
||||
allow-wildcard-with-all=no
|
||||
|
||||
# Analyse import fallback blocks. This can be used to support both Python 2 and
|
||||
# 3 compatible code, which means that the block might have code that exists
|
||||
# only in one or another interpreter, leading to false positives when analysed.
|
||||
analyse-fallback-blocks=no
|
||||
|
||||
# Deprecated modules which should not be used, separated by a comma
|
||||
deprecated-modules=regsub,
|
||||
TERMIOS,
|
||||
Bastion,
|
||||
rexec
|
||||
|
||||
# Create a graph of external dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
ext-import-graph=
|
||||
|
||||
# Create a graph of every (i.e. internal and external) dependencies in the
|
||||
# given file (report RP0402 must not be disabled)
|
||||
import-graph=
|
||||
|
||||
# Create a graph of internal dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
int-import-graph=
|
||||
|
||||
# Force import order to recognize a module as part of the standard
|
||||
# compatibility libraries.
|
||||
known-standard-library=
|
||||
|
||||
# Force import order to recognize a module as part of a third party library.
|
||||
known-third-party=enchant
|
||||
|
||||
|
||||
[EXCEPTIONS]
|
||||
|
||||
# Exceptions that will emit a warning when being caught. Defaults to
|
||||
# "Exception"
|
||||
overgeneral-exceptions=Exception
|
||||
|
||||
0
pre_commit_hooks/loaderon_hooks/__init__.py
Normal file
0
pre_commit_hooks/loaderon_hooks/__init__.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from pre_commit_logic.util.template_methods.checker_template_method import CheckerTemplateMethod
|
||||
from pre_commit_logic.util.git_helpers import get_current_branch_name
|
||||
|
||||
|
||||
class BranchNameChecker(CheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
self.parser.add_argument('-r', '--regex', help='Regex that git current branch must match.')
|
||||
|
||||
def _perform_checks(self):
|
||||
regular_expression = self.args.regex
|
||||
pattern = re.compile(regular_expression)
|
||||
current_branch_name = get_current_branch_name()
|
||||
if not pattern.match(current_branch_name):
|
||||
self.inform_check_failure('El nombre de la rama debe ser del estilo {}'.format(regular_expression))
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return BranchNameChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from pre_commit_logic.util.template_methods.lines_checker_template_method import LinesCheckerTemplateMethod
|
||||
|
||||
|
||||
class ClassDocstringChecker(LinesCheckerTemplateMethod):
|
||||
def _check_line(self):
|
||||
regular_expression = r'^(\t| )*class .+\(.*\):'
|
||||
pattern = re.compile(regular_expression)
|
||||
if pattern.match(self._file_line):
|
||||
self.__check_class_docstring(self._file_line_index)
|
||||
|
||||
def __check_class_docstring(self, class_line_index):
|
||||
class_first_line = self._file_lines[class_line_index + 1]
|
||||
if class_first_line in ['\n', '\r\n']:
|
||||
self.inform_check_failure('El docstring de la clase {} está separado de su clase por una o más líneas en '
|
||||
'blanco.'.format(self._file_lines[class_line_index]))
|
||||
if not class_first_line.strip().startswith('\"\"\"'):
|
||||
self.inform_check_failure('La clase {} no tiene docstring.'.format(self._file_lines[class_line_index]))
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return ClassDocstringChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
39
pre_commit_hooks/loaderon_hooks/general_hooks/check_line.py
Normal file
39
pre_commit_hooks/loaderon_hooks/general_hooks/check_line.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from pre_commit_logic.util.template_methods.lines_checker_template_method import LinesCheckerTemplateMethod
|
||||
|
||||
|
||||
class LinesChecker(LinesCheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
super(LinesChecker, self)._add_arguments_to_parser()
|
||||
self.parser.add_argument('-l', '--line-to-check', action='append', help='Regex to check.')
|
||||
self.parser.add_argument('-r', '--regexp-to-match', action='append', help='Regex to match.')
|
||||
|
||||
def _check_arguments(self):
|
||||
self.check_arguments_size_match(self.args.line_to_check, self.args.regexp_to_match)
|
||||
|
||||
def _check_line(self):
|
||||
for line_index, line_to_check in enumerate(self.args.line_to_check):
|
||||
line_to_check_pattern = re.compile(line_to_check)
|
||||
if line_to_check_pattern.match(self._file_line):
|
||||
line_regexp_to_match = self.args.regexp_to_match[line_index]
|
||||
correct_pattern = re.compile(line_regexp_to_match)
|
||||
if not correct_pattern.match(self._file_line):
|
||||
self.inform_check_failure(
|
||||
"Una de las líneas con '{}' no está correctamente formulada. Línea {}: \n\n{}\n"
|
||||
"Debería cumplir la expresión regular: {}".format(
|
||||
line_to_check,
|
||||
self._file_line_index + 1,
|
||||
self._file_line,
|
||||
line_regexp_to_match
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return LinesChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Checks files locations."""
|
||||
import os
|
||||
import re
|
||||
|
||||
from pre_commit_logic.util.template_methods.file_checker_template_method import FileCheckerTemplateMethod
|
||||
from pre_commit_logic.util.string_helpers import matches_any_regexp
|
||||
|
||||
|
||||
class LocationChecker(FileCheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
super(LocationChecker, self)._add_arguments_to_parser()
|
||||
self.parser.add_argument(
|
||||
'-ed', '--directories', action='append',
|
||||
help='Directory regex to be added to white list. Can be set multiple times to add'
|
||||
'multiple directories to white list.',
|
||||
)
|
||||
self.parser.add_argument(
|
||||
'-ef', '--files', action='append',
|
||||
help="Files regex, separated by a white space, to be added to it's corresponded"
|
||||
"directory's white list. Order of this argument declaration matches order of"
|
||||
"--directories declaration, so as to add files to that directory's files whitelist."
|
||||
"This argument can be therefore be set multiple times so as to match --directories sets.",
|
||||
)
|
||||
|
||||
def _check_file(self):
|
||||
"""Check filename location against enabled directories and their enabled files."""
|
||||
self.check_arguments_size_match(self.args.directories, self.args.files)
|
||||
file_directory_path = os.path.dirname(self.filename)
|
||||
file_name = os.path.basename(self.filename)
|
||||
location_enabled = False
|
||||
for directory_regexp in self.args.directories:
|
||||
pattern = re.compile(directory_regexp)
|
||||
if pattern.match(file_directory_path):
|
||||
location_enabled = True
|
||||
file_enabled = self.file_enabled_for_directory(directory_regexp, file_name)
|
||||
if not file_enabled:
|
||||
self.inform_check_failure('El archivo {} no está permitido para el directorio {}'
|
||||
.format(self.filename, file_directory_path))
|
||||
if not location_enabled:
|
||||
self.inform_check_failure('El directorio {} no está habilitado'.format(file_directory_path))
|
||||
|
||||
def file_enabled_for_directory(self, directory_regexp, filename):
|
||||
directory_position_in_arguments = self.args.directories.index(directory_regexp)
|
||||
directory_files_whitelist = self.args.files[directory_position_in_arguments]
|
||||
files_reg_expressions = directory_files_whitelist.split(' ')
|
||||
return matches_any_regexp(filename, files_reg_expressions)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return LocationChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Executes Pylint checks on all git modified and added files."""
|
||||
import re
|
||||
|
||||
from pylint.lint import Run
|
||||
from pylint.reporters.text import TextReporter
|
||||
|
||||
from pre_commit_logic.util.template_methods.file_checker_template_method import FileCheckerTemplateMethod
|
||||
from pre_commit_logic.util.file_helpers import find_file_starting_from_reference_file_directory
|
||||
|
||||
|
||||
class PylintChecker(FileCheckerTemplateMethod):
|
||||
def __init__(self, argv):
|
||||
super(PylintChecker, self).__init__(argv)
|
||||
self.pylint_output = WritableObject()
|
||||
|
||||
def _add_arguments_to_parser(self):
|
||||
super(PylintChecker, self)._add_arguments_to_parser()
|
||||
self.parser.add_argument('-e', '--exclude', help='Excluded files to check.')
|
||||
|
||||
def _check_file(self):
|
||||
try:
|
||||
self.run_pylint_except_in_excluded_files()
|
||||
except SystemExit as exception:
|
||||
self.manage_pylint_result(exception)
|
||||
|
||||
def run_pylint_except_in_excluded_files(self):
|
||||
excluded_files_regex = self.args.exclude
|
||||
pattern = re.compile(excluded_files_regex)
|
||||
if not pattern.match(self.filename):
|
||||
self.run_pylint_on_file()
|
||||
|
||||
def run_pylint_on_file(self):
|
||||
"""Runs pylint with .pylint config file if found, default config otherwise."""
|
||||
pylint_configuration_file = find_file_starting_from_reference_file_directory(__file__, '.pylintrc')
|
||||
if pylint_configuration_file:
|
||||
Run(['--rcfile', pylint_configuration_file, self.filename], reporter=TextReporter(self.pylint_output))
|
||||
else:
|
||||
Run([self.filename], reporter=TextReporter(self.pylint_output))
|
||||
|
||||
def manage_pylint_result(self, exception):
|
||||
print self.pylint_output.read()
|
||||
if exception.code != 0:
|
||||
self.inform_check_failure('')
|
||||
|
||||
|
||||
class WritableObject(object):
|
||||
"""Simple writable object for pylint."""
|
||||
|
||||
def __init__(self):
|
||||
self.__content = ''
|
||||
|
||||
def write(self, line):
|
||||
"""Adds line to object content."""
|
||||
self.__content = self.__content + '\n' + line
|
||||
|
||||
def read(self):
|
||||
"""Returns object content."""
|
||||
return self.__content
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return PylintChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pre_commit_logic.util.template_methods.file_checker_template_method import FileCheckerTemplateMethod
|
||||
from pre_commit_logic.util.file_helpers import read_file_line
|
||||
|
||||
|
||||
class XMLEncodingChecker(FileCheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
super(XMLEncodingChecker, self)._add_arguments_to_parser()
|
||||
self.parser.add_argument('-e', '--encoding', help='Desired encoding.')
|
||||
|
||||
def _check_file(self):
|
||||
first_line = read_file_line(self.filename)
|
||||
desired_encoding = self.args.encoding.rstrip()
|
||||
first_line = first_line.rstrip('\n')
|
||||
if first_line != desired_encoding:
|
||||
self.inform_check_failure(
|
||||
'El archivo {} no comienza con la línea "{}" (verifica también espacios en blanco)'.format(
|
||||
self.filename,
|
||||
desired_encoding
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return XMLEncodingChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
|
||||
from pre_commit_logic.util.template_methods.file_bunches_lines_checker_template_method import \
|
||||
FileBunchesLinesCheckerTemplateMethod
|
||||
|
||||
|
||||
class ModelNameAttributeChecker(FileBunchesLinesCheckerTemplateMethod):
|
||||
def __init__(self, argv):
|
||||
super(ModelNameAttributeChecker, self).__init__(argv)
|
||||
self.__module_name = ''
|
||||
name_attribute_regex = r'^(\t| )*_name = .+'
|
||||
self.__name_pattern = re.compile(name_attribute_regex)
|
||||
inherit_attribute_regex = r'^(\t| )*_inherit = .+'
|
||||
self.__inherit_pattern = re.compile(inherit_attribute_regex)
|
||||
self.__name_line = ''
|
||||
self.__inherit_line = ''
|
||||
|
||||
def _get_regexp(self):
|
||||
return r'^(\t| )*class.+'
|
||||
|
||||
def _check_file(self):
|
||||
self.__module_name = self._set_module_name()
|
||||
super(ModelNameAttributeChecker, self)._check_file()
|
||||
|
||||
def _set_module_name(self):
|
||||
models_folder_directory_path = os.path.dirname(self.filename)
|
||||
module_directory_path = os.path.dirname(models_folder_directory_path)
|
||||
return os.path.basename(module_directory_path)
|
||||
|
||||
def _check_bunch(self):
|
||||
super(ModelNameAttributeChecker, self)._check_bunch()
|
||||
if self.__name_line and not self.__has_multiple_inheritance():
|
||||
self.__check_name()
|
||||
|
||||
def _check_line(self):
|
||||
"""
|
||||
We will use this inherited method (which runs through all file lines) in order to gather lines that are required
|
||||
to perform the lines bunch check.
|
||||
"""
|
||||
if self.__name_pattern.match(self._file_line):
|
||||
self.__name_line = self._file_line.strip('_name = ')
|
||||
if self.__inherit_pattern.match(self._file_line):
|
||||
self.__inherit_line = self._file_line.strip('_inherit = ')
|
||||
|
||||
def __has_multiple_inheritance(self):
|
||||
return '[' in self.__inherit_line and ',' in self.__inherit_line
|
||||
|
||||
def __check_name(self):
|
||||
correct_name_regex = r'[\'\"]' + self.__module_name + r'\..+[\'\"]'
|
||||
correct_name_pattern = re.compile(correct_name_regex)
|
||||
if not correct_name_pattern.match(self.__name_line):
|
||||
self.inform_check_failure(
|
||||
'El nombre de modelo {} no incluye como prefijo el nombre del módulo {}.'.format(
|
||||
self.__name_line.strip('_name = '),
|
||||
self.__module_name
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return ModelNameAttributeChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from pre_commit_logic.util.template_methods.files_bunches_checker_template_method import \
|
||||
FileBunchesCheckerTemplateMethod
|
||||
|
||||
|
||||
class ViewFieldsOrderChecker(FileBunchesCheckerTemplateMethod):
|
||||
def __init__(self, argv):
|
||||
super(ViewFieldsOrderChecker, self).__init__(argv)
|
||||
name_line_regex = r'^(\t| )*<field name="name">.+<\/field>(\t| )*'
|
||||
self._name_line_pattern = re.compile(name_line_regex)
|
||||
model_line_regex = r'^(\t| )*<field name="model">.+<\/field>(\t| )*'
|
||||
self._model_line_pattern = re.compile(model_line_regex)
|
||||
self._record_line = None
|
||||
self._name_line = None
|
||||
self._model_line = None
|
||||
|
||||
def _get_regexp(self):
|
||||
return r'^(\t| )*<record id=.+ model="ir.ui.view">(\t| )*'
|
||||
|
||||
def _check_bunch(self):
|
||||
self._record_line = self._bunch_of_lines[0].strip()
|
||||
self._name_line = self._bunch_of_lines[1]
|
||||
self._model_line = self._bunch_of_lines[2]
|
||||
self._perform_check()
|
||||
|
||||
def _perform_check(self):
|
||||
if not self._name_line_pattern.match(self._name_line):
|
||||
self.inform_check_failure("El primer campo (field) declarado en un record de vista debe ser 'name'. "
|
||||
"Vista: {}".format(self._record_line))
|
||||
if not self._model_line_pattern.match(self._model_line):
|
||||
self.inform_check_failure("El segundo campo (field) declarado en un record de vista debe ser 'model'. "
|
||||
"Vista: {}".format(self._record_line))
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return ViewFieldsOrderChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from pre_commit_logic.odoo_specific_hooks.check_view_fields_order import ViewFieldsOrderChecker
|
||||
|
||||
|
||||
class ViewNameChecker(ViewFieldsOrderChecker):
|
||||
def __init__(self, argv):
|
||||
super(ViewNameChecker, self).__init__(argv)
|
||||
self._name_line = None
|
||||
self._model_line = None
|
||||
|
||||
def _perform_check(self):
|
||||
self.__make_required_strips()
|
||||
correct_name_regex = r'<field name="name">' + self._model_line + \
|
||||
r'\.(search|form|tree|filter)(\.inherit)?<\/field>'
|
||||
correct_name_pattern = re.compile(correct_name_regex)
|
||||
if not correct_name_pattern.match(self._name_line):
|
||||
strip_name_line = self._name_line.strip()
|
||||
strip_name_line = strip_name_line.strip('<field name="name">')
|
||||
strip_name_line = strip_name_line.strip('</field>')
|
||||
self.inform_check_failure("El nombre de la vista {} no cumple el formato {}."
|
||||
.format(strip_name_line, correct_name_regex))
|
||||
|
||||
def __make_required_strips(self):
|
||||
self._model_line = self._model_line.strip()
|
||||
self._model_line = self._model_line[20:-8]
|
||||
self._name_line = self._name_line.strip()
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return ViewNameChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
0
pre_commit_hooks/loaderon_hooks/util/__init__.py
Normal file
0
pre_commit_hooks/loaderon_hooks/util/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
class CheckFailedException(Exception):
|
||||
pass
|
||||
58
pre_commit_hooks/loaderon_hooks/util/file_helpers.py
Normal file
58
pre_commit_hooks/loaderon_hooks/util/file_helpers.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def read_file(file_path, only_first_line=False):
|
||||
opened_file = open(file_path)
|
||||
if only_first_line:
|
||||
lines = opened_file.readline()
|
||||
else:
|
||||
lines = opened_file.readlines()
|
||||
opened_file.close()
|
||||
return lines
|
||||
|
||||
|
||||
def read_file_line(file_path):
|
||||
return read_file(file_path, True)
|
||||
|
||||
|
||||
def read_file_lines(file_path):
|
||||
return read_file(file_path)
|
||||
|
||||
|
||||
def find_file_starting_from_reference_file_directory(reference_file, file_to_find):
|
||||
"""Attempts to find file_to_find by navigating through directories from reference_file parent directory."""
|
||||
file_path = os.path.realpath(reference_file)
|
||||
folder_path = os.path.dirname(file_path)
|
||||
for root, unused_dirs, files in os.walk(folder_path):
|
||||
if file_to_find in files:
|
||||
return os.path.join(root, file_to_find)
|
||||
return None
|
||||
|
||||
|
||||
def get_indexes_of_lines_per_regex(file_lines, regex):
|
||||
regex_pattern = re.compile(regex)
|
||||
indexes_of_lines_defining_regex = []
|
||||
for index, line in enumerate(file_lines):
|
||||
if regex_pattern.match(line):
|
||||
indexes_of_lines_defining_regex.append(index)
|
||||
return indexes_of_lines_defining_regex
|
||||
|
||||
|
||||
def get_bunches_of_lines_dividing_by_regex(file_lines, regex):
|
||||
lines = []
|
||||
indexes_of_lines_per_regex = get_indexes_of_lines_per_regex(file_lines, regex)
|
||||
for index, index_of_lines in enumerate(indexes_of_lines_per_regex):
|
||||
try:
|
||||
next_regex_index = indexes_of_lines_per_regex[index + 1]
|
||||
current_regex_lines = file_lines[index_of_lines:next_regex_index]
|
||||
except IndexError:
|
||||
current_regex_lines = file_lines[index_of_lines:]
|
||||
lines.append(current_regex_lines)
|
||||
return lines
|
||||
|
||||
|
||||
def split_by_regexp(filename, regex):
|
||||
file_lines = read_file_lines(filename)
|
||||
return get_bunches_of_lines_dividing_by_regex(file_lines, regex)
|
||||
9
pre_commit_hooks/loaderon_hooks/util/git_helpers.py
Normal file
9
pre_commit_hooks/loaderon_hooks/util/git_helpers.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_current_branch_name():
|
||||
output = subprocess.check_output(['git', 'symbolic-ref', 'HEAD'])
|
||||
output = output.splitlines()
|
||||
head_branches = output[0]
|
||||
return head_branches.strip().split('/')[-1]
|
||||
11
pre_commit_hooks/loaderon_hooks/util/string_helpers.py
Normal file
11
pre_commit_hooks/loaderon_hooks/util/string_helpers.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
|
||||
def matches_any_regexp(string, regexp_list):
|
||||
"""Checks if string matches any of regexp in regexp_list."""
|
||||
for regexp in regexp_list:
|
||||
pattern = re.compile(regexp)
|
||||
if pattern.match(string):
|
||||
return True
|
||||
return False
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import argparse
|
||||
from abc import abstractmethod
|
||||
from argparse import ArgumentTypeError
|
||||
|
||||
from pre_commit_logic.util.check_failed_exception import CheckFailedException
|
||||
|
||||
|
||||
class CheckerTemplateMethod(object):
|
||||
def __init__(self, argv):
|
||||
self.parser = argparse.ArgumentParser()
|
||||
self._add_arguments_to_parser()
|
||||
self.args = self.parser.parse_args(argv)
|
||||
self._check_arguments()
|
||||
|
||||
def _add_arguments_to_parser(self):
|
||||
pass
|
||||
|
||||
def _check_arguments(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
"""Prepare args and then check locations."""
|
||||
try:
|
||||
self._perform_checks()
|
||||
return 0
|
||||
except ArgumentTypeError as ex:
|
||||
print ex.message
|
||||
return 1
|
||||
except CheckFailedException as ex:
|
||||
print ex.message
|
||||
return 2
|
||||
|
||||
@abstractmethod
|
||||
def _perform_checks(self):
|
||||
pass
|
||||
|
||||
def inform_check_failure(self, message):
|
||||
raise CheckFailedException(message)
|
||||
|
||||
def check_arguments_size_match(self, arguments_one, arguments_two):
|
||||
if not arguments_one:
|
||||
arguments_one = []
|
||||
if not arguments_two:
|
||||
arguments_two = []
|
||||
if len(arguments_one) != len(arguments_two):
|
||||
self.inform_check_failure('Las listas de argumentos no tienen el mismo largo.')
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from abc import abstractmethod
|
||||
|
||||
from pre_commit_logic.util.template_methods.files_bunches_checker_template_method import \
|
||||
FileBunchesCheckerTemplateMethod
|
||||
from pre_commit_logic.util.template_methods.lines_checker_template_method import LinesCheckerTemplateMethod
|
||||
|
||||
|
||||
class FileBunchesLinesCheckerTemplateMethod(FileBunchesCheckerTemplateMethod, LinesCheckerTemplateMethod):
|
||||
@abstractmethod
|
||||
def _get_regexp(self):
|
||||
pass
|
||||
|
||||
def _check_bunch(self):
|
||||
"""
|
||||
This method uses LinesCheckerTemplateMethod's _check_lines. Which receives self._file_lines. In this case, our
|
||||
'file lines' will be the bunches of lines got by split_by_classes.
|
||||
"""
|
||||
self._file_lines = self._bunch_of_lines
|
||||
self._check_lines()
|
||||
|
||||
@abstractmethod
|
||||
def _check_line(self):
|
||||
pass
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from abc import abstractmethod
|
||||
|
||||
from pre_commit_logic.util.template_methods.checker_template_method import CheckerTemplateMethod
|
||||
|
||||
|
||||
class FileCheckerTemplateMethod(CheckerTemplateMethod):
|
||||
def __init__(self, argv):
|
||||
super(FileCheckerTemplateMethod, self).__init__(argv)
|
||||
self.filename = ''
|
||||
|
||||
def _add_arguments_to_parser(self):
|
||||
self.parser.add_argument('filenames', nargs='*')
|
||||
|
||||
def _perform_checks(self):
|
||||
"""For each file, check it's location."""
|
||||
for self.filename in self.args.filenames:
|
||||
self._check_file()
|
||||
|
||||
@abstractmethod
|
||||
def _check_file(self):
|
||||
pass
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from abc import abstractmethod
|
||||
|
||||
from pre_commit_logic.util.file_helpers import split_by_regexp
|
||||
from pre_commit_logic.util.template_methods.file_checker_template_method import FileCheckerTemplateMethod
|
||||
|
||||
|
||||
class FileBunchesCheckerTemplateMethod(FileCheckerTemplateMethod):
|
||||
def __init__(self, argv):
|
||||
super(FileBunchesCheckerTemplateMethod, self).__init__(argv)
|
||||
self._bunch_of_lines = []
|
||||
|
||||
def _check_file(self):
|
||||
regexp = self._get_regexp()
|
||||
bunches_of_lines = split_by_regexp(self.filename, regexp)
|
||||
for self._bunch_of_lines in bunches_of_lines:
|
||||
self._check_bunch()
|
||||
|
||||
@abstractmethod
|
||||
def _get_regexp(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def _check_bunch(self):
|
||||
pass
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from abc import abstractmethod
|
||||
|
||||
from pre_commit_logic.util.template_methods.file_checker_template_method import FileCheckerTemplateMethod
|
||||
from pre_commit_logic.util.file_helpers import read_file_lines
|
||||
|
||||
|
||||
class LinesCheckerTemplateMethod(FileCheckerTemplateMethod):
|
||||
def __init__(self, argv):
|
||||
super(LinesCheckerTemplateMethod, self).__init__(argv)
|
||||
self._file_lines = []
|
||||
self._file_line = ''
|
||||
self._file_line_index = 0
|
||||
|
||||
def _check_file(self):
|
||||
self._file_lines = read_file_lines(self.filename)
|
||||
self._check_lines()
|
||||
|
||||
def _check_lines(self):
|
||||
for self._file_line_index, self._file_line in enumerate(self._file_lines):
|
||||
self._check_line()
|
||||
|
||||
@abstractmethod
|
||||
def _check_line(self):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue