ansible / community

This repository is being archived. See https://github.com/ansible-community/presentations and https://github.com/ansible-community/meetings for the new locations
Apache License 2.0
489 stars 144 forks source link

Help with IDE local linting. #564

Closed pm98zz-c closed 3 years ago

pm98zz-c commented 4 years ago

Hi there,

I'm new to Ansible devel, and started making changes to an existing module, but quickly realized my default linting/auto-formatting setup (pylint) kept on messing up with Ansible coding-standards.

Typically, pylint/.pycodestyle would move import to the top, contrary to guidelines indicating to leave them below the doc block, for example.

I realize I can catch those after the fact with ansible-test sanity, but I'd rather have them auto-fixed and/or flagged on the fly in my IDE (like on most projects).

Not sure if I'm missing something obvious here, but I cannot find anywhere any such configuration (.editorconfig, .pycodestyle, etc...) to drop in my project.

Is this something I've just been unable to find, and if not, would it not be useful for the wider community to have such linter standards easily available?

imjoseangel commented 4 years ago

@pm98zz-c We can have a chat in the IRC if you want some help. I personally use VSCode following these steps:

From Ansible Developing Testing. You can read:

ansible-test sanity --test pep8
ansible-test sanity --test validate-modules

From here I can assume you have to use pep8. With VSCode:

Setup your exceptions. For instance:

    "python.linting.pylintEnabled": false,
    "python.linting.pycodestyleEnabled": true,
    "python.linting.pycodestyleArgs": [
        "--ignore=E402"
    ]

Hope it helps

pm98zz-c commented 4 years ago

Hi, thanks a lot for the tip. The title of my issue probably was misleading, in that I wasn't only seeking for "help" for myself. What I wanted to point out was, as a first time contributor, that it could be a good thing to have those preset available (hence posting it under the community project, and not asking directly in IRC).

When you contribute to various projects, potentially in various languages, each with their own slightly different standards, you feel more welcome if the repo already provides you with presets so you don't have to think too much about it or fiddle around from one project to the other. Usually, it consists of

Those settings must already exist "somewhere" as they're in use in ansible-test sanity --test pep8 and in the "shippable" tests, but I couldn't find them anywhere.

Thoughts about having them directly in the ansible repo, or at least added to the documentation?

imjoseangel commented 4 years ago

Fully agree with it.

Besides the .editorconfig that I think is a great idea and I use it everywhere; I think having specific documentation about this matter could be great with recommended linting and techniques for Ansible development.

tremble commented 4 years ago

For what it's worth the configurations used by ansible-test can be found in the main ansible repo:

pylint:

pycodestyle (formerly known as pep8): (ignored messages)

With the migration over to 'collections' I think it's going to be much harder to coordinate getting the various . files in place, but I do like the idea of making it as easy as possible to run any of the tests.

There's also a lot of custom code (validate-modules) which is specific to Ansible, for which I think ansible-test is probably the best wrapper.

pm98zz-c commented 4 years ago

Thanks a ton. For some reason I was expecting to find them under the "hacking" dir, I should have thought of the tests one...