Skip to content

Commit df6ec46

Browse files
committed
[Refactor] since default doesn’t do anything, ensure that defaults are correct
1 parent 9b16cab commit df6ec46

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

lib/rules/button-has-type.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ function isCreateElement(node) {
2323
// Rule Definition
2424
// ------------------------------------------------------------------------------
2525

26+
const optionDefaults = {
27+
button: true,
28+
submit: true,
29+
reset: true
30+
};
31+
2632
module.exports = {
2733
meta: {
2834
docs: {
@@ -35,15 +41,15 @@ module.exports = {
3541
type: 'object',
3642
properties: {
3743
button: {
38-
default: true,
44+
default: optionDefaults.button,
3945
type: 'boolean'
4046
},
4147
submit: {
42-
default: true,
48+
default: optionDefaults.submit,
4349
type: 'boolean'
4450
},
4551
reset: {
46-
default: true,
52+
default: optionDefaults.reset,
4753
type: 'boolean'
4854
}
4955
},
@@ -52,11 +58,7 @@ module.exports = {
5258
},
5359

5460
create: function(context) {
55-
const configuration = Object.assign({
56-
button: true,
57-
submit: true,
58-
reset: true
59-
}, context.options[0]);
61+
const configuration = Object.assign({}, optionDefaults, context.options[0]);
6062

6163
function reportMissing(node) {
6264
context.report({

lib/rules/jsx-curly-brace-presence.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ module.exports = {
4444
{
4545
type: 'object',
4646
properties: {
47-
props: {enum: OPTION_VALUES, default: OPTION_NEVER},
48-
children: {enum: OPTION_VALUES, default: OPTION_NEVER}
47+
props: {enum: OPTION_VALUES, default: DEFAULT_CONFIG.props},
48+
children: {enum: OPTION_VALUES, default: DEFAULT_CONFIG.children}
4949
},
5050
additionalProperties: false
5151
},

lib/rules/jsx-tag-spacing.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
'use strict';
66

7-
const has = require('has');
87
const getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');
98
const docsUrl = require('../util/docsUrl');
109

@@ -219,6 +218,13 @@ function validateBeforeClosing(context, node, option) {
219218
// Rule Definition
220219
// ------------------------------------------------------------------------------
221220

221+
const optionDefaults = {
222+
closingSlash: 'never',
223+
beforeSelfClosing: 'always',
224+
afterOpening: 'never',
225+
beforeClosing: 'allow'
226+
};
227+
222228
module.exports = {
223229
meta: {
224230
docs: {
@@ -245,28 +251,13 @@ module.exports = {
245251
enum: ['always', 'never', 'allow']
246252
}
247253
},
248-
default: {
249-
closingSlash: 'never',
250-
beforeSelfClosing: 'always',
251-
afterOpening: 'never',
252-
beforeClosing: 'allow'
253-
},
254+
default: optionDefaults,
254255
additionalProperties: false
255256
}
256257
]
257258
},
258259
create: function (context) {
259-
const options = {
260-
closingSlash: 'never',
261-
beforeSelfClosing: 'always',
262-
afterOpening: 'never',
263-
beforeClosing: 'allow'
264-
};
265-
for (const key in options) {
266-
if (has(options, key) && has(context.options[0] || {}, key)) {
267-
options[key] = context.options[0][key];
268-
}
269-
}
260+
const options = Object.assign({}, optionDefaults, context.options[0]);
270261

271262
return {
272263
JSXOpeningElement: function (node) {

lib/rules/self-closing-comp.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const docsUrl = require('../util/docsUrl');
1010
// Rule Definition
1111
// ------------------------------------------------------------------------------
1212

13+
const optionDefaults = {component: true, html: true};
14+
1315
module.exports = {
1416
meta: {
1517
docs: {
@@ -24,11 +26,11 @@ module.exports = {
2426
type: 'object',
2527
properties: {
2628
component: {
27-
default: true,
29+
default: optionDefaults.component,
2830
type: 'boolean'
2931
},
3032
html: {
31-
default: true,
33+
default: optionDefaults.html,
3234
type: 'boolean'
3335
}
3436
},
@@ -58,7 +60,7 @@ module.exports = {
5860
}
5961

6062
function isShouldBeSelfClosed(node) {
61-
const configuration = context.options[0] || {component: true, html: true};
63+
const configuration = Object.assign({}, optionDefaults, context.options[0]);
6264
return (
6365
configuration.component && isComponent(node) ||
6466
configuration.html && isTagName(node.name.name)

0 commit comments

Comments
 (0)