-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 06cce9b
Showing
8 changed files
with
355 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.pyc | ||
.tox | ||
.eggs | ||
*.egg | ||
*.egg-info | ||
build | ||
dist | ||
*.zip | ||
.cache | ||
*.sw* | ||
*.log | ||
docs/build/html/* | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (C) 2017-2018 Ian Stapleton Cordasco <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Flake8-JSON | ||
=========== | ||
|
||
This is a plugin for Flake8 that will format the output as JSON. By default, | ||
the output is **not** pretty-printed. We would love to add that as a separate | ||
formatter option, though. | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
.. code-block:: bash | ||
pip install flake8-json | ||
Usage | ||
----- | ||
|
||
.. code-block:: bash | ||
flake8 --format=json ... | ||
Competitors | ||
----------- | ||
|
||
None that I could find on PyPI | ||
|
||
|
||
Maintenance Policy | ||
------------------ | ||
|
||
This project is seeking maintainers. Please open an issue if you're interested | ||
and ensure that you've read the PyCQA's `Code of Conduct`_. | ||
|
||
|
||
.. _Code of Conduct: | ||
http://meta.pycqa.org/en/latest/code-of-conduct.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[metadata] | ||
name = flake8-json | ||
description = JSON Formatting Reporter plugin for Flake8 | ||
long_description = file:README.rst | ||
author = Ian Stapleton Cordasco | ||
author_email = [email protected] | ||
url = https://gitlab.com/pycqa/flake8-json | ||
license = MIT | ||
license_file = LICENSE | ||
classifiers = | ||
Development Status :: 5 - Production/Stable | ||
Environment :: Console | ||
Framework :: Flake8 | ||
Intended Audience :: Developers | ||
License :: OSI Approved :: MIT License | ||
Programming Language :: Python | ||
Programming Language :: Python :: 2 | ||
Programming Language :: Python :: 2.7 | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.4 | ||
Programming Language :: Python :: 3.5 | ||
Programming Language :: Python :: 3.6 | ||
Topic :: Software Development :: Quality Assurance | ||
|
||
[options] | ||
include-package-data = True | ||
packages = find: | ||
python-requires = >=2.7,!=3.0,!=3.1,!=3.2,!=3.3 | ||
# NOTE(sigmavirus24): Uncomment this after | ||
# https://github.com/pypa/setuptools/issues/1136 is fixed | ||
# package-dir = | ||
# = src/ | ||
|
||
[options.packages.find] | ||
where = src/ | ||
|
||
[options.entry_points] | ||
flake8.report = | ||
json = flake8_json_reporter.reporters:DefaultJSON | ||
|
||
[wheel] | ||
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Packaging logic for Flake8-JSON.""" | ||
import os | ||
import sys | ||
|
||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) # noqa | ||
|
||
import flake8_json_reporter | ||
import setuptools | ||
|
||
setuptools.setup( | ||
version=flake8_json_reporter.__version__, | ||
# NOTE(sigmavirus24): Remove this and uncomment the lines in setup.cfg | ||
# after https://github.com/pypa/setuptools/issues/1136 is fixed | ||
package_dir={ | ||
'': 'src/', | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""flake8_json_reporter module.""" | ||
__version__ = '17.12.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Module containing all of the JSON reporters for Flake8.""" | ||
from __future__ import print_function, unicode_literals | ||
|
||
import json | ||
|
||
from flake8.formatting import base | ||
|
||
|
||
class DefaultJSON(base.BaseFormatter): | ||
"""The non-pretty-printing JSON formatter.""" | ||
|
||
def after_init(self): | ||
"""Force newline to be empty.""" | ||
self.newline = '' | ||
|
||
def _write(self, output): | ||
if self.output_fd is not None: | ||
self.output_fd.write(output + self.newline) | ||
if self.output_fd is None or self.options.tee: | ||
print(output, end=self.newline) | ||
|
||
def write_line(self, line): | ||
"""Override write for convenience.""" | ||
self.write(line, None) | ||
|
||
def start(self): | ||
"""Override the default to start printing JSON.""" | ||
super(DefaultJSON, self).start() | ||
self.write_line('{') | ||
self.files_reported_count = 0 | ||
|
||
def stop(self): | ||
"""Override the default to finish printing JSON.""" | ||
self.write_line('}') | ||
|
||
def beginning(self, filename): | ||
"""We're starting a new file.""" | ||
if self.files_reported_count > 0: | ||
self.write_line(', "{}": ['.format(filename)) | ||
else: | ||
self.write_line('"{}": ['.format(filename)) | ||
self.reported_errors_count = 0 | ||
|
||
def finished(self, filename): | ||
"""We've finished processing a file.""" | ||
self.files_reported_count += 1 | ||
self.write_line(']') | ||
|
||
def dictionary_from(self, violation): | ||
"""Convert a Violation to a dictionary.""" | ||
return { | ||
key: getattr(violation, key) | ||
for key in [ | ||
'code', | ||
'filename', | ||
'line_number', | ||
'column_number', | ||
'text', | ||
'physical_line', | ||
] | ||
} | ||
|
||
def format(self, violation): | ||
"""Format a violation.""" | ||
formatted = json.dumps(self.dictionary_from(violation)) | ||
if self.reported_errors_count > 0: | ||
self.write_line(', {}'.format(formatted)) | ||
else: | ||
self.write_line(formatted) | ||
self.reported_errors_count += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
[tox] | ||
minversion=2.3.1 | ||
envlist = py27,py33,py34,py35,py36,flake8,linters,docs | ||
|
||
[testenv] | ||
deps = | ||
mock>=2.0.0 | ||
pytest!=3.0.5 | ||
coverage | ||
commands = | ||
coverage run --parallel-mode -m pytest {posargs} | ||
coverage combine | ||
coverage report -m | ||
|
||
[testenv:venv] | ||
deps = | ||
. | ||
commands = {posargs} | ||
|
||
# Linters | ||
[testenv:flake8] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
flake8 | ||
flake8-docstrings>=0.2.7 | ||
flake8-import-order>=0.9 | ||
pep8-naming | ||
flake8-colors | ||
commands = | ||
flake8 src/flake8_json_reporter/ setup.py | ||
|
||
[testenv:pylint] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
pyflakes | ||
pylint | ||
commands = | ||
pylint src/flake8_json_reporter/ | ||
|
||
[testenv:doc8] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
sphinx | ||
doc8 | ||
commands = | ||
doc8 docs/source/ | ||
|
||
[testenv:mypy] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
mypy-lang | ||
commands = | ||
mypy flake8 | ||
|
||
[testenv:bandit] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
bandit | ||
commands = | ||
bandit -r src/flake8_json_reporter/ -c .bandit.yml | ||
|
||
[testenv:linters] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
{[testenv:flake8]deps} | ||
{[testenv:pylint]deps} | ||
{[testenv:doc8]deps} | ||
{[testenv:readme]deps} | ||
{[testenv:bandit]deps} | ||
commands = | ||
{[testenv:flake8]commands} | ||
{[testenv:pylint]commands} | ||
{[testenv:doc8]commands} | ||
{[testenv:readme]commands} | ||
{[testenv:bandit]commands} | ||
|
||
# Documentation | ||
[testenv:docs] | ||
basepython = python3 | ||
deps = | ||
-rdocs/source/requirements.txt | ||
commands = | ||
sphinx-build -E -W -c docs/source/ -b html docs/source/ docs/build/html | ||
sphinx-build -E -W -c docs/source/ -b man docs/source/ docs/build/man | ||
|
||
[testenv:serve-docs] | ||
basepython = python3 | ||
skip_install = true | ||
changedir = docs/build/html | ||
deps = | ||
commands = | ||
python -m http.server {posargs} | ||
|
||
[testenv:readme] | ||
basepython = python3 | ||
deps = | ||
readme_renderer | ||
commands = | ||
python setup.py check -r -s | ||
|
||
# Release tooling | ||
[testenv:build] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
wheel | ||
setuptools | ||
commands = | ||
python setup.py -q sdist bdist_wheel | ||
|
||
[testenv:release] | ||
basepython = python3 | ||
skip_install = true | ||
deps = | ||
{[testenv:build]deps} | ||
twine >= 1.5.0 | ||
commands = | ||
{[testenv:build]commands} | ||
twine upload --skip-existing dist/* | ||
|
||
# Flake8 Configuration | ||
[flake8] | ||
# Ignore some flake8-docstrings errors | ||
# NOTE(sigmavirus24): While we're still using flake8 2.x, this ignore line | ||
# defaults to selecting all other errors so we do not need select=E,F,W,I,D | ||
# Once Flake8 3.0 is released and in a good state, we can use both and it will | ||
# work well \o/ | ||
ignore = D203 | ||
exclude = | ||
.tox, | ||
.git, | ||
__pycache__, | ||
docs/source/conf.py, | ||
build, | ||
dist, | ||
tests/fixtures/*, | ||
*.pyc, | ||
*.egg-info, | ||
.cache, | ||
.eggs | ||
max-complexity = 10 | ||
import-order-style = google | ||
application-import-names = flake8 | ||
format = ${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s |