mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
75a23c0b31
It was getting a bit lost halfway down the contributing/code instructions, in between the detailed git instructions. Also reordered the docs TOC for that folder by renaming the files.
2.3 KiB
2.3 KiB
JavaScript Coding Conventions
Overview
This document provides guidelines for code formatting to developers contributing
to SilverStripe. It applies to all JavaScript files in the framework/
and cms/
modules.
In 2016, SilverStripe started a rewrite of its CMS interface in
ES6 and
ReactJS. Code written prior to this rewrite
might not follow these conventions, and is placed in a legacy/
folder structure.
Browser support
Check our requirements documentation.
Conventions
We follow the AirBnB JavaScript Conventions.
A lot of their rules can be validated via ESLint,
and can be checked locally via npm run lint
.
File and Folder Naming
- All frontend files (CSS, JavaScript, images) should be placed in
a
client/
folder on the top level of the module - Frontend files relating to the
framework
CMS UI should be placed inadmin/client
- File names should follow the AirBnB Naming Conventions
- The
client/src/components
folder should contain only React presentational components. These components should be self-contained, and shouldn't know about Redux state. - The
client/src/containers
folder should contain only React container components - React classes in
client/src/components
andclient/src/containers
should have one folder per component, alongside aREADME.md
and SCSS files where applicable. - The
client/src/state
folder should contain Redux actions, action types and reducers. Each set of these should be kept in a folder named the same as its reducer state key. - JavaScript tests should be named after the module/class they're testing,
with their file name suffixed with
-tests.js
. - JavaScript tests should be placed in a
tests/
subfolder alongside the module code.