guzart / gulp-ng-constant

Gulp plugin for dynamic generation of angular constant modules.
MIT License
109 stars 26 forks source link

Lint warnings/errors on generated constant module #24

Open stillesjo opened 9 years ago

stillesjo commented 9 years ago

While dependency injecting a generated constant module, I get the following lint errors/warnings

  line 2  col 3   Missing "use strict" statement.
  line 2  col 37  Strings must use singlequote.

I'm aware that I can create own template files to avoid these lint entries but I think it would be a good idea if this could work directly.

stillesjo commented 9 years ago

Just saw the PR that handles strict mode. How about single-quote though?

zhaocnus commented 8 years ago

This is a workaround I use

gulp.task('config', function () {
  gulp.src('app/config.json')
    .pipe(ngConstant({
      // ngConstant options
    }))

    // add 'use strict;', and change double quotes to single quotes
    // or you can add jshint ignore instead
    .pipe( through2.obj((chunk, enc, callback) => {
      var str = chunk.contents.toString();
      str = str.replace(/"/g, '\'')
        .replace('angular.module', `'use strict';\r\nangular.module`);

      // replace contents
      chunk.contents = new Buffer(str);

      // done
      callback(null, chunk);
    }) )

    // optional: use jsbeautifier to prettify js
    .pipe( plugins.jsbeautifier({
      indentSize: 2,
      preserveNewlines: false
    }) )

    .pipe(gulp.dest('dist'));
});
loren138 commented 8 years ago

A bit shorter code:

gulp.task('config', function () {
  gulp.src('app/config.json')
    .pipe(ngConstant({
      // ngConstant options
    }))

    // add 'use strict;', (commented because I don't need that part)
    // .pipe(replace('angular.module', `'use strict';\r\nangular.module`));
    // change double quotes to single quotes
    // or you can add jshint ignore instead
    .pipe(replace(/"/g, '\''))

    .pipe(gulp.dest('dist'));
});

You will also need var replace = require('gulp-replace'); at the top of your file and "gulp-replace": "~0.5.3", in your package.json.

Also, don't forget to run npm install after editing package.json.

zhaocnus commented 8 years ago

@loren138 : Ah yes...using gulp-replace is better idea!