-
Notifications
You must be signed in to change notification settings - Fork 696
Use ESLint and compatible with .jshintrc
#1338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bb701d9
5b0ad5f
afacad7
8a74117
5b821c6
420e582
8956216
d51f877
c6f6d40
aa8356d
66297aa
3048c86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,159 @@ | ||
| const vfs = require("vinyl-fs"); | ||
| const eslint = require("gulp-eslint"); | ||
| const reporter = require("gulp-reporter"); | ||
| vfs.src([ | ||
| "**/*.js", | ||
| "!node_modules/**/*", | ||
| "!dist/**/*", | ||
| "!test/repos/**/*", | ||
| "!.git/**/*" | ||
| ]) | ||
| .pipe(eslint()) | ||
| const { | ||
| Repository, | ||
| Reference, | ||
| Diff, | ||
| Blob, | ||
| Merge, | ||
| } = require("../"); | ||
| const through = require("through2"); | ||
| const Vinyl = require("vinyl"); | ||
| const debug = require("gulp-debug"); | ||
|
|
||
| function getRepository(){ | ||
| return Repository.open(process.env.GIT_DIR || ".git"); | ||
| } | ||
|
|
||
| function cached() { | ||
| return getRepository().then(repository => ( | ||
| Promise.all([ | ||
| Reference.nameToId(repository, "HEAD").then(head => ( | ||
| repository.getCommit(head) | ||
| )).then(commit => ( | ||
| commit.getTree() | ||
| )), | ||
| repository.index(), | ||
| ]).then(([old_tree, index]) => ( | ||
| Diff.treeToIndex(repository, old_tree, index).then(diff => ( | ||
| diff.patches() | ||
| )).then(arrayConvenientPatch => ( | ||
| arrayConvenientPatch.map(convenientPatch => ({ | ||
| repository: repository, | ||
| index: index, | ||
| convenientPatch: convenientPatch, | ||
| indexEntry: index.getByPath(convenientPatch.newFile().path()), | ||
| })) | ||
| )) | ||
| )) | ||
| )); | ||
| } | ||
|
|
||
| function diff() { | ||
| return getRepository().then(repository => ( | ||
| Promise.all([ | ||
| repository.getMasterCommit().catch(()=>( | ||
| repository.getBranchCommit("origin/master") | ||
| )), | ||
| repository.getHeadCommit(), | ||
| repository.index(), | ||
| ]).then(([masterCommit, headCommit, index]) => ( | ||
| Merge.base(repository, masterCommit, headCommit).then(oid => ( | ||
| repository.getCommit(oid) | ||
| )).then(commit => ( | ||
| commit.getTree() | ||
| )).then(old_tree => ( | ||
| Diff.treeToWorkdirWithIndex(repository, old_tree) | ||
| )).then(diff => ( | ||
| diff.patches() | ||
| )).then(arrayConvenientPatch => ( | ||
| arrayConvenientPatch.filter(convenientPatch => ( | ||
| !convenientPatch.isDeleted() | ||
| )).map(convenientPatch => ({ | ||
| repository: repository, | ||
| index: index, | ||
| convenientPatch: convenientPatch, | ||
| indexEntry: index.getByPath(convenientPatch.newFile().path()), | ||
| })) | ||
| )) | ||
| )) | ||
| )); | ||
| } | ||
|
|
||
| function readBlob(matcher) { | ||
| return through.obj(function (file, enc, callback) { | ||
| const { | ||
| repository, | ||
| indexEntry, | ||
| } = file.git; | ||
| Blob.lookup(repository, indexEntry.id).then(function(blob) { | ||
| if(!blob.isBinary() && matcher.test(file.path)) { | ||
| file.git.content = blob.content(); | ||
| file.contents = file.git.content; | ||
| callback(null, file); | ||
| } else { | ||
| callback(); | ||
| } | ||
| }).catch(callback); | ||
| }); | ||
| } | ||
|
|
||
| function updateIndex() { | ||
| let index; | ||
| return through.obj(function (file, enc, callback) { | ||
| if(file.contents.equals(file.git.content)) { | ||
| callback(null, file); | ||
| return; | ||
| } else { | ||
| const { | ||
| repository, | ||
| indexEntry, | ||
| } = file.git; | ||
|
|
||
| index = file.git.index; | ||
|
|
||
| indexEntry.id = Blob.createFromBuffer( | ||
| repository, | ||
| file.contents, | ||
| Buffer.byteLength(file.contents) | ||
| ); | ||
|
|
||
| index.add(indexEntry).then(() => ( | ||
| callback(null, file) | ||
| )).catch(callback); | ||
| } | ||
| }, function (cb) { | ||
| // flush function | ||
| if(index) { | ||
| index.write().then(cb); | ||
| } else { | ||
| cb(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function toStream(fn) { | ||
| var stream = through.obj(); | ||
| fn().then(files => { | ||
| files.forEach(file => { | ||
| stream.push(new Vinyl({ | ||
| base: process.cwd(), | ||
| cwd: __dirname, | ||
| path: file.indexEntry.path, | ||
| git: file, | ||
| })); | ||
| }); | ||
| stream.end(); | ||
| }).catch(ex => { | ||
| stream.emit("error", ex); | ||
| }); | ||
| return stream; | ||
| } | ||
|
|
||
| toStream(process.env.GIT_AUTHOR_DATE ? cached : diff) | ||
| .pipe(readBlob(/(jsx?|es\d*)$/)) | ||
| .pipe(debug({ | ||
| title: "eslint" | ||
| })) | ||
| .pipe(eslint({ | ||
| fix: process.argv.indexOf("--fix") > 0, | ||
| })) | ||
| .pipe(updateIndex()) | ||
| .pipe(reporter({ | ||
| // fail only error write before 2017-7-31 | ||
| // fail only for new error. | ||
| expires: new Date("2017-8-2"), | ||
| author: null, | ||
| })).resume().on("error", (e) => { | ||
| console.error(String(e)) | ||
| process.exitCode = -1 | ||
| console.error(String(e)); | ||
| process.exitCode = -1; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,13 +49,16 @@ | |
| "combyne": "~0.8.1", | ||
| "coveralls": "~2.11.4", | ||
| "eslint": "^4.4.1", | ||
| "gulp-debug": "^3.1.0", | ||
| "gulp-eslint": "^4.0.0", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want this package in NodeGit. |
||
| "gulp-reporter": "^2.2.1", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want this package in NodeGit. |
||
| "husky": "^0.14.3", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this package for? |
||
| "istanbul": "~0.3.20", | ||
| "js-beautify": "~1.5.10", | ||
| "lcov-result-merger": "~1.0.2", | ||
| "mocha": "~2.3.4", | ||
| "vinyl-fs": "^2.4.4", | ||
| "through2": "^2.0.3", | ||
| "vinyl": "^2.1.0", | ||
| "walk": "^2.3.9" | ||
| }, | ||
| "vendorDependencies": { | ||
|
|
@@ -87,7 +90,8 @@ | |
| "rebuildDebug": "node generate && npm run babel && node-gyp configure --debug build", | ||
| "recompile": "node-gyp configure build", | ||
| "recompileDebug": "node-gyp configure --debug build", | ||
| "pretest": "node lifecycleScripts/lint.js", | ||
| "precommit": "npm run pretest -- --fix", | ||
| "pretest": "node lifecycleScripts/lint", | ||
| "test": "node --expose-gc test", | ||
| "xcodeDebug": "node-gyp configure -- -f xcode" | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want this package in NodeGit.