Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 34015c7

Browse files
formly-botKent C. Dodds
authored andcommitted
chore(eslint): Upgrade, remove semicolons, add dangling commas
1 parent c335d9a commit 34015c7

31 files changed

+3215
-3212
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ before_install:
1717
before_script:
1818
- npm prune
1919
script:
20+
- npm run eslint
2021
- npm run test
2122
- npm run check-coverage
2223
after_success:

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
"build:dist": "webpack --progress --colors --set-env-NODE_ENV=development",
2828
"build:prod": "webpack --progress --colors --set-env-NODE_ENV=production",
2929
"build": "npm run build:dist & npm run build:prod",
30+
"eslint:test": "eslint -c other/test.eslintrc --ignore-pattern '**/*.+(test|mock).js' src/",
31+
"eslint:src": "eslint -c other/src.eslintrc --ignore-pattern '!**/*.+(test|mock).js' src/",
32+
"eslint": "npm run eslint:test -s && npm run eslint:src -s",
3033
"test": "karma start --single-run --set-env-COVERAGE=true --set-env-NODE_ENV=test",
3134
"test:watch": "karma start --set-env-COVERAGE=true --set-env-NODE_ENV=test",
3235
"test:debug": "karma start --browsers Chrome --set-env-NODE_ENV=test",
3336
"start": "npm run test:watch",
3437
"check-coverage": "istanbul check-coverage --statements 93 --branches 89 --functions 92 --lines 92",
3538
"report-coverage": "cat ./coverage/lcov.info | node_modules/.bin/codecov",
3639
"commit": "git-cz",
37-
"prepublish": "npm run build",
38-
"postpublish": "publish-latest --user-email [email protected] --user-name formly-bot",
39-
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
40+
"publish-latest": "publish-latest --user-email [email protected] --user-name formly-bot",
41+
"semantic-release": "semantic-release pre && npm run build && npm publish && npm run publish-latest && semantic-release post"
4042
},
4143
"config": {
4244
"ghooks": {
43-
"commit-msg": "./node_modules/.bin/validate-commit-msg && npm t && npm run check-coverage"
45+
"commit-msg": "./node_modules/.bin/validate-commit-msg && npm run eslint && npm t && npm run check-coverage"
4446
},
4547
"commitizen": {
4648
"path": "node_modules/cz-conventional-changelog"
@@ -65,8 +67,8 @@
6567
"cracks": "3.1.1",
6668
"cz-conventional-changelog": "1.1.4",
6769
"deindent": "0.1.0",
68-
"eslint-config-kentcdodds": "4.0.1",
6970
"eslint": "1.7.3",
71+
"eslint-config-kentcdodds": "5.0.0",
7072
"eslint-loader": "1.1.0",
7173
"eslint-plugin-mocha": "1.0.0",
7274
"ghooks": "0.3.2",

src/angular-fix/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// some versions of angular don't export the angular module properly,
22
// so we get it from window in this case.
3-
let angular = require('angular');
3+
let angular = require('angular')
44

55
/* istanbul ignore next */
66
if (!angular.version) {
7-
angular = window.angular;
7+
angular = window.angular
88
}
9-
export default angular;
9+
export default angular
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
import angular from 'angular-fix';
2-
export default formlyCustomValidation;
1+
import angular from 'angular-fix'
2+
export default formlyCustomValidation
33

44
// @ngInject
55
function formlyCustomValidation(formlyUtil) {
66
return {
77
restrict: 'A',
88
require: 'ngModel',
99
link: function formlyCustomValidationLink(scope, el, attrs, ctrl) {
10-
const opts = scope.options;
11-
opts.validation.messages = opts.validation.messages || {};
10+
const opts = scope.options
11+
opts.validation.messages = opts.validation.messages || {}
1212
angular.forEach(opts.validation.messages, (message, key) => {
1313
opts.validation.messages[key] = () => {
14-
return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue);
15-
};
16-
});
14+
return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue)
15+
}
16+
})
1717

1818

19-
const useNewValidatorsApi = ctrl.hasOwnProperty('$validators') && !attrs.hasOwnProperty('useParsers');
20-
angular.forEach(opts.validators, angular.bind(null, addValidatorToPipeline, false));
21-
angular.forEach(opts.asyncValidators, angular.bind(null, addValidatorToPipeline, true));
19+
const useNewValidatorsApi = ctrl.hasOwnProperty('$validators') && !attrs.hasOwnProperty('useParsers')
20+
angular.forEach(opts.validators, angular.bind(null, addValidatorToPipeline, false))
21+
angular.forEach(opts.asyncValidators, angular.bind(null, addValidatorToPipeline, true))
2222

2323
function addValidatorToPipeline(isAsync, validator, name) {
24-
setupMessage(validator, name);
25-
validator = angular.isObject(validator) ? validator.expression : validator;
24+
setupMessage(validator, name)
25+
validator = angular.isObject(validator) ? validator.expression : validator
2626
if (useNewValidatorsApi) {
27-
setupWithValidators(validator, name, isAsync);
27+
setupWithValidators(validator, name, isAsync)
2828
} else {
29-
setupWithParsers(validator, name, isAsync);
29+
setupWithParsers(validator, name, isAsync)
3030
}
3131
}
3232

3333
function setupMessage(validator, name) {
34-
const message = validator.message;
34+
const message = validator.message
3535
if (message) {
3636
opts.validation.messages[name] = () => {
37-
return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue);
38-
};
37+
return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue)
38+
}
3939
}
4040
}
4141

4242
function setupWithValidators(validator, name, isAsync) {
43-
const validatorCollection = isAsync ? '$asyncValidators' : '$validators';
43+
const validatorCollection = isAsync ? '$asyncValidators' : '$validators'
4444

4545
ctrl[validatorCollection][name] = function evalValidity(modelValue, viewValue) {
46-
return formlyUtil.formlyEval(scope, validator, modelValue, viewValue);
47-
};
46+
return formlyUtil.formlyEval(scope, validator, modelValue, viewValue)
47+
}
4848
}
4949

5050
function setupWithParsers(validator, name, isAsync) {
51-
let inFlightValidator;
51+
let inFlightValidator
5252
ctrl.$parsers.unshift(function evalValidityOfParser(viewValue) {
53-
const isValid = formlyUtil.formlyEval(scope, validator, ctrl.$modelValue, viewValue);
53+
const isValid = formlyUtil.formlyEval(scope, validator, ctrl.$modelValue, viewValue)
5454
if (isAsync) {
55-
ctrl.$pending = ctrl.$pending || {};
56-
ctrl.$pending[name] = true;
57-
inFlightValidator = isValid;
55+
ctrl.$pending = ctrl.$pending || {}
56+
ctrl.$pending[name] = true
57+
inFlightValidator = isValid
5858
isValid.then(() => {
5959
if (inFlightValidator === isValid) {
60-
ctrl.$setValidity(name, true);
60+
ctrl.$setValidity(name, true)
6161
}
6262
}).catch(() => {
6363
if (inFlightValidator === isValid) {
64-
ctrl.$setValidity(name, false);
64+
ctrl.$setValidity(name, false)
6565
}
6666
}).finally(() => {
67-
const $pending = ctrl.$pending || {};
67+
const $pending = ctrl.$pending || {}
6868
if (Object.keys($pending).length === 1) {
69-
delete ctrl.$pending;
69+
delete ctrl.$pending
7070
} else {
71-
delete ctrl.$pending[name];
71+
delete ctrl.$pending[name]
7272
}
73-
});
73+
})
7474
} else {
75-
ctrl.$setValidity(name, isValid);
75+
ctrl.$setValidity(name, isValid)
7676
}
77-
return viewValue;
78-
});
77+
return viewValue
78+
})
7979
}
80-
}
81-
};
80+
},
81+
}
8282
}
Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,128 @@
11
/* eslint no-unused-vars:0, max-len:0 */
2-
import _ from 'lodash';
3-
import angular from 'angular-fix';
2+
import _ from 'lodash'
3+
import angular from 'angular-fix'
44

5-
import testUtils from '../test.utils.js';
5+
import testUtils from '../test.utils.js'
66

7-
const {shouldWarnWithLog} = testUtils;
7+
const {shouldWarnWithLog} = testUtils
88

99
describe(`formly-custom-validation`, function() {
10-
let $compile, $timeout, $q, scope, $log, formlyConfig;
11-
const formTemplate = `<form name="myForm">TEMPLATE</form>`;
12-
beforeEach(window.module('formly'));
10+
let $compile, $timeout, $q, scope, $log, formlyConfig
11+
const formTemplate = `<form name="myForm">TEMPLATE</form>`
12+
beforeEach(window.module('formly'))
1313
beforeEach(inject((_$compile_, _$timeout_, _$q_, $rootScope, _$log_, _formlyConfig_) => {
14-
$compile = _$compile_;
15-
$timeout = _$timeout_;
16-
$q = _$q_;
17-
scope = $rootScope.$new();
18-
scope.options = {validation: {}, validators: {}, asyncValidators: {}};
19-
$log = _$log_;
20-
formlyConfig = _formlyConfig_;
21-
}));
14+
$compile = _$compile_
15+
$timeout = _$timeout_
16+
$q = _$q_
17+
scope = $rootScope.$new()
18+
scope.options = {validation: {}, validators: {}, asyncValidators: {}}
19+
$log = _$log_
20+
formlyConfig = _formlyConfig_
21+
}))
2222

2323
describe(`using parsers`, () => {
2424
checkApi(formTemplate.replace(
2525
`TEMPLATE`, `<input ng-model="input" name="field" formly-custom-validation use-parsers />`
26-
), angular.version.minor >= 3);
27-
});
26+
), angular.version.minor >= 3)
27+
})
2828

2929
describe(`using $validators`, () => {
3030
checkApi(formTemplate.replace(
3131
`TEMPLATE`, `<input ng-model="input" name="field" formly-custom-validation />`
32-
));
33-
});
32+
))
33+
})
3434

3535
describe(`options.validation.messages`, () => {
3636
it(`should convert all strings to functions`, () => {
3737
scope.options.validation = {
3838
messages: {
39-
isHello: `'"' + $viewValue + '" is not "hello"'`
40-
}
41-
};
39+
isHello: `'"' + $viewValue + '" is not "hello"'`,
40+
},
41+
}
4242
$compile(formTemplate.replace(
4343
`TEMPLATE`, `<input ng-model="input" name="field" formly-custom-validation />`
44-
))(scope);
44+
))(scope)
4545

46-
expect(typeof scope.options.validation.messages.isHello).to.eq('function');
47-
const field = scope.myForm.field;
48-
field.$setViewValue('sup');
49-
expect(scope.options.validation.messages.isHello()).to.eq('"sup" is not "hello"');
50-
});
51-
});
46+
expect(typeof scope.options.validation.messages.isHello).to.eq('function')
47+
const field = scope.myForm.field
48+
field.$setViewValue('sup')
49+
expect(scope.options.validation.messages.isHello()).to.eq('"sup" is not "hello"')
50+
})
51+
})
5252

5353
function checkApi(template, versionThreeOrBetterAndEmulating) {
54-
const value = `hello`;
54+
const value = `hello`
5555
describe(`validators`, () => {
56-
const validate = doValidation.bind(null, template, 'hello', false);
56+
const validate = doValidation.bind(null, template, 'hello', false)
5757
it(`should pass if returning a string that passes`, () => {
58-
validate(`$viewValue === "${value}"`, true);
59-
});
58+
validate(`$viewValue === "${value}"`, true)
59+
})
6060

6161
it(`should fail if returning a string that fails`, () => {
62-
validate(`$viewValue !== "${value}"`, false);
63-
});
62+
validate(`$viewValue !== "${value}"`, false)
63+
})
6464

6565
it(`should pass if it's a function that passes`, () => {
66-
validate(viewValue => viewValue === value, true);
67-
});
66+
validate(viewValue => viewValue === value, true)
67+
})
6868

6969
it(`should fail if it's a function that fails`, () => {
70-
validate(viewValue => viewValue !== value, false);
71-
});
72-
});
70+
validate(viewValue => viewValue !== value, false)
71+
})
72+
})
7373

7474
describe(`asyncValidators`, () => {
75-
const validate = doValidation.bind(null, template, 'hello', true);
75+
const validate = doValidation.bind(null, template, 'hello', true)
7676
it(`should pass if it's a function that returns a promise that resolves`, () => {
77-
validate(() => $q.when(), true);
78-
});
77+
validate(() => $q.when(), true)
78+
})
7979

8080
it(`should fail if it's a function that returns a promise that rejects`, () => {
81-
validate(() => $q.reject(), false);
82-
});
81+
validate(() => $q.reject(), false)
82+
})
8383

8484
it(`should be pending until the promise is resolved`, () => {
85-
const deferred = $q.defer();
86-
const deferred2 = $q.defer();
87-
scope.options.asyncValidators.isHello = () => deferred.promise;
88-
scope.options.asyncValidators.isHey = () => deferred2.promise;
89-
$compile(template)(scope);
90-
const field = scope.myForm.field;
91-
scope.$digest();
92-
field.$setViewValue(value);
93-
94-
expect(field.$pending).to.exist;
95-
expect(field.$pending.isHello).to.be.true;
96-
expect(field.$pending.isHey).to.be.true;
85+
const deferred = $q.defer()
86+
const deferred2 = $q.defer()
87+
scope.options.asyncValidators.isHello = () => deferred.promise
88+
scope.options.asyncValidators.isHey = () => deferred2.promise
89+
$compile(template)(scope)
90+
const field = scope.myForm.field
91+
scope.$digest()
92+
field.$setViewValue(value)
93+
94+
expect(field.$pending).to.exist
95+
expect(field.$pending.isHello).to.be.true
96+
expect(field.$pending.isHey).to.be.true
9797

9898
// because in angular 1.3 they do some interesting stuff with $pending, so can only test $pending in 1.2
9999
if (!versionThreeOrBetterAndEmulating) {
100-
deferred.resolve();
101-
scope.$digest();
100+
deferred.resolve()
101+
scope.$digest()
102102

103-
expect(field.$pending).to.exist;
104-
expect(field.$pending.isHey).to.be.true;
105-
expect(field.$pending.isHello).to.not.exist;
103+
expect(field.$pending).to.exist
104+
expect(field.$pending.isHey).to.be.true
105+
expect(field.$pending.isHello).to.not.exist
106106

107-
deferred2.reject();
108-
scope.$digest();
109-
expect(field.$pending).to.not.exist;
107+
deferred2.reject()
108+
scope.$digest()
109+
expect(field.$pending).to.not.exist
110110
}
111-
});
112-
});
111+
})
112+
})
113113
}
114114

115115
function doValidation(template, value, isAsync, validator, pass) {
116116
if (isAsync) {
117-
scope.options.asyncValidators.isHello = validator;
117+
scope.options.asyncValidators.isHello = validator
118118
} else {
119-
scope.options.validators.isHello = validator;
119+
scope.options.validators.isHello = validator
120120
}
121-
$compile(template)(scope);
122-
const field = scope.myForm.field;
123-
scope.$digest();
124-
field.$setViewValue(value);
125-
scope.$digest();
126-
expect(field.$valid).to.eq(pass);
121+
$compile(template)(scope)
122+
const field = scope.myForm.field
123+
scope.$digest()
124+
field.$setViewValue(value)
125+
scope.$digest()
126+
expect(field.$valid).to.eq(pass)
127127
}
128-
});
128+
})

0 commit comments

Comments
 (0)