From 3c6bd555b4d0e535e29ca02043fb7c5d4e581fdc Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Fri, 15 Jul 2022 23:52:35 +0200 Subject: [PATCH] doc: add style guide (#746) * doc: add style guide * doc: style guide for python and markdown * doc: consistent use of periods and explicit double quotes in style guide Co-authored-by: Hussein Farran * doc: better define string style in style guide * doc: add format string literals to style guide * doc: add HTML, CSS and JS to style guide Co-authored-by: Hussein Farran --- docs/style.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++ docs/world api.md | 8 ++++---- 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 docs/style.md diff --git a/docs/style.md b/docs/style.md new file mode 100644 index 00000000..a9f55caa --- /dev/null +++ b/docs/style.md @@ -0,0 +1,49 @@ +# Style Guide + +## Generic + +* This guide can be ignored for data files that are not to be viewed in an editor. +* 120 character per line for all source files. +* Avoid white space errors like trailing spaces. + + +## Python Code + +* We mostly follow [PEP8](https://peps.python.org/pep-0008/). Read below to see the differences. +* 120 characters per line. PyCharm does this automatically, other editors can be configured for it. +* Strings in core code will be `"strings"`. In other words: double quote your strings. +* Strings in worlds should use double quotes as well, but imported code may differ. +* Prefer [format string literals](https://peps.python.org/pep-0498/) over string concatenation, + use single quotes inside them: `f"Like {dct['key']}"` +* Use type annotation where possible. + + +## Markdown + +* We almost follow [Google's styleguide](https://google.github.io/styleguide/docguide/style.html). + Read below for differences. +* For existing documents, try to follow its style or ask to completely reformat it. +* 120 characters per line. +* One space between bullet/number and text. +* No lazy numbering. + + +## HTML + +* Indent with 2 spaces for new code. +* kebab-case for ids and classes. + + +## CSS + +* Indent with 2 spaces for new code. +* `{` on the same line as the selector. +* No space between selector and `{`. + + +## JS + +* Indent with 2 spaces. +* Indent `case` inside `switch ` with 2 spaces. +* Use single quotes. +* Semicolons are required after every statement. diff --git a/docs/world api.md b/docs/world api.md index a1138c9e..4fa81f4a 100644 --- a/docs/world api.md +++ b/docs/world api.md @@ -236,7 +236,7 @@ class MyGameLocation(Location): game: str = "My Game" # override constructor to automatically mark event locations as such - def __init__(self, player: int, name = '', code = None, parent = None): + def __init__(self, player: int, name = "", code = None, parent = None): super(MyGameLocation, self).__init__(player, name, code, parent) self.event = code is None ``` @@ -487,14 +487,14 @@ def create_items(self) -> None: for item in map(self.create_item, mygame_items): if item in exclude: exclude.remove(item) # this is destructive. create unique list above - self.world.itempool.append(self.create_item('nothing')) + self.world.itempool.append(self.create_item("nothing")) else: self.world.itempool.append(item) # itempool and number of locations should match up. # If this is not the case we want to fill the itempool with junk. junk = 0 # calculate this based on player settings - self.world.itempool += [self.create_item('nothing') for _ in range(junk)] + self.world.itempool += [self.create_item("nothing") for _ in range(junk)] ``` #### create_regions @@ -628,7 +628,7 @@ class MyGameLogic(LogicMixin): def _mygame_has_key(self, world: MultiWorld, player: int): # Arguments above are free to choose # it may make sense to use World as argument instead of MultiWorld - return self.has('key', player) # or whatever + return self.has("key", player) # or whatever ``` ```python # __init__.py