andreoliwa / nitpick

Enforce the same settings on multiple projects
https://nitpick.readthedocs.io/
MIT License
399 stars 25 forks source link

contains_json with `false` doesn't work #504

Open ryo-murai opened 2 years ago

ryo-murai commented 2 years ago

nitpick does not report any violations that json value has to be false.

Current behavior

I have a style file like below.

# style.toml
[".vscode/settings.json".contains_json]
"python.linting.pylintEnabled" = "false"
"python.linting.flake8Enabled" = "true"

nitpick check works at flake8Enabled = true as expected. However, checking pylintEnabled = false always results "No violations found" regardless actual value is true or false.

Expected behavior

nitpick properly reports a violation by checking a falsy json value.

Steps to reproduce

  1. create a style file like above mentioned.
  2. create .vscode/setting.json which contains "{"python.linting.pylintEnabled" = true}.
  3. run nitpick check

Context

Our team members use the MS VSCode as a python development environment. I'm trying to write a style of .vscode/settings.json, to apply the same setting to our projects.

Your environment

$ pipenv shell
  ...
$ which python3
/Users/mrr/dev/python/workspaces/nitpick-json-test/.venv/bin/python3

$ python3 -V
Python 3.9.12

$ pip freeze
appdirs==1.4.4
attrs==22.1.0
autorepr==0.3.0
cattrs==22.1.0
certifi==2022.6.15
charset-normalizer==2.1.1
click==8.1.3
ConfigUpdater==3.1.1
dictdiffer==0.9.0
dpath==2.0.6
exceptiongroup==1.0.0rc9
flake8==5.0.4
flatten-dict==0.4.2
furl==2.1.3
identify==2.5.5
idna==3.3
jmespath==1.0.1
loguru==0.6.0
marshmallow==3.17.1
marshmallow-polyfield==5.10
mccabe==0.7.0
more-itertools==8.14.0
nitpick==0.32.0
orderedmultidict==1.0.1
packaging==21.3
pluggy==1.0.0
pycodestyle==2.9.1
pyflakes==2.5.0
pyparsing==3.0.9
python-slugify==6.1.2
requests==2.28.1
requests-cache==0.9.6
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
six==1.16.0
sortedcontainers==2.4.0
StrEnum==0.4.8
text-unidecode==1.3
toml==0.10.2
tomlkit==0.11.4
url-normalize==1.4.3
urllib3==1.26.12

cat $(which flake8)
#!/Users/mrr/dev/python/workspaces/nitpick-json-test/.venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from flake8.main.cli import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

For more information, see the CONTRIBUTING guide.

andreoliwa commented 2 years ago

Thanks for the report. 🙏🏻

The JSON plugin is a bit old and very limited. It will need a revamp in the not-so-distant future, to be more flexible like the YAML plugin.