Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config linting script that checks for bool casing #6203

Merged
merged 12 commits into from Oct 23, 2019

Conversation

@anoadragon453
Copy link
Member

anoadragon453 commented Oct 12, 2019

Add a linting script that enforces all boolean values in the default config be lowercase.

This has annoyed me for a while so I decided to fix it.

Pipelines repo PR: matrix-org/pipelines#12 Not necessary anymore.

@anoadragon453 anoadragon453 requested a review from matrix-org/synapse-core Oct 12, 2019
@anoadragon453 anoadragon453 self-assigned this Oct 12, 2019
@anoadragon453 anoadragon453 added this to In progress in Homeserver Task Board via automation Oct 12, 2019
Copy link
Member

richvdh left a comment

great idea, couple of tweaks though

@@ -0,0 +1,9 @@
#!/bin/bash

This comment has been minimized.

Copy link
@richvdh

richvdh Oct 15, 2019

Member

it might be simpler just to grep for the incorrect formats, rather than try to correct them?

This comment has been minimized.

Copy link
@anoadragon453

anoadragon453 Oct 21, 2019

Author Member

I considered this at first, but I wanted to be able to add this to scripts-dev/lint.sh which could get run in a pre-commit hook for instance.

This comment has been minimized.

Copy link
@richvdh

richvdh Oct 22, 2019

Member

I'm not quite sure that follows... lint.sh doesn't correct for incorrect imports or pep8 failures, it just complains if they are wrong.

There might be value in having a script to correct the problems, but given how often it's likely to be a problem versus the added complexity of this script, I don't think it's worthwhile?

# Exits with 0 if there are no problems, or another code otherwise.

# Fix non-lowercase true/false values
sed -i -E "s/(#.*): +True(.*)/\1: true\2/g; s/(#.*): +False(.*)/\1: false\2/g;" synapse/config/*.py

This comment has been minimized.

Copy link
@richvdh

richvdh Oct 15, 2019

Member
  1. why do we require a #
  2. some of the groups are redundant:
Suggested change
sed -i -E "s/(#.*): +True(.*)/\1: true\2/g; s/(#.*): +False(.*)/\1: false\2/g;" synapse/config/*.py
sed -i -E "s/(#.*): +True/\1: true/g; s/(#.*): +False/\1: false/g;" synapse/config/*.py

This comment has been minimized.

Copy link
@anoadragon453

anoadragon453 Oct 21, 2019

Author Member

The code can contain false positives without the hash, such as docstrings:

use_worker_options (bool): True to use the 'worker_log_config' option

This comment has been minimized.

Copy link
@richvdh

richvdh Oct 22, 2019

Member

ahhh. we should probably run it on the sample config rather than attempt to match only the config bits within synapse/config.

tox.ini Outdated Show resolved Hide resolved
anoadragon453 and others added 4 commits Oct 21, 2019
Co-Authored-By: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
…g/synapse into anoa/lowercase_config_defaults
@anoadragon453 anoadragon453 requested a review from richvdh Oct 21, 2019
Copy link
Member

richvdh left a comment

I think it's worth noting that your script has missed

enabled: False
.

@anoadragon453

This comment has been minimized.

Copy link
Member Author

anoadragon453 commented Oct 22, 2019

I think it's worth noting that your script has missed

enabled: False

.

Yep, had to fix this case manually. I've also switched it so that the script just fixes the sample config instead of your code. I also changed the git diff to only check the sample config, so that it doesn't print out any changes you've made otherwise.

Copy link
Member

richvdh left a comment

lgtm then

@anoadragon453 anoadragon453 merged commit 409c62b into develop Oct 23, 2019
18 checks passed
18 checks passed
buildkite/synapse Build #5047 passed (20 minutes, 37 seconds)
Details
buildkite/synapse/check-sample-config Passed (1 minute, 33 seconds)
Details
buildkite/synapse/check-style Passed (1 minute, 39 seconds)
Details
buildkite/synapse/isort Passed (16 seconds)
Details
buildkite/synapse/mypy Passed (25 seconds)
Details
buildkite/synapse/newspaper-newsfile Passed (41 seconds)
Details
buildkite/synapse/packaging Passed (17 seconds)
Details
buildkite/synapse/pipeline Passed (3 seconds)
Details
buildkite/synapse/python-3-dot-5-slash-postgres-9-dot-5 Passed (17 minutes, 6 seconds)
Details
buildkite/synapse/python-3-dot-5-slash-sqlite Passed (6 minutes, 2 seconds)
Details
buildkite/synapse/python-3-dot-5-slash-sqlite-slash-old-deps Passed (7 minutes, 42 seconds)
Details
buildkite/synapse/python-3-dot-6-slash-sqlite Passed (5 minutes, 36 seconds)
Details
buildkite/synapse/python-3-dot-7-slash-postgres-11 Passed (18 minutes, 28 seconds)
Details
buildkite/synapse/python-3-dot-7-slash-postgres-9-dot-5 Passed (17 minutes, 27 seconds)
Details
buildkite/synapse/python-3-dot-7-slash-sqlite Passed (5 minutes, 51 seconds)
Details
buildkite/synapse/sytest-python-3-dot-5-slash-postgres-9-dot-6-slash-monolith Passed (16 minutes, 57 seconds)
Details
buildkite/synapse/sytest-python-3-dot-5-slash-postgres-9-dot-6-slash-workers Passed (16 minutes, 23 seconds)
Details
buildkite/synapse/sytest-python-3-dot-5-slash-sqlite-slash-monolith Passed (13 minutes, 20 seconds)
Details
Homeserver Task Board automation moved this from In progress to Done Oct 23, 2019
@anoadragon453 anoadragon453 deleted the anoa/lowercase_config_defaults branch Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.