Skip to content

Commit bf0e1f5

Browse files
gucong3000stephenlacy
authored andcommitted
lint files by git diff (#149)
* lint files by git diff * eslint fix * fix mocha cli error * update eslint rule keyword-spacing * fix test case of `git.commit` * remove bufferstreams
1 parent 94190f2 commit bf0e1f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+660
-286
lines changed

.eslintrc.json

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"extends": [
6+
"eslint:recommended"
7+
],
8+
"root": true,
9+
"rules": {
10+
"block-scoped-var": "error",
11+
"camelcase": "error",
12+
"comma-spacing": [
13+
"error",
14+
{
15+
"after": true,
16+
"before": false
17+
}
18+
],
19+
"eqeqeq": [
20+
"error",
21+
"smart"
22+
],
23+
"indent": [
24+
"error",
25+
2,
26+
{
27+
"SwitchCase": 1
28+
}
29+
],
30+
"keyword-spacing": [
31+
"error",
32+
{
33+
"after": true,
34+
"before": true
35+
}
36+
],
37+
"linebreak-style": "error",
38+
"max-depth": [
39+
"error",
40+
5
41+
],
42+
"max-statements": [
43+
"error",
44+
50
45+
],
46+
"new-cap": 0,
47+
"no-console": [
48+
"off",
49+
{
50+
"allow": [
51+
"warn",
52+
"error",
53+
"info",
54+
"dir",
55+
"time",
56+
"debug"
57+
]
58+
}
59+
],
60+
"no-extend-native": "error",
61+
"no-undef": "error",
62+
"no-unused-expressions": "error",
63+
"no-unused-vars": "off",
64+
"quotes": [
65+
"error",
66+
"single",
67+
{
68+
"avoidEscape": true
69+
}
70+
],
71+
"semi": [
72+
"error",
73+
"always",
74+
{
75+
"omitLastInOneLineBlock": false
76+
}
77+
],
78+
"space-before-blocks": [
79+
"error",
80+
"always"
81+
],
82+
"space-infix-ops": "error",
83+
"spaced-comment": [
84+
"error",
85+
"always"
86+
],
87+
"strict": [
88+
"error",
89+
"safe"
90+
]
91+
}
92+
}

.jshintrc

-20
This file was deleted.

.npmignore

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
lib-cov
2-
*.seed
3-
*.log
41
*.csv
52
*.dat
3+
*.gz
4+
*.log
65
*.out
76
*.pid
8-
*.gz
7+
*.seed
8+
*.sublime*
99
.DS_store
10-
11-
pids
10+
.editorconfig
11+
.eslintrc*
12+
.gitignore
13+
.grunt
14+
.lock-wscript
15+
.node_repl_history
16+
.stylelintrc*
17+
.travis.yml
18+
.vscode
19+
appveyor.yml
20+
coverage
21+
gulpfile.js
22+
lib-cov
1223
logs
13-
results
14-
15-
npm-debug.log
1624
node_modules
17-
*.sublime*
25+
npm-debug.log*
26+
pids
27+
results
28+
test

.travis.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "4.1.1"
5-
- "0.12"
4+
- "stable"
5+
- "6"
6+
- "4"
67
before_install:
7-
- git config --global user.email "you@example.com"
8-
- git config --global user.name "Your Name"
8+
- git config --global user.email "you@example.com"
9+
- git config --global user.name "Your Name"

examples/gulpfile.js

+42-25
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@ var git = require('../');
55

66
// Init a git repo
77

8-
gulp.task('init', function(){
8+
gulp.task('init', function() {
99
git.init();
1010
});
1111

1212

1313
// Add files
1414

15-
gulp.task('add', function(){
15+
gulp.task('add', function() {
1616
gulp.src('./*')
1717
.pipe(git.add());
1818
});
1919

2020

2121
// Commit files
2222

23-
gulp.task('commit', function(){
23+
gulp.task('commit', function() {
2424
gulp.src('./*', {buffer:false})
2525
.pipe(git.commit('initial commit'));
2626
});
2727

2828
// Commit files with arguments
29-
gulp.task('commitopts', function(){
29+
gulp.task('commitopts', function() {
3030
gulp.src('./*')
3131
.pipe(git.commit('initial commit', {args: '-v'}));
3232
});
3333

3434
// Commit files using raw arguments, without message checking
35-
gulp.task('commitraw', function(){
35+
gulp.task('commitraw', function() {
3636
gulp.src('./*')
3737
.pipe(git.commit(undefined, {
3838
args: '-m "initial commit"',
@@ -41,19 +41,19 @@ gulp.task('commitraw', function(){
4141
});
4242

4343
// Commit files using raw arguments, without message checking
44-
gulp.task('commitmulti', function(){
44+
gulp.task('commitmulti', function() {
4545
gulp.src('./*')
4646
.pipe(git.commit(['initial commit', 'additional message']));
4747
});
4848

4949
// Commit files using the multiline option
50-
gulp.task('commitmultiline', function(){
50+
gulp.task('commitmultiline', function() {
5151
gulp.src('./*')
5252
.pipe(git.commit(['initial commit', 'additional message'], { mutiline: true }));
5353
});
5454

5555
// Commit files with multiline messages
56-
gulp.task('commitmultiline', function(){
56+
gulp.task('commitmultiline', function() {
5757
gulp.src('./*')
5858
.pipe(git.commit('initial commit\nadditional message'));
5959
});
@@ -72,88 +72,105 @@ gulp.task('clonesub', function() {
7272
});
7373
});
7474

75+
// Lint js files in index before git commit
76+
gulp.task('precommit', function() {
77+
var eslint = require('gulp-eslint');
78+
// get changes between HEAD and index
79+
return git.diff('--cached', {
80+
args: '-- *.js'
81+
})
82+
// Read file contents from git index
83+
.pipe(git.catFile())
84+
// Lint files that different between HEAD and index
85+
.pipe(eslint())
86+
// Outputs the lint results to the console.
87+
.pipe(eslint.format())
88+
// To have the process exit with an error code (1) on
89+
.pipe(eslint.failAfterError());
90+
});
91+
7592
// Add remote
7693

77-
gulp.task('remote', function(){
94+
gulp.task('remote', function() {
7895
git.addRemote('origin', 'https://github.com/stevelacy/git-test', function (err) {
79-
//if (err) ...
96+
// if (err) ...
8097
});
8198
});
8299

83100

84101
// Push to remote repo
85102

86-
gulp.task('push', function(){
103+
gulp.task('push', function() {
87104
git.push('origin', 'master', function (err) {
88-
//if (err) ...
105+
// if (err) ...
89106
});
90107
});
91108

92109

93110
// Pull from remote repo
94111

95-
gulp.task('pull', function(){
112+
gulp.task('pull', function() {
96113
git.pull('origin', 'master', function (err) {
97114
if (err) console.log(err);
98115
});
99116
});
100117

101118
// Pull from remote repo with only origin
102119

103-
gulp.task('pull-origin', function(){
120+
gulp.task('pull-origin', function() {
104121
git.pull('origin', function (err) {
105122
if (err) console.log(err);
106123
});
107124
});
108125

109126
// Pull from all remote branches and tags
110127

111-
gulp.task('pull-all', function(){
128+
gulp.task('pull-all', function() {
112129
git.pull(function (err) {
113130
if (err) console.log(err);
114131
});
115132
});
116133

117134
// Pull from array of branches
118135

119-
gulp.task('pull-array', function(){
136+
gulp.task('pull-array', function() {
120137
git.pull('origin', ['master', 'development'], function (err) {
121138
if (err) console.log(err);
122139
});
123140
});
124141

125142
// Tag the repo
126143

127-
gulp.task('tag', function(){
144+
gulp.task('tag', function() {
128145
git.tag('v1.1.1', 'Version message', function (err) {
129-
//if (err) ...
146+
// if (err) ...
130147
});
131148
});
132149

133150
// Tag the repo WITH signed key
134-
gulp.task('tagsec', function(){
151+
gulp.task('tagsec', function() {
135152
git.tag('v1.1.1', 'Version message with signed key', {signed:true}, function (err) {
136-
//if (err) ...
153+
// if (err) ...
137154
});
138155
});
139156

140-
gulp.task('push-tag', function(){
157+
gulp.task('push-tag', function() {
141158
git.push('origin', 'v1.1.1', function (err) {
142-
//if (err) ...
159+
// if (err) ...
143160
});
144161
});
145162

146163

147-
gulp.task('rm', function(){
164+
gulp.task('rm', function() {
148165
gulp.src('./delete')
149166
.pipe(git.rm({args: '-f'}));
150167
});
151168

152-
gulp.task('addSubmodule', function(){
169+
gulp.task('addSubmodule', function() {
153170
git.addSubmodule('https://github.com/stevelacy/git-test', 'git-test', {args: '-b master'});
154171
});
155172

156-
gulp.task('updateSubmodules', function(){
173+
gulp.task('updateSubmodules', function() {
157174
git.updateSubmodule({args: '--init'});
158175
});
159176

lib/add.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ module.exports = function (opt) {
2525

2626
var cmd = 'git add ' + escape(paths) + ' ' + opt.args;
2727
var that = this;
28-
var maxBuffer = opt.maxBuffer || 200*1024;
28+
var maxBuffer = opt.maxBuffer || 200 * 1024;
2929

30-
exec(cmd, {cwd: cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr){
30+
exec(cmd, {cwd: cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
3131
if (err) cb(err);
3232
if (!opt.quiet) gutil.log(stdout, stderr);
3333
files.forEach(that.push.bind(that));

lib/addRemote.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ module.exports = function (remote, url, opt, cb) {
1717
if (!opt.cwd) opt.cwd = process.cwd();
1818
if (!opt.args) opt.args = ' ';
1919

20-
var maxBuffer = opt.maxBuffer || 200*1024;
20+
var maxBuffer = opt.maxBuffer || 200 * 1024;
2121

2222
var cmd = 'git remote add ' + opt.args + ' ' + escape([remote, url]);
23-
return exec(cmd, {cwd: opt.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr){
23+
return exec(cmd, {cwd: opt.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
2424
if (err) cb(err);
2525
if (!opt.quiet) gutil.log(stdout, stderr);
2626
cb();

0 commit comments

Comments
 (0)