Skip to content

chore: Update eslint and peer dependencies #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "airbnb",
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"strict": [0, "global"],
"func-names": 0,
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-color-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const util = require('util');
const Components = require('../util/Components');
const styleSheet = require('../util/stylesheet');

const StyleSheets = styleSheet.StyleSheets;
const astHelpers = styleSheet.astHelpers;
const { StyleSheets } = styleSheet;
const { astHelpers } = styleSheet;

module.exports = Components.detect((context) => {
const styleSheets = new StyleSheets();
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-inline-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const util = require('util');
const Components = require('../util/Components');
const styleSheet = require('../util/stylesheet');

const StyleSheets = styleSheet.StyleSheets;
const astHelpers = styleSheet.astHelpers;
const { StyleSheets } = styleSheet;
const { astHelpers } = styleSheet;

module.exports = Components.detect((context) => {
const styleSheets = new StyleSheets();
Expand Down
26 changes: 13 additions & 13 deletions lib/rules/no-raw-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
module.exports = (context) => {
const options = context.options[0] || {};

const elementName = node => (
node.openingElement &&
node.openingElement.name &&
node.openingElement.name.type === 'JSXIdentifier' &&
node.openingElement.name.name
const elementName = (node) => (
node.openingElement
&& node.openingElement.name
&& node.openingElement.name.type === 'JSXIdentifier'
&& node.openingElement.name.name
);

const report = (node) => {
Expand All @@ -33,18 +33,18 @@ module.exports = (context) => {
const skippedElements = options.skip ? options.skip : [];
const allowedElements = ['Text', 'TSpan', 'StyledText', 'Animated.Text'].concat(skippedElements);

const hasOnlyLineBreak = value => /^[\r\n\t\f\v]+$/.test(value.replace(/ /g, ''));
const hasOnlyLineBreak = (value) => /^[\r\n\t\f\v]+$/.test(value.replace(/ /g, ''));

const getValidation = node => !allowedElements.includes(elementName(node.parent));
const getValidation = (node) => !allowedElements.includes(elementName(node.parent));

return {
Literal(node) {
const parentType = node.parent.type;
const onlyFor = ['JSXExpressionContainer', 'JSXElement'];
if (typeof node.value !== 'string' ||
hasOnlyLineBreak(node.value) ||
!onlyFor.includes(parentType) ||
(node.parent.parent && node.parent.parent.type === 'JSXAttribute')
if (typeof node.value !== 'string'
|| hasOnlyLineBreak(node.value)
|| !onlyFor.includes(parentType)
|| (node.parent.parent && node.parent.parent.type === 'JSXAttribute')
) return;

const isStringLiteral = parentType === 'JSXExpressionContainer';
Expand All @@ -62,8 +62,8 @@ module.exports = (context) => {

TemplateLiteral(node) {
if (
node.parent.type !== 'JSXExpressionContainer' ||
(node.parent.parent && node.parent.parent.type === 'JSXAttribute')
node.parent.type !== 'JSXExpressionContainer'
|| (node.parent.parent && node.parent.parent.type === 'JSXAttribute')
) return;

if (getValidation(node.parent)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-unused-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
const Components = require('../util/Components');
const styleSheet = require('../util/stylesheet');

const StyleSheets = styleSheet.StyleSheets;
const astHelpers = styleSheet.astHelpers;
const { StyleSheets } = styleSheet;
const { astHelpers } = styleSheet;

module.exports = Components.detect((context, components) => {
const styleSheets = new StyleSheets();
Expand Down
15 changes: 7 additions & 8 deletions lib/rules/sort-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const {
module.exports = (context) => {
const order = context.options[0] || 'asc';
const options = context.options[1] || {};
const ignoreClassNames = options.ignoreClassNames;
const ignoreStyleProperties = options.ignoreStyleProperties;
const { ignoreClassNames } = options;
const { ignoreStyleProperties } = options;
const isValidOrder = order === 'asc' ? (a, b) => a <= b : (a, b) => a >= b;

const sourceCode = context.getSourceCode();
Expand All @@ -40,7 +40,7 @@ module.exports = (context) => {
let sortOrder = 0;
if (isEitherShortHand(identifierA, identifierB)) {
return a.range[0] - b.range[0];
} else if (identifierA < identifierB) {
} if (identifierA < identifierB) {
sortOrder = -1;
} else if (identifierA > identifierB) {
sortOrder = 1;
Expand All @@ -53,10 +53,9 @@ module.exports = (context) => {
const currentName = getStylePropertyIdentifier(current);
const prevName = getStylePropertyIdentifier(prev);
const hasComments = array
.map(prop => sourceCode.getComments(prop))
.map((prop) => sourceCode.getComments(prop))
.reduce(
(hasComment, comment) =>
hasComment || comment.leading.length > 0 || comment.trailing > 0,
(hasComment, comment) => hasComment || comment.leading.length > 0 || comment.trailing > 0,
false
);

Expand Down Expand Up @@ -94,8 +93,8 @@ module.exports = (context) => {
const currentName = getStylePropertyIdentifier(current);

if (
arrayName === 'style properties' &&
isEitherShortHand(prevName, currentName)
arrayName === 'style properties'
&& isEitherShortHand(prevName, currentName)
) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/split-platform-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (context) {
if (node.type === 'Property') {
const key = node.key || node.argument;
return key.type === 'Identifier' ? key.name : key.value;
} else if (node.type === 'Identifier') {
} if (node.type === 'Identifier') {
return node.name;
}
}
Expand All @@ -36,8 +36,8 @@ module.exports = function (context) {

function reportErrors(components, filename) {
const containsAndroidAndIOS = (
hasNodeWithName(components, 'IOS') &&
hasNodeWithName(components, 'Android')
hasNodeWithName(components, 'IOS')
&& hasNodeWithName(components, 'Android')
);

components.forEach((node) => {
Expand Down
39 changes: 18 additions & 21 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Components.prototype.set = function (node, props) {
return;
}
const id = this.getId(currentNode);
this.list[id] = Object.assign({}, this.list[id], props);
this.list[id] = { ...this.list[id], ...props };
};

/**
Expand Down Expand Up @@ -151,17 +151,12 @@ function componentRule(rule, context) {
return false;
}

const returnsJSX =
node[property] &&
node[property].type === 'JSXElement'
;
const returnsReactCreateElement =
node[property] &&
node[property].callee &&
node[property].callee.property &&
node[property].callee.property.name === 'createElement'
;

const returnsJSX = node[property]
&& node[property].type === 'JSXElement';
const returnsReactCreateElement = node[property]
&& node[property].callee
&& node[property].callee.property
&& node[property].callee.property.name === 'createElement';
return Boolean(returnsJSX || returnsReactCreateElement);
},

Expand All @@ -172,9 +167,9 @@ function componentRule(rule, context) {
*/
getParentComponent: function () {
return (
utils.getParentES6Component() ||
utils.getParentES5Component() ||
utils.getParentStatelessComponent()
utils.getParentES6Component()
|| utils.getParentES5Component()
|| utils.getParentStatelessComponent()
);
},

Expand All @@ -184,6 +179,7 @@ function componentRule(rule, context) {
* @returns {ASTNode} component node, null if we are not in a component
*/
getParentES5Component: function () {
// eslint-disable-next-line react/destructuring-assignment
let scope = context.getScope();
while (scope) {
const node = scope.block && scope.block.parent && scope.block.parent.parent;
Expand Down Expand Up @@ -218,6 +214,7 @@ function componentRule(rule, context) {
* @returns {ASTNode} component node, null if we are not in a component
*/
getParentStatelessComponent: function () {
// eslint-disable-next-line react/destructuring-assignment
let scope = context.getScope();
while (scope) {
const node = scope.block;
Expand Down Expand Up @@ -266,7 +263,7 @@ function componentRule(rule, context) {
return null;
}
let variableInScope;
const variables = context.getScope().variables;
const { variables } = context.getScope();
for (i = 0, j = variables.length; i < j; i++) { // eslint-disable-line no-plusplus
if (variables[i].name === variableName) {
variableInScope = variables[i];
Expand All @@ -279,12 +276,12 @@ function componentRule(rule, context) {

// Find the variable declaration
let defInScope;
const defs = variableInScope.defs;
const { defs } = variableInScope;
for (i = 0, j = defs.length; i < j; i++) { // eslint-disable-line no-plusplus
if (
defs[i].type === 'ClassName' ||
defs[i].type === 'FunctionName' ||
defs[i].type === 'Variable'
defs[i].type === 'ClassName'
|| defs[i].type === 'FunctionName'
|| defs[i].type === 'Variable'
) {
defInScope = defs[i];
break;
Expand Down Expand Up @@ -392,7 +389,7 @@ function componentRule(rule, context) {

// Update the provided rule instructions to add the component detection
const ruleInstructions = rule(context, components, utils);
const updatedRuleInstructions = Object.assign({}, ruleInstructions);
const updatedRuleInstructions = { ...ruleInstructions };
Object.keys(detectionInstructions).forEach((instruction) => {
updatedRuleInstructions[instruction] = (node) => {
detectionInstructions[instruction](node);
Expand Down
Loading