Skip to content

Commit 9205857

Browse files
committed
feature(writejson) add jshint, jscs
1 parent e8b4602 commit 9205857

8 files changed

Lines changed: 69 additions & 20 deletions

File tree

.jscsrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"preset": "crockford",
3+
"requireSpaceAfterKeywords": false,
4+
"requireCapitalizedConstructors": false,
5+
"disallowTrailingWhitespace": "ignoreEmptyLines",
6+
"disallowTrailingComma": false,
7+
"validateIndentation": false,
8+
"requireCurlyBraces": false,
9+
"requireVarDeclFirst": false,
10+
"requireMultipleVarDecl": false,
11+
"requireSpacesInAnonymousFunctionExpression": {
12+
"beforeOpeningCurlyBrace": true
13+
},
14+
"excludeFiles": [
15+
"node_modules/**",
16+
"modules/**",
17+
"bower_components/**"
18+
]
19+
}

.jshintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"esnext": true,
3+
"unused" : true,
4+
"bitwise" : false,
5+
"browser" : true,
6+
"devel" : true,
7+
"eqeqeq" : true,
8+
"jquery" : false,
9+
"newcap" : false,
10+
"noarg" : true,
11+
"node" : true,
12+
"noempty" : true,
13+
"nonew" : true,
14+
"strict" : true,
15+
"undef" : true,
16+
"evil" : true,
17+
"expr" : true,
18+
"quotmark": "single",
19+
"validthis": true
20+
}

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.jscsrc
2+
.jshintrc
3+
.travis.yml
4+
test

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_js:
44
- 4
55

66
script:
7+
- npm run codestyle
78
- npm test
89

910
notifications:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ writejson.sync.try('data.json', {hello: 'world'});
3131
MIT
3232

3333
[NPMIMGURL]: https://img.shields.io/npm/v/writejson.svg?style=flat
34-
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/writejson/master.svg?style=flat
35-
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/writejson.svg?style=flat
34+
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/node-writejson/master.svg?style=flat
35+
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/node-writejson.svg?style=flat
3636
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
3737
[NPMURL]: https://npmjs.org/package/writejson "npm"
38-
[BuildStatusURL]: https://travis-ci.org/coderaiser/writejson "Build Status"
39-
[DependencyStatusURL]: https://gemnasium.com/coderaiser/writejson "Dependency Status"
38+
[BuildStatusURL]: https://travis-ci.org/coderaiser/node-writejson "Build Status"
39+
[DependencyStatusURL]: https://gemnasium.com/coderaiser/node-writejson "Dependency Status"
4040
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
4141

lib/writejson.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fs = require('fs'),
55

66
module.exports = function(name, json, callback) {
77
check(name, json);
8-
checkCB(callback);
8+
checkCB(callback);
99

1010
var str,
1111
error = tryCatch(function() {
@@ -15,7 +15,7 @@ module.exports = function(name, json, callback) {
1515
if (error)
1616
callback(error);
1717
else
18-
fs.writeFile(name, str, callback);
18+
fs.writeFile(name, str, callback);
1919
};
2020

2121
module.exports.sync = sync;
@@ -35,13 +35,12 @@ module.exports.sync.try = function(name, data) {
3535
return error;
3636
};
3737

38-
function check(name, json, callback) {
38+
function check(name, json) {
3939
if (typeof name !== 'string')
4040
throw Error('name should be string!');
4141

4242
if (typeof json !== 'object')
4343
throw Error('json should be object!');
44-
4544
}
4645

4746
function checkCB(callback) {

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
},
1010
"main": "lib/writejson.js",
1111
"scripts": {
12+
"jscs": "jscs --esnext lib test",
13+
"jshint": "jshint lib test",
14+
"codestyle": "npm-run-all jshint jscs",
1215
"test": "tape test/*.js"
1316
},
1417
"repository": {
@@ -24,6 +27,9 @@
2427
"try-catch": "~1.0.0"
2528
},
2629
"devDependencies": {
30+
"jscs": "^2.7.0",
31+
"jshint": "^2.8.0",
32+
"npm-run-all": "^1.4.0",
2733
"tape": "^4.2.2"
2834
}
2935
}

test/writejson.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ let fs = require('fs');
66
let test = require('tape');
77
let writejson = require('..');
88

9-
let tmp = os.tmpdir();
10-
let name = path.join(tmp, String(Math.random()));
11-
let json = {
9+
const tmp = os.tmpdir();
10+
const NAME = path.join(tmp, String(Math.random()));
11+
const json = {
1212
hello: 'world'
1313
};
1414

1515
test('writejson: should write json data to file', t => {
16-
writejson(name, json, error => {
16+
writejson(NAME, json, error => {
1717
t.notOk(error, 'no write error');
1818

19-
fs.readFile(name, 'utf8', (error, data) => {
19+
fs.readFile(NAME, 'utf8', (error, data) => {
2020
t.notOk(error, 'no read error');
2121
t.deepEqual(json, JSON.parse(data), 'data should be equal');
2222

23-
fs.unlink(name, error => {
23+
fs.unlink(NAME, error => {
2424
t.notOk(error, 'no remove error');
2525
t.end();
2626
});
@@ -29,7 +29,7 @@ test('writejson: should write json data to file', t => {
2929
});
3030

3131
test('writejson: no args', t => {
32-
t.throws(writejson, /name should be string!/, 'name check');
32+
t.throws(writejson, /name should be string!/, 'NAME check');
3333
t.end();
3434
});
3535

@@ -48,16 +48,16 @@ test('writejson: no callback', t => {
4848
});
4949

5050
test('writejson.sync: should write json data to file synchonously', t => {
51-
writejson.sync(name, json);
52-
let data = fs.readFileSync(name, 'utf8');
51+
writejson.sync(NAME, json);
52+
let data = fs.readFileSync(NAME, 'utf8');
5353
t.ok(data, 'data should be read');
5454
t.deepEqual(json, JSON.parse(data), 'data should be equal');
55-
fs.unlinkSync(name);
55+
fs.unlinkSync(NAME);
5656
t.end();
5757
});
5858

5959
test('writejson.sync: no args', t => {
60-
t.throws(writejson.sync, /name should be string!/, 'name check');
60+
t.throws(writejson.sync, /name should be string!/, 'NAME check');
6161
t.end();
6262
});
6363

@@ -69,7 +69,7 @@ test('writejson.sync: no json', t => {
6969
});
7070

7171
test('writejson.sync.try: no args', t => {
72-
t.throws(writejson.sync.try, /name should be string!/, 'name check');
72+
t.throws(writejson.sync.try, /name should be string!/, 'NAME check');
7373
t.end();
7474
});
7575

0 commit comments

Comments
 (0)