Skip to content

Commit fdd5999

Browse files
committed
Add code style guide
1 parent 624b06b commit fdd5999

File tree

4 files changed

+303
-1
lines changed

4 files changed

+303
-1
lines changed

CODE_OF_CONDUCT.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING_GUIDE.md

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
---
2+
description: >-
3+
Contributing guide to scikit.js including set up guide, and a brief intro to folder structure
4+
---
5+
6+
# Contributing Guide
7+
8+
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
9+
10+
For contributors familiar with open-source, below is a quick guide to setting up scikit.js locally.
11+
12+
```text
13+
git clone https://github.com/opensource9ja/scikit.js.git
14+
cd scikit.js
15+
git checkout -b <your-branch-name>
16+
17+
yarn test:clean
18+
```
19+
20+
The following folders are available:
21+
* `estimators`: All Machine learning algorithms.
22+
* `model_selection`: Functions related to model selection.
23+
* `preprocessing`: All functions for preprocessing data before, during and after training
24+
25+
The following files are available in the root directory:
26+
* `index`: Entry file which exports all features.
27+
* `utils`: A collection of reusable utility functions.
28+
* `types`: A file for declaring Typescript types.
29+
30+
31+
Some important scripts in the package.json file are:
32+
* `test`: Run all test that satisfy the given pattern. Defaults to `test/**/**/*.test.ts` (All tests will be run)
33+
* `test:clean` : Build the source to `dist` folder before running all test that satisfy the given pattern. This is useful when testing a new feature.
34+
* `build` : Compiles the src to the `dist` folder.
35+
* `build:clean` : Cleans/Remove old folders before compiling the src to the `dist` folder.
36+
37+
38+
## Code Style
39+
### File names
40+
File names must be all lowercase and compound names must be seperated by dots (.). E.g `label.encoder.ts`.
41+
42+
### Source file structure
43+
44+
Files consist of the following, in order:
45+
46+
- License or copyright information, if present
47+
- ES import statements
48+
- The file’s source code
49+
50+
Example:
51+
52+
```javascript
53+
/**
54+
* @license
55+
* Copyright 2021, JsData. All rights reserved.
56+
*
57+
* This source code is licensed under the MIT license found in the
58+
* LICENSE file in the root directory of this source tree.
59+
60+
* Unless required by applicable law or agreed to in writing, software
61+
* distributed under the License is distributed on an "AS IS" BASIS,
62+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63+
* See the License for the specific language governing permissions and
64+
* limitations under the License.
65+
* ==========================================================================
66+
*/
67+
68+
import table from 'table-data'
69+
import me from 'you'
70+
import { cat, dog, eagle } from '../animals'
71+
72+
/**
73+
* Returns the sum of two numbers
74+
* @param number num1
75+
* @param number num2
76+
* @returns number
77+
*/
78+
getSum(num1, num2) {
79+
return num1 + num2
80+
81+
```
82+
83+
### Naming Convention
84+
85+
#### Class names
86+
Class, interface, record, and typedef names are written in UpperCamelCase e.g `ImageProcessor`.
87+
Type names are typically nouns or noun phrases. For example, Request, ImmutableList, or VisibilityMode.
88+
89+
#### Method names
90+
Method names are written in lowerCamelCase e.g `addNum`. Names for private methods must start with a dollar sign e.g `$startAddition`, and should be declared as private.
91+
92+
Method names are typically verbs or verb phrases. For example, `sendMessage` or `$stopProcess`. Getter and setter methods for properties are never required, but if they are used they should be named `getFoo` (or optionally `isFoo` or `hasFoo` for booleans), or `setFoo(value)` for setters.
93+
94+
#### Constant names
95+
Constant names use `CONSTANT_CASE`: all uppercase letters, with words separated by underscores.
96+
97+
### JSDOC Guidelines
98+
99+
Documentation helps clarify what a function or a method is doing. It also gives insight to users of the function or methods on what parameters to pass in and know what the function will return.
100+
101+
Sample documentation:
102+
103+
```javascript
104+
/**
105+
* Add two series of the same length
106+
* @param series1 The first Series. Defaults to []
107+
* @param series2 The second Series. Defaults to []
108+
* @returns Series
109+
* @example
110+
* ```
111+
* import { addSeries } from "scikit.js"
112+
*
113+
* const newSeries = addSeries(Sf1, Sf2)
114+
* newSeries.shape.print()
115+
* // [10, 4]
116+
* ```
117+
*/
118+
const addSeries = (series1, series2) => {
119+
//DO something here
120+
return new Series()
121+
}
122+
123+
```
124+
125+
## **Writing tests**
126+
127+
We strongly encourage contributors to write tests for their code. Like many packages, danfojs uses mocha
128+
129+
All tests should go into the tests subdirectory and place in the corresponding module. The tests folder contains some current examples of tests, and we suggest looking to these for inspiration.
130+
131+
Below is the general Framework to write a test for each module.
132+
133+
```javascript
134+
import { assert } from "chai"
135+
import { addSeries } from '../../dist' //compiled build
136+
137+
describe("Name of the class|module", function(){
138+
139+
it("name of the methods| expected result",function(){
140+
141+
//write your test code here
142+
//use assert.{proprty} to test your code
143+
})
144+
145+
});
146+
```
147+
148+
For a class with lots of methods.
149+
150+
```python
151+
import { assert } from "chai"
152+
import { DataFrame } from '../../src/core/frame'
153+
154+
describe("Name of the class|module", function(){
155+
156+
describe("method name 1", function(){
157+
158+
it("expected result",function(){
159+
160+
//write your test code here
161+
//use assert.{proprty} to test your code
162+
})
163+
})
164+
165+
describe("method name 2", function(){
166+
167+
it("expected result",function(){
168+
169+
//write your test code here
170+
//use assert.{proprty} to test your code
171+
})
172+
})
173+
.......
174+
});
175+
```
176+
177+
178+
179+
### **Running the test case**
180+
181+
To run the test for the module/file you created/edited,
182+
183+
**1\)** Open the package.json
184+
185+
**2\)** change the name of the test file to the file name you want. and don't forget the file is in the test folder
186+
187+
```python
188+
"scripts": {
189+
"test": "....... tests/[sub_directory_name]/filename.test.ts",
190+
```
191+
192+
**3\)** run the test in clean mode
193+
194+
```python
195+
yarn test:clean
196+
```
197+
198+
Learn more about mocha [here](https://mochajs.org/)

src/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2021, JsData. All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ==========================================================================
14+
*/
15+
116
import MinMaxScaler from "./preprocessing/scalers/min.max.scaler"
217
import StandardScaler from "./preprocessing/scalers/standard.scaler"
318

src/utils.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
import { ArrayType1D, ArrayType2D } from "types";
1+
/**
2+
* @license
3+
* Copyright 2021, JsData. All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
27
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ==========================================================================
14+
*/
15+
import { ArrayType1D, ArrayType2D } from "types";
316

417
/**
518
* Generates an array of dim (row x column) with inner values set to zero

0 commit comments

Comments
 (0)