Fueled / django-init

Project template used at Fueled for scaffolding new Django based projects. :dizzy:
Other
189 stars 46 forks source link

feat(pre-commit): Add pre-commit hooks #345

Closed CuriousLearner closed 5 years ago

CuriousLearner commented 5 years ago

Why was this change necessary?

Add pre-commit-hooks for better code quality

How does it address the problem?

Enforces code quality checks

Are there any side effects?

None.

saurabh-fueled commented 5 years ago

This is what i got after fresh install, i didn't much in the details yet. But i guess this much should be helpful to move forward if anyone wants to take a look or for future references.

is not of type 'array'
/Users/theskumar/work/venv/lib/python3.7/site-packages/pre_commit/clientlib/validate_base.py:46: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  obj = load_strategy(file_contents)
An error has occurred: InvalidConfigError: Invalid content: .pre-commit-config.yaml
{'repos': [{'repo': 'git://github.com/pre-commit/pre-commit-hooks', 'rev': 'v1.4.0', 'hooks': [{'id': 'flake8'}, {'id': 'end-of-file-fixer'}, {'id': 'trailing-whitespace'}, {'id': 'check-case-conflict'}, {'id': 'check-merge-conflict'}, {'id': 'check-yaml'}, {'id': 'detect-private-key'}, {'id': 'forbid-new-submodules'}, {'id': 'check-json'}, {'id': 'pretty-format-json'}, {'id': 'check-added-large-files'}, {'id': 'double-quote-string-fixer'}, {'id': 'fix-encoding-pragma'}]}, {'repo': 'git://github.com/CuriousLearner/pre-commit-python-sorter', 'sha': '5294cde9d51cff119af537e987c30c320e9fbe2f', 'hooks': [{'id': 'python-import-sorter', 'args': ['--silent-overwrite']}]}]} is not of type 'array'

Failed validating 'type' in schema:
    {'items': {'properties': {'hooks': {'items': {'properties': {'additional_dependencies': {'items': {'type': 'string'},
                                                                                             'type': 'array'},
                                                                 'always_run': {'type': 'boolean'},
                                                                 'args': {'items': {'type': 'string'},
                                                                          'type': 'array'},
                                                                 'exclude': {'type': 'string'},
                                                                 'files': {'type': 'string'},
                                                                 'id': {'type': 'string'},
                                                                 'language_version': {'type': 'string'}},
                                                  'required': ['id'],
                                                  'type': 'object'},
                                        'minItems': 1,
                                        'type': 'array'},
                              'repo': {'type': 'string'},
                              'sha': {'type': 'string'}},
               'required': ['repo', 'hooks'],
               'type': 'object'},
     'minItems': 1,
     'type': 'array'}

On instance:
    {'repos': [{'hooks': [{'id': 'flake8'},
                          {'id': 'end-of-file-fixer'},
                          {'id': 'trailing-whitespace'},
                          {'id': 'check-case-conflict'},
                          {'id': 'check-merge-conflict'},
                          {'id': 'check-yaml'},
                          {'id': 'detect-private-key'},
                          {'id': 'forbid-new-submodules'},
                          {'id': 'check-json'},
                          {'id': 'pretty-format-json'},
                          {'id': 'check-added-large-files'},
                          {'id': 'double-quote-string-fixer'},
                          {'id': 'fix-encoding-pragma'}],
                'repo': 'git://github.com/pre-commit/pre-commit-hooks',
                'rev': 'v1.4.0'},
               {'hooks': [{'args': ['--silent-overwrite'],
                           'id': 'python-import-sorter'}],
                'repo': 'git://github.com/CuriousLearner/pre-commit-python-sorter',
                'sha': '5294cde9d51cff119af537e987c30c320e9fbe2f'}]}
Check the log at ~/.pre-commit/pre-commit.log
CuriousLearner commented 5 years ago

Let me check it.

vikalpj commented 5 years ago

lets close https://github.com/Fueled/django-init/pull/166 when this PR is deployed :)

CuriousLearner commented 5 years ago

@saurabh-fueled Updated the branch with master and I'm able to run the pre-commit hooks by generating a new project.

Can you please test it once on your end? If everything is fine, we can merge this!

Thanks!

vikalpj commented 5 years ago

@CuriousLearner The issue is the precommit version. use pre-commit==1.16.1

everything should work fine

vikalpj commented 5 years ago

There are few more updated versions post 1.16.1 but the config file is not compatible to those changes.

CuriousLearner commented 5 years ago

Hey @vikalpj

I can update the version, but I'm able to run the hooks with 1.15.2

Okay, error on my side. I should've tried it on using the version added in this PR. I will update the version.

vikalpj commented 5 years ago

@CuriousLearner the version in the PR is 0.8.2 added in commit https://github.com/Fueled/django-init/blob/e9a94b23fe4ca639c548f9c3657ef191da1d09dd/%7B%7Bcookiecutter.github_repository%7D%7D/requirements/development.txt#L33

CuriousLearner commented 5 years ago

@vikalpj Yeah noticed that from your previous comment. Updated it.