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

Codestyle and formatting rules #34

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

MichalVasut
Copy link
Contributor

@MichalVasut MichalVasut commented Oct 11, 2022

As requested by here by @bcaseyrls I've prepared codestyle document and some formatting rules.

I've also moved .md files to /docs folder (except README.md - this imho needs to be in the root)

I'm not english native speaker (it's my second language) so there probably are some typos and grammar things that needs to be fixed, could you please check it?

There are few things that needs to be tweaked

  • we can discuss the parameters of formatting rules.
  • there is section Conflicting names (@bcaseyrls also opened the issue for that) where I've proposed 2 solutions.
    • the second one (javascript modules) is obvious, but postponed for later (check discussion in the attached issue)
    • the first one (naming convetion) is prefered for now, but it's rather my draft / wip and needs some discussion

Rendered /docs/codestyle.md, for more comfortable reading.

> I noticed that both the FanChart view and the Ahnentafal view had an "Ahnentafel" class. I was concerned about there being more than one window.Ahnentafel. Both views seemed to work, but I was seeing some odd problems during integration into WikiTree.com and thought it wouldn't hurt to change this. I modified the class name in the Ahnentafel view (to be "AhnentafelAncestorList").

#### Solutions
1. Agree on some naming conventintions that would prevent this, e.g. use of prefix
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs discussion and the agreement on how to solve this...

@Clarke-11007
Copy link
Contributor

Clarke-11007 commented Oct 11, 2022 via email

@MichalVasut
Copy link
Contributor Author

Hello Greg,

first of all, this is imho the recommendation rather than enforcement.

If you are using VSCode, there is useful setting, type

F1 or CTRL+SHIFT+P (or Mac alternative) -> >preferences: Open Settings (UI) and check Format on Save

image

The thing with filenames depends on consensus - I'll mark the pull request as DRAFT, because it needs a few things to be solved.

@MichalVasut MichalVasut marked this pull request as draft October 11, 2022 19:44
@Clarke-11007
Copy link
Contributor

Clarke-11007 commented Oct 11, 2022 via email

| Rule | Value | Note |
| --- | :---: | --- |
| Line length | 120 characters | |
| Indentation | 4 spaces | |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my personal preference - I'm python coder and this is golden standard in python. I've thought about 2 spaces (also suggested by Google JS guidelines) and it's more compact, but I'm used to 4 spaces and those 2 doesn't look so clear and it's IMHO harder to orient, but thats what I feel.

I'm against using tabs

  • editors can be set to make spaces on tab key press
  • Github makes ver large spaces for tab
  • it doesn't really matter it you save some characters (1 character for tab vs N characters for every space)

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. Two spaces is not enough, and we should definitely use four. I also agree they should be actual spaces. Editors can just do the replacement so the tab key itself works as expected. But storing tab characters in the file means everything gets out of alignment when viewed later.

The .prettierrc file that's currently in the repo sets tabWidth to two (2) spaces for HTML and CSS files. Is there a reason not to just have those files also use four-space indentation? (It also has an "override" for .js files, but that sets the tabWidth to the default 4; that's probably unnecessary.)

@ke4tch
Copy link
Contributor

ke4tch commented Oct 12, 2022

Oh, I missed the discussion. Yes, I agree that the file name should match the contents. And mine did, I changed them, and plan to change them back since I see this discussion. git will just have to deal with it.

On some long ago project I had to learn to convert from 4 space to 2 space indentation. The only time it becomes an issue is with a deep hierarchy. That is something that might be seen in an html file or a Vue .

Some of the existing code does have tabs in it, on the browser. I noticed it today editing with vim. (Yes, old school but if you can type its faster)

@bcaseyrls
Copy link
Contributor

My personal preference would be to stick with four spaces everywhere. Deep hierarchies can get wide, for sure, but I feel it's unusual for it to be a problem and would prefer the most common state to be more readable. But I'm happy to concede a 2-space indent for HTML, if that's what others prefer. I don't see it being a problem ever for CSS, though, which is currently one of the 2-space exceptions in the .prettierrc config.

Vim is great, and pretty much always available. I still frequently use it myself, though I confess I've grown to like some of the features in VS Code. I do miss being able to pipe sections out to awk or something for big scripted edits. Every IDE has a tradeoff, I suppose.

I'm not inclined to make a big/separate project of reformatting existing code to match the draft/developing code style. My thought would be to just clean that up as other edits are done to particular files/sections, and try to follow the guidelines for new code.

@RobPavey
Copy link

RobPavey commented Oct 12, 2022

My personal vote would be 2 spaces for indentation. It is the default in prettier and what the Google standards suggest. It is also what I use in all my projects.

Personally I would suggest doing a one off reformat of everything. Otherwise, if people are using format on save then every PR for a while is going to be a mixture of reformatting and actual significant changes. Which makes it hard to review.

@MichalVasut
Copy link
Contributor Author

What about this one? There are still ongoing discussions mainly about two things

  • 2 vs 4 spaces indentation
  • file naming style

And every vatiation has its pros & cons (supporters & "haters"). We can let the discussion going further or maybe it would be better to let some authority ( let's say owners of the repo) decide best solition.

@bcaseyrls
Copy link
Contributor

Ok, in the interest of moving forward:

  • 4-space indentations for code files (for readability for my old eyes and/or Python devs)
  • 2-space indentations in HTML/CSS, where structure means less
  • files which are entirely a single class named after the class with PascalCase; meaning in filenames is helpful
  • All other files should be all lower case, with underscores (snake case).

I agree with @RobPavey that a single resave makes sense here to avoid lots of spurious diffs as development proceeds. I've gone through and renamed a few files and resaved them using the .prettierrc config as noted above.

@ke4tch
Copy link
Contributor

ke4tch commented Oct 16, 2022

My old eyes agree with Brian (even though I have not yet contributed).

But there should be consensus between this and the browser extension wikitree/wikitree-browser-extension#11

@harrislineage
Copy link
Member

I agree with @bcaseyrls.

@bcaseyrls bcaseyrls merged commit 542a2b6 into wikitree:main Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants