From 791fcf22d1dfe5b7b981f16b17bdb269e87238bb Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 31 Jan 2023 16:27:27 -0800 Subject: [PATCH 1/3] ci: Remove pylint --- .pylintrc | 361 ----------------------- Makefile | 4 - requirements/dev.txt | 1 - samtranslator/model/api/api_generator.py | 2 - samtranslator/model/eventsources/push.py | 1 - samtranslator/public/models.py | 8 +- samtranslator/public/parser.py | 6 +- samtranslator/public/sdk/parameter.py | 6 +- samtranslator/utils/py27hash_fix.py | 3 - 9 files changed, 13 insertions(+), 379 deletions(-) delete mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 230785756..000000000 --- a/.pylintrc +++ /dev/null @@ -1,361 +0,0 @@ -[MASTER] - -# Specify a configuration file. -#rcfile= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Add files or directories to the ignore list. They should be base names, not -# paths. -ignore=compat.py, __main__.py - -# Pickle collected data for later comparisons. -persistent=yes - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins= - pylint.extensions.check_elif, # Else If Used checker - pylint.extensions.emptystring, # compare to empty string - pylint.extensions.comparetozero, # compare to 0 - pylint.extensions.docparams, # Parameter documentation checker - -# Use multiple processes to speed up Pylint. -# Pylint has a bug on multitread, turn it off. -jobs=1 - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - -# 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= - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# 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. See also the "--disable" option for examples. -#enable= - -# 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= - C0209, # consider-using-f-string. There are too many of them - W0613, # Unused argument %r - W0640, # Cell variable %s defined in loop A variable used in a closure is defined in a loop - R0902, # Too many instance attributes (%s/%s) - R0913, # Too many arguments (%s/%s) - W0703, # Catching too general exception %s - R0904, # Too many public methods (%s/%s) - R0914, # Too many local variables (%s/%s) - R0915, # Too many statements - C0415, # Import outside toplevel (%s) Used when an import statement is used anywhere other than the module toplevel. Move this import to the top of the file. - C0115, # missing-class-docstring - W9006, # "%s" not documented as being raised - W9011, # Missing return documentation - W9012, # Missing return type documentation - W9016, # "%s" missing in parameter type documentation - C0103, # Class constant name "%s" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern) (invalid-name) - R0401, # Cyclic import - C0411, # import ordering - W9015, # missing parameter in doc strings - C0301, # line to long - C0114, # missing-module-docstring - W1202, # Use lazy % formatting in logging functions (logging-format-interpolation) - E1101, # No member - W0212, # protected-access - W0201, # attribute-defined-outside-init - C2001, # Avoid comparisons to zero (compare-to-zero) - R0912, # too many branches - C0412, # Imports from package samtranslator are not grouped (ungrouped-imports) - E0203, # access-member-before-definition - W0221, # arguments-differ - R1702, # too-many-nested-blocks - W0105, # String statement has no effect (pointless-string-statement) - C0112, # empty-docstring - C0116, # missing-function-docstring - W9017, # differing-param-doc - W9018, # differing-type-doc - W0511, # fixme - C0302, # too-many-lines - W9013, # missing-yield-doc - W9014, # missing-yield-type-doc - - -[REPORTS] - -# Set the output format. Available formats are text, parseable, colorized, msvs -# (visual studio) and html. 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 - -# 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= - - -[BASIC] - -# Good variable names which should always be accepted, separated by a comma -good-names=e,i,j,k,n,ex,Run,_ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=yes - -# Regular expression matching correct function names -function-rgx=[a-z_][a-z0-9_]{2,50}$ - -# Regular expression matching correct variable names -variable-rgx=[a-z_][a-z0-9_]{0,50}$ - -# Regular expression matching correct constant names -const-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$ - -# Regular expression matching correct attribute names -attr-rgx=[a-z_][a-z0-9_]{1,50}$ - -# Regular expression matching correct argument names -argument-rgx=[a-z_][a-z0-9_]{0,50}$ - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct class names -class-rgx=[A-Z_][a-zA-Z0-9]+$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Regular expression matching correct method names -method-rgx=[a-z_][a-z0-9_]{2,50}$ - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -# To improve our docstring without spending too much effort at a time, -# here set it to 30 and decrease it gradually in the future. -docstring-min-length=30 - - -[FORMAT] - -# Maximum number of characters on a single line. -max-line-length=120 - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# 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 - -# Maximum number of lines in a module -max-module-lines=1000 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX - - -[SIMILARITIES] - -# Minimum lines number of a similarity. -min-similarity-lines=12 - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - - -[SPELLING] - -# 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 - - -[TYPECHECK] - -# 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 - -# 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 -ignored-modules= - -# List of classes names for which member attributes should not be checked -# (useful for classes with attributes dynamically set). -ignored-classes=SQLObject - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E0201 when accessed. Python regular -# expressions are accepted. -generated-members=REQUEST,acl_users,aq_parent,objects,DoesNotExist,md5,sha1,sha224,sha256,sha384,sha512 - - -[VARIABLES] - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_|dummy|ignore - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# 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 - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# 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 - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.* - -# Maximum number of locals for function / method body -max-locals=17 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of statements in function / method body -max-statements=30 - -# Maximum number of parents for a class (see R0901). -max-parents=6 - -# Maximum number of attributes for a class (see R0902). -max-attributes=7 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=0 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - - -[IMPORTS] - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=regsub,string,TERMIOS,Bastion,rexec,UserDict - -# 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 external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=Exception diff --git a/Makefile b/Makefile index 01ce7026a..5800f806f 100755 --- a/Makefile +++ b/Makefile @@ -35,13 +35,9 @@ black-check: bin/yaml-format.py --check integration --add-test-metadata lint: - # experimental: use ruff to perform checks before pylint to see - # if it can check issues before pylint ruff samtranslator bin schema_source # mypy performs type check mypy --strict samtranslator bin schema_source - # Linter performs static analysis to catch latent bugs - pylint --rcfile .pylintrc samtranslator schema_source # cfn-lint to make sure generated CloudFormation makes sense bin/run_cfn_lint.sh diff --git a/requirements/dev.txt b/requirements/dev.txt index a2a399185..3324a1fee 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,7 +5,6 @@ pytest-cov~=2.10.1 pytest-xdist~=2.5 pytest-env~=0.6.2 pytest-rerunfailures~=9.1.1 -pylint~=2.15.0 pyyaml~=5.4 ruff==0.0.237 # loose the requirement once it is more stable diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 5d4308319..f06dab43b 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -428,7 +428,6 @@ def _construct_stage( def _construct_api_domain( self, rest_api: ApiGatewayRestApi, route53_record_set_groups: Any ) -> Tuple[Optional[ApiGatewayDomainName], Optional[List[ApiGatewayBasePathMapping]], Any]: - # pylint: disable=duplicate-code """ Constructs and returns the ApiGateway Domain and BasepathMapping """ @@ -585,7 +584,6 @@ def _construct_record_sets_for_domain( return recordset_list def _construct_alias_target(self, domain: Dict[str, Any], api_domain_name: str, route53: Any) -> Dict[str, Any]: - # pylint: disable=duplicate-code alias_target = {} target_health = route53.get("EvaluateTargetHealth") diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index af89b10a3..d4cd96566 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -751,7 +751,6 @@ def _get_permission(self, resources_to_link, stage, suffix): # type: ignore[no- return self._construct_permission(resources_to_link["function"], source_arn=source_arn, suffix=suffix) # type: ignore[no-untyped-call] def _add_swagger_integration(self, api, api_id, function, intrinsics_resolver): # type: ignore[no-untyped-def] - # pylint: disable=duplicate-code """Adds the path and method for this Api event source to the Swagger body for the provided RestApi. :param model.apigateway.ApiGatewayRestApi rest_api: the RestApi to which the path and method should be added. diff --git a/samtranslator/public/models.py b/samtranslator/public/models.py index 41b1f2f0f..7553aa01e 100644 --- a/samtranslator/public/models.py +++ b/samtranslator/public/models.py @@ -1,3 +1,5 @@ -# flake8: noqa -# pylint: disable=W0611 -from samtranslator.model.resource_policies import ResourcePolicies, PolicyTypes +from typing import List + +from samtranslator.model.resource_policies import PolicyTypes, ResourcePolicies + +__all__: List[str] = ["PolicyTypes", "ResourcePolicies"] diff --git a/samtranslator/public/parser.py b/samtranslator/public/parser.py index 16486767d..dbb8c1004 100644 --- a/samtranslator/public/parser.py +++ b/samtranslator/public/parser.py @@ -1,3 +1,5 @@ -# flake8: noqa -# pylint: disable=W0611 +from typing import List + from samtranslator.parser.parser import Parser + +__all__: List[str] = ["Parser"] diff --git a/samtranslator/public/sdk/parameter.py b/samtranslator/public/sdk/parameter.py index 6f091916e..8f397a222 100644 --- a/samtranslator/public/sdk/parameter.py +++ b/samtranslator/public/sdk/parameter.py @@ -1,3 +1,5 @@ -# flake8: noqa -# pylint: disable=W0611 +from typing import List + from samtranslator.sdk.parameter import SamParameterValues + +__all__: List[str] = ["SamParameterValues"] diff --git a/samtranslator/utils/py27hash_fix.py b/samtranslator/utils/py27hash_fix.py index ecf189ecb..0f42faba5 100644 --- a/samtranslator/utils/py27hash_fix.py +++ b/samtranslator/utils/py27hash_fix.py @@ -372,7 +372,6 @@ def __reduce__(self): # type: ignore[no-untyped-def] """ Method necessary to fully pickle Python 3 subclassed dict objects with attribute fields. """ - # pylint: disable = W0235 return super().__reduce__() def __setitem__(self, key, value): # type: ignore[no-untyped-def] @@ -550,7 +549,6 @@ def values(self): # type: ignore[no-untyped-def] list list of values """ - # pylint: disable=consider-using-dict-items return [self[k] for k in self] def items(self): # type: ignore[no-untyped-def] @@ -562,7 +560,6 @@ def items(self): # type: ignore[no-untyped-def] list list of items """ - # pylint: disable=consider-using-dict-items return [(k, self[k]) for k in self] def setdefault(self, key, default): # type: ignore[no-untyped-def] From e1e38f782b47120edf094a5b41937d5edf27026f Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 31 Jan 2023 16:36:41 -0800 Subject: [PATCH 2/3] Loose ruff requirement, the risk of new version having more errors benefit the team to make code better --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 3324a1fee..ab7eacfdf 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -6,7 +6,7 @@ pytest-xdist~=2.5 pytest-env~=0.6.2 pytest-rerunfailures~=9.1.1 pyyaml~=5.4 -ruff==0.0.237 # loose the requirement once it is more stable +ruff~=0.0.237 # Test requirements pytest~=6.2.5 From 156a310da5b4b2d0e84fd3c2d7a41e4149a97097 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 31 Jan 2023 16:42:29 -0800 Subject: [PATCH 3/3] Tight ruff requirement again --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index ab7eacfdf..3324a1fee 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -6,7 +6,7 @@ pytest-xdist~=2.5 pytest-env~=0.6.2 pytest-rerunfailures~=9.1.1 pyyaml~=5.4 -ruff~=0.0.237 +ruff==0.0.237 # loose the requirement once it is more stable # Test requirements pytest~=6.2.5