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

Code conventions #151

Open
hayribakici opened this issue Mar 20, 2023 · 2 comments
Open

Code conventions #151

hayribakici opened this issue Mar 20, 2023 · 2 comments

Comments

@hayribakici
Copy link
Collaborator

While browsing through the endpoint files, I stumbled upon methods with no parameters (e.g. playlist.me) that are written with get properties and actual methods with no parameters (e.g. me.savedShows()). It would be nice to iron out the inconsistancy with a set code convention rules (contributing.md) or at least a guide (e.g. an issue or wiki-page) for new developers who want to add more features.

@rinukkusu
Copy link
Owner

Sounds like a great idea!

@hayribakici
Copy link
Collaborator Author

hayribakici commented Apr 26, 2023

Here are my suggestions so far. Please feel free to add/change/remove/... them:

Suggested conventions:

  1. Methods with no parameters should be written as a property, e.g.
Bar get foo => ...;

or if it is an async operation:

Future<Bar> get foo async => ...;
  1. All members of the models should be written in camelCase. If the API returns a value with_underscore, use @Jsonkey(name: 'with_underscore') to map the json entry e.g.
@Jsonkey(name: 'with_underscore')
Bar? withUnderscore;
  1. Append query parameters in a variable:
/// Gets [Foo] given [bar]
Future<Foo> getFoo(Bar bar) async {
  final query = _buildQuery({'bar': bar});
  return await _api._get('$_path?$query');
}
  1. GET request methods should have unit tests. The path for the API (e.g. v1/me/tracks) reflects the json response files in the test/data/ folder.
  2. Methods with only one line should be written with the shorthand => arrow syntax.
  3. Each endpoint method must have a documentation on what it does. It can be copied from the spotify documentation as well.
  4. Use enum instead of String for types returned by the API. See the Album class for examples.
  5. Create an enhanced enum with a String key for the API. See dart's documentation for that and the Me.TimeRange enum as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants