Skip to content

Commit 6895dd3

Browse files
committed
Merge pull request #5 from rachelnicole/lintandtests
Update plugin for linting and coveralls and new validation
2 parents 2b16f86 + 71b11ac commit 6895dd3

File tree

7 files changed

+34
-75
lines changed

7 files changed

+34
-75
lines changed

.eslintrc-ava.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
extends:
2+
- punchcard/configurations/ava

.eslintrc.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
11
extends:
2-
- punchcard
3-
4-
env:
5-
es6: true
6-
7-
rules:
8-
no-empty-label: 0 # hides deprecated rule
9-
space-after-keywords: 0 # hides deprecated rule
10-
space-before-keywords: 0 # hides deprecated rule
11-
space-return-throw-case: 0 # hides deprecated rule
12-
keyword-spacing: 2 # replaces `space-after-keywords`, `space-before-keywords`, and `space-return-throw-case`
13-
strict: 1 # fixes a circular bug
2+
- punchcard

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_js:
44
cache:
55
directories:
66
- node_modules
7+
after_success: npm run coverage
78
notifications:
89
slack:
910
secure: Wwh0JLcQnGtHoAaUSc/6oQrTBhdz4zS26tflVUa2aFraVFt7sUcHMjWBWYDO2KpVRXjeky2JslwGCpwuoNUIBwl6Ah89MoeR3pQBXEfMPTHfkMPfl/XtPvl/q7JjzOcsOya0zdRPVgGHWc/ikd5Yd3Gn8yTmwWjW0UyrKkIeTmBb0L2DK4ZaeV3qFuL3CVW+ziW6c6fscicej2jOKb0OgwPw4Qdtczn9ueTN+GY4Jr+4L9hSaL3UR6H+JBaFikfc0pMboFU86ZIB0J8ig4+jZWI07dHJUNo8vOxdRwPiItjf75RqkGMkub2tS5wH1Wn3VF3O1STw4JsBtvsieScHQ3jetWzWAbM+LLptNYoGGVN18GxzJx+i1afPqxoadOKTle3ldI+ePJJrX7pSMjSYzPmnKRjl9fecnmMcLS8UOG+tIIxkhq8jkQ4DY0Jm9V/ID5+4+0YgTei4rQ8gkCpfYMi1AcFOO0flBFxFsQGuTFWVHOFpijde82QXPdvJAmAlciFwAfH8gMOvh3ptzesdtzxKrD/Ftw7/mQLHhajC2x9GUAq/zmelNMner8JMapQ5wreA4E3oEumBfk4AaAe2WsKVMtA1V6A9btAXClklyNMy+wf4Zz0dZaKo8a6dG3jDFQ02r2aGrpLsDesbqalmpvI8D701OwCd5ROAWRTG5e8=

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* email Input Plugin
35
*
@@ -26,8 +28,7 @@ module.exports = {
2628
label: 'email',
2729
placeholder: 'add your email',
2830
settings: {
29-
'domains': ['foo.com', 'bar.com', 'baz.com'],
30-
'regex': /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/,
31+
empty: true,
3132
},
3233
},
3334
},

lib/validation.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
1+
'use strict';
2+
13
/**
24
* Validation for email Input Plugin
35
*
4-
* @param {Object} input - inputs in this plugin's instance and their values as {String}
5-
* @param {Object} input.target - the triggering input's name and value as {String}
6-
* @param {String} input.target.name - the triggering input's name
7-
* @param {String|Bool} input.target.value - the triggering input's value
8-
* @param {Object} input.all - all inputs in this plugin's instance
9-
* @param {String|Bool} input.all.email - value of input email
10-
* @param {Object} [settings] - settings for this input plugin instance
11-
* @param {Object} [settings.target] - the triggering input's settings as an {Object}
12-
* @param {Object} [settings.all] - all settings in this plugin instance as an {Object}
13-
* @param {Object} [settings.all.email] - settings of input email {Object}
6+
* @param {object} input - inputs in this plugin's instance and their values as {string}
7+
* @param {object} input.target - the triggering input's name and value as {string}
8+
* @param {string} input.target.name - the triggering input's name
9+
* @param {string|bool} input.target.value - the triggering input's value
10+
* @param {object} input.all - all inputs in this plugin's instance
11+
* @param {string|bool} input.all.email - value of input email
1412
*
15-
* @returns {Bool|String} true or a string with the text describing the error
13+
* @returns {bool|string} true or a string with the text describing the error
1614
*
1715
* @module emailValidation
1816
*/
19-
module.exports = function emailValidation(input, settings) {
20-
'use strict';
21-
let domains;
2217

23-
domains = settings.target.domains || ['foo.com', 'bar.com', 'baz.com'];
24-
if (!Array.isArray(domains)) {
25-
domains = [String(domains)];
26-
}
18+
const isEmail = require('validator/lib/isEmail');
2719

28-
if (!settings.target.regex.test(input.target.value)) {
20+
module.exports = function emailValidation(input) {
21+
if (!isEmail(input.target.value)) {
2922
return 'Not a valid e-mail address.';
3023
}
3124

32-
if (!domains.some(domain => (input.target.value.indexOf(domain, input.target.value.length - domain.length) !== -1))) {
33-
return `Email must be within the following domains: ${domains.toString()}`;
34-
}
35-
3625
return true;
3726
};

package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@
99
"ava": "ava | tap-diff",
1010
"ava:watch": "ava --watch | tap-diff",
1111
"nyc": "nyc --all npm run ava",
12-
"lint": "eslint ./"
13-
}, "repository": {
12+
"lint": "eslint index.js lib && eslint -c ./.eslintrc-ava.yml tests",
13+
"coverage": "nyc report --reporter=text-lcov | coveralls"
14+
},
15+
"repository": {
1416
"type": "git",
1517
"url": "[email protected]:punchcard-cms/input-plugin-email.git"
1618
},
1719
"contributors": [
1820
"Scott Nath <[email protected]>"
1921
],
2022
"license": "Apache-2.0",
21-
"dependencies": {},
23+
"dependencies": {
24+
"validator": "^5.2.0"
25+
},
2226
"devDependencies": {
23-
"ava": "^0.12.0",
24-
"eslint": "2.2.0",
25-
"eslint-config-punchcard": "^0.1.2",
27+
"ava": "^0.14.0",
28+
"coveralls": "^2.11.9",
29+
"eslint": "^2.10.0",
30+
"eslint-config-punchcard": "^1.0.1",
2631
"nyc": "^6.0.0",
2732
"punchcard-content-types": "^0.1.0",
28-
"tap-diff": "^0.1.1"
33+
"tap-diff": "^0.1.1",
34+
"validator": "^5.2.0"
2935
},
3036
"engines": {
3137
"node": "5.7",

tests/validation.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,14 @@ const input = {
99
},
1010
};
1111

12-
const settings = {
13-
target: {
14-
domains: ['foo.com', 'bar.com', 'baz.com'],
15-
regex: /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/,
16-
},
17-
};
18-
19-
2012
// Valid input
2113
test('valid input', t => {
22-
t.true(validation(input, settings), 'Valid input returns true');
14+
t.true(validation(input), 'Valid input returns true');
2315
});
2416

2517
test('validate text is email', t => {
2618
const ip = input;
2719
ip.target.value = 'scott@scott';
28-
t.is(validation(ip, settings), 'Not a valid e-mail address.', 'Must be an actual email address');
20+
t.is(validation(ip), 'Not a valid e-mail address.', 'Must be an actual email address');
2921
});
3022

31-
test('Validate email is not among default domains', t => {
32-
const ip = input;
33-
ip.target.value = '[email protected]';
34-
t.is(validation(ip, settings), 'Email must be within the following domains: foo.com,bar.com,baz.com', 'Validate if entered email matches any default domains.');
35-
});
36-
37-
test('Validate email is within a single implementation-defined domain', t => {
38-
const ip = input;
39-
ip.target.value = '[email protected]';
40-
const set = settings;
41-
set.target.domains = 'test.com';
42-
t.is(validation(ip, set), true, 'Validate if entered email is within a single, implementation-defined domain.');
43-
});
44-
45-
test('Validate email is within an array of implementation-defined domains', t => {
46-
const ip = input;
47-
ip.target.value = '[email protected]';
48-
const set = settings;
49-
set.target.domains = ['test2.com', 'test.com'];
50-
t.is(validation(ip, set), true, 'Validate if entered email is within an array of implementation-defined domains');
51-
});

0 commit comments

Comments
 (0)