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 a GitHub "Action" to enforce code style #15

Merged
merged 11 commits into from
Nov 13, 2020

Conversation

SirMoM
Copy link
Contributor

@SirMoM SirMoM commented Nov 4, 2020

As proposed in #12. Let's discuss the results.

logger.gd Outdated
Comment on lines 57 to 62
print(
(
"[ERROR] [logger] Could not create the '%s' directory; exited with error %d."
% [base_dir, err]
)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not an improvement IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. This happens because the line length is capped at 100. I could change the command to:
gdformat --line-length=500 logger.gd
This should solve this kind of formatting!

logger.gd Outdated

func validate_path(path):
"""Validate the path given as argument, making it possible to write to
the designated file or folder. Returns whether the path is valid."""
if !(path.is_abs_path() or path.is_rel_path()):
if ! (path.is_abs_path() or path.is_rel_path()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a weird style change. Maybe replace ! with not and then it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is still the case and an issue was created: Scony/godot-gdscript-toolkit#106
How do we want to approach this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say work it around with not instead of !, which is also more pythonic.

logger.gd Outdated
"path": get_path(),
"queue_mode": get_queue_mode()
}
return {"path": get_path(), "queue_mode": get_queue_mode()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it keep them split if you add a trailing comma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it would be good to do then, it's more readable IMO.

logger.gd Outdated
"module": "{MOD}",
"message": "{MSG}"
}
const FORMAT_IDS = {"level": "{LVL}", "module": "{MOD}", "message": "{MSG}"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to add a trailing comma to keep them on separate lines.

@@ -261,17 +284,17 @@ var invalid_memory_cache = false
var logfiles = {}
var modules = {}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... Autoformatters are dumb :)
I guess we can live with it.

logger.gd Outdated Show resolved Hide resolved
@SirMoM
Copy link
Contributor Author

SirMoM commented Nov 5, 2020

Right now the linter will always fail due to its configuration:

class-definitions-order:
- tools
- classnames
- extends
- signals
- enums
- consts
- exports
- pubvars
- prvvars
- onreadypubvars
- onreadyprvvars
- others
class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
class-name: ([A-Z][a-z0-9]*)+
class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
comparison-with-itself: null
constant-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
disable: []
duplicated-load: null
enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
enum-name: ([A-Z][a-z0-9]*)+
expression-not-assigned: null
function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
function-arguments-number: 10
function-load-variable-name: ([A-Z][a-z0-9]*)+
function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
load-constant-name: (([A-Z][a-z0-9]*)+|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
max-file-lines: 1000
max-line-length: 100
max-public-methods: 20
mixed-tabs-and-spaces: null
private-method-call: null
signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
sub-class-name: _?([A-Z][a-z0-9]*)+
trailing-whitespace: null
unnecessary-pass: null
unused-argument: null

To make the linter somewhat useful I propose to disable: disable: [class-definitions-order, max-file-lines, max-line-length, max-public-methods]

Is this something I should do?
Or how should we use the linter?

logger.gd Outdated Show resolved Hide resolved
logger.gd Outdated
@@ -631,8 +641,7 @@ func load_config(configfile = default_configfile_path):
# Load modules config and initialize them
modules = {}
for module_cfg in config.get_value(PLUGIN_NAME, "modules"):
var module = Module.new(module_cfg["name"], module_cfg["output_level"], \
module_cfg["output_strategies"], get_logfile(module_cfg["logfile_path"]))
var module = Module.new(module_cfg["name"], module_cfg["output_level"], module_cfg["output_strategies"], get_logfile(module_cfg["logfile_path"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it keep things multiline if written this way?

Suggested change
var module = Module.new(module_cfg["name"], module_cfg["output_level"], module_cfg["output_strategies"], get_logfile(module_cfg["logfile_path"]))
var module = Module.new(
module_cfg["name"],
module_cfg["output_level"],
module_cfg["output_strategies"],
get_logfile(module_cfg["logfile_path"])
)

or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this will be formatted to one line.

@akien-mga
Copy link
Member

Sorry for the delay. Yeah disabling what you need for the linter to pass seems good. We can always assess the options that we had to disable in a second step once we have a working formatter and linter merged.

As for the max line length, you can experiment with e.g. 120 or 140 (we use 120 for Python formatting in Godot code for example) to avoid splitting everything needlessly, but still split the occasional very long lines. But if the output is not good, I'm also fine with setting 500 to be virtually unlimited.

@SirMoM
Copy link
Contributor Author

SirMoM commented Nov 13, 2020

As for the max line length, you can experiment with e.g. 120 or 140 (we use 120 for Python formatting in Godot code for example) to avoid splitting everything needlessly, but still split the occasional very long lines

I set it to 150. It looks like that value works (for now).

@SirMoM
Copy link
Contributor Author

SirMoM commented Nov 13, 2020

I think this is as good as it gets, but if you want to have some things improved let me know.
Thanks @akien-mga for the feedback!

@akien-mga akien-mga merged commit 496f816 into KOBUGE-Games:master Nov 13, 2020
@akien-mga
Copy link
Member

Thanks!

@SirMoM SirMoM deleted the github-actions branch November 13, 2020 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants