sbaudoin / sonar-ansible

SonarQube plugin to analyze Ansible playbooks
Apache License 2.0
71 stars 17 forks source link

Problem with regexp rawIssue 'Matcher new50Splitter = Pattern.compile("^(.*):([0-9]+): ([^ ]+)$").matcher(rawIssue);' #53

Open mandracke76 opened 2 years ago

mandracke76 commented 2 years ago

Hello,

The regexp here don't match the lint error

The good syntax must be "^(.):([0-9]+): ([^ ]+)(.)$"

My execution context is:

...
maven-3.6-jdk-11
org/sonarsource/parent/parent/59.0.29/parent-59.0.29
org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.0.2155/sonar-maven-plugin-3.9.0.2155
org/sonarsource/scanner/api/sonar-scanner-api/2.16.1.361/sonar-scanner-api-2.16.1.361
...
[INFO] SonarQube version: 8.9.7
[INFO] Default locale: "en", source code encoding: "UTF-8"
[INFO] Load global settings
...
[INFO] Sensor Ansible Lint Sensor [ansible]
[INFO] ansible version:
[INFO] ansible [core 2.12.8]
[INFO]   config file = None
[INFO]   configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
[INFO]   ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
[INFO]   ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
[INFO]   executable location = /usr/local/bin/ansible
[INFO]   python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
[INFO]   jinja version = 3.1.2
[INFO]   libyaml = True
[INFO] ansible-lint version:
[INFO] ansible-lint 6.5.0 using ansible 2.12.8
[WARNING] Invalid issue syntax, ignoring: src/main/resources/xxxxxx/meta/main.yml:1: schema (schema[meta])
[WARNING] Invalid issue syntax, ignoring: src/main/resources/xxxxxx/meta/main.yml:1: schema (schema[meta])
[INFO] Sensor Ansible Lint Sensor [ansible] (done) | time=19441ms

My YAML file for test is :

galaxy_info:
  author: ME
  description: my ansible role
  company: ME

  # If the issue tracker for your role is not on github, uncomment the
  # next line and provide a value
  issue_tracker_url: https://xxx.com/devops/roles/xxx/-/issues

  # Some suggested licenses:
  # - BSD (default)
  # - MIT
  # - GPLv2
  # - GPLv3
  # - Apache
  # - CC-BY
  license: BSD

  min_ansible_version: 1.2

  # If this a Container Enabled role, provide the minimum Ansible Container version.
  # min_ansible_container_version:

  # Optionally specify the branch Galaxy will use when accessing the GitHub
  # repo for this role. During role install, if no tags are available,
  # Galaxy will use this branch. During import Galaxy will access files on
  # this branch. If Travis integration is configured, only notifications for this
  # branch will be accepted. Otherwise, in all cases, the repo's default branch
  # (usually master) will be used.
  # github_branch:

  #
  # platforms is a list of platforms, and each platform has a name and a list of versions.
  #
  platforms:
    - name: ArchLinux
      versions:
        - all
  # - name: SomePlatform
  #   versions:
  #   - all
  #   - 1.0
  #   - 7
  #   - 99.99

  galaxy_tags: []
    # List tags for your role here, one per line. A tag is a keyword that describes
    # and categorizes the role. Users find roles by searching for tags. Be sure to
    # remove the '[]' above, if you add tags to this list.
    #
    # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
    #       Maximum 20 tags per role.

dependencies: []
  # List your role dependencies here, one per line. Be sure to remove the '[]' above,
  # if you add dependencies to this list.
mandracke76 commented 2 years ago

For information, I have no error in this technical context:

maven-3.6-jdk-11
...
org/sonarsource/scanner/api/sonar-scanner-api/2.12.0.1661/sonar-scanner-api-2.12.0.1661.jar
org/sonarsource/parent/parent/48/parent-48.pom
org/sonarsource/scanner/maven/sonar-maven-plugin/3.6.0.1398/sonar-maven-plugin-3.6.0.1398.jar
...
[INFO] SonarQube version: 8.9.7
[INFO] Default locale: "en", source code encoding: "UTF-8"
[INFO] Load global settings
...
[INFO] Sensor Ansible Lint Sensor [ansible]
[INFO] ansible version:
[INFO] ansible 2.9.12
[INFO]   config file = None
[INFO]   configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
[INFO]   ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
[INFO]   executable location = /usr/local/bin/ansible
[INFO]   python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]
[INFO] ansible-lint version:
[INFO] ansible-lint 4.2.0
[INFO] Sensor Ansible Lint Sensor [ansible] (done) | time=15137ms
alexist commented 2 years ago

Same issue for me with : ansible-lint 6.8.2, ansible 2.13.5 This was working with : ansible-lint 4.2.0, ansible 2.9.12

alexist commented 2 years ago

I have created PR-56 to handle ansible-lint 6.5 format. I have added in AbstractAnsibleSensor.java a new matcher that handle ansible-lint 6.5.0 format

Matcher new65Splitter = Pattern.compile("^(.*):([0-9]+): ([^ ]+) \\((.*)\\)$").matcher(rawIssue);

I have not yet tested this modification in sonar.

tbielaszewski commented 1 year ago

I recently upgraded to Debian 12 and immediately run into this problem. ansible-lint 6.13.1 using ansible 2.14.3, SonarQube updated to 9.9, sonar-scanner-5.0.1.3006-linux and sonar-ansible-plugin 2.5.1. I tried this PR-56 and it got rid of WARN: Invalid issue syntax, but SonarQube still shows 0 issues and it should show tons of them.

alexist commented 1 year ago

Same for me, we tested the PR too, and it's not working. Still not tested yet, because we have to upgrade our sonar before : ansible-lint can generate sarif reports, sonar can import sarif reports.

tbielaszewski commented 1 year ago

I made a second try. In SonarQube i checked "Quality Profile" for my project and turns out many rules were inactive. After activating more rules (i had 49 active, now 92), "code smells" are back, but i can see 2 problems:

  1. all code smells i get are with tag "ansiblelint-5", there are none with tag ansiblelint-4, 3.5 or 3.4 like there maybe should be. i guess ansiblelint-5 tag took over issues from previous tags - brief glance at src/main/resources/org/sonar/l10n/ansible/rules/ansible suggest they do, but i haven't checked if all are covered
  2. i suppose ansible 6.x adds more rules (i haven't checked) and this plugin looks like it's not updated for 2 years old, so those rules are probably skipped. updating this plugin would probably require more work than just this PR