Skip to content

Commit

Permalink
[styleguide] added api and filename sections
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Nov 23, 2015
1 parent 65d68a8 commit 330061d
Showing 1 changed file with 51 additions and 24 deletions.
75 changes: 51 additions & 24 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,41 +773,36 @@ When creating a utility function, attach it as a lodash mixin.

Several already exist, and can be found in `src/kibana/utils/_mixins.js`

## Modules

Kibana uses AMD modules to organize code, and require.js to load those modules.

Even Angular code is loaded this way.

### Module paths
## Filenames

Paths to modules should not be relative (ie. no dot notation). Instead, they should be loaded from one of the defined paths in the require config.
All filenames should use `snake_case` and *can* start with an underscore if the module is not intended to be used outside of it's containing module.

*Right:*

```js
require('some/base/path/my_module');
require('another/path/another_module');
```
- `src/kibana/index_patterns/index_pattern.js`
- `src/kibana/index_patterns/_field.js`

*Wrong:*
- `src/kibana/IndexPatterns/IndexPattern.js`
- `src/kibana/IndexPatterns/Field.js`

```js
require('../my_module');
require('./path/another_module');
```
## Modules

Kibana uses WebPack, which supports many types of module definitions.

### CommonJS Syntax

Module dependencies should be loaded via the CommonJS syntax:
Module dependencies should be written using CommonJS or ES2015 syntax:

*Right:*

```js
define(function (require) {
var _ = require('lodash');
...
});
const _ = require('lodash');
module.exports = ...;
```

```js
import _ from 'lodash';
export default ...;
```

*Wrong:*
Expand All @@ -824,7 +819,7 @@ Kibana is written in Angular, and uses several utility methods to make using Ang

### Defining modules

Angular modules are defined using a custom require module named `module`. It is used as follows:
Angular modules are defined using a custom require module named `ui/modules`. It is used as follows:

```js
var app = require('ui/modules').get('app/namespace');
Expand Down Expand Up @@ -872,7 +867,7 @@ require('ui/routes')

# Html Style Guide

### Multiple attribute values
## Multiple attribute values

When a node has multiple attributes that would cause it to exceed the line character limit, each attribute including the first should be on its own line with a single indent. Also, when a node that is styled in this way has child nodes, there should be a blank line between the openening parent tag and the first child tag.

Expand All @@ -888,6 +883,38 @@ When a node has multiple attributes that would cause it to exceed the line chara
</ul>
```

# Api Style Guide

## Paths

API routes must start with the `/api/` path segment, and should be followed by the plugin id if applicable:

*Right:* `/api/marvel/v1/nodes`
*Wrong:* `/marvel/api/v1/nodes`

## Versions

Kibana won't be supporting multiple API versions, so API's should not define a version.

*Right:* `/api/kibana/index_patterns`
*Wrong:* `/api/kibana/v1/index_patterns`

## snake_case

Kibana uses `snake_case` for the entire API, just like Elasticsearch. All urls, paths, query string parameters, values, and bodies should be `snake_case` formatted.

*Right:*
```
POST /api/kibana/index_patterns
{
"id": "...",
"time_field_name": "...",
"fields": [
...
]
}
```

# Attribution

This JavaScript guide forked from the [node style guide](https://github.com/felixge/node-style-guide) created by [Felix Geisendörfer](http://felixge.de/) and is
Expand Down

0 comments on commit 330061d

Please sign in to comment.