Skip to content

Commit 8e3c8bf

Browse files
committed
Eslint some stuff
1 parent 7055ef4 commit 8e3c8bf

23 files changed

+1472
-1411
lines changed

.eslintrc.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true
5+
},
6+
"parserOptions": {
7+
"ecmaVersion": 6,
8+
"sourceType": "module"
9+
},
10+
"extends": "google",
11+
"rules": {
12+
"array-bracket-spacing": [
13+
2,
14+
"always",
15+
{
16+
"objectsInArrays": false,
17+
"arraysInArrays": false
18+
}
19+
],
20+
"object-curly-spacing": [
21+
2,
22+
"always",
23+
{
24+
"objectsInObjects": false,
25+
"arraysInObjects": false
26+
}
27+
],
28+
"brace-style": [
29+
2,
30+
"stroustrup",
31+
{
32+
"allowSingleLine": true
33+
}
34+
],
35+
"max-len": [
36+
2,
37+
120,
38+
{ "ignoreStrings": true }
39+
],
40+
"semi": [
41+
2,
42+
"always"
43+
],
44+
"linebreak-style": "off",
45+
"space-before-function-paren": "off",
46+
"valid-jsdoc": "off",
47+
"no-invalid-this": "off"
48+
}
49+
}

karma.conf.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
// Karma configuration
2-
2+
/* eslint-disable no-var */
33
var fs = require('fs');
44
var path = require('path');
55
var origin = fs.existsSync(path.resolve(__dirname, '../angular-schema-form-bootstrap/dist/angular-schema-form-bootstrap.js'));
66
var include = (origin)
77
? '../angular-schema-form-bootstrap/dist/angular-schema-form-bootstrap.js'
88
: 'dist/angular-schema-form-bootstrap.js';
9-
console.log("Karma bootstrap:" + origin);
9+
console.log('Karma bootstrap:' + origin);
1010

1111
module.exports = function(config) {
1212
config.set({
1313
// base path, that will be used to resolve files and exclude
1414
basePath: '.',
1515

1616
// frameworks to use
17-
frameworks: ['mocha', 'chai-sinon'],
17+
frameworks: [ 'mocha', 'chai-sinon' ],
1818

1919
// list of files / patterns to load in the browser
2020
files: [
2121
'node_modules/babel-polyfill/dist/polyfill.js',
2222
'bower_components/jquery/dist/jquery.min.js',
2323
'test/lib/angular.js',
2424
'test/lib/angular-mocks.js',
25-
'bower_components/tv4/tv4.js',
25+
//'bower_components/tv4/tv4.js',
2626
'dist/angular-schema-form.js',
2727
include,
28-
'src/**/*.spec.js'
28+
'src/**/*.spec.js',
2929
// 'src/**/sf-schema.directive.spec.js'
3030
],
3131

@@ -34,28 +34,32 @@ module.exports = function(config) {
3434

3535
// test results reporter to use
3636
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
37-
reporters: ['dots','progress','coverage','growler'],
37+
reporters: [ 'mocha', 'coverage', 'growler' ],
38+
39+
mochaReporter: {
40+
showDiff: true,
41+
},
3842

3943
preprocessors: {
40-
'src/**/*.js': ['coverage']
44+
'src/**/*.js': [ 'coverage' ],
4145
},
4246
babelPreprocessor: {
4347
options: {
44-
presets: ['es2015'],
45-
sourceMap: 'inline'
48+
presets: [ 'es2015' ],
49+
sourceMap: 'inline',
4650
},
4751
filename: function (file) {
4852
return file.originalPath.replace(/\.js$/, '.es5.js');
4953
},
5054
sourceFileName: function (file) {
5155
return file.originalPath;
52-
}
56+
},
5357
},
5458

5559
// optionally, configure the reporter
5660
coverageReporter: {
5761
type: 'lcov',
58-
dir: 'coverage/'
62+
dir: 'coverage/',
5963
},
6064

6165
// web server port
@@ -70,7 +74,7 @@ module.exports = function(config) {
7074
// config.LOG_INFO || config.LOG_DEBUG
7175
logLevel: config.LOG_DEBUG,
7276

73-
loggers: [{type: 'console'}],
77+
loggers: [{ type: 'console' }],
7478

7579
// enable / disable watching file and executing tests whenever any file changes
7680
autoWatch: true,
@@ -83,16 +87,16 @@ module.exports = function(config) {
8387
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
8488
// - PhantomJS
8589
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
86-
browsers: ['PhantomJS'],
90+
browsers: [ 'PhantomJS' ],
8791

8892
// If browser does not capture in given timeout [ms], kill it
8993
captureTimeout: 60000,
9094

9195
client: {
92-
captureConsole: true
96+
captureConsole: true,
9397
},
9498
// Continuous Integration mode
9599
// if true, it capture browsers, run tests and exit
96-
singleRun: false
100+
singleRun: false,
97101
});
98102
};

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"dist": "webpack --config webpack.config.dist.js",
1515
"watch": "webpack --watch",
1616
"testlinux": "rm -fr coverage && ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS karma.conf.js && find coverage/ -name lcov.info -print0 | xargs -0 cat | ./node_modules/coveralls/bin/coveralls.js",
17-
"test": "karma start karma.conf.js --log-level debug --single-run",
17+
"lint": "eslint src/**/*.js",
18+
"test": "webpack && karma start karma.conf.js --log-level debug --single-run",
1819
"tests": "karma start karma.conf.js --log-level debug --auto-watch"
1920
},
2021
"author": "json-schema-form",
@@ -29,11 +30,6 @@
2930
"bugs": {
3031
"url": "https://github.com/json-schema-form/angular-schema-form/issues"
3132
},
32-
"dependencies": {
33-
"angular": ">= 1.2",
34-
"tv4": "~1.0.15",
35-
"angular-sanitize": ">= 1.2"
36-
},
3733
"keywords": [
3834
"angular",
3935
"angularjs",
@@ -44,20 +40,29 @@
4440
"ui-schema",
4541
"schema"
4642
],
43+
"dependencies": {
44+
"angular": ">= 1.2",
45+
"tv4": "~1.0.15",
46+
"angular-sanitize": ">= 1.2"
47+
},
4748
"devDependencies": {
4849
"babel-core": "^6.18.2",
4950
"babel-loader": "^6.2.8",
5051
"babel-plugin-add-module-exports": "^0.2.1",
5152
"babel-polyfill": "^6.16.0",
5253
"babel-preset-es2015": "^6.18.0",
5354
"chai": "^3.5.0",
55+
"diff": "^3.2.0",
56+
"eslint": "^3.19.0",
57+
"eslint-config-google": "^0.7.1",
5458
"html-webpack-externals-plugin": "^2.1.2",
5559
"karma": "^1.3.0",
5660
"karma-babel-preprocessor": "^6.0.1",
5761
"karma-chai-sinon": "^0.1.5",
5862
"karma-coverage": "^1.1.1",
5963
"karma-growler-reporter": "0.0.1",
6064
"karma-mocha": "^1.3.0",
65+
"karma-mocha-reporter": "^2.2.3",
6166
"karma-phantomjs-launcher": "^1.0.2",
6267
"karma-webpack": "^1.8.0",
6368
"mocha": "^3.2.0",

src/directives/schema-validate.directive.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import angular from 'angular';
22

3+
/**
4+
* I am the schema-validate directive
5+
*
6+
* @param {function} sfValidator
7+
* @param {function} $parse
8+
* @param {function} sfSelect
9+
* @param {function} $interpolate
10+
*
11+
* @return {object} I am the directive properties made available to Angular
12+
*/
313
export default function(sfValidator, $parse, sfSelect, $interpolate) {
414
return {
515
restrict: 'A',
@@ -14,33 +24,33 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
1424
// So we emit it up to the decorator directive so it can put it on scope.
1525
scope.$emit('schemaFormPropagateNgModelController', ngModel);
1626

17-
var error = null;
18-
var form = scope.$eval(attrs.schemaValidate);
27+
let error = null;
28+
let form = scope.$eval(attrs.schemaValidate);
1929

20-
//TODO move this out of validate
21-
var copyTo = (typeof form.copyValueTo === 'string')? [ form.copyValueTo ]: form.copyValueTo;
30+
// TODO move this out of validate
31+
let copyTo = (typeof form.copyValueTo === 'string')? [ form.copyValueTo ]: form.copyValueTo;
2232
if (copyTo && copyTo.length) {
2333
ngModel.$viewChangeListeners.push(function() {
24-
var context = {
25-
"model": scope.model,
26-
"form": form,
27-
"arrayIndex": scope.$index,
28-
"arrayIndices": scope.arrayIndices,
29-
"path": scope.path,
30-
"$i": scope.$i,
31-
"$index": scope.$index
34+
let context = {
35+
'model': scope.model,
36+
'form': form,
37+
'arrayIndex': scope.$index,
38+
'arrayIndices': scope.arrayIndices,
39+
'path': scope.path,
40+
'$i': scope.$i,
41+
'$index': scope.$index,
3242
};
3343
angular.forEach(copyTo, function(copyToPath) {
34-
var path = copyToPath.replace(/\[/g,"[{{ ").replace(/\]/g," }}]").replace(/^model\./,"");
44+
let path = copyToPath.replace(/\[/g, '[{{ ').replace(/\]/g, ' }}]').replace(/^model\./, '');
3545
path = $interpolate(path)(context);
3646
sfSelect(path, scope.model, ngModel.$modelValue);
3747
});
3848
});
3949
};
4050
// Validate against the schema.
4151

42-
var validate = function(viewValue, triggered) {
43-
//Still might be undefined
52+
let validate = function(viewValue, triggered) {
53+
// Still might be undefined
4454
if (!form) {
4555
return viewValue;
4656
}
@@ -50,8 +60,8 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
5060
return viewValue;
5161
}
5262

53-
var result = sfValidator(form, viewValue);
54-
//console.log('result is', result)
63+
let result = sfValidator(form, viewValue);
64+
// console.log('result is', result)
5565
// Since we might have different tv4 errors we must clear all
5666
// errors that start with tv4-
5767
Object.keys(ngModel.$error)
@@ -110,16 +120,16 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
110120
// updating if we've found an error.
111121
if (ngModel.$validators) {
112122
ngModel.$validators.schemaForm = function() {
113-
//console.log('validators called.')
123+
// console.log('validators called.')
114124
// Any error and we're out of here!
115125
return !Object.keys(ngModel.$error).some(function(e) { return e !== 'schemaForm';});
116126
};
117127
}
118128

119-
var schema = form.schema;
129+
let schema = form.schema;
120130

121131
// A bit ugly but useful.
122-
scope.validateField = function(formName, triggered) {
132+
scope.validateField = function(formName, triggered) {
123133
let noField = (formName === undefined);
124134
// If we have specified a form name, and this model is not within
125135
// that form, then leave things be.
@@ -166,12 +176,12 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
166176
}
167177
};
168178

169-
var first = true;
179+
let first = true;
170180
ngModel.$formatters.push(function(val) {
171181
// When a form first loads this will be called for each field.
172182
// we usually don't want that.
173-
if (ngModel.$pristine && first &&
174-
(!scope.options || scope.options.validateOnRender !== true)) {
183+
if (ngModel.$pristine && first &&
184+
(!scope.options || scope.options.validateOnRender !== true)) {
175185
first = false;
176186
return val;
177187
}
@@ -187,6 +197,6 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
187197
scope.schemaError = function() {
188198
return error;
189199
};
190-
}
200+
},
191201
};
192202
}

0 commit comments

Comments
 (0)