webex / web-styleguide

Coding style guide for how we develop for the web
https://developer.webex.com
MIT License
8 stars 7 forks source link

Adjusting React component, class, and file naming #11

Open bzang opened 6 years ago

bzang commented 6 years ago

While we mostly use kebab case for file names with no jsx extension. The proposed guidelines by AirBnb are very compelling. What are everyone else's thoughts? Below is the except from: https://github.com/airbnb/javascript/tree/master/react#naming

Naming

adamweeks commented 6 years ago

I like the file name matching the component name. Problem I have is how would we need to restructure the widget repo to match? Right now the folder names are the same as the npm module names, making them easy to find.

bzang commented 6 years ago

I would say the naming on the top level packages don’t need to change. Individual files and folders inside each package would. This would also take some tooling changes if we are to use the jsx extension. I feel like the file extension would encourage us to actually separate the presentation from the app logic a lot more.

ianwremmel commented 6 years ago

I'd say definitely keep the package names kebab case, since that's the defacto standard on npm.

Earlyish in the web client days, we used PascalCase filenames before switching to kebab and it was occasionally problematic. I spent a lot of time explaining the differences between case-sensitive and case-insensitive file systems.

adamweeks commented 6 years ago

So the filename would be: react-component-avatar/src/Avatar.jsx which would be used via import Avatar from '@ciscospark/react-component-avatar'? @bzang

bzang commented 6 years ago

Yup exactly. The Avatar.jsx file would be the actual component. We would still use an index.js file to coordinate the package exports. In cases where the component is super simple where it would wouldn’t make sense to have another file we could just stick with an index.jsx

adamweeks commented 6 years ago

Trying to process how that would work given this directive above:

However, for root components of a directory, use index.jsx as the filename and use the directory name as the component name:

It would just be react-component-avatar/src/index.jsx then?

bzang commented 6 years ago

Adding @aimeex3 and @andrewholsted to the thread.

bzang commented 6 years ago

@adamweeks, yes you're right.

The instructions above get a bit goofy for mono repos. I think we have to consider the root to be /packages/node_modules/@ciscospark/react-component-avatar So anything contained inside would have to follow the rules. So the root component for that package is src/index.jsx.

In cases where the component is more complicated and we have to create sub-components, they'd be in something like src/components/Badge.jsx or src/components/ActivityMenu.jsx.