Coder Social home page Coder Social logo

gulp-jscs's Introduction

gulp-jscs Build Status

Check JavaScript code style with JSCS

Issues with the output should be reported on the JSCS issue tracker.

Install

$ npm install --save-dev gulp-jscs

Usage

Reporting

const gulp = require('gulp');
const jscs = require('gulp-jscs');

gulp.task('default', () => {
	return gulp.src('src/app.js')
		.pipe(jscs())
		.pipe(jscs.reporter());
});

Fixing

const gulp = require('gulp');
const jscs = require('gulp-jscs');

gulp.task('default', () => {
	return gulp.src('src/app.js')
		.pipe(jscs({fix: true}))
		.pipe(gulp.dest('src'));
});

Reporting & fixing & failing on lint error

const gulp = require('gulp');
const jscs = require('gulp-jscs');

gulp.task('default', () => {
	return gulp.src('src/app.js')
		.pipe(jscs({fix: true}))
		.pipe(jscs.reporter())
		.pipe(jscs.reporter('fail'))
		.pipe(gulp.dest('src'));
});

Results

A jscs object will be attached to the file object.
An example with one error might look like this:

{
	success: false,  // or true if no errors
	errorCount: 1,   // number of errors in the errors array
	errors: [{       // an array of jscs error objects
		filename: 'index.js',  // basename of the file
		rule: 'requireCamelCaseOrUpperCaseIdentifiers',  // the rule which triggered the error
		message: 'All identifiers must be camelCase or UPPER_CASE',  // error message
		line: 32,  // error line number
		column: 7  // error column
	}]
};

API

JSCS config should be placed in a .jscsrc file.

jscs([options])

options

fix

Type: boolean
Default: false

Make JSCS attempt to auto-fix your files.
Be sure to pipe to gulp.dest if you use this option.

configPath

Type: string
Default: JSCS will search for the config file up to your home directory.

Set the path to the JSCS config file.
Only use this option when it can't be found automatically.

jscs.reporter([reporter])

reporter

Type: string
Default: console

See the JSCS reporter docs for supported input.

Can be used multiple times in the same pipeline.

This plugin also ships with some custom reporters:

  • fail - Emits an error at the end of the stream if there are lint errors.
  • failImmediately - Emits an error immediately if there are lint errors.

License

MIT © Sindre Sorhus

gulp-jscs's People

Contributors

acburdine avatar demurgos avatar jansensan avatar jayeb avatar joemaller avatar kadamwhite avatar koistya avatar kutsenkoa avatar lukaszfiszer avatar mikesherov avatar moox avatar rniemeyer avatar sboudrias avatar sindresorhus avatar slayer95 avatar tcoopman avatar thomasdezeeuw avatar ultcombo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-jscs's Issues

Add filter function

Hello! In my project I have large legacy codebase, so I cannot lint whole files. I want lint only specific ranges of the file and search errors in it.
For example I have file:

function hello () {
  return +'4';
}

function hello2 () {
  return +'5';
}

jscs will fail on following loc: 2 and 6. But I want to ignore error in 6 loc. Is it possible to add filter function here which will take error and vinyl file object and then decide add error or not?

error on run

this is a terminal log:

$ gulp jscs
[gulp] Using gulpfile /Users/vstarkov/projects/box/gulpfile.js
[gulp] Starting 'jscs'...
[gulp] 'jscs' errored after 175 ms Cannot read property 'configPath' of undefined

/Users/vstarkov/projects/box/node_modules/gulp/node_modules/orchestrator/index.js:153
                        throw err;
                              ^
TypeError: Cannot read property 'configPath' of undefined
    at Checker.configure (/Users/vstarkov/projects/box/node_modules/gulp-jscs/node_modules/jscs/lib/checker.js:27:21)
    at module.exports (/Users/vstarkov/projects/box/node_modules/gulp-jscs/index.js:13:10)
    at Gulp.<anonymous> (/Users/vstarkov/projects/box/gulpfile.js:32:15)
    at module.exports (/Users/vstarkov/projects/box/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:31:7)
    at Gulp.Orchestrator._runTask (/Users/vstarkov/projects/box/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/vstarkov/projects/box/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/vstarkov/projects/box/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:77:20
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)

Gulpfile.js:

var gulp = require('gulp'),
    notify = require("gulp-notify"),
    jscs = require('gulp-jscs');

gulp.task('jscs', function() {
    gulp.src('js/main.js')
        .pipe(jscs(/*'.jscsrc'*/))
        .pipe(notify('JS was validated with JSCS!'));
});

gulp.task('lint', [ 'jshint', 'csslint'/*, 'jscs'*/ ]);
gulp.task('test', [ 'lint' ]);

depencies in package.json:

{
  // …
  "devDependencies": {
    "gulp": "~3.5.6",
    "gulp-csscomb": "~0.1.0",
    "gulp-notify": "~1.2.1",
    "gulp-jscs": "~0.4.0",
    "gulp-jshint": "~1.5.0",
    "jshint-stylish": "~0.1.5",
    "gulp-csslint": "~0.1.3"
  }
}

What I'm doing wrong?

Implement different reporters

I'd be very useful to be able to configure and use different reporters. I plan to submit a PR implementing it, but as is quite a important feature, I'd prefer to discuss it before:

  • linting and reporting should be separated: $.jscs() and $.jscs.reporter('my-reporter') (similarly to https://github.com/spenceralger/gulp-jshint)
  • we cannot use node-jscs reporters directly - they all write output to console.log, so they need to be ported and modified
  • checkstyle and xunit reporter should combine all errors in a single single, vinyl file object. They shouldn't emit error event despite linting errors (use case: CI reports)
  • other reporters should fail when linting errors occur
  • support for custom reporters

What are your thoughts?

Allow passing a jscs as an option

It would be nice to be able to pass your own jscs instance as an option, instead of using this module's jscs dep.

Otherwise, if there are updates to jscs you want and you're using gulp-jscs, you have to wait for an update or make PR.

Plugin crashes

I was just trying to use gulp-jscs plugin for the first time, but was unable to get it running. I have a very simple environment with gulp, where everything works fine until I add gulp-jscs to the pipeline.

This is how the crash looks like (from the terminal):

[gulp] Using file /Users/michal/Dropbox/www/withlove-admin/gulpfile.js
[gulp] Working directory changed to /Users/michal/Dropbox/www/withlove-admin
[gulp] Running 'watch'...
[gulp] Finished 'watch' in 10 ms
File /Users/michal/Dropbox/www/withlove-admin/dev/scripts/main.js was changed, running tasks...
gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.
[gulp] Running 'jscodetyle'...
[gulp] Running 'scripts'...
[gulp] Errored 'jscodetyle' in 67 ms Operator + should not stick to preceding expression at test.js :
     4 |a = 0;
     5 |b = 1
     6 |x = a+1;
-------------^
     7 |

Operator + should not stick to following expression at test.js :
     4 |a = 0;
     5 |b = 1
     6 |x = a+1;
-------------^
     7 |

/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp/node_modules/orchestrator/index.js:153
            throw err;
                  ^
[gulp] Error in plugin 'gulp-jscs': Operator + should not stick to preceding expression at test.js :
     4 |a = 0;
     5 |b = 1
     6 |x = a+1;
-------------^
     7 |

Operator + should not stick to following expression at test.js :
     4 |a = 0;
     5 |b = 1
     6 |x = a+1;
-------------^
     7 |
    at Transform._flush (/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp-jscs/index.js:35:23)
    at Transform.<anonymous> (/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:130:12)
    at Transform.g (events.js:175:14)
    at Transform.EventEmitter.emit (events.js:92:17)
    at finishMaybe (/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:12)
    at endWritable (/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:363:3)
    at Transform.Writable.end (/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:341:5)
    at Stream.onend (stream.js:79:10)
    at Stream.EventEmitter.emit (events.js:117:20)
    at end (/Users/michal/Dropbox/www/withlove-admin/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:116:39)

This is how I pipe the plugin:

gulp.task('jscodetyle', function() {
  return gulp.src('dev/scripts/**/*.js')
    .pipe(jscs());
});

Then I just call it from gulp.watch when any .js file changes. This is how the whole gulpfile.js looks like:

var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss = require('gulp-minify-css'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    clean = require('gulp-clean'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    livereload = require('gulp-livereload'),
    lr = require('tiny-lr'),
    jscs = require('gulp-jscs'),
    server = lr();

gulp.task('styles', function() {
    return gulp.src('dev/styles/main.scss')
        .pipe(sass({ style: 'expanded' }))
        .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
        .pipe(gulp.dest('dist/assets/css'))
        .pipe(rename({suffix: '.min'}))
        .pipe(minifycss())
        .pipe(gulp.dest('dist/assets/css'))
        .pipe(livereload(server))
        .pipe(notify({ message: 'Styles task complete' }));
});

gulp.task('scripts', function() {
  return gulp.src('dev/scripts/**/*.js')
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('dist/assets/js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('dist/assets/js'))
    .pipe(livereload(server))
    .pipe(notify({ message: 'Scripts task complete' }));
});

gulp.task('jscodetyle', function() {
  return gulp.src('dev/scripts/**/*.js')
    .pipe(jscs());
});

gulp.task('images', function() {
  return gulp.src('dev/images/**/*')
    .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
    .pipe(gulp.dest('dist/assets/img'))
    .pipe(livereload(server))
    .pipe(notify({ message: 'Images task complete' }));
});

gulp.task('html', function() {
    return gulp.src('dev/*.html')
      .pipe(gulp.dest('dist/'))
      .pipe(livereload(server))
      .pipe(notify({ message: 'HTML task complete' }));
});

gulp.task('clean', function() {
  return gulp.src(['dist/assets/css', 'dist/assets/js', 'dist/assets/img'], {read: false})
    .pipe(clean());
});

gulp.task('default', ['clean'], function() {
    gulp.run('jscodetyle', 'styles', 'scripts', 'images');
});

gulp.task('watch', function() {

  // Watch .html files
  gulp.watch('dev/*.html', function(event) {
    console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    gulp.run('html');
  });

  // Watch .scss files
  gulp.watch('dev/styles/**/*.scss', function(event) {
    console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    gulp.run('styles');
  });

  // Watch .js files
  gulp.watch('dev/scripts/**/*.js', function(event) {
    console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    gulp.run('jscodetyle');
    gulp.run('scripts');
  });

  // Watch image files
  gulp.watch('dev/images/**/*', function(event) {
    console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    gulp.run('images');
  });

});

Append errors to file object through a namespace

As seen at https://github.com/spenceralger/gulp-jshint#results, gulp-jshint puts some of its results on the file object so that errors can be handled later in the gulp process. I am using this feature in conjunction with gulp-notify to create desktop notifications when linting errors are found. I'd like to be able to do the same for code style errors.

Ideally, I'd like something very similar to what jshint uses:

file.jscs.success = true
file.jscs.errors = []
file.jscs.rules = {} // shows the rules which were loaded from the config file or passed in as options

File path length - unable to delete folder on Windows

When working with gulp-jscs on a Windows machine, the setup of gulp results in a file path that is too long for Windows to be able to delete. This makes it difficult to delete any parent folder containing gulp-jscs.

Similar problem seen here and now fixed: gulpjs/gulp#630

Can anything be done to fix this?

example

Unhandled stream error in pipe

I am not sure if this is expected or not, but I get the following when I run gulp-jscs and there are errors in the JS. There is an exception that wraps the jscs error list. This seems to be caused by the PluginError that is thrown. My expectation was that there would not be any exception thrown and instead just the jscs errors logged. Also, I noticed the first jscs error is on the same line as the gutil.log statement.

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
[gulp] Error in plugin 'gulp-jscs': Operator , should stick to preceding expression at module.js :
    21 |    'li.common.four-oh-four',
    22 |    'li.common.to-top'
    23 |    ,'li.common.button'
------------^
    at Transform._flush (/Users/adam.ayres/lia/LDKn/node_modules/gulp-jscs/index.js:35:23)
    at Transform.<anonymous> (/Users/adam.ayres/lia/LDKn/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:130:12)
    at Transform.g (events.js:175:14)
    at Transform.EventEmitter.emit (events.js:92:17)
    at finishMaybe (/Users/adam.ayres/lia/LDKn/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:354:12)
    at endWritable (/Users/adam.ayres/lia/LDKn/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:361:3)
    at Transform.Writable.end (/Users/adam.ayres/lia/LDKn/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:339:5)
    at Stream.onend (stream.js:79:10)
    at Stream.EventEmitter.emit (events.js:117:20)
    at end (/Users/adam.ayres/lia/LDKn/node_modules/gulp/node_modules/map-stream/index.js:108:39)
    at queueData (/Users/adam.ayres/lia/LDKn/node_modules/gulp/node_modules/map-stream/index.js:57:17)
    at next (/Users/adam.ayres/lia/LDKn/node_modules/gulp/node_modules/map-stream/index.js:68:5)
    at /Users/adam.ayres/lia/LDKn/node_modules/gulp/node_modules/map-stream/index.js:77:7
    at /Users/adam.ayres/lia/LDKn/node_modules/gulp/lib/createInputStream/bufferFile.js:7:5
    at fs.js:266:14
    at /Users/adam.ayres/lia/LDKn/node_modules/gulp-karma/node_modules/karma/node_modules/graceful-fs/graceful-fs.js:103:5
    at /Users/adam.ayres/lia/LDKn/node_modules/gulp/node_modules/graceful-fs/graceful-fs.js:103:5
    at Object.oncomplete (fs.js:107:15)

jscs version bump breaks gulp-jscs

This line here throws an error.

TypeError: Object [object Object] has no method '_isExcluded'

Something has changed in the jscs upgrade to 1.8.0. I was able to fix this by pinning the dependency in the package.json to 1.7.3.

Is the ideal solve to pin to this version or to fix index.js accordingly?

jscs as peerDependency?

Just picking this module to ask about peerDependencies. Webpack recommends using peerDependencies so it's easier to use/update (from you app) the library being wrapped by the plugin. Is that frowned up on gulp plugins?

error in the end of report

Expected indentation of 4 characters at main.js :
   251 |
   252 |  return self;
   253 | };
------------^
   254 |
   255 | new App(doc, FileAPI, new Dom()).init();

Expected indentation of 4 characters at main.js :
   253 | };
   254 |
   255 | new App(doc, FileAPI, new Dom()).init();
------------^
   256 |
   257 |})(this, this.document);
    at Transform._flush (/Users/vstarkov/Documents/Яндекс.Диск/projects/FBK/blackbox/node_modules/gulp-jscs/index.js:39:23)
    at Transform.<anonymous> (/Users/vstarkov/Documents/Яндекс.Диск/projects/FBK/blackbox/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
    at Transform.g (events.js:175:14)
    at Transform.EventEmitter.emit (events.js:92:17)
    at finishMaybe (/Users/vstarkov/Documents/Яндекс.Диск/projects/FBK/blackbox/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:372:12)
    at endWritable (/Users/vstarkov/Documents/Яндекс.Диск/projects/FBK/blackbox/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:379:3)
    at Transform.Writable.end (/Users/vstarkov/Documents/Яндекс.Диск/projects/FBK/blackbox/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:357:5)
    at Stream.onend (stream.js:79:10)
    at Stream.EventEmitter.emit (events.js:117:20)
    at end (/Users/vstarkov/Documents/Яндекс.Диск/projects/FBK/blackbox/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:116:39)

TypeError: Object [object Object] has no method '_isExcluded'

Hi there,

I used this plugin every day while I'm building internal modules... I started getting this error today and I was wondering if any of your dependencies started failing today :( Is there anything I can do to prevent that?

Thanks!

$ gulp
[13:41:51] Using gulpfile ~/dev/github-intuit/sp-quality/Gulpfile.js
[13:41:51] Starting 'build'...
[13:41:51] Starting 'clean'...
[13:41:51] Finished 'clean' after 19 ms
[13:41:51] Starting 'check'...

/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/index.js:30
        if (checker._isExcluded(file.path)) {
                    ^
TypeError: Object [object Object] has no method '_isExcluded'
    at DestroyableTransform.through.obj.emit.gutil.PluginError.showStack [as _transform] (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/index.js:30:15)
    at DestroyableTransform.Transform._read (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jscs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at write (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jshint/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jshint/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/home/mdesales/dev/github-intuit/sp-quality/node_modules/gulp-jshint/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at DestroyableTransform.emit (events.js:92:17)

Can't get it to write fixed files back to system

No problems running the plugin to analyze my code using the following task. However when I add fix:true, nothing changes in the files and JSCS now acts like it isn't running at all... when I remove the object passed into the JSCS plugin and remove the gulp.dest() line, it will report code style issues.

So, it seems either passing in the fix:true or tying to write back the fixed files causes JSCS to short circuit internally... ideas?

var $ = require('gulp-load-plugins')({lazy: true});
gulp.task('vet', function () {
  log('Analyzing source with JSHint and JSCS');

  return gulp
    .src(config.allJs, {base: './'})
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish', {verbose: true}))
    .pipe($.jscs({fix:true}))
    .pipe(gulp.dest('./'));
});

esnext option doesn't appear to be working

Using the following syntax:

gulp.task('jscs', function(){
  return gulp.src('src/*.js')
      .pipe(jscs({
        esnext: true
      }))
});

I don't get any output. Running jscs --esnext on the CLI reports properly, and using the option with the gulp-jscs-custom module works though.

jscs errors

Hey,

Thanks for making the quick update from the pr I did.

One thing though is that it still stops any kind of gulp process and throws the exception out, if you don't pass the exception to the callback. (i.e "cb(err)".)

Adding the following seemed to do the trick on my side:
this.push(file);
cb(err);

Failed on bootstrap/js/*.js

Task

gulp.task('scripts', function() {
  gulp.src(path.join(app.bower.dir, 'bootstrap/js/*.js'))
    .pipe(tasks.jscs())
    .pipe(gulp.dest(path.join(app.scripts.dst, 'bootstrap')));
});

Error

[gulp] Using file /home/baka/test/Gulpfile.js
[gulp] Working directory changed to /home/baka/test
[gulp] Running 'scripts'...
[gulp] Finished 'scripts' in 65 ms

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: gulp-jscs:
Operator , should stick to preceding expression at carousel.js :
    41 |  Carousel.DEFAULTS = {
    42 |    interval: 5000
    43 |  , pause: 'hover'
----------^
    44 |  , wrap: true
    45 |  }

Operator , should stick to preceding expression at carousel.js :
    42 |    interval: 5000
    43 |  , pause: 'hover'
    44 |  , wrap: true
----------^
    45 |  }
    46 |

    at /home/baka/test/node_modules/gulp-jscs/index.js:21:14
    at wrappedMapper (/home/baka/test/node_modules/gulp-jscs/node_modules/event-stream/node_modules/map-stream/index.js:76:19)
    at Stream.stream.write (/home/baka/test/node_modules/gulp-jscs/node_modules/event-stream/node_modules/map-stream/index.js:88:21)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:95:17)
    at queueData (/home/baka/test/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:38:21)
    at queueData (/home/baka/test/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:51:14)
    at queueData (/home/baka/test/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:51:14)
    at next (/home/baka/test/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:68:5)
    at /home/baka/test/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:77:7

Environment

baka@gentoo ~/test $ npm list --depth=0
[email protected] /home/baka/test
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
baka@gentoo ~/test $ bower list
bower check-new     Checking for new versions of the project dependencies..
test#0.0.1 /home/baka/test
├─┬ bootstrap#3.0.3
│ └── jquery#2.0.3
├─┬ jquery.cookie#1.4.0
│ └── jquery#2.0.3
└── videojs#4.3.0

Reporter output in Windows

Currently, this plugin emits an error containing the code style errors string and then gulp logs the unhandled error to the console. However, logging errors to the console does not apply the formatting correctly (at least in Windows). Logging the code style errors directly to the console instead of emitting them as an Error object would fix the issue, here's the before and after:

However, this would require either rewriting the unit tests or emitting the message twice (log directly to console, and as part of the PluginError message).

jscs 1.7.3 update?

Any plans to update jscs to 1.7.3?
Would that just be a simple as a package.json change or would that be more involved?

Adding option "fix" also requires you to specify "configPath"

I love the fact that the plugin now supports fix - great job!

However, when I added the fix option gulp-jscs no longer uses my own .jscsrc file.

I would expect the following to still default to using ./.jscsrc.

return gulp.src('app.js')
        .pipe(plugins.jscs({
            fix: true
        }))
        .pipe(gulp.dest('./src'));

But it doesn't. I have to specify

return gulp.src('app.js')
        .pipe(plugins.jscs({
            configPath: '.jscsrc',
            fix: true
        }))
        .pipe(gulp.dest('./src'));

Likewise I expect

return gulp.src('app.js')
        .pipe(plugins.jscs({}))
        .pipe(gulp.dest('./src'));

to equal

return gulp.src('app.js')
        .pipe(plugins.jscs())
        .pipe(gulp.dest('./src'));

gulp-jscs doesn't output anything when used in gulp-watch pipeline

Full disclosure: I'm not sure this is a gulp-jscs problem. This is a crosspost from StackOverflow.

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var watch = require('gulp-watch');

var paths = {
        scripts: ['./js/*.js']
    }    
var jscsRunner = jscs({
        disallowMixedSpacesAndTabs: true // etc
    });    
var jshintRunner = jshint({
        browser: true // etc
    });

// this outputs messages from jshint no problem
gulp.task('jshint', function() {
    return gulp.src(paths.scripts)
    .pipe(jshintRunner)
    .pipe(jshint.reporter('default'));
});

// this outputs messages from jscs no problem
gulp.task('jscs', function() {
    return gulp.src(paths.scripts)
    .pipe(jscsRunner);
});

// this only outputs messages from jshint
gulp.task('watch', function() {
    return watch(paths.scripts)
    .pipe(jscsRunner)
    .pipe(jshintRunner)
    .pipe(jshint.reporter('default'));
});

The problem is that when I run gulp watch I get no output from jscs, but when I run gulp jscs it works.

So it seems to be connected to gulp-watch. Either that or I'm missing something really stupid here, in which case I'd be glad if you could help me out.

TypeError: Cannot delete property 'esnext' of #<Object>

Hi,

With the latest version (1.2.0), I've got this error.
I use gulp-jscs with these settings:

.pipe(jscs({
  preset: 'crockford',
  validateIndentation: 2,
  requireMultipleVarDecl: null,
  disallowDanglingUnderscores: null
}));

Here, the full traceback:

[12:43:38] TypeError: Cannot delete property 'esnext' of #<Object>
    at module.exports (/home/alexis/workspace/mimosa/node_modules/gulp-jscs/index.js:15:10)
    at Gulp.gulp.task.gulp.src.pipe.templateCache.module (/home/alexis/workspace/mimosa/gulpfile.js:328:11)
    at module.exports (/home/alexis/workspace/mimosa/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/home/alexis/workspace/mimosa/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/home/alexis/workspace/mimosa/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/home/alexis/workspace/mimosa/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/lib/node_modules/gulp/bin/gulp.js:121:20
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:902:3

I have no problem with the 1.1.2.

Thanks.

JSHint Directives ignored

For data that comes over an API I can not use camelcase in the names, so I'd like to use something like:

function (data) {
    /* jshint ignore:start */
    return data.verbose_name + ': ' + data.name;
    /* jshint ignore:end */
};

or even better:

function (data) {
    /* jshint camelcase:false */
    return data.verbose_name + ': ' + data.name;
};

http://www.jshint.com/docs/

Don't fail task

I kinda like this option in gulp-jshint https://github.com/spalger/gulp-jshint#fail-reporter So the task doesn't have to fail if not specified. Is it standard for gulp? Do you think it's a good idea to implement it here?

I usually combine gulp-jshint and gulp-jscs in my projects but the settings look completely inconsistent (I expect them to have similar apis).

Update jscs lib

Hi all,
just curious about supporting of new JSCS version which supports more new ES2015/ES6 features, like destructuring.

For example,

function someFn(a, b, {c = 1, d = 2} = {}) {
    // some code
}

Current version of JSCS (1.12) which gulp-jscs depends on, throws a ParseError because Esprima parser doesn't support syntax like this.

Maybe there is some workaround on this?

Thanks so much

Set base jscs to ^1.12.0

I know there's been a few of these requests in the past, but I think 1.12.0 is significant enough to merit bumping the lower bounds of the gulp-jscs package.

Ideally, this would be to eventually support allowing options like auto-fixing through, considering thats a whopper of a feature to be missing through gulp.

Started getting unexpected errors

Hi I started getting unexpected errors after updating to "gulp-jscs": "^1.1.2", from "gulp-jscs": "^0.6.0",

Illegal space before opening round brace at app.js :
    99 |        '<img src="//travis-ci.org/Adaptv/adapt-strap.svg"> | current v{{ version }}</p>',
   100 |      link: function (scope) {
   101 |        $http.get('bower.json').success(function (response) {
------------------------------------------------^
   102 |          scope.version = response.version;
   103 |        });

So I configured my .jscsrc file to allow that space

{
    "preset": "google",

    "requireParenthesesAroundIIFE": true,
    "maximumLineLength": 120,
    "validateLineBreaks": "LF",
    "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",

    "requireSpacesInFunctionExpression": {
        "beforeOpeningRoundBrace": true,
        "beforeOpeningCurlyBrace": true
    }

    "disallowKeywords": ["with"],
    "disallowSpacesInsideObjectBrackets": null,
    "disallowImplicitTypeConversion": ["string"]
}

But the error is still there. please help

Recursive jscs limited to 16 files?

I'm not sure if I'm doing something wrong, but when I feed an array of sources to gulp.src that includes a wildcard that recursively results in more than sixteen files, jscs only checks the first 16 files it encounters. An example src : ./assets/js/**/*.js

Though if I run jscs from the command line with that source, it hits all the files.

Print a stack-trace on error

I am getting the following error message:

[14:52:05] 'jscs' errored after 2.04 s
[14:52:05] Error in plugin 'gulp-jscs'
Message:
    Cannot read property 'value' of undefined

You should propagate any exceptions thrown by jscs or at the very least print their stack-trace.

StringChecker TypeError: _createConfiguration undefined

"gulp-jscs": "^1.6.0"
TypeError: undefined is not a function
    at StringChecker (node_modules\jscs\lib\string-checker.js:26:32)
    at Checker (node_modules\jscs\lib\checker.js:15:19)
    at Gulp.<anonymous> (gulp\jscs.js:17:10)
    at module.exports (node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (node_modules\gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (node_modules\gulp\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (node_modules\gulp\node_modules\orchestrator\index.js:134:8)
    at AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Module.runMain [as _onTimeout] (module.js:503:11)

Running a simple gulp task:

gulp.task('testjscs', function(callback){
    return gulp.src('./src/precompile/js/**/*.js')
        .pipe(jscs());
});

Running grunt version of jscs task works fine.

Allow config file to be found by searching up through parent folders.

When jscs is run from the command line, if a config file is not specified it's default behaviour is to look for a config file in the current directory, then its parent, grandparent, ... until it finds one.

This doesn't seem to be possible through this plugin. Because the plugin assumes that if a path is not given that settings are going to be provided directly with no config file.

Perhaps it could be changed so that if no configPath is given (and no options) that it would call loadConfigFile.load without the configPath, so that it would search up through parents. I don't think doing this would cause problems for existing gulpfiles, because currently in this scenario it would be looking in the current folder for .jscsrc; with this change it would be looking in the current folder before looking in parent folders.

Doing something like this in index.js should do the job.

if (Object.keys(options).length === 0) {
        checker.configure(loadConfigFile.load(configPath));
} else {
        checker.configure(options);
}

Error: Should not stick to preceding expression.

Hello,

I found a bug in gulp-jscs while writing a filter test in angluarjs. I have included the output on the console. Let me know if you need more information or if I can asset in any way.

[gulp] Error in plugin 'gulp-jscs': Operator - should not stick to preceding expression at billingFilters.spec.js :
    36 |        expect(currencySuffix(25145)).to.be.eq('$25.15k');
    37 |        expect(currencySuffix(12315100000)).to.be.eq('$12.32b');
    38 |        expect(currencySuffix(-1359314.12)).to.be.eq('($1.36)m');
--------------------------------------^
    39 |    });

Specify both configPath AND esnext options?

Looks like it is impossible to specify both { esnext: true } and configPath options in a single call. I believe the CLI options should be a separate argument from the code style options, so a new API signature could be:

jscs(configPath | lintOptions, cliOptions)

Example usage:

jscs('.jscsrc', { esnext: true })

Thoughts?

// cc @sindresorhus

Unknown node type JSXElement

Getting this message with gulp-jscs. Possibly related to facebookarchive/esprima@2d47a78 ?

[package.json]
...
"devDependencies": {
    "esprima-fb": "^13001.1001.0-dev-harmony-fb",
    "gulp": "^3.8.11",
    "gulp-jscs": "^1.4.0",
  }
...
[gulpfile.js]
...
gulp.task('jscs', function() {
    return gulp.src([
            './app/**/*.js'
        ])
        .pipe(jscs());
});
...

Force option needed

We really need a force option so that gulp won't exit the task if jscs throws an error (à la grunt-jscs).
The current behavior makes it impossible to use gulp-jscs in our project which contains a lot of legacy code.

How do you feel about that?

Note: This may be related to #21.

SyntaxError: Unable to load JSCS config file

I am using Gulp 3.9.0 and Gulp-jscs 2.0.0. When I try to runt he following Gulp task I get the error below:

gulp.task("lint-js", function () {
    return gulp
        .src(paths.scripts + "**/*.js")
        .pipe(jscs());
});
> cmd.exe /c gulp -b "C:\WebApplication1\WebApplication1" --color --gulpfile "C:\WebApplication1\WebApplication1\Gulpfile.js" lint-js
[18:53:55] Using gulpfile C:\WebApplication1\WebApplication1\Gulpfile.js
[18:53:55] Starting 'lint-js'...
[18:53:55] 'lint-js' errored after 234 ms
[18:53:55] SyntaxError: Unable to load JSCS config file at C:\WebApplication1\WebApplication1\.jscsrc
Unexpected token 
    at Object.parse (native)
    at Object.exports.getContent (C:\WebApplication1\WebApplication1\node_modules\gulp-jscs\node_modules\jscs\lib\cli-config.js:74:28)
    at Object.exports.load (C:\WebApplication1\WebApplication1\node_modules\gulp-jscs\node_modules\jscs\lib\cli-config.js:112:21)
    at module.exports (C:\WebApplication1\WebApplication1\node_modules\gulp-jscs\index.js:37:37)
    at Gulp.gulp.task.sources.css.map.gulp.src.pipe.pipe.pipe.pipe.pipe.pipe.minifyCss.keepSpecialComments (C:\WebApplication1\WebApplication1\Gulpfile.js:232:15)
    at module.exports (C:\WebApplication1\WebApplication1\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\WebApplication1\WebApplication1\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\WebApplication1\WebApplication1\node_modules\gulp\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\WebApplication1\WebApplication1\node_modules\gulp\node_modules\orchestrator\index.js:134:8)
    at C:\WebApplication1\WebApplication1\node_modules\gulp\bin\gulp.js:129:20
    at process._tickCallback (node.js:419:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:906:3
Process terminated with code 1.

Here is a full copy of my .jscsrc file:

{
  "requireCurlyBraces": [
    "if",
    "else",
    "for",
    "while",
    "do",
    "try",
    "catch"
  ],
  "requireSpaceAfterKeywords": [
    "if",
    "else",
    "for",
    "while",
    "do",
    "switch",
    "case",
    "return",
    "try",
    "catch",
    "function",
    "typeof"
  ],
  "requireSpaceBeforeBlockStatements": true,
  "requireParenthesesAroundIIFE": true,
  "requireSpacesInConditionalExpression": true,
  "disallowSpacesInNamedFunctionExpression": {
    "beforeOpeningRoundBrace": true
  },
  "disallowSpacesInFunctionDeclaration": {
    "beforeOpeningRoundBrace": true
  },
  "requireSpaceBetweenArguments": true,
  "requireMultipleVarDecl": "onevar",
  "requireVarDeclFirst": true,
  "requireBlocksOnNewline": true,
  "disallowEmptyBlocks": true,
  "disallowSpacesInsideArrayBrackets": true,
  "disallowSpacesInsideParentheses": true,
  "disallowDanglingUnderscores": true,
  "requireCommaBeforeLineBreak": true,
  "disallowSpaceAfterPrefixUnaryOperators": true,
  "disallowSpaceBeforePostfixUnaryOperators": true,
  "disallowSpaceBeforeBinaryOperators": [
    ","
  ],
  "requireSpacesInForStatement": true,
  "requireSpacesInAnonymousFunctionExpression": {
    "beforeOpeningRoundBrace": true,
    "beforeOpeningCurlyBrace": true
  },
  "requireSpaceBeforeBinaryOperators": true,
  "requireSpaceAfterBinaryOperators": true,
  "disallowKeywords": [
    "with",
    "continue"
  ],
  "validateIndentation": 4,
  "disallowMixedSpacesAndTabs": true,
  "disallowTrailingWhitespace": true,
  "disallowTrailingComma": true,
  "disallowKeywordsOnNewLine": [
    "else"
  ],
  "requireLineFeedAtFileEnd": true,
  "requireCapitalizedConstructors": true,
  "requireDotNotation": true,
  "disallowNewlineBeforeBlockStatements": true,
  "disallowMultipleLineStrings": true,
  "requireSpaceBeforeObjectValues": true
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

I also asked this question on the node-jscs project page here jscs-dev/node-jscs#1786.

semver issue ?

Right now I just got an issue because of a jscs update through gulp-jscs (about deprecated rules)
Maybe you should go to 1.x & follow a bit more the tool versionning ?

TypeError: Object.keys called on non-object

I get this error when I run gulp. What I'm doing wrong? Can you help me to fix it? Thanks!

C:\xampp\htdocs\test>gulp
[10:54:45] Using gulpfile C:\xampp\htdocs\test\gulpfile.js
[10:54:45] Starting 'jscs'...
[10:54:45] 'jscs' errored after 54 ms
[10:54:45] TypeError: Object.keys called on non-object
    at Function.keys (native)
    at NodeConfiguration.Configuration._throwNonCamelCaseErrorIfNeeded (C:\xampp
\htdocs\test\node_modules\gulp-jscs\node_modules\jscs\lib\config\configuration.j
s:461:12)
    at NodeConfiguration.Configuration.load (C:\xampp\htdocs\test\node_modules\g
ulp-jscs\node_modules\jscs\lib\config\configuration.js:52:10)
    at StringChecker.configure (C:\xampp\htdocs\test\node_modules\gulp-jscs\node
_modules\jscs\lib\string-checker.js:66:29)
    at Checker.configure (C:\xampp\htdocs\test\node_modules\gulp-jscs\node_modul
es\jscs\lib\checker.js:26:39)
    at module.exports (C:\xampp\htdocs\test\node_modules\gulp-jscs\index.js:31:1
1)
    at Gulp.<anonymous> (C:\xampp\htdocs\test\gulpfile.js:46:15)
    at module.exports (C:\xampp\htdocs\test\node_modules\gulp\node_modules\orche
strator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\xampp\htdocs\test\node_modules\gulp\node_m
odules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\xampp\htdocs\test\node_modules\gulp\node_m
odules\orchestrator\index.js:214:10)

Gulpfile.js:

'use strict';

// Include gulp
var gulp = require('gulp');

// Include Plugins
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var less = require('gulp-less');
var path = require('path');
var browserSync = require('browser-sync');
var reload      = browserSync.reload;
var jscs = require('gulp-jscs');
var noop = function () {};
var stylish = require('gulp-jscs-stylish');

// Less to Css
gulp.task('less', function () {
    return gulp.src('src/less/styles.less')
        .pipe(less())
        .pipe(gulp.dest('dist/css'));
});

// Lint Task
gulp.task('lint', function() {
    return gulp.src('src/js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

// Concatenate & Minify JS
gulp.task('scripts', function () {
    return gulp.src('src/js/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

// Check JS code style
gulp.task('jscs', function () {
    gulp.src(['src/js/*.js'])
        .pipe(jscs())      // enforce style guide 
        .on('error', noop) // don't stop on error 
        .pipe(stylish());  // log style errors 
});

// Watch Files For Changes
gulp.task('watch', function () {


    // local
    browserSync({
        proxy: "localhost/test/"
    });

    gulp.watch('src/js/*.js', ['jscs', 'lint', 'scripts']);
    gulp.watch('src/less/*.less', ['less']);
    gulp.watch(['src/less/*.less', '*.htm']).on('change', reload);

});

// Default Task
gulp.task('default', ['jscs', 'lint', 'scripts', 'watch']);

depencies in package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "gulp": "^3.8.11",
    "bootstrap": "^3.3.4",
    "jquery": "^2.1.3"
  },
  "devDependencies": {
    "browser-sync": "^2.3.1",
    "gulp": "^3.8.11",
    "gulp-concat": "^2.2.0",
    "gulp-jscs": "^1.4.0",
    "gulp-jscs-stylish": "^1.0.2",
    "gulp-jshint": "^1.9.4",
    "gulp-less": "^3.0.1",
    "gulp-rename": "^1.2.0",
    "uglify": "^0.1.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

no color in output

I'm trying to run jscs using gulp-jscs without color in the error output because despite my terminal accepting the gulp coloring just fine, jscs output is a mess of \[32 style ANSI strings instead of actual color. I know the jscs CLI can be told to use --no-color but for the life of me I can't figure out how to make the gulp-jscs task do the same. There's no mention in the docs anywhere, and no amount of Google or Stackoverflow is getting me any closer to an answer =)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.