-
Notifications
You must be signed in to change notification settings - Fork 117
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
Support fix
option
#109
Support fix
option
#109
Conversation
Add `gulpEslint.outputFixes` to write fixed contents by CLIEngine to the files using exaples from `CLIEngine.outputFixes`.
No tests. |
@shinnn |
I appreciate the PR and tests; however, I'm not certain of the approach. Since gulp is basically streaming transformation tool, I believe it would be better to apply the fix to file.contents and use standard gulp.dest to write to disk. I've recently published a release candidate that includes support for the "fix" option (among other things). This pre-release version can be installed using the "rc" tag, like so: npm install gulp-eslint@rc If you could, try it out and see if the following approach works for you: var gulp = require('gulp');
var eslint = require('gulp-eslint');
gulp.task('lint-fix', function () {
return gulp.src('js/**/*.js')
.pipe(eslint({ fix: true }))
.pipe(eslint.format())
.pipe(gulp.dest('./'));
}); Alternatively, here's a version that writes only writes files that eslint fixed, using var gulp = require('gulp');
var eslint = require('gulp-eslint');
var gulpIf = require('gulp-if');
function isFixed(file) {
return file.eslint && typeof file.eslint.output === 'string';
}
gulp.task('lint-fix', function () {
return gulp.src('js/**/*.js')
.pipe(eslint({ fix: true }))
.pipe(eslint.format())
.pipe(gulpIf(isFixed, gulp.dest('./')));
}); By folding the fix to the gulp stream, it leaves the possibility for additional linting, transforms, concatenation, etc. Besides, with eslint able to "fix" source now, it's becoming a transformation tool (like a rule-based browserify-lite). |
Hi, I am using the rc version like this: function isFixed(file) {
return file.eslint && typeof file.eslint.output === 'string';
}
gulp.task("lint", function() {
return gulp.src("js/**/*.js")
.pipe(eslint({
fix: true,
rules: {
"no-multi-spaces": 2,
"indent": [2, 2, {"SwitchCase": 1}]
}
}))
.pipe(eslint.formatEach())
.pipe(eslint.failAfterError())
.pipe(gulpIf(isFixed, gulp.dest("./")));
}); When I run |
And I found the issue - in |
Add
gulpEslint.outputFixes
which write fixed contents to the files.For example: