mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[styleguide] added api and filename sections
This commit is contained in:
parent
65d68a8734
commit
330061df3a
1 changed files with 51 additions and 24 deletions
|
@ -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
|
||||
## Filenames
|
||||
|
||||
Kibana uses AMD modules to organize code, and require.js to load those modules.
|
||||
|
||||
Even Angular code is loaded this way.
|
||||
|
||||
### Module paths
|
||||
|
||||
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:*
|
||||
|
@ -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');
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue