sk- / git-lint

improving source code one step at a time
Apache License 2.0
236 stars 78 forks source link

yamllint is not using the arguments fed to it #144

Closed MareoRaft closed 5 years ago

MareoRaft commented 5 years ago

When running git lint, I get output that includes

Linting file: myfile.yaml
line 3, col 81: Error: line too long (136 > 80 characters) (line-length)

even though I have under "yaml" in my .gitlint.yaml:

  arguments:
    - --format
    - parsable
    - --config-data
    - "{{extends: default, rules: {{line-length: disable}}}}"

To confirm that the arguments are in fact being ignored, I have successfully run yamllint -c .yamllint.yaml -f parsable myfile.yaml on my machine, producing an output that ignores line-length. Then by changing my gitlint config to

  arguments:
    - -c
    - .yamllint.yaml
    - -f
    - parsable

and running git lint again, I yet again produce output that shows line-length errors.

sk- commented 5 years ago

I just tried it out and it works. Maybe you put your configuration in the wrong place. Note that is has to be at the root of your repo and be called .gitlint.yaml.

MareoRaft commented 5 years ago

This issue still stands. I have verified that my .gitlint.yaml file is running, namely by commenting out the yamllint key and subcontents entirely. Then git-lint skips linting yaml files entirely. Is there more information I can provide that will give you more insight into the issue?

sk- commented 5 years ago

Please provide the gitlint version you are running, the path of your configuration file as well as the contents of it. (Feel free to redact some parts)

MareoRaft commented 5 years ago

git-lint 0.1.2 yamllint 1.15.0

I used a yaml validator to verify that both of the following files are valid yaml.

Contents of /Users/Matthew/programming/AR/.gitlint.yaml:

# This file originally began as a template written by Sebastion Kreft, and has been modified...    
# Copyright 2013-2014 Sebastian Kreft
#... 
# Javascript
eslint:
  extensions:
  - .js
  command: sh
  arguments:
    - ./client/scripts/eslint.sh
    - ./src
  filter: "(?P<line>{lines}):(?P<column>\\d+)\\s+error\\s+(?P<message>.+)"
  installation: "cd client && npm install --no-package-lock eslint"
# YAML
yaml:
  extensions:
    - .yaml
    - .yml
  command: yamllint
  arguments:
    - -c
    - .yamllint.yaml
    - -f
    - parsable
  # Matches either:
  # - syntax error, on any lineee
  # - other error, on a modified line only
  filter: >-
    ^{filename}:(?P<line>{lines}|\d+(?=:\d+:
    \[error\] syntax error:)):(?P<column>\d+):
    \[(?P<severity>\S+)\] (?P<message>.+)$

  installation: Run pip install yamllint.

Contents of /Users/Matthew/programming/AR/.yamllint.yaml:

# Config file for yamllint.
# Github: https://github.com/adrienverge/yamllint
# default rules: https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration

extends: default

rules:
  document-start: enable
  line-length: disable

Thank you kindly for taking another look.

sk- commented 5 years ago

There are two different issues being reported here.

The one I tested out, is that you are indeed able to pass inline config data to yamllint with --config-data.

The second one you are reporting is when specifying the configuration of a specific yamllint config file. I think the problem there is that you need to specify a full path to the config file as commands are not run relative to any directory.

To test out that theory, you could run git-lint both from /Users/Matthew/programming/AR/ and from a subdirectory.

You could also get the full output of yamllint, from the cache directory. In your case it will be something like /Users/Matthew/.git-lint/cache/yamllint/Users/Matthew/programming/AR/path/to/yaml.yaml

MareoRaft commented 5 years ago

Ahhh, that clears everything up

So in the end the arguments were fine. It was the regex that wasn't. Working snippet:

yaml:
  extensions:
    - .yaml
    - .yml
  command: yamllint
  arguments:
    - -f
    - parsable
    - --config-data
    - "{{extends: default, rules: {{document-start: disable, line-length: disable}}}}"
  filter: >-
    ^{filename}:(?P<line>{lines}|\d+(?=:\d+:
    \[(?:error|warning)\] .*:?)):(?P<column>\d+):
    \[(?P<severity>\S+)\] (?P<message>.+)$
  installation: Run pip install yamllint.

Do you want me to look into it further and open a PR for this? The original source code said the regex matched an other error, on a modified line only, but the regex did not match that AFAIK.