Skip to content

Commit

Permalink
[eslint] enable and autofix object-shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 19, 2019
1 parent e14f2b8 commit 28914aa
Show file tree
Hide file tree
Showing 99 changed files with 598 additions and 599 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],

"object-shorthand": 1,
"import/order": 1,
"no-useless-escape": 1,
"import/newline-after-import": 1,
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const activeRulesConfig = configureAsError(activeRules);
const deprecatedRules = filterRules(allRules, rule => rule.meta.deprecated);

module.exports = {
deprecatedRules: deprecatedRules,
deprecatedRules,
rules: allRules,
configs: {
recommended: {
Expand Down
12 changes: 6 additions & 6 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = {
});

components.set(node, {
invalidProps: invalidProps
invalidProps
});
}

Expand All @@ -197,7 +197,7 @@ module.exports = {
message: config.message || 'Prop name ({{ propName }}) doesn\'t match rule ({{ pattern }})',
data: {
component: propName,
propName: propName,
propName,
pattern: config.rule
}
});
Expand All @@ -216,7 +216,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
ClassProperty: function (node) {
ClassProperty(node) {
if (!rule || !propsUtil.isPropTypesDeclaration(node)) {
return;
}
Expand All @@ -231,7 +231,7 @@ module.exports = {
}
},

MemberExpression: function (node) {
MemberExpression(node) {
if (!rule || !propsUtil.isPropTypesDeclaration(node)) {
return;
}
Expand All @@ -247,7 +247,7 @@ module.exports = {
validatePropNaming(component.node, node.parent.right.properties);
},

ObjectExpression: function (node) {
ObjectExpression(node) {
if (!rule) {
return;
}
Expand All @@ -261,7 +261,7 @@ module.exports = {
});
},

TypeAlias: function (node) {
TypeAlias(node) {
// Cache all ObjectType annotations, we will check them at the end
if (node.right.type === 'ObjectTypeAnnotation') {
objectTypeAnnotations.set(node.id.name, node.right);
Expand Down
12 changes: 6 additions & 6 deletions lib/rules/button-has-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ module.exports = {
}]
},

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

function reportMissing(node) {
context.report({
node: node,
node,
message: 'Missing an explicit type attribute for button'
});
}
Expand All @@ -76,19 +76,19 @@ module.exports = {
const q = quoteFn || (x => `"${x}"`);
if (!(value in configuration)) {
context.report({
node: node,
node,
message: `${q(value)} is an invalid value for button type attribute`
});
} else if (!configuration[value]) {
context.report({
node: node,
node,
message: `${q(value)} is a forbidden value for button type attribute`
});
}
}

return {
JSXElement: function (node) {
JSXElement(node) {
if (node.openingElement.name.name !== 'button') {
return;
}
Expand All @@ -107,7 +107,7 @@ module.exports = {
checkValue(node, propValue);
}
},
CallExpression: function (node) {
CallExpression(node) {
if (!isCreateElement(node, context)) {
return;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ module.exports = {

if (destructuringProps && components.get(node) && configuration === 'never') {
context.report({
node: node,
node,
message: 'Must never use destructuring props assignment in SFC argument'
});
} else if (destructuringContext && components.get(node) && configuration === 'never') {
context.report({
node: node,
node,
message: 'Must never use destructuring context assignment in SFC argument'
});
}
Expand All @@ -77,7 +77,7 @@ module.exports = {
const isPropUsed = (node.object.name === 'props' || node.object.name === 'context') && !isAssignmentToProp(node);
if (isPropUsed && configuration === 'always') {
context.report({
node: node,
node,
message: `Must use destructuring ${node.object.name} assignment`
});
}
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports = {
!(ignoreClassFields && isInClassProperty(node))
) {
context.report({
node: node,
node,
message: `Must use destructuring ${node.object.property.name} assignment`
});
}
Expand All @@ -121,7 +121,7 @@ module.exports = {

FunctionExpression: handleStatelessComponent,

MemberExpression: function (node) {
MemberExpression(node) {
const SFCComponent = components.get(context.getScope(node).block);
const classComponent = utils.getParentComponent(node);
if (SFCComponent) {
Expand All @@ -132,7 +132,7 @@ module.exports = {
}
},

VariableDeclarator: function (node) {
VariableDeclarator(node) {
const classComponent = utils.getParentComponent(node);
const SFCComponent = components.get(context.getScope(node).block);

Expand All @@ -146,7 +146,7 @@ module.exports = {

if (SFCComponent && destructuringSFC && configuration === 'never') {
context.report({
node: node,
node,
message: `Must never use destructuring ${node.init.name} assignment`
});
}
Expand All @@ -156,7 +156,7 @@ module.exports = {
!(ignoreClassFields && node.parent.type === 'ClassProperty')
) {
context.report({
node: node,
node,
message: `Must never use destructuring ${node.init.property.name} assignment`
});
}
Expand Down
18 changes: 9 additions & 9 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ module.exports = {

return {

ClassProperty: function (node) {
ClassProperty(node) {
if (!propsUtil.isDisplayNameDeclaration(node)) {
return;
}
markDisplayNameAsDeclared(node);
},

MemberExpression: function (node) {
MemberExpression(node) {
if (!propsUtil.isDisplayNameDeclaration(node.property)) {
return;
}
Expand All @@ -140,7 +140,7 @@ module.exports = {
markDisplayNameAsDeclared(component.node);
},

FunctionExpression: function (node) {
FunctionExpression(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
Expand All @@ -149,7 +149,7 @@ module.exports = {
}
},

FunctionDeclaration: function (node) {
FunctionDeclaration(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
Expand All @@ -158,7 +158,7 @@ module.exports = {
}
},

ArrowFunctionExpression: function (node) {
ArrowFunctionExpression(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
Expand All @@ -167,28 +167,28 @@ module.exports = {
}
},

MethodDefinition: function (node) {
MethodDefinition(node) {
if (!propsUtil.isDisplayNameDeclaration(node.key)) {
return;
}
markDisplayNameAsDeclared(node);
},

ClassExpression: function (node) {
ClassExpression(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
markDisplayNameAsDeclared(node);
},

ClassDeclaration: function (node) {
ClassDeclaration(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
markDisplayNameAsDeclared(node);
},

ObjectExpression: function (node) {
ObjectExpression(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
// Search for the displayName declaration
node.properties.forEach((property) => {
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/forbid-component-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
}]
},

create: function (context) {
create(context) {
const configuration = context.options[0] || {};
const forbid = new Map((configuration.forbid || DEFAULTS).map((value) => {
const propName = typeof value === 'string' ? value : value.propName;
Expand All @@ -70,7 +70,7 @@ module.exports = {
}

return {
JSXAttribute: function (node) {
JSXAttribute(node) {
const tag = node.parent.name.name;
if (tag && tag[0] !== tag[0].toUpperCase()) {
// This is a DOM node, not a Component, so exit.
Expand All @@ -84,7 +84,7 @@ module.exports = {
}

context.report({
node: node,
node,
message: `Prop \`${prop}\` is forbidden on Components`
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/forbid-dom-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
}]
},

create: function (context) {
create(context) {
function isForbidden(prop) {
const configuration = context.options[0] || {};

Expand All @@ -51,7 +51,7 @@ module.exports = {
}

return {
JSXAttribute: function (node) {
JSXAttribute(node) {
const tag = node.parent.name.name;
if (!(tag && tag[0] !== tag[0].toUpperCase())) {
// This is a Component, not a DOM node, so exit.
Expand All @@ -65,7 +65,7 @@ module.exports = {
}

context.report({
node: node,
node,
message: `Prop \`${prop}\` is forbidden on DOM Nodes`
});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
}]
},

create: function (context) {
create(context) {
const sourceCode = context.getSourceCode();
const configuration = context.options[0] || {};
const forbidConfiguration = configuration.forbid || [];
Expand Down Expand Up @@ -83,18 +83,18 @@ module.exports = {
function reportIfForbidden(element, node) {
if (has(indexedForbidConfigs, element)) {
context.report({
node: node,
node,
message: errorMessageForElement(element)
});
}
}

return {
JSXOpeningElement: function (node) {
JSXOpeningElement(node) {
reportIfForbidden(sourceCode.getText(node.name), node.name);
},

CallExpression: function (node) {
CallExpression(node) {
if (!isValidCreateElement(node)) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/forbid-foreign-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
]
},

create: function (context) {
create(context) {
const config = context.options[0] || {};
const allowInPropTypes = config.allowInPropTypes || false;

Expand Down Expand Up @@ -94,7 +94,7 @@ module.exports = {
}

return {
MemberExpression: function (node) {
MemberExpression(node) {
if (
node.property &&
(
Expand All @@ -117,7 +117,7 @@ module.exports = {
}
},

ObjectPattern: function (node) {
ObjectPattern(node) {
const propTypesNode = node.properties.find(property => property.type === 'Property' && property.key.name === 'propTypes');

if (propTypesNode) {
Expand Down
Loading

0 comments on commit 28914aa

Please sign in to comment.