Skip to content
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

Lint warnings/errors on generated constant module #24

Open
stillesjo opened this issue Oct 13, 2015 · 4 comments
Open

Lint warnings/errors on generated constant module #24

stillesjo opened this issue Oct 13, 2015 · 4 comments

Comments

@stillesjo
Copy link

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
Copy link
Author

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

@zhaocnus
Copy link

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
Copy link

loren138 commented Feb 8, 2016

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
Copy link

zhaocnus commented Feb 8, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants