Skip to content

Commit

Permalink
[Refactor] since default doesn’t do anything, ensure that defaults …
Browse files Browse the repository at this point in the history
…are correct
  • Loading branch information
ljharb committed Feb 24, 2018
1 parent 9b16cab commit df6ec46
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
18 changes: 10 additions & 8 deletions lib/rules/button-has-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function isCreateElement(node) {
// Rule Definition
// ------------------------------------------------------------------------------

const optionDefaults = {
button: true,
submit: true,
reset: true
};

module.exports = {
meta: {
docs: {
Expand All @@ -35,15 +41,15 @@ module.exports = {
type: 'object',
properties: {
button: {
default: true,
default: optionDefaults.button,
type: 'boolean'
},
submit: {
default: true,
default: optionDefaults.submit,
type: 'boolean'
},
reset: {
default: true,
default: optionDefaults.reset,
type: 'boolean'
}
},
Expand All @@ -52,11 +58,7 @@ module.exports = {
},

create: function(context) {
const configuration = Object.assign({
button: true,
submit: true,
reset: true
}, context.options[0]);
const configuration = Object.assign({}, optionDefaults, context.options[0]);

function reportMissing(node) {
context.report({
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ module.exports = {
{
type: 'object',
properties: {
props: {enum: OPTION_VALUES, default: OPTION_NEVER},
children: {enum: OPTION_VALUES, default: OPTION_NEVER}
props: {enum: OPTION_VALUES, default: DEFAULT_CONFIG.props},
children: {enum: OPTION_VALUES, default: DEFAULT_CONFIG.children}
},
additionalProperties: false
},
Expand Down
27 changes: 9 additions & 18 deletions lib/rules/jsx-tag-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

const has = require('has');
const getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');
const docsUrl = require('../util/docsUrl');

Expand Down Expand Up @@ -219,6 +218,13 @@ function validateBeforeClosing(context, node, option) {
// Rule Definition
// ------------------------------------------------------------------------------

const optionDefaults = {
closingSlash: 'never',
beforeSelfClosing: 'always',
afterOpening: 'never',
beforeClosing: 'allow'
};

module.exports = {
meta: {
docs: {
Expand All @@ -245,28 +251,13 @@ module.exports = {
enum: ['always', 'never', 'allow']
}
},
default: {
closingSlash: 'never',
beforeSelfClosing: 'always',
afterOpening: 'never',
beforeClosing: 'allow'
},
default: optionDefaults,
additionalProperties: false
}
]
},
create: function (context) {
const options = {
closingSlash: 'never',
beforeSelfClosing: 'always',
afterOpening: 'never',
beforeClosing: 'allow'
};
for (const key in options) {
if (has(options, key) && has(context.options[0] || {}, key)) {
options[key] = context.options[0][key];
}
}
const options = Object.assign({}, optionDefaults, context.options[0]);

return {
JSXOpeningElement: function (node) {
Expand Down
8 changes: 5 additions & 3 deletions lib/rules/self-closing-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const docsUrl = require('../util/docsUrl');
// Rule Definition
// ------------------------------------------------------------------------------

const optionDefaults = {component: true, html: true};

module.exports = {
meta: {
docs: {
Expand All @@ -24,11 +26,11 @@ module.exports = {
type: 'object',
properties: {
component: {
default: true,
default: optionDefaults.component,
type: 'boolean'
},
html: {
default: true,
default: optionDefaults.html,
type: 'boolean'
}
},
Expand Down Expand Up @@ -58,7 +60,7 @@ module.exports = {
}

function isShouldBeSelfClosed(node) {
const configuration = context.options[0] || {component: true, html: true};
const configuration = Object.assign({}, optionDefaults, context.options[0]);
return (
configuration.component && isComponent(node) ||
configuration.html && isTagName(node.name.name)
Expand Down

0 comments on commit df6ec46

Please sign in to comment.