From 5ba27a035cc4445a6f1ba432c7db9163a431343f Mon Sep 17 00:00:00 2001 From: Spencer Phillip Young Date: Mon, 8 Nov 2021 18:04:01 -0800 Subject: [PATCH] add pre-commit --- .coveragerc | 2 +- .pre-commit-config.yaml | 7 +++++++ LICENSE | 2 +- MANIFEST.in | 2 +- README.md | 10 +++++----- docs/QuickStart.rst | 1 - docs/comments.rst | 1 - docs/conf.py | 2 +- docs/docrequirements.txt | 2 +- docs/extending.rst | 1 - docs/how.rst | 2 -- json5/__init__.py | 2 +- json5/dumper.py | 26 +++++++++++++------------- json5/utils.py | 2 -- setup.cfg | 2 +- tests/test_json_helpers.py | 2 +- tests/test_modelizer.py | 2 +- tests/test_regressions.py | 2 +- 18 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.coveragerc b/.coveragerc index b9fe047..bfa0343 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,2 @@ [run] -source = json5 \ No newline at end of file +source = json5 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a8f3bc8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace diff --git a/LICENSE b/LICENSE index f49a4e1..261eeb9 100644 --- a/LICENSE +++ b/LICENSE @@ -198,4 +198,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/MANIFEST.in b/MANIFEST.in index 689e50f..c1a7121 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include LICENSE -include README.md \ No newline at end of file +include README.md diff --git a/README.md b/README.md index 906b0fa..f9b9c6e 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ JSON5 for Python -[![Documentation Status](https://readthedocs.org/projects/json-five/badge/?version=latest)](https://json-five.readthedocs.io/en/latest/?badge=latest) -[![Build Status](https://travis-ci.com/spyoungtech/json-five.svg?branch=master)](https://travis-ci.com/spyoungtech/json-five) -[![version](https://img.shields.io/pypi/v/json-five.svg?colorB=blue)](https://pypi.org/project/json-five/) -[![pyversion](https://img.shields.io/pypi/pyversions/json-five.svg?)](https://pypi.org/project/json-five/) +[![Documentation Status](https://readthedocs.org/projects/json-five/badge/?version=latest)](https://json-five.readthedocs.io/en/latest/?badge=latest) +[![Build Status](https://travis-ci.com/spyoungtech/json-five.svg?branch=master)](https://travis-ci.com/spyoungtech/json-five) +[![version](https://img.shields.io/pypi/v/json-five.svg?colorB=blue)](https://pypi.org/project/json-five/) +[![pyversion](https://img.shields.io/pypi/pyversions/json-five.svg?)](https://pypi.org/project/json-five/) [![Coverage](https://coveralls.io/repos/github/spyoungtech/json-five/badge.svg?branch=master)](https://coveralls.io/github/spyoungtech/json-five?branch=master) ## Installation @@ -44,5 +44,5 @@ See also the [full documentation](https://json-five.readthedocs.io/en/latest/) ## Status -This project is still in early stages of development. Check the [issues](https://github.com/spyoungtech/json-five/issues) +This project is still in early stages of development. Check the [issues](https://github.com/spyoungtech/json-five/issues) page to see known bugs and unimplemented features. diff --git a/docs/QuickStart.rst b/docs/QuickStart.rst index 6d56121..c4d71cb 100644 --- a/docs/QuickStart.rst +++ b/docs/QuickStart.rst @@ -37,4 +37,3 @@ You can also work directly with strings Want to do more? Check out :doc:`/extending` to dive deeper! - diff --git a/docs/comments.rst b/docs/comments.rst index 14fd416..7e0fb29 100644 --- a/docs/comments.rst +++ b/docs/comments.rst @@ -20,4 +20,3 @@ any whitespace or comments that appear before or after the node. This section will be expanded with time, the API for working with comments will likely change alot in future versions. - diff --git a/docs/conf.py b/docs/conf.py index 351350e..07fa37a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -52,4 +52,4 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] \ No newline at end of file +html_static_path = ['_static'] diff --git a/docs/docrequirements.txt b/docs/docrequirements.txt index 1072c83..607db20 100644 --- a/docs/docrequirements.txt +++ b/docs/docrequirements.txt @@ -1,2 +1,2 @@ sphinx==3.0.3 -sphinx_rtd_theme==0.4.3 \ No newline at end of file +sphinx_rtd_theme==0.4.3 diff --git a/docs/extending.rst b/docs/extending.rst index 1bd9868..d073606 100644 --- a/docs/extending.rst +++ b/docs/extending.rst @@ -132,4 +132,3 @@ The resulting model: ], trailing_comma=None, ) - diff --git a/docs/how.rst b/docs/how.rst index dac316c..87432e7 100644 --- a/docs/how.rst +++ b/docs/how.rst @@ -133,5 +133,3 @@ The default dumper dumps python objects directly to JSON text. .. _JSON5 grammar: https://spec.json5.org/#grammar - - diff --git a/json5/__init__.py b/json5/__init__.py index 2799355..5f02c39 100644 --- a/json5/__init__.py +++ b/json5/__init__.py @@ -1,3 +1,3 @@ from .loader import loads, load from .dumper import dumps, dump -from .utils import JSON5DecodeError \ No newline at end of file +from .utils import JSON5DecodeError diff --git a/json5/dumper.py b/json5/dumper.py index 20d464d..3692151 100644 --- a/json5/dumper.py +++ b/json5/dumper.py @@ -47,9 +47,9 @@ def __init__(self, env=None): @singledispatchmethod def dump(self, obj): raise NotImplementedError(f"Cannot dump node {repr(obj)}") - + to_json = dump.register - + @to_json(dict) def dict_to_json(self, d): self.env.write('{', indent=0) @@ -69,15 +69,15 @@ def dict_to_json(self, d): self.env.write('\n', indent=0) else: self.env.write(', ', indent=0) - + if self.env.indent: self.env.indent_level -= 1 self.env.write('\n') self.env.write('}') else: self.env.write('}', indent=0) - - + + @to_json(int) def int_to_json(self, i): self.env.write(str(i), indent=0) @@ -90,7 +90,7 @@ def identifier_to_json(self, s): def str_to_json(self, s): self.env.write(json.dumps(s), indent=0) - + @to_json(list) def list_to_json(self, l): self.env.write('[', indent=0) @@ -112,8 +112,8 @@ def list_to_json(self, l): if self.env.indent: self.env.indent_level -= 1 self.env.write(']') - - + + @to_json(float) def float_to_json(self, f): if f == math.inf: @@ -297,16 +297,16 @@ class Modelizer: @singledispatchmethod def modelize(self, obj): raise NotImplementedError(f"Cannot modelize object of type {type(obj)}") - + to_model = modelize.register - + @to_model(str) def str_to_model(self, s): if repr(s).startswith("'"): return SingleQuotedString(s, raw_value=repr(s)) else: return DoubleQuotedString(s, raw_value=repr(s)) - + @to_model(dict) def dict_to_model(self, d): kvps = [] @@ -314,14 +314,14 @@ def dict_to_model(self, d): kvp = KeyValuePair(key=self.modelize(key), value=self.modelize(value)) kvps.append(kvp) return JSONObject(*kvps) - + @to_model(list) def list_to_model(self, lst): list_values = [] for v in lst: list_values.append(self.modelize(v)) return JSONArray(*list_values) - + @to_model(int) def int_to_model(self, i): return Integer(str(i)) diff --git a/json5/utils.py b/json5/utils.py index f29a524..c4530b2 100644 --- a/json5/utils.py +++ b/json5/utils.py @@ -31,5 +31,3 @@ def __init__(self, msg, token): def __reduce__(self): return self.__class__, (self.msg, self.token) - - diff --git a/setup.cfg b/setup.cfg index 0792c86..8183238 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -license_files = LICENSE \ No newline at end of file +license_files = LICENSE diff --git a/tests/test_json_helpers.py b/tests/test_json_helpers.py index e83055e..165409b 100644 --- a/tests/test_json_helpers.py +++ b/tests/test_json_helpers.py @@ -13,4 +13,4 @@ def test_repr_does_not_contain_wsc(): assert 'wsc' not in repr(model) def test_identifier_does_not_need_explicit_raw_value(): - assert Identifier('foo').raw_value == 'foo' \ No newline at end of file + assert Identifier('foo').raw_value == 'foo' diff --git a/tests/test_modelizer.py b/tests/test_modelizer.py index cc4bda5..17ef270 100644 --- a/tests/test_modelizer.py +++ b/tests/test_modelizer.py @@ -30,4 +30,4 @@ def test_modelize_nan(): def test_modelize_double_quote_string(): s = "'" - assert loads(dumps(modelize(s), dumper=ModelDumper())) == s \ No newline at end of file + assert loads(dumps(modelize(s), dumper=ModelDumper())) == s diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 35cf919..68a0f29 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -16,4 +16,4 @@ def test_no_hang2(): def test_no_hang3(): json_string = '[true, {foo:]false}' with pytest.raises(JSON5DecodeError) as exc_info: - loads(json_string) \ No newline at end of file + loads(json_string)