Skip to content

Commit

Permalink
[eslint] fix func-names and change object-shorthand to 'always'
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Nov 1, 2019
1 parent 8093565 commit 0dd8d11
Show file tree
Hide file tree
Showing 28 changed files with 59 additions and 57 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -16,6 +16,7 @@
"rules": {
"comma-dangle": [2, "never"],
"object-curly-spacing": [2, "never"],
"object-shorthand": [2, "always"],
"array-bracket-spacing": [2, "never"],
"max-len": [2, 120, {
"ignoreStrings": true,
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/boolean-prop-naming.js
Expand Up @@ -282,7 +282,8 @@ module.exports = {
}
},

'Program:exit': function () {
// eslint-disable-next-line object-shorthand
'Program:exit'() {
if (!rule) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/default-props-match-prop-types.js
Expand Up @@ -80,7 +80,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
'Program:exit': function () {
'Program:exit'() {
const list = components.list();

// If no defaultProps could be found, we don't report anything.
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/display-name.js
Expand Up @@ -227,7 +227,7 @@ module.exports = {
}
},

'Program:exit': function () {
'Program:exit'() {
const list = components.list();
// Report missing display name for all components
Object.keys(list).filter(component => !list[component].hasDisplayName).forEach((component) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-closing-bracket-location.js
Expand Up @@ -236,7 +236,7 @@ module.exports = {
lastAttributeNode[getOpeningElementId(node.parent)] = node;
},

'JSXOpeningElement:exit': function (node) {
'JSXOpeningElement:exit'(node) {
const attributeNode = lastAttributeNode[getOpeningElementId(node)];
const cachedLastAttributeEndPos = attributeNode ? attributeNode.range[1] : null;
let expectedNextLine;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-filename-extension.js
Expand Up @@ -80,7 +80,7 @@ module.exports = {
JSXElement: handleJSX,
JSXFragment: handleJSX,

'Program:exit': function () {
'Program:exit'() {
if (!invalidNode) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/jsx-fragments.js
Expand Up @@ -58,7 +58,7 @@ module.exports = {

function getFixerToLong(jsxFragment) {
const sourceCode = context.getSourceCode();
return function (fixer) {
return function fix(fixer) {
let source = sourceCode.getText();
source = replaceNode(source, jsxFragment.closingFragment, closeFragLong);
source = replaceNode(source, jsxFragment.openingFragment, openFragLong);
Expand All @@ -71,7 +71,7 @@ module.exports = {

function getFixerToShort(jsxElement) {
const sourceCode = context.getSourceCode();
return function (fixer) {
return function fix(fixer) {
let source = sourceCode.getText();
let lengthDiff;
if (jsxElement.closingElement) {
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports = {
}
},

'Program:exit': function () {
'Program:exit'() {
jsxElements.forEach((node) => {
const openingEl = node.openingElement;
const elName = elementType(openingEl);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent.js
Expand Up @@ -95,7 +95,7 @@ module.exports = {
* @private
*/
function getFixerFunction(node, needed) {
return function (fixer) {
return function fix(fixer) {
const indent = Array(needed + 1).join(indentChar);
return fixer.replaceTextRange(
[node.range[0] - node.loc.start.column, node.range[0]],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-max-props-per-line.js
Expand Up @@ -62,7 +62,7 @@ module.exports = {
}, ''));
}
const code = output.join('\n');
return function (fixer) {
return function fix(fixer) {
return fixer.replaceTextRange([front, back], code);
};
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/jsx-sort-props.js
Expand Up @@ -132,7 +132,7 @@ const generateFixerFunction = (node, context, reservedList) => {
.slice(0)
.map(group => group.slice(0).sort((a, b) => contextCompare(a, b, options)));

return function (fixer) {
return function fixFunction(fixer) {
const fixers = [];
let source = sourceCode.getText();

Expand Down Expand Up @@ -178,15 +178,15 @@ function validateReservedFirstConfig(context, reservedFirst) {
));

if (reservedFirst.length === 0) {
return function (decl) {
return function report(decl) {
context.report({
node: decl,
message: 'A customized reserved first list must not be empty'
});
};
}
if (nonReservedWords.length > 0) {
return function (decl) {
return function report(decl) {
context.report({
node: decl,
message: 'A customized reserved first list must only contain a subset of React reserved props.' +
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-array-index-key.js
Expand Up @@ -213,7 +213,7 @@ module.exports = {
checkPropValue(value.expression);
},

'CallExpression:exit': function (node) {
'CallExpression:exit'(node) {
const mapIndexParamName = getMapIndexParamName(node);
if (!mapIndexParamName) {
return;
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-direct-mutation-state.js
Expand Up @@ -119,21 +119,21 @@ module.exports = {
}
},

'CallExpression:exit': function (node) {
'CallExpression:exit'(node) {
components.set(node, {
inCallExpression: false
});
},

'MethodDefinition:exit': function (node) {
'MethodDefinition:exit'(node) {
if (node.kind === 'constructor') {
components.set(node, {
inConstructor: false
});
}
},

'Program:exit': function () {
'Program:exit'() {
const list = components.list();

Object.keys(list).forEach((key) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-multi-comp.js
Expand Up @@ -58,7 +58,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
'Program:exit': function () {
'Program:exit'() {
if (components.length() <= 1) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-set-state.js
Expand Up @@ -72,7 +72,7 @@ module.exports = {
});
},

'Program:exit': function () {
'Program:exit'() {
const list = components.list();
Object.keys(list).filter(component => !isValid(list[component])).forEach((component) => {
reportSetStateUsages(list[component]);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unescaped-entities.js
Expand Up @@ -109,7 +109,7 @@ module.exports = {
}

return {
'Literal, JSXText': function (node) {
'Literal, JSXText'(node) {
if (jsxUtil.isJSX(node.parent)) {
reportInvalidEntity(node);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unused-prop-types.js
Expand Up @@ -131,7 +131,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
'Program:exit': function () {
'Program:exit'() {
const list = components.list();
// Report undeclared proptypes for all classes
Object.keys(list).filter(component => mustBeValidated(list[component])).forEach((component) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/no-unused-state.js
Expand Up @@ -231,7 +231,7 @@ module.exports = {
}
},

'ObjectExpression:exit': function (node) {
'ObjectExpression:exit'(node) {
if (!classInfo) {
return;
}
Expand All @@ -242,7 +242,7 @@ module.exports = {
}
},

'ClassDeclaration:exit': function () {
'ClassDeclaration:exit'() {
if (!classInfo) {
return;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ module.exports = {
}
},

'ClassProperty:exit': function (node) {
'ClassProperty:exit'(node) {
if (
classInfo &&
!node.static &&
Expand All @@ -326,7 +326,7 @@ module.exports = {
classInfo.aliases = new Set();
},

'MethodDefinition:exit': function () {
'MethodDefinition:exit'() {
if (!classInfo) {
return;
}
Expand Down Expand Up @@ -422,7 +422,7 @@ module.exports = {
}
},

'ExperimentalSpreadProperty, SpreadElement': function (node) {
'ExperimentalSpreadProperty, SpreadElement'(node) {
if (classInfo && isStateReference(node.argument)) {
classInfo = null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-read-only-props.js
Expand Up @@ -33,7 +33,7 @@ module.exports = {
},

create: Components.detect((context, components) => ({
'Program:exit': function () {
'Program:exit'() {
const list = components.list();

Object.keys(list).forEach((key) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/prefer-stateless-function.js
Expand Up @@ -196,21 +196,21 @@ module.exports = {
* Mark component as pure as declared
* @param {ASTNode} node The AST node being checked.
*/
const markSCUAsDeclared = function (node) {
function markSCUAsDeclared(node) {
components.set(node, {
hasSCU: true
});
};
}

/**
* Mark childContextTypes as declared
* @param {ASTNode} node The AST node being checked.
*/
const markChildContextTypesAsDeclared = function (node) {
function markChildContextTypesAsDeclared(node) {
components.set(node, {
hasChildContextTypes: true
});
};
}

/**
* Mark a setState as used
Expand Down Expand Up @@ -351,7 +351,7 @@ module.exports = {
markReturnAsInvalid(node);
},

'Program:exit': function () {
'Program:exit'() {
const list = components.list();
Object.keys(list).forEach((component) => {
if (
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prop-types.js
Expand Up @@ -183,7 +183,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
'Program:exit': function () {
'Program:exit'() {
const list = components.list();
// Report undeclared proptypes for all classes
Object.keys(list).filter(component => mustBeValidated(list[component])).forEach((component) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-default-props.js
Expand Up @@ -80,7 +80,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
'Program:exit': function () {
'Program:exit'() {
const list = components.list();

Object.keys(list).filter(component => list[component].declaredPropTypes).forEach((component) => {
Expand Down

0 comments on commit 0dd8d11

Please sign in to comment.