Skip to content

Commit

Permalink
Enable object-curly-spacing eslint rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 26, 2015
1 parent bfceaab commit 402edd7
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 132 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Expand Up @@ -13,7 +13,6 @@
"max-statements": [2, 19],
"new-cap": [2, { "capIsNewExceptions": ["Template"] }],
"no-extra-parens": [0],
"object-curly-spacing": [0, "always"],
"operator-linebreak": [2, "after"]
}
}
16 changes: 8 additions & 8 deletions example/complex.js
Expand Up @@ -27,9 +27,9 @@ var complexForm = forms.create({
name: fields.string({
required: validators.required('%s is required, silly!')
}),
email: fields.email({required: true, label: 'Email Address'}),
email: fields.email({ required: true, label: 'Email Address' }),
website: fields.url(),
password: fields.password({required: true}),
password: fields.password({ required: true }),
password_confirm: fields.password({
required: true,
validators: [validators.matchField('password')]
Expand Down Expand Up @@ -58,19 +58,19 @@ var complexForm = forms.create({
]
}),
more_options: fields.array({
choices: {one: 'item 1', two: 'item 2', three: 'item 3'},
choices: { one: 'item 1', two: 'item 2', three: 'item 3' },
widget: widgets.multipleCheckbox()
}),
even_more: fields.string({
choices: {one: 'item 1', two: 'item 2', three: 'item 3'},
choices: { one: 'item 1', two: 'item 2', three: 'item 3' },
widget: widgets.multipleRadio()
}),
and_more: fields.array({
choices: {one: 'item 1', two: 'item 2', three: 'item 3'},
choices: { one: 'item 1', two: 'item 2', three: 'item 3' },
widget: widgets.multipleSelect()
}),
notes: fields.string({
widget: widgets.textarea({rows: 6})
widget: widgets.textarea({ rows: 6 })
}),
spam_me: fields['boolean'](),
nested_1: {
Expand All @@ -84,13 +84,13 @@ http.createServer(function (req, res) {
complexForm.handle(req, {
success: function (form) {
var req_data = parse(req.url, 1).query;
res.writeHead(200, {'Content-Type': 'text/html'});
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<h1>Success!</h1>');
res.write('<h2>' + util.inspect(req_data) + '</h2>');
res.end('<pre>' + util.inspect(form.data) + '</pre>');
},
other: function (form) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(template.expand({
form: form.toHTML(),
method: 'POST',
Expand Down
22 changes: 11 additions & 11 deletions example/simple.js
Expand Up @@ -16,35 +16,35 @@ var template = jsontemplate.Template(

// our example registration form
var reg_form = forms.create({
username: fields.string({required: true}),
password: fields.password({required: true}),
username: fields.string({ required: true }),
password: fields.password({ required: true }),
confirm: fields.password({
required: true,
validators: [validators.matchField('password')]
}),
personal: {
name: fields.string({required: true, label: 'Name'}),
email: fields.email({required: true, label: 'Email'}),
name: fields.string({ required: true, label: 'Name' }),
email: fields.email({ required: true, label: 'Email' }),
address: {
address1: fields.string({required: true, label: 'Address 1'}),
address2: fields.string({label: 'Address 2'}),
city: fields.string({required: true, label: 'City'}),
state: fields.string({required: true, label: 'State'}),
zip: fields.number({required: true, label: 'ZIP'})
address1: fields.string({ required: true, label: 'Address 1' }),
address2: fields.string({ label: 'Address 2' }),
city: fields.string({ required: true, label: 'City' }),
state: fields.string({ required: true, label: 'State' }),
zip: fields.number({ required: true, label: 'ZIP' })
}
}
});

http.createServer(function (req, res) {
reg_form.handle(req, {
success: function (form) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<h1>Success!</h1>');
res.end('<pre>' + util.inspect(form.data) + '</pre>');
},
// perhaps also have error and empty events
other: function (form) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(template.expand({
form: form.toHTML(),
enctype: '',
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets.js
Expand Up @@ -171,7 +171,7 @@ exports.multipleCheckbox = function (options) {
var inputHTML = tag('input', [attrs, userAttrs, w.attrs || {}]);

// label element
var labelHTML = tag('label', {'for': id, classes: w.labelClasses}, f.choices[k]);
var labelHTML = tag('label', { 'for': id, classes: w.labelClasses }, f.choices[k]);

return html + inputHTML + labelHTML;
}, '');
Expand Down Expand Up @@ -219,7 +219,7 @@ exports.multipleRadio = function (options) {
};
var inputHTML = tag('input', [attrs, userAttrs, w.attrs || {}]);
// label element
var labelHTML = tag('label', {'for': id, classes: w.labelClasses}, f.choices[k]);
var labelHTML = tag('label', { 'for': id, classes: w.labelClasses }, f.choices[k]);

return html + inputHTML + labelHTML;
}, '');
Expand Down
8 changes: 4 additions & 4 deletions test/test-fields.js
Expand Up @@ -130,7 +130,7 @@ var testField = function (field) {

test(field + ' validate required', function (t) {
t.plan(5);
var f = fields[field]({required: true});
var f = fields[field]({ required: true });
f.validators = [];
f.bind(undefined).validate('form', function (err, fieldObject) {
t.equal(fieldObject.value, undefined);
Expand Down Expand Up @@ -290,7 +290,7 @@ test('email validators', function (t) {
fields.email().validators[0].toString(),
forms.validators.email().toString()
);
var f = fields.email({validators: [fn1, fn2]});
var f = fields.email({ validators: [fn1, fn2] });
t.equal(
f.validators[0].toString(),
forms.validators.email().toString()
Expand Down Expand Up @@ -350,7 +350,7 @@ test('url validators', function (t) {
fields.url().validators[0].toString(),
forms.validators.url().toString()
);
var f = fields.url({validators: [fn1, fn2]});
var f = fields.url({ validators: [fn1, fn2] });
t.equal(
f.validators[0].toString(),
forms.validators.url().toString()
Expand Down Expand Up @@ -382,7 +382,7 @@ test('date validators', function (t) {
fields.date().validators[0].toString(),
forms.validators.date().toString()
);
var f = fields.date({validators: [fn1, fn2]});
var f = fields.date({ validators: [fn1, fn2] });
t.equal(
f.validators[0].toString(),
forms.validators.date().toString()
Expand Down
54 changes: 27 additions & 27 deletions test/test-form.js
Expand Up @@ -20,7 +20,7 @@ test('bind', function (t) {
t.equal(form.isValid, undefined);

// bound
var f = form.bind({field1: 'data one', field2: 'data two'});
var f = form.bind({ field1: 'data one', field2: 'data two' });
t.equal(f.fields.field1.value, 'data one');
t.equal(f.fields.field1.data, 'data one');
t.equal(f.fields.field1.error, undefined);
Expand All @@ -32,7 +32,7 @@ test('bind', function (t) {
t.equal(f.bind, undefined);
t.equal(f.handle, undefined);

t.deepEqual(f.data, {field1: 'data one', field2: 'data two'});
t.deepEqual(f.data, { field1: 'data one', field2: 'data two' });
t.notEqual(form, f, 'bind returns new form object');

t.end();
Expand All @@ -48,7 +48,7 @@ test('bind with missing field in data keeps field in form', function (t) {
t.equal(form.isValid, undefined);

// bound
var f = form.bind({field1: 'data one'});
var f = form.bind({ field1: 'data one' });
t.equal(f.fields.field1.value, 'data one');
t.equal(f.fields.field1.data, 'data one');
t.equal(f.fields.field1.error, undefined);
Expand All @@ -60,7 +60,7 @@ test('bind with missing field in data keeps field in form', function (t) {
t.equal(f.bind, undefined);
t.equal(f.handle, undefined);

t.deepEqual(f.data, {field1: 'data one', field2: ''});
t.deepEqual(f.data, { field1: 'data one', field2: '' });
t.notEqual(form, f, 'bind returns new form object');

t.end();
Expand All @@ -78,7 +78,7 @@ test('validate', function (t) {
}]
})
});
var data = {field1: 'data one', field2: 'data two'};
var data = { field1: 'data one', field2: 'data two' };
form.bind(data).validate(function (err, f) {
t.equal(f.fields.field1.value, 'data one');
t.equal(f.fields.field1.data, 'data one');
Expand All @@ -87,7 +87,7 @@ test('validate', function (t) {
t.equal(f.fields.field2.data, 'data two');
t.equal(f.fields.field2.error, 'validation error');

t.deepEqual(f.data, {field1: 'data one', field2: 'data two'});
t.deepEqual(f.data, { field1: 'data one', field2: 'data two' });
t.notEqual(form, f, 'bind returns new form object');

t.notOk(f.isValid());
Expand Down Expand Up @@ -158,7 +158,7 @@ test('validate invalid data', function (t) {

test('handle empty', function (t) {
t.plan(3);
var f = forms.create({field1: forms.fields.string()});
var f = forms.create({ field1: forms.fields.string() });
f.bind = function () {
t.fail('bind should not be called');
};
Expand Down Expand Up @@ -187,7 +187,7 @@ test('handle empty', function (t) {

test('handle success', function (t) {
t.plan(8);
var f = forms.create({field1: forms.fields.string()});
var f = forms.create({ field1: forms.fields.string() });
var callOrder = [];
f.bind = function () {
callOrder.push('bind');
Expand All @@ -199,7 +199,7 @@ test('handle success', function (t) {
t.ok(true, 'validate called');
callback(null, f);
};
f.handle({field1: 'test'}, {
f.handle({ field1: 'test' }, {
empty: function () {
t.fail('empty should not be called');
},
Expand All @@ -214,7 +214,7 @@ test('handle success', function (t) {
t.fail('other should not be called');
}
});
f.handle({field1: 'test'}, {
f.handle({ field1: 'test' }, {
other: function () {
t.ok(true, 'other called');
t.equal(callOrder.length, 2);
Expand All @@ -225,7 +225,7 @@ test('handle success', function (t) {

test('handle empty object', function (t) {
t.plan(3);
var f = forms.create({field1: forms.fields.string()});
var f = forms.create({ field1: forms.fields.string() });
f.bind = function () {
t.ok(true, 'bind called');
f.fields.field1.error = 'some error';
Expand Down Expand Up @@ -261,7 +261,7 @@ test('handle empty object', function (t) {

test('handle sends callbacks', function (t) {
t.plan(9);
var f = forms.create({field1: forms.fields.string()});
var f = forms.create({ field1: forms.fields.string() });

f.bind = function () {
f.isValid = function () { return true; };
Expand All @@ -276,7 +276,7 @@ test('handle sends callbacks', function (t) {
t.equal(typeof callbacks.empty, 'function');
}
});
f.handle({field1: 'test'}, {
f.handle({ field1: 'test' }, {
success: function testing(form, callbacks) {
t.equal(Object.keys(callbacks).length, 1);
t.equal(typeof callbacks.success, 'function');
Expand All @@ -287,7 +287,7 @@ test('handle sends callbacks', function (t) {
f.isValid = function () { return false; };
return f;
};
f.handle({field1: 'test'}, {
f.handle({ field1: 'test' }, {
success: function yay() {},
error: function nay(form, callbacks) {
t.equal(Object.keys(callbacks).length, 2);
Expand All @@ -296,7 +296,7 @@ test('handle sends callbacks', function (t) {
}
});

f.handle({field1: 'test'}, {
f.handle({ field1: 'test' }, {
other: function testing(form, callbacks) {
t.equal(Object.keys(callbacks).length, 1);
t.equal(typeof callbacks.other, 'function');
Expand All @@ -312,13 +312,13 @@ test('handle missing multi-form section', function (t) {
section1: { field1: forms.fields.string() },
section2: { field1: forms.fields.string() }
});
f.bind({section1: { field1: 'string' }});
f.bind({ section1: { field1: 'string' } });
t.ok(true, 'Form handled missing section ok.');
});

test('handle error', function (t) {
t.plan(5);
var f = forms.create({field1: forms.fields.string()});
var f = forms.create({ field1: forms.fields.string() });
f.bind = function () {
t.ok(true, 'bind called');
f.fields.field1.error = 'some error';
Expand All @@ -329,7 +329,7 @@ test('handle error', function (t) {
t.ok(true, 'validate called');
callback(null, f);
};
f.handle({foo: 'bar'}, {
f.handle({ foo: 'bar' }, {
empty: function () {
t.fail('empty should not be called');
},
Expand All @@ -354,7 +354,7 @@ test('handle error', function (t) {

test('handle ServerRequest GET', function (t) {
t.plan(1);
var f = forms.create({field1: forms.fields.string()}),
var f = forms.create({ field1: forms.fields.string() }),
req = new http.IncomingMessage();
req.method = 'GET';
req.url = '/?field1=test';
Expand All @@ -368,9 +368,9 @@ test('handle ServerRequest GET', function (t) {

test('handle ServerRequest POST', function (t) {
t.plan(1);
var f = forms.create({field1: forms.fields.string()}),
var f = forms.create({ field1: forms.fields.string() }),
req = new http.IncomingMessage();
req.body = {field1: 'test'};
req.body = { field1: 'test' };
req.method = 'POST';
f.handle(req, {
success: function (form) {
Expand Down Expand Up @@ -422,9 +422,9 @@ test('validates past first error with validatePastFirstError option', function (

test('handle ServerRequest POST with bodyDecoder', function (t) {
t.plan(1);
var f = forms.create({field1: forms.fields.string()}),
var f = forms.create({ field1: forms.fields.string() }),
req = new http.IncomingMessage();
req.body = {field1: 'test'};
req.body = { field1: 'test' };
req.method = 'POST';
f.handle(req, {
success: function (form) {
Expand All @@ -435,7 +435,7 @@ test('handle ServerRequest POST with bodyDecoder', function (t) {
});

test('div', function (t) {
var f = forms.create({fieldname: forms.fields.string()});
var f = forms.create({ fieldname: forms.fields.string() });
t.equal(
f.toHTML(),
'<div class="field">' +
Expand All @@ -448,7 +448,7 @@ test('div', function (t) {

test('div required', function (t) {
var f = forms.create({
fieldname: forms.fields.string({required: true})
fieldname: forms.fields.string({ required: true })
});
t.equal(
f.toHTML(),
Expand All @@ -462,8 +462,8 @@ test('div required', function (t) {

test('div bound', function (t) {
t.plan(1);
var form = forms.create({name: forms.fields.string()});
form.bind({name: 'val'}).validate(function (err, f) {
var form = forms.create({ name: forms.fields.string() });
form.bind({ name: 'val' }).validate(function (err, f) {
t.equal(
f.toHTML(),
'<div class="field">' +
Expand Down

0 comments on commit 402edd7

Please sign in to comment.