Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upTidy config file #12877
Tidy config file #12877
Conversation
highfive
commented
Aug 15, 2016
|
Heads up! This PR modifies the following files:
|
| import toml | ||
|
|
||
| # Load configs from servo-tidy.toml if config file exists | ||
| if os.path.exists("./servo-tidy.toml"): |
This comment has been minimized.
This comment has been minimized.
edunham
Aug 15, 2016
•
Contributor
Please catch the case in which the config file does not exist, as well. Printing "./servo-tidy.toml config file is required but was not found" and exiting would be fine.
A user who naively deletes the config file will get a confusing pile of errors later when the code tries to read from a var like exclude that only exists if the config file exists and was read successfully, so let's save them from that.
This comment has been minimized.
This comment has been minimized.
edunham
Aug 15, 2016
Contributor
Also, why have you split the config-file-reading logic between the top level here and the set_configs function down at L86?
This comment has been minimized.
This comment has been minimized.
UK992
Aug 15, 2016
Author
Contributor
set_config was meant for override default configs. Top-level logic was to set constants for ignored files/dirs, But now its added to config under ignore.
| @@ -104,6 +76,23 @@ | |||
| " accessible to\n// web pages." | |||
| ] | |||
|
|
|||
| # Default configs | |||
| config = { | |||
This comment has been minimized.
This comment has been minimized.
edunham
Aug 15, 2016
•
Contributor
Why do you have a default config dict, but no default for exclude or ignored_dirs? (up on L25, see other line note)
|
Thank you for the PR! The config file looks great to me. However, it looks like you're taking two separate approaches to how the config file should be treated, and I'd personally find the code much easier to read and debug if you standardized on one or the other. The approaches that I'm seeing you take are:
Either approach would be ok -- (1) would probably be easier to implement, requiring fewer lines of code and less reasoning about defaults, whereas (2) would make tidy behave more gracefully (though perhaps in a silently wrong manner, depending on the project) if it was used without a config file or with a malformed config. For tidy's current usage, I think the config file is mandatory. Regardless of whether you implement default values for missing configs, the absence of a config file should cause tidy to exit with a helpful error message. |
|
Now its unified to |
|
Looks great to me! Thanks for making those changes. @wafflespeanut, want to take a quick look too, since highfive picked you for this one? |
|
Of course! This is in my queue. I'll look into it :) |
|
Last commit adds checking for wrong keys or tables in tidy config file. This will prevent adding wrong keys/tables. |
28a59fe
to
6add322
|
|
|
Sorry I let this bitrot. I'll look into this tonight |
| @@ -706,11 +737,16 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f | |||
| continue | |||
| with open(filename, "r") as f: | |||
| contents = f.read() | |||
| lines = contents.splitlines(True) | |||
| if filename.endswith(os.path.join(os.sep, "servo-tidy.toml")): | |||
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Aug 18, 2016
•
Member
This may not be the correct place to check the config file, since that's probably the first thing that we should be doing. Let's move check_config_file to scan, have a separate variable binding config_errors for this thing, and chain with the other iterators in such a way that this is done first.
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| # Load configs from servo-tidy.toml | ||
| if os.path.exists("./servo-tidy.toml"): |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Aug 18, 2016
•
Member
Looks like we're using "servo-tidy.toml" throughout the code - maybe put that as a constant at the top (say, CONFIG_FILE_PATH?)
This comment has been minimized.
This comment has been minimized.
| @@ -694,6 +695,36 @@ def check_spec(file_name, lines): | |||
| brace_count -= 1 | |||
|
|
|||
|
|
|||
| def check_config_file(lines): | |||
| current_table = "" | |||
| for idx, line in enumerate(lines): | |||
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Aug 18, 2016
Member
Since we've planned to prioritize this check, instead of relying on collect_errors_for_files, we should initially check whether the config file exists, get the contents, and begin tidying.
This comment has been minimized.
This comment has been minimized.
|
Can you please squash the commits appropriately? |
|
done. |
|
I still have a few nits, but I don't wanna be nitpicky about those. I'll take care of it later. Thanks for doing this! :) @bors-servo r+ |
|
|
Tidy config file This is wip workaround for #10841 Adds ``servo-tidy.toml`` with configs and ignored dirs, files and packages. This will allow to set custom configuration per repo. It's an example how could config file looks like. I want opinion on that, if this is right approaches and how to improve it. cc @edunham <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12877) <!-- Reviewable:end -->
|
|
highfive
commented
Aug 21, 2016
|
|
@bors-servo retry #11574 |
|
|
|
|
UK992 commentedAug 15, 2016
•
edited by larsbergstrom
This is wip workaround for #10841
Adds
servo-tidy.tomlwith configs and ignored dirs, files and packages.This will allow to set custom configuration per repo.
It's an example how could config file looks like.
I want opinion on that, if this is right approaches and how to improve it.
cc @edunham
This change is