Comma first validation with no space - jshint

I am building a JSHint set for a JavaScript suite that I am writing. My habit with writing objects is as follows:
var obj = {
hello: 'World'
,foo: 'Bar'
,name: 'Dave'
};
I use Grunt and grunt-contrib-jshint to run the validations with the following options:
browser: true
eqeqeq: false
laxcomma: true
white: true
indent: 2
When I run grunt jshint I get errors that a space is expected after the commas. How do I ignore this space?

You can ignore specific errors in the way written in the doc;
https://github.com/gruntjs/grunt-contrib-jshint
here is a quote
Ignoring specific warnings
If you would like to ignore a specific warning:
[L24:C9] W015: Expected '}' to have an indentation at 11 instead at 9.
You can toggle it by prepending - to the warning id as an option:
grunt.initConfig({
jshint: {
ignore_warning: {
options: {
'-W015': true,
},
src: ['**/*.js'],
},
},
});
Update.
Also, I am using such config and don't have comma errors
,defaultOptions = {
curly: true,
eqeqeq: true,
immed: true,
latedef: 'nofunc',
newcap: true,
noarg: true,
nonew: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
camelcase: true,
quotmark: true,
// lax
laxcomma: true,
// environment
browser: true,
devel: true,
jquery: true,
}

Related

How to fix Error parsing triggers: Cannot find module '../../ when deploying Firebase Functions on Gitlab CI

I have a Firebase project with Typescript functions
When I install, build and deploy from my console using firebase deploy all works fine.
But, when I try to do the same using my .gitlab-ci.yml script I get an error that it can't find my relative import.
Error: Error parsing triggers: Cannot find module '../../config/version'
Require stack:
The Typescript code is:
// utilsController.ts
import { serverVersion } from '../../config/version'
And that is converted to
// utilsController.js
const version_1 = require("../../config/version");
And apparently firebase deploy does not like this when running on Gitlab CI, but it works without a problem from my machine.
My tsconfig.json looks like this:
{
"compilerOptions": {
/* Basic Options */
"incremental": true,
"module": "commonjs",
"outDir": "lib",
"target": "es2015",
/* Strict Type-Checking Options */
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
/* Additional Checks */
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
/* Module Resolution Options */
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
/* Experimental Options */
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
/* Advanced Options */
"forceConsistentCasingInFileNames": true,
"sourceMap": true
},
"compileOnSave": true,
"include": [
"src"
]
}
I made this error go away and I am pretty sure is was an update of tsconfig.json, that did the trick. Probably the "target" should be "es2017" for my setup to work.
I simply created a new Firebase Functions Typescript project using firebase-tools CLI and departed in the tsconfig from that.
New, working tsconfig is:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
/* Module Resolution Options */
"resolveJsonModule": true,
/* Experimental Options */
"esModuleInterop": true,
"experimentalDecorators": true,
},
"compileOnSave": true,
"include": [
"src"
]
}

Create subtasks that override `options` but use task level `src`

My gruntfile thus far
uglify: {
src: [
...
],
dest: 'js/application.min.js',
options: {
'compress': {},
'reserveDOMCache': true,
'enclose': undefined,
'exportAll': false,
'expression': false,
'preserveComments': false,
'report': 'min',
'sourceMap': false,
'sourceMapIn': undefined,
'sourceMapIncludeSources': false,
'sourceMapName': undefined,
'wrap': undefined
},
development: {
options: {
'beautify': false,
'mangle': true
}
},
production: {
options: {
'beautify': true,
'mangle': false
}
}
}
However when I run the task uglify:development it will respond with No files created.
As far as I know this is not possible. You need to explicitly define a src for each target.
You could declare a variable outside of the config and add it to each target:
var mySources = ['file1.txt', 'file2.txt']; //declared outside config
development: {
src: mySources, //add variable to each target
Or you can declare a variable inside the config:
mySourcesInside: ['file1.txt'], //declared within config
development: {
src: '<%= mySourcesInside%>', //reference variable in each target
Alternatively you could use something like grunt-override-config https://github.com/masakura/grunt-override-config and declare just one uglify target and overrides for the options.

Running grunt with mochaProtractor specifying dependancies?? chai assertion library?

I've set up a gruntfile that looks like the following. The aim being to perform e2e tests using protractor for my angularjs project. When running this using mochaProtractor Chrome fires up as expect but the lint is telling me that I'm missing the dependancies for the expect statement. This should referencing the assertion library chai. How do I include dependencies for chai to get this to work correctly?
Thanks
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
watch: {
scripts: {
files: ['public/specs/e2e/*.js'],
tasks: ['mochaProtractor','jshint'],
options: {
spawn: false,
},
},
},
jshint: {
all: [
'Gruntfile.js',
'public/app/js/*.js'
],
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
unused: true,
boss: true,
eqnull: true,
node: true
}
},
mochaProtractor: {
options: {
browsers: ['Chrome']
},
files: ['public/specs/e2e/*.js'],
baseUrl: 'http://localhost:3000/'
},
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha-protractor');
Below is the spec I'm trying to test against. Note: I added the require statement at the top in attempt to get it to work. Any thoughts?
var chai = require('chai');
var expect = chai.expect;
describe("Given a task entry screen", function() {
ptor = protractor.getInstance();
beforeEach(function() {
ptor.get('#/');
button = ptor.findElement(protractor.By.className('btn-say-hello'));
button.click();
});
it('says hello', function() {
message = ptor.findElement(protractor.By.className('message'));
expect(message.getText()).toEqual('Hello!');
});
});
You have to add chai as a dev dependency in your package.json.
{
"name": "yourProject",
"devDependencies": {
"chai": "~1.8.1"
}
}
then install the dependenvy via
npm install`
and then you should be able to write a spec :
var chai = require('chai');
var expect = chai.expect;
describe("Given a task entry screen", function() {
ptor = protractor.getInstance();
beforeEach(function() {
ptor.get('#/');
button = ptor.findElement(protractor.By.className('btn-say-hello'));
button.click();
});
it('says hello', function() {
message = ptor.findElement(protractor.By.className('message'));
expect(message.getText()).toEqual('Hello!');
});
});

jshint grunt exported options

Hi I'm trying to achieve the following. I'm using grunt for jshint validating.
Somewhere in a file I have used:
var logger = function () {
// some ode
}
Because logger is never actually used jshint correctly shows me the following error.
W098: 'logger' is defined but never used.
I could set unused to false and it would work perfectly. But I actually want the option to take place in other files and warn me about unused variables. So the unused option is not gonna work for me.
I also saw that I could use a inline comment like this:
* exported EXPORTED_LIB */
But I would actually prefer to avoid cluttering my files with such comments. Is there any chance I can specify an exported options in my grunt file like I can for example for globals.
Heres the jshint part of my gruntfile:
jshint: {
// global options
options: {
camelcase: true,
curly: true,
eqeqeq: true,
forin: true,
immed: true,
indent: 4,
latedef: true,
newcap: true,
noarg: true,
nonew: true,
plusplus: false,
quotmark: 'single',
undef: true,
unused: true,
strict: true,
maxparams: 4,
maxdepth: 4,
trailing: true,
maxlen: 120,
browser: true,
node: true
},
server_logger: {
src: [BASE_PATH_SERVER_LOGGER, '/**/*.js'].join(''),
options: {
browser: false
}
},
client_logger: {
src: [BASE_PATH_CLIENT_LOGGER, '/**/*.js'].join(''),
options: {
node: false,
devel: true
}
}
}
Thanks for your time.
Best regards
Playerwtf
UPDATE: I made an issue on jshint github repository here
This was recently fixxed and works now as I would expect it.
github-issue
As an example I use it like this in my gruntfile
client_logger: {
expand: true,
cwd: BASE_PATH_CLIENT_LOGGER,
src: '**/*.js',
options: {
node: false,
devel: true,
globals: {
logger: true,
expect: true,
it: true,
describe: true,
beforeEach: true,
afterEach: true
},
exported: ['logger']
}
}
But the npm module was not yet updated. If you want this to work you will have to manually copy the newest version from the jshint github repository and replace the one in the current module or wait until it is updated.
i think you can exclude files in your src-files, so you could exclude your logger file from your basic linting (i suppose the logger file is logger.js here), and lint the logger file separatly with the unused-flag turned off.
read more about that here -> "! at the beginning of a pattern will negate the match"
you could set the cwd (and leave the join stuff). see more about that in the docs: Building the files object dynamically
jshint: {
// global options
options: {
... your global options here
},
server_logger: {
options: {
browser: false
},
files: [{
cwd: BASE_PATH_SERVER_LOGGER,
src: ['/**/*.js', '!logger.js']
}]
},
client_logger: {
options: {
node: false,
devel: true
},
files: [{
cwd: BASE_PATH_CLIENT_LOGGER,
src: ['/**/*.js', '!logger.js']
}]
},
lint_logger: {
options: {
unused: false
},
files: [{
src: ['logger.js']
}]
}
}
not 100% sure if that works, but i think it should at least lead you into the right direction. if you need to specify a path and not only a file for excluding you could put your logger-file in a separate folder an just exclude that folder!

getting Mixed spaces and tabs error in grunt.js, how to remove it?

My jshint code is:
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
},
and I am calling that as:
grunt.registerTask('foo', 'lint');// For running in cmd you need grunt.cmd foo.
How can I overcome with this error ???
You could fix the mixed tabs and spaces :)
Or add the smarttabs option to ignore the error:
jshint: {
options: {
smarttabs: true
}
}
Or if you only want to disable warnings per file, add this to the top of the files with the errors:
/*jshint smarttabs:true */
JSHint documentation: http://www.jshint.com/docs/

Resources