Open HAKASHUN opened 9 years ago
/** ... */
で囲まなければならない/** ... */
で囲まれた部分になる。/**
* ここに名前
* @param {number} [num] 数字。
* @return {string} 文字列。
*/
function hoge(num) { ...
*
があるコメントの仕方に統一し、コードの統一性と可視性を高める@example
使用箇所は、その性質上、*
が先頭にあってはならないので注意/**
* @ngdoc service
* @name $window
*
* @description
* A reference to the browser's `window` object. While `window`
* is globally available in JavaScript, it causes testability problems, because
* it is a global variable. In angular we always refer to it through the
* `$window` service, so it may be overridden, removed or mocked for testing.
*
* Expressions, like the one defined for the `ngClick` directive in the example
* below, are evaluated with respect to the current scope. Therefore, there is
* no risk of inadvertently coding in a dependency on a global value in such an
* expression.
*
* @example
<example module="windowExample">
<file name="index.html">
<script>
angular.module('windowExample', [])
.controller('ExampleController', ['$scope', '$window', function($scope, $window) {
$scope.greeting = 'Hello, World!';
$scope.doGreeting = function(greeting) {
$window.alert(greeting);
};
}]);
</script>
<div ng-controller="ExampleController">
<input type="text" ng-model="greeting" />
<button ng-click="doGreeting(greeting)">ALERT</button>
</div>
</file>
<file name="protractor.js" type="protractor">
it('should display the greeting in the input box', function() {
element(by.model('greeting')).sendKeys('Hello, E2E Tests');
// If we click the button it will block the test runner
// element(':button').click();
});
</file>
</example>
*/
@ngdoc
AngularJSのソースでは以下が使われています。
@ngdoc module
(Ex. ngTouch)@ngdoc provider
(Ex. $routeProvider)@ngdoc service
@ngdoc directive
@ngdoc filter
@ngdoc method
@ngdoc type
@ngdoc property
@ngdoc event
@ngdoc function
@ngdoc object
@ngdoc input
Angular Materialのソースでは以下が使われています。
@ngdoc module
@ngdoc directive
@ngdoc service
@ngdoc object
Angular MaterialではAngular本体と比べて、docを書きすぎないようにしているのか、アノテーションの範囲が少ない感じでした。
@ngdoc module
@ngdoc directive
@ngdoc service
@ngdoc provider
@ngdoc filter
@ngdoc object
上記6つに絞ったルールでよいかもしれません。
@name
@ngdoc module
angular.module('{{モジュール名}}')
の{{モジュール名}}
をそのまま書く/**
* @ngdoc module
* @name material.services.theming
...
angular.module('material.services.theming', []);
@ngdoc directive
Module.directive('{{ディレクティブ名}}')
の{{ディレクティブ名}}
をそのまま書く/**
* @ngdoc directive
* @name mdSubheader
...
Module.directive('mdSubheader', [])
@ngdoc service
Module.factory('{{ファクトリ名}}')
の{{ファクトリ名}}
をそのまま書くModule.service('{{サービス名}}')
の{{サービス名}}
をそのまま書く/**
* @ngdoc service
* @name $mdToast
...
Module.factory('$mdToast', [])
@ngdoc provider
Module.provider('{{プロバイダ名}}')
の{{プロバイダ名}}
をそのまま書く/**
* @ngdoc provider
* @name $controllerProvider
...
Module.provider('$controllerProvider', [])
@ngdoc filter
Module.filter('{{フィルタ名}}')
の{{フィルタ名}}
をそのまま書く/**
* @ngdoc filter
* @name orderBy
...
Module.filter('orderBy', [])
@ngdoc object
Module.constant('{{コンスタント名}}', {})
の{{コンスタント名}}
をそのまま書く/**
* @ngdoc object
* @name $ionicLoadingConfig
...
Module.constant('$ionicLoadingConfig', {
template: '<i class="icon ion-loading-d"></i>'
});
Module.config([])
の{{モジュール名}}.config
をそのまま書く/**
* @ngdoc object
* @name sample.config
...
angular.module('sample').config([function(){}]);
@ngdoc controller
を定義しているが、その他のngdoc的にはそのような定義は存在しない@ngdoc object
を指定してあげる例が多いので採用するModule.controller('{{コントローラ名}}', [])
の{{コントローラ名}}
をそのまま書く/**
* @ngdoc object
* @name mdSidenavController
...
function mdSidenavController($scope, $element...
Module.controller('mdSidenavController', mdSidenavController);
@description
used to provide a description of a component in markdown Writing-AngularJS-Documentation
jsDocでは、html
を用いてdescriptionを書くこともありますが、AngularJSプロジェクトでは、Markdownによって記載することが多いです。
/**
...
* @description
* The `<md-card>` directive is a container element used within `<md-content>` containers.
*
* Cards have constant width and variable heights; where the maximum height is limited to what can
* fit within a single view on a platform, but it can temporarily expand as needed
...
*/
@module
@name
にモジュール名とターゲット名を含めるケースもありますが、モジュール名とターゲット固有の名前は分けて記述する方がわかりやすいと思います。@ngdoc module
を記述している場合は、@name
と同じ内容を記述することになるため、省略します。/**
* @ngdoc module
* @name material.components.sidenav
*
* @description
* A Sidenav QP component.
*/
var Module = angular.module('material.components.sidenav', []);
/*
* @ngdoc object
* @name mdSidenavController
* @module material.components.sidenav
*
* @description
* The controller for mdSidenav components.
*/
...
Module.controller('mdSidenavController', mdSidenavController)
@param
@param {type} name description
AngularJS | Angular Material | ionic |
---|---|---|
string | string | string |
boolean | boolean | boolean |
Function | function | function / Function |
number | number | number |
Object | object | object/Object |
DOMElement /Element | el | HTMLElement |
expression | expression | expression |
Error | 使用箇所なし | 使用箇所なし |
RegExp | 使用箇所なし | 使用箇所なし |
Array | 使用箇所なし | 使用箇所なし |
DOMEvent | ||
int | ||
Promise/promise |
type |
---|
string |
boolean |
Function |
number |
Object |
DOMElement |
expression |
Error |
RegExp |
Array |
Promise |
http://www38.atwiki.jp/aias-jsstyleguide2/pages/17.html#id_6f37ee9a
|
でtypeをつなぐ@param {string|DOMElement}
!
をtypeの先頭に書く@param {!Object}
=
をtypeの後方に書く@param {Object=}
/**
* 4つの引数を取ります。そのうち2つはnullを許容し、2つは省略可能です。
* @param {!Object} nonNull 必須(undefinedは不可)、nullは不可。
* @param {Object} mayBeNull 必須(undefinedは不可)、nullでもよい。
* @param {!Object=} opt_nonNull 省略可 (undefinedでもよい)、しかし値があるなら、
* それはnullであってはならない!
* @param {Object=} opt_mayBeNull 省略可 (undefinedでもよい)、nullでもよい。
*/
function strangeButTrue(nonNull, mayBeNull, opt_nonNull, opt_mayBeNull) {
// ...
};
@returns
@returns {type} description
@param
で決めたものと同じ@returns {*}
@restrict
(@ngdoc directive
時のみ)@restrict E
@ngdoc
@name
@module
@description
@restrict
@param
@returns
@ngdoc
タイプ別のアノテーション@ngdoc |
@name |
@module |
@description |
@restrict |
@param |
@returns |
---|---|---|---|---|---|---|
module | ○ | × | ○ | × | × | × |
directive | ○ | ○ | ○ | ○ | △ | × |
service | ○ | ○ | ○ | × | △ | ○ |
provider | ○ | ○ | ○ | × | × | △ |
filter | ○ | ○ | ○ | × | ○ | ○ |
object | ○ | ○ | ○ | × | × | × |
ポイント
文献