gulp-ng-config icon indicating copy to clipboard operation
gulp-ng-config copied to clipboard

Values of constans wrapped in double quotes breaks JSHint

Open jayrmotta opened this issue 10 years ago • 17 comments

A part of the strings on this file are written in single quotes and the other part is written in double quotes and it breaks JSHint validation.

Example:

angular.module('foo.config', [])
.constant('foo', "bar");

jayrmotta avatar Jan 14 '15 11:01 jayrmotta

Whoops! thanks

atticoos avatar Jan 14 '15 14:01 atticoos

For now, may be good to ignore the generated file in your jshint task.

atticoos avatar Jan 31 '15 23:01 atticoos

@ajwhite that's fine!

Here is my workaround until we fix it:

gulp.task('config', function() {
  var env = argv.env ? argv.env : 'development';

  gulp.src('conf/' + env + '.json')
  .pipe(gulpNgConfig('cockpitUi.config', {
    wrap: '(function () {\n\'use strict\';\n/*jshint ignore:start*/\n return <%= module %> /*jshint ignore:end*/\n})();'
  }))
  .pipe(rename('config.js'))
  .pipe(gulp.dest('src/app/'));
});

Just ignore the rename and env hack, I did that so I could change among many configs easily.

jayrmotta avatar Feb 01 '15 21:02 jayrmotta

+1 for defaulting to single quotes. @jayrmotta's wrap solution worked for me.

jasonswett avatar May 01 '15 20:05 jasonswett

Placing on the roadmap

atticoos avatar May 01 '15 20:05 atticoos

Fixed in #29 by @psalaets :+1:

atticoos avatar Jun 26 '15 05:06 atticoos

Actually, just realized the PR was for double quotes, which broke your tests.

Going to reopen for further consideration. A possibility would be to configure singleQuotes: Boolean, or to add jshintIgnore: true

atticoos avatar Jun 26 '15 05:06 atticoos

I would be OK with either one. Just would be nice to get rid of the warning for now.

singleQuotes: Boolean has the advantage that it would work not only with jshint but also with jscs and similiar tools though.

johannesjo avatar Aug 06 '15 22:08 johannesjo

Would it be that hard to transform "strings" to 'strings' during the JSON to JS process?

Adding JSHint rules sounds more like a temporary workaround than a true solution to me.

wembernard avatar Aug 20 '15 13:08 wembernard

@wembernard yep, we'll be going with the singleQuotes mode. It should not be that hard, just some escaping required. Feel free to open a PR

atticoos avatar Aug 20 '15 14:08 atticoos

@ajwhite I forked your project and managed to handle this by changing

_.each(jsonObj, function (value, key) {
  constants.push({
    name: key,
    value: JSON.stringify(value, null, spaces)
  });
});

to

_.each(jsonObj, function (value, key) {
  var processedValue;

  if (typeof value === 'boolean' || typeof value === 'number') {
    processedValue = value;
  } else {
    processedValue = JSON.stringify(value, null, spaces).replace(/"/g, '\'');
  }

  constants.push({
    name: key,
    value: processedValue
  });
});

However, I can't find a way to pass your gulp test.

wembernard avatar Aug 21 '15 09:08 wembernard

The outputs have changed, so all the tests will fail. This should only happen if single quote property is provided

atticoos avatar Aug 21 '15 13:08 atticoos

exist a method or function to change the doublequotes to singlequote after gulp-ng-config?

porfidev avatar Jun 13 '16 18:06 porfidev

Sounds pretty good to me! GJ!

markmssd avatar Sep 20 '16 05:09 markmssd

Hi, any news about this? I don't think an option for singleQuote has been added and my generated file has double quote yet. Thanks

Torone avatar Nov 29 '16 13:11 Torone

Any news? Thanks! :)

franbueno avatar Jan 24 '17 19:01 franbueno

Well, I just created a plugin that do the dirty job. You can find it here: https://www.npmjs.com/package/gulp-replace-quotes. It replace single quotes to double quotes or vice versa...

Torone avatar Jan 29 '17 13:01 Torone