Add /package-lock.json to .gitgnore
[UglifyJS.git] / CONTRIBUTING.md
1 Contributing
2 ============
3
4 ## Documentation
5
6 Every new feature and API change should be accompanied by a README additon.
7
8 ## Testing
9
10 All features and bugs should have tests that verify the fix. You can run all
11 tests using `npm test`.
12
13 The most common type of test are tests that verify input and output of the
14 Uglify transforms. These tests exist in `test/compress`. New tests can be added
15 either to an existing file or in a new file `issue-xxx.js`.
16
17 Tests that cannot be expressed as a simple AST can be found in `test/mocha`.
18
19 ## Code style
20
21 - File encoding must be `UTF-8`.
22 - `LF` is always used as a line ending.
23 - Statements end with semicolons.
24 - Indentation uses 4 spaces, switch `case` 2 spaces.
25 - Identifiers use `snake_case`.
26 - Strings use double quotes (`"`).
27 - Use a trailing comma for multiline array and object literals to minimize diffs.
28 - The Uglify code only uses ES5, even in the `harmony` branch.
29 - Line length should be at most 80 cols, except when it is easier to read a
30   longer line.
31 - If both sides of a comparison are of the same type, `==` and `!=` are used.
32 - Multiline conditions place `&&` and `||` first on the line.
33
34 **Example feature**
35
36 ```js
37 OPT(AST_Debugger, function(self, compressor) {
38     if (compressor.option("drop_debugger"))
39         return make_node(AST_EmptyStatement, self);
40     return self;
41 });
42 ```
43
44 **Example test case**
45
46 ```js
47 drop_debugger: {
48     options = {
49         drop_debugger: true,
50     }
51     input: {
52         debugger;
53         if (foo) debugger;
54     }
55     expect: {
56         if (foo);
57     }
58 }
59 ```
60
61