Skip to content

Commit 49fc582

Browse files
author
Alexej Yaroshevich
committed
initial functionality
Signed-off-by: Alexej Yaroshevich <[email protected]>
0 parents  commit 49fc582

16 files changed

Lines changed: 1118 additions & 0 deletions

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
indent_style = spaces
11+
indent_size = 4
12+
13+
[package.json]
14+
indent_size = 2

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.idea
3+
*.sublime-*
4+
/npm-debug.log

.jscsrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "google"
3+
}

.jshintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
jscs-jsdoc-browser.js

.jshintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"node" : true,
3+
"bitwise" : true,
4+
"undef" : true,
5+
"eqeqeq" : true,
6+
"forin" : true,
7+
"immed" : true,
8+
"noarg" : true,
9+
"unused" : true,
10+
"maxlen" : 120,
11+
"predef" : ["describe", "it", "beforeEach", "afterEach"]
12+
}

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
3+
node_js:
4+
- "0.11"
5+
- "0.10"
6+
- "0.8"
7+
8+
matrix:
9+
allow_failures:
10+
- node_js: "0.11"

CONTRIBUTION.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Contribution Guide
2+
==================
3+
4+
This document describes some points about contribution process for jscs package.
5+
6+
The maintainers of the project are:
7+
* Alexej Yaroshevich (@zxqfox).
8+
9+
The project is being developed within community. Maintainer merges pull-requests, fixes critical bugs.
10+
11+
Pull-requests
12+
-------------
13+
14+
If you fixed or added something useful to the project, you can send pull-request.
15+
It will be reviewed by maintainer and accepted, or commented for rework, or declined.
16+
17+
Bugs
18+
----
19+
20+
If you found an error, typo or any other flaw in the project,
21+
please report about it using [GitHub Issues](https://github.com/zxqfox/jscs-jsdoc/issues).
22+
The more details you provide, the easier it could be reproduced and the faster it could be fixed.
23+
Unfortunately, sometimes the bug can only be reproduced in your project or in your environment,
24+
so maintainers cannot reproduce it. In this case we believe you can fix the bug and send us the fix.
25+
26+
Features
27+
--------
28+
29+
It you've got an idea about a new feature, it's most likely that you'll have to implement it on your own.
30+
If you cannot implement the feature, but it is very important, you can create an issue at GitHub,
31+
but expect it to be declined by the maintainer.

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright 2013 Alexej Yaroshevich and other contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# jsdoc
2+
[![Build Status](https://secure.travis-ci.org/zxqfox/jscs-jsdoc.svg?branch=master)](http://travis-ci.org/zxqfox/jscs-jsdoc)
3+
[![NPM version](https://badge.fury.io/js/jsdoc.png)](http://badge.fury.io/js/jsdoc)
4+
[![Dependency Status](https://david-dm.org/zxqfox/jscs-jsdoc.png)](https://david-dm.org/zxqfox/jscs-jsdoc)
5+
6+
`jscs-jsdoc` plugin for [jscs](https://github.com/mdevils/node-jscs/).
7+
8+
## Friendly packages
9+
10+
* JSCS: https://github.com/mdevils/node-jscs/
11+
12+
## Plugin installation
13+
14+
`jscs-jsdoc` can be installed using `npm`.
15+
Install it globally if you are using globally installed `jscs`
16+
17+
npm -g install jscs-jsdoc
18+
19+
Or install it into your project
20+
21+
npm install jscs-jsdoc --save-dev
22+
23+
## Usage
24+
25+
To use plugin you should add it to configuration file `.jscsrc`:
26+
27+
```json
28+
{
29+
"additionalRules": [
30+
"node_modules/jscs-jsdoc/lib/rules/*.js"
31+
],
32+
"jsDoc": {
33+
}
34+
}
35+
```
36+
37+
## Configuration
38+
39+
### jsDoc
40+
41+
Enables JsDoc validation.
42+
43+
Type: `Object`
44+
45+
Values:
46+
47+
- "checkParamNames" ensures param names in jsdoc and in function declaration are equal
48+
- "requireParamTypes" ensures params in jsdoc contains type
49+
- "checkRedundantParams" reports redundant params in jsdoc
50+
- "checkReturnTypes" tries to compare function result type with declared type in jsdoc
51+
- "requireReturnTypes" ensures returns in jsdoc contains type
52+
- "checkRedundantReturns" reports redundant returns in jsdoc
53+
- "checkTypes" reports invalid types in jsdoc
54+
55+
#### Example
56+
57+
```js
58+
"jsDoc": {
59+
"checkParamNames": true,
60+
"checkRedundantParams": true,
61+
"requireParamTypes": true,
62+
"checkReturnTypes": true,
63+
"checkRedundantReturns": true,
64+
"requireReturnTypes": true,
65+
"checkTypes": true
66+
}
67+
```
68+
69+
##### Valid
70+
71+
```js
72+
/**
73+
* Adds style error to the list
74+
*
75+
* @param {String} message
76+
* @param {Number|Object} line
77+
* @param {Number} [column]
78+
* @returns {String[]}
79+
*/
80+
add: function(message, line, column) {
81+
return ['foo', 'bar'];
82+
}
83+
```
84+
85+
##### Invalid
86+
87+
```js
88+
/**
89+
* Adds style error to the list
90+
*
91+
* @param {String} message
92+
* @param {Number,Object} line
93+
* @param {Number} [column]
94+
* @returns {String}
95+
*/
96+
add: function() {
97+
}
98+
```
99+
100+
## Browser Usage
101+
102+
File [jscs-jsdoc-browser.js](jscs-jsdoc-browser.js) contains browser-compatible version of `jscs-jsdoc`.
103+
104+
Download and include `jscs-jsdoc-browser.js` into your page just after `jscs-browser.js`.
105+
106+
```html
107+
<script src="jscs-browser.js"></script>
108+
<script src="jscs-jsdoc-browser.js"></script>
109+
<script>
110+
var checker = new JscsStringChecker();
111+
checker.registerDefaultRules();
112+
checker.configure({'jsDoc': {/*...*/}});
113+
var errors = checker.checkString('var x, y = 1;');
114+
errors.getErrorList().forEach(function(error) {
115+
console.log(errors.explainError(error));
116+
});
117+
</script>
118+
```

lib/esprima-helpers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
closestScopeNode : closestScopeNode,
3+
treeIterator : require('jscs/lib/tree-iterator')
4+
};
5+
6+
var scopeNodeTypes = [
7+
'Program',
8+
'FunctionDeclaration',
9+
'FunctionExpression'
10+
];
11+
12+
/**
13+
* Search for the closest scope node tree for Node
14+
* @param {{type: String}} n
15+
*/
16+
function closestScopeNode (n) {
17+
while (n && scopeNodeTypes.indexOf(n.type) === -1) {
18+
n = n.parentNode;
19+
}
20+
return n;
21+
}

0 commit comments

Comments
 (0)