GithubHelp home page GithubHelp logo

cnescatlab / cnes-pylint-extension Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 93 KB

cnes-pylint-extension is a python checker, which adds CNES specific checks to pylint.

Home Page: https://pypi.org/project/cnes-pylint-extension/

License: GNU General Public License v3.0

Python 100.00%
pylint python-checker

cnes-pylint-extension's People

Contributors

antonyricard avatar begarco avatar diegorodriguez31 avatar dupuisa avatar fbessou avatar louisjdmartin avatar sancretor avatar topin2001 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

fbessou

cnes-pylint-extension's Issues

Add installation manual

Expected behavior

The installation manual should be accessible by users.

Actual behavior

The installation manual is only accessible by CNES.

Steps to reproduce behavior

Read the doc.

Detection version

4.0

Fix the test

Is your feature request related to a problem? Please describe.

The test file, located in the test folder can't be run, because they're outdated.

Describe the solution you'd like

I wan't to be able to ran the test to see if my script is correct

Upgrade Pylint compatibility

Expected behavior

CNES Pylint Extension should be compatible with the latest version of Pylint

Actual behavior

Only compatible with 2.1.1

Steps to reproduce behavior

Install it with latest version of Pylint and run an analysis on a python script

Detection version

v4.0.0

pylint 2.17.1 issue

Hi I have an issue under Fedora
pip install cnes-pylint-extension
ok

pylint --version
pylint 2.17.1
astroid 2.15.0
Python 3.11.2 (main, Feb  8 2023, 00:00:00) [GCC 13.0.1 20230208 (Red Hat 13.0.1-0)]
pylint --persistent=n --load-plugins=cnes_checker workspace/bla.py
************* Module Command line or configuration file
Command line or configuration file:1:0: E0013: Plugin 'cnes_checker' is impossible to load, is it installed ? ('No module named 'cnes_checker'') (bad-plugin-value)

But :

python
Python 3.11.2 (main, Feb  8 2023, 00:00:00) [GCC 13.0.1 20230208 (Red Hat 13.0.1-0)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cnes_checker
>>>

Non-compatibility of cnes-pylint-extension version 6 with pylint version 3

We are using version 6 of cnes-pylint-extension on the Hysope 2 project.
We would now like to upgrade to version 3 of pylint. At the moment, this is not compatible with the current version of the extension.

Are there any plans to release a new version of this extension and when?

Pending your reply, we are going to deactivate this extension and migrate to pylint vesrion 3, in order to benefit from the most recent pylint improvements.

sonar-scanner error when empty line on

Describe the bug

We detect an error using your plugin in a specific case.
We have rules in our SonarQube to add specific comment on the first lines of a module.
If an issue is detected on empty line sonar-scanner shown an error because the first and end pointer is the same :

Strack trace
ERROR: Error during SonarScanner execution java.lang.IllegalArgumentException: Start pointer [line=1, lineOffset=0] should be before end pointer [line=1, lineOffset=0] at org.sonar.api.utils.Preconditions.checkArgument(Preconditions.java:43) at org.sonar.api.batch.fs.internal.DefaultInputFile.newRangeValidPointers(DefaultInputFile.java:348) at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:281) at org.sonar.scanner.externalissue.ExternalIssueImporter.fillLocation(ExternalIssueImporter.java:133) at org.sonar.scanner.externalissue.ExternalIssueImporter.importIssue(ExternalIssueImporter.java:81) at org.sonar.scanner.externalissue.ExternalIssueImporter.execute(ExternalIssueImporter.java:57) at org.sonar.scanner.externalissue.ExternalIssuesImportSensor.execute(ExternalIssuesImportSensor.java:74) at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48) at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85) at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59) at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77) at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59) at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123) at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392) at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388) at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123) at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123) at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72) at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66) at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) at com.sun.proxy.$Proxy0.execute(Unknown Source) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189) at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138) at org.sonarsource.scanner.cli.Main.execute(Main.java:112) at org.sonarsource.scanner.cli.Main.execute(Main.java:75) at org.sonarsource.scanner.cli.Main.main(Main.java:61)

To reproduce

Here the incriminated code :

"""
Classe Database Interrogation
"""

import ast

tree = ast.parse("print('à')")
for node in ast.walk(tree):
    print(node)
    print(node.__dict__)
    print("children: " + str([x for x in ast.iter_child_nodes(node)]) + "\\n")

Here the configuration file :

pylintrc_RNC2015_D
[MASTER]
# Specify a configuration file.
#rcfile=

# Python code to execute, usually for sys.path manipulation such as # pygtk.require().
#init-hook=

# Profiled execution.
profile=no

# Add files or directories to the blacklist. They should be base names, not # paths.
ignore=CVS

# 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=cnes_checker,pylint.extensions.check_elif,pylint_sonarjson


[MESSAGES CONTROL]


# 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.
# 2015/07/09 : C0103 (invalid-name/PY.NAME.Convention), R0801 (duplicate-code/COM.PROJECT.CodeCloning) 
#              and R0915 (too-many-statements/COM.MET.LineOfCode) rules enabled
#              In addition, C0102 and W0141 have to be enabled for bad-names and bad-functions rules
disable=all
enable=R5104,W0703,R5402,R5401,R5105,R0203,R0204,R5403,R5106,R0401,W0102,W9097,E0108,R5103,F0002,W9096,C0204,C0203,E0213,C0122,W9095,W0312,W0406,R5101,W0622,W0621,W0404,W0403,R5201,R5301,R5302,R5102,R0915,W0602,E0602,C0412,W0612,C0113,W0603,E0601,C0411,C0413,C0326

max-bool-expr=5
max-returns=1
max-nested-blocks=5

# 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"


[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

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=yes

# 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)

# Add a comment according to your evaluation note. This is used by the global
# evaluation report (RP0004).
comment=no

# 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]

# Required attributes for module, separated by a comma
required-attributes=

# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input

# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression which should only match correct module level names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match correct attribute names in class
# bodies
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata

# 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.
docstring-min-length=-1


[FORMAT]

# Maximum number of characters on a single line.
max-line-length=100

# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\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

# List of optional constructs for which whitespace checking is disabled
no-space-check=trailing-comma,dict-separator

# 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='    '


[SIMILARITIES]

# Minimum lines number of a similarity.
min-similarity-lines=4

# Ignore comments when computing similarities.
ignore-comments=yes

# Ignore docstrings when computing similarities.
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=no


[VARIABLES]

# Tells whether we should check for unused import in __init__ files.
init-import=no

# A regular expression matching the beginning of the name of dummy variables
# (i.e. not used).
dummy-variables-rgx=_$|dummy

# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=


[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 classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject

# When zope mode is activated, add a predefined set of Zope acquired attributes
# to generated-members.
zope=no

# 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


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO


[CLASSES]

# List of interface methods to ignore, separated by a comma. This is used for
# instance to not check methods defines in Zope's Interface base class.
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by

# 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


[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=15

# Maximum number of return / yield for function / method body
max-returns=1

# Maximum number of branch for function / method body
max-branches=12

# Maximum number of statements in function / method body
max-statements=80

# Add for RNC CNES
accept-no-param-doc=n
max-mccabe-number=15
max-simplified-mccabe-number=12
max-nested-blocks=6
min-func-comments-ratio=20
min-module-comments-ratio=20
min-func-size-to-check-comments=10
max-bool-expr=5
max-decorators=5

# Maximum number of parents for a class (see R0901).
max-parents=7

# 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=2

# 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,TERMIOS,Bastion,rexec

# 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


[SONARQUBE]

# Define SonarQube rules to enable importing Pylint results with customized
# severity and type. Option sonar.externalIssuesReportPaths must be used with
# sonar-scanner. To generate the json file, package pylint-sonarjson must be
# installed.
# For more information see: https://github.com/omegacen/pylint-sonarjson
sonar-rules=C0113:MINOR:10:CODE_SMELL,C0122:MINOR:10:CODE_SMELL,C0203:MINOR:10:CODE_SMELL,C0204:MINOR:10:CODE_SMELL,C0326:MINOR:10:CODE_SMELL,C0411:MINOR:10:CODE_SMELL,C0412:MINOR:10:CODE_SMELL,C0413:MINOR:10:CODE_SMELL,E0108:MINOR:10:CODE_SMELL,E0213:MAJOR:10:CODE_SMELL,E0601:MAJOR:10:CODE_SMELL,E0602:MAJOR:10:CODE_SMELL,F0002:MAJOR:10:CODE_SMELL,R0203:MINOR:10:CODE_SMELL,R0204:CRITICAL:10:CODE_SMELL,R0401:MINOR:10:CODE_SMELL,R0915:MINOR:10:CODE_SMELL,R5101:CRITICAL:10:CODE_SMELL,R5102:CRITICAL:10:CODE_SMELL,R5103:CRITICAL:10:CODE_SMELL,R5104:CRITICAL:10:CODE_SMELL,R5105:CRITICAL:10:CODE_SMELL,R5106:CRITICAL:10:CODE_SMELL,R5201:CRITICAL:10:CODE_SMELL,R5301:CRITICAL:10:CODE_SMELL,R5302:CRITICAL:10:CODE_SMELL,R5401:BLOCKER:10:CODE_SMELL,R5402:BLOCKER:10:CODE_SMELL,R5403:BLOCKER:10:CODE_SMELL,W0102:MINOR:10:CODE_SMELL,W0312:MAJOR:10:CODE_SMELL,W0403:MINOR:10:CODE_SMELL,W0404:MINOR:10:CODE_SMELL,W0406:MINOR:10:CODE_SMELL,W0602:MINOR:10:CODE_SMELL,W0603:MINOR:10:CODE_SMELL,W0612:MINOR:10:CODE_SMELL,W0621:MINOR:10:CODE_SMELL,W0622:MINOR:10:CODE_SMELL,W0703:MINOR:10:CODE_SMELL,W9095:CRITICAL:10:CODE_SMELL,W9096:CRITICAL:10:CODE_SMELL,W9097:CRITICAL:10:CODE_SMELL
output-format=sonarjson

Here the commands :

python -m venv .venv
source .venv/bin/activate
pip install pip --upgrade
pip install cnes-pylint-extension 
pip install pylint-sonarjson==1.0.5
pylint ast_example.py --rcfile=pylintrc_RNC2015_D --exit-zero --halt-on-invalid-sonar-rules n

Here the output :

json output
{
    "issues": [
        {
            "engineId": "PYLINT",
            "ruleId": "W9095",
            "type": "CODE_SMELL",
            "primaryLocation": {
                "message": "\"author\" field missing from ast_example docstring",
                "filePath": "ast_example.py",
                "textRange": {
                    "startLine": 1,
                    "startColumn": 0
                }
            },
            "severity": "CRITICAL",
            "effortMinutes": 10
        },
        {
            "engineId": "PYLINT",
            "ruleId": "W9095",
            "type": "CODE_SMELL",
            "primaryLocation": {
                "message": "\"version\" field missing from ast_example docstring",
                "filePath": "ast_example.py",
                "textRange": {
                    "startLine": 1,
                    "startColumn": 0
                }
            },
            "severity": "CRITICAL",
            "effortMinutes": 10
        },
        {
            "engineId": "PYLINT",
            "ruleId": "W9095",
            "type": "CODE_SMELL",
            "primaryLocation": {
                "message": "\"date\" field missing from ast_example docstring",
                "filePath": "ast_example.py",
                "textRange": {
                    "startLine": 1,
                    "startColumn": 0
                }
            },
            "severity": "CRITICAL",
            "effortMinutes": 10
        }
    ]
}

Expected behavior

2 possibilities :

  • The 3 errors begins to line 2
  • The error W9097 - missing-docstring-description at line 1 is thrown

User environment

  • OS: Redhat 8.6
  • Python 3.8.6

Improve information to be able to resolve issues

Is your feature request related to a problem? Please describe.

When there is an issue in SonarQube, no details are available (here for rule PYLINT:W9095) when clicking "Why is it an issue?" :
image

Describe the solution you'd like

It would be nice to have details for all the rules (why is it an issue) and an example describing what is expected.

  • For example, for the rule PYLINT:W9095, we don't have enough details to find the expected format:
    image
    It would be nice to have an example with the expected format, when clicking "Why is it an issue?".

  • For example, for the rule PYLINT:R5403,
    image
    It would be nice to know why it is better to use argparse module, in what context (not when just passing arguments maybe).

  • For example, for the rule PYLINT:R5401,
    image
    It would be nice to know why consider dropping sys.exit() and how to replace it.

Versions

  • cnes-pylint-extension: 6.0.0
  • sonarQube: Community Edition Version 8.9.6 (build 50800)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.