Skip to content

Commit

Permalink
Merge branch 'master' into noUsedProps
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Suvorova authored and Diana Suvorova committed Jul 21, 2017
2 parents 430a89f + ac72383 commit 64e837b
Show file tree
Hide file tree
Showing 52 changed files with 267 additions and 325 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"guard-for-in": 2,
"no-alert": 2,
"no-caller": 2,
"no-confusing-arrow": 2,
"no-div-regex": 2,
"no-else-return": 2,
"no-eq-null": 2,
Expand Down Expand Up @@ -81,6 +82,7 @@
"no-void": 0,
"no-warning-comments": 2,
"no-with": 2,
"prefer-arrow-callback": 2,
"radix": 2,
"vars-on-top": 0,
"wrap-iife": 2,
Expand All @@ -105,6 +107,9 @@
"indent": [2, 2, {
"SwitchCase": 1
}],
"arrow-body-style": [2, "as-needed"],
"arrow-parens": [2, "as-needed"],
"arrow-spacing": 2,
"brace-style": 2,
"camelcase": 0,
"comma-spacing": 2,
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/default-props-match-prop-types.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce all defaultProps have a corresponding non-required PropType (default-props-match-prop-types)
# Enforce all defaultProps have a corresponding non-required PropType (react/default-props-match-prop-types)

This rule aims to ensure that any `defaultProp` has a non-required `PropType` declaration.

Expand Down Expand Up @@ -154,7 +154,7 @@ NotAComponent.propTypes = {

```js
...
"default-props-match-prop-types": [<enabled>, { "allowRequiredDefaults": <boolean> }]
"react/default-props-match-prop-types": [<enabled>, { "allowRequiredDefaults": <boolean> }]
...
```

Expand Down
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ function configureAsError(rules) {
return result;
}

const activeRules = filterRules(allRules, function(rule) {
return !rule.meta.deprecated;
});
const activeRules = filterRules(allRules, rule => !rule.meta.deprecated);
const activeRulesConfig = configureAsError(activeRules);

const deprecatedRules = filterRules(allRules, function(rule) {
return rule.meta.deprecated;
});
const deprecatedRules = filterRules(allRules, rule => rule.meta.deprecated);

module.exports = {
deprecatedRules: deprecatedRules,
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
}]
},

create: Components.detect(function(context, components, utils) {
create: Components.detect((context, components, utils) => {
const sourceCode = context.getSourceCode();
const config = context.options[0] || {};
const rule = config.rule ? new RegExp(config.rule) : null;
Expand Down Expand Up @@ -118,7 +118,7 @@ module.exports = {
const component = components.get(node) || node;
const invalidProps = component.invalidProps || [];

proptypes.forEach(function (prop) {
proptypes.forEach(prop => {
const propKey = getPropKey(prop);
const flowCheck = (
prop.type === 'ObjectTypeProperty' &&
Expand Down Expand Up @@ -146,7 +146,7 @@ module.exports = {
* @param {Object} component The component to process
*/
function reportInvalidNaming(component) {
component.invalidProps.forEach(function (propNode) {
component.invalidProps.forEach(propNode => {
const propName = getPropName(propNode);
context.report({
node: propNode,
Expand Down Expand Up @@ -192,7 +192,7 @@ module.exports = {
}

// Search for the proptypes declaration
node.properties.forEach(function(property) {
node.properties.forEach(property => {
if (!isPropTypesDeclaration(property.key)) {
return;
}
Expand All @@ -213,7 +213,7 @@ module.exports = {
}

const list = components.list();
Object.keys(list).forEach(function (component) {
Object.keys(list).forEach(component => {
// If this is a functional component that uses a global type, check it
if (
list[component].node.type === 'FunctionDeclaration' &&
Expand Down
44 changes: 18 additions & 26 deletions lib/rules/default-props-match-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
}]
},

create: Components.detect(function(context, components, utils) {
create: Components.detect((context, components, utils) => {
const configuration = context.options[0] || {};
const allowRequiredDefaults = configuration.allowRequiredDefaults || false;
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
Expand Down Expand Up @@ -91,7 +91,7 @@ module.exports = {
* @returns {ASTNode|null} Return null if the variable could not be found, ASTNode otherwise.
*/
function findVariableByName(name) {
const variable = variableUtil.variablesInScope(context).find((item) => item.name === name);
const variable = variableUtil.variablesInScope(context).find(item => item.name === name);

if (!variable || !variable.defs[0] || !variable.defs[0].node) {
return null;
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = {

function resolveUnionTypeAnnotation(node) {
// Go through all the union and resolve any generic types.
return node.types.map(function(annotation) {
return node.types.map(annotation => {
if (annotation.type === 'GenericTypeAnnotation') {
return resolveGenericTypeAnnotation(annotation);
}
Expand All @@ -154,17 +154,13 @@ module.exports = {
* @returns {Object[]} Array of PropType object representations, to be consumed by `addPropTypesToComponent`.
*/
function getPropTypesFromObjectExpression(objectExpression) {
const props = objectExpression.properties.filter(function(property) {
return property.type !== 'ExperimentalSpreadProperty';
});
const props = objectExpression.properties.filter(property => property.type !== 'ExperimentalSpreadProperty');

return props.map(function(property) {
return {
name: property.key.name,
isRequired: isRequiredPropType(property.value),
node: property
};
});
return props.map(property => ({
name: property.key.name,
isRequired: isRequiredPropType(property.value),
node: property
}));
}

/**
Expand All @@ -188,7 +184,7 @@ module.exports = {

case 'UnionTypeAnnotation':
const union = resolveUnionTypeAnnotation(node.typeAnnotation);
properties = union.reduce(function(acc, curr) {
properties = union.reduce((acc, curr) => {
if (!curr) {
return acc;
}
Expand All @@ -206,11 +202,9 @@ module.exports = {
break;
}

const props = properties.filter(function(property) {
return property.type === 'ObjectTypeProperty';
});
const props = properties.filter(property => property.type === 'ObjectTypeProperty');

return props.map(function(property) {
return props.map(property => {
// the `key` property is not present in ObjectTypeProperty nodes, so we need to get the key name manually.
const tokens = context.getFirstTokens(property, 1);
const name = tokens[0].value;
Expand All @@ -237,12 +231,10 @@ module.exports = {
return 'unresolved';
}

return objectExpression.properties.map(function(defaultProp) {
return {
name: defaultProp.key.name,
node: defaultProp
};
});
return objectExpression.properties.map(defaultProp => ({
name: defaultProp.key.name,
node: defaultProp
}));
}

/**
Expand Down Expand Up @@ -348,7 +340,7 @@ module.exports = {
return;
}

defaultProps.forEach(function(defaultProp) {
defaultProps.forEach(defaultProp => {
const prop = propFromName(propTypes, defaultProp.name);

if (prop && (allowRequiredDefaults || !prop.isRequired)) {
Expand Down Expand Up @@ -567,7 +559,7 @@ module.exports = {
}

// Search for the proptypes declaration
node.properties.forEach(function(property) {
node.properties.forEach(property => {
if (property.type === 'ExperimentalSpreadProperty') {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
}]
},

create: Components.detect(function(context, components, utils) {
create: Components.detect((context, components, utils) => {
const sourceCode = context.getSourceCode();
const config = context.options[0] || {};
const ignoreTranspilerName = config.ignoreTranspilerName || false;
Expand Down Expand Up @@ -209,7 +209,7 @@ module.exports = {
ObjectExpression: function(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
// Search for the displayName declaration
node.properties.forEach(function(property) {
node.properties.forEach(property => {
if (!property.key || !isDisplayNameDeclaration(property.key)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {

const indexedForbidConfigs = {};

forbidConfiguration.forEach(function(item) {
forbidConfiguration.forEach(item => {
if (typeof item === 'string') {
indexedForbidConfigs[item] = {element: item};
} else {
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/forbid-foreign-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ module.exports = {
},

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

if (propTypesNode) {
context.report({
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
* @returns {void}
*/
function checkForbidden(declarations) {
declarations.forEach(function(declaration) {
declarations.forEach(declaration => {
if (declaration.type !== 'Property') {
return;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ module.exports = {
},

ObjectExpression: function(node) {
node.properties.forEach(function(property) {
node.properties.forEach(property => {
if (!property.key) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-boolean-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const NEVER = 'never';
const errorData = new WeakMap();
function getErrorData(exceptions) {
if (!errorData.has(exceptions)) {
const exceptionProps = Array.from(exceptions, (name) => `\`${name}\``).join(', ');
const exceptionProps = Array.from(exceptions, name => `\`${name}\``).join(', ');
const exceptionsMessage = exceptions.size > 0 ? ` for the following props: ${exceptionProps}` : '';
errorData.set(exceptions, {exceptionsMessage: exceptionsMessage});
}
Expand Down
64 changes: 33 additions & 31 deletions lib/rules/jsx-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
},
fixable: 'code',

schema: [{
schema: {
definitions: {
basicConfig: {
type: 'object',
Expand Down Expand Up @@ -60,41 +60,43 @@ module.exports = {
}]
}
},

oneOf: [{
allOf: [{
$ref: '#/definitions/basicConfig'
}, {
type: 'object',
properties: {
attributes: {
$ref: '#/definitions/basicConfigOrBoolean'
},
children: {
$ref: '#/definitions/basicConfigOrBoolean'
type: 'array',
items: [{
oneOf: [{
allOf: [{
$ref: '#/definitions/basicConfig'
}, {
type: 'object',
properties: {
attributes: {
$ref: '#/definitions/basicConfigOrBoolean'
},
children: {
$ref: '#/definitions/basicConfigOrBoolean'
}
}
}
}]
}, {
enum: SPACING_VALUES
}]
}, {
enum: SPACING_VALUES
}]
}, {
type: 'object',
properties: {
allowMultiline: {
type: 'boolean'
},
spacing: {
type: 'object',
properties: {
objectLiterals: {
enum: SPACING_VALUES
type: 'object',
properties: {
allowMultiline: {
type: 'boolean'
},
spacing: {
type: 'object',
properties: {
objectLiterals: {
enum: SPACING_VALUES
}
}
}
}
},
additionalProperties: false
}]
},
additionalProperties: false
}]
}
},

create: function(context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-equals-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {

return {
JSXOpeningElement: function(node) {
node.attributes.forEach(function(attrNode) {
node.attributes.forEach(attrNode => {
if (!hasEqual(attrNode)) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/jsx-filename-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ module.exports = {
}

const allowedExtensions = getExtensionsConfig();
const isAllowedExtension = allowedExtensions.some(function (extension) {
return filename.slice(-extension.length) === extension;
});
const isAllowedExtension = allowedExtensions.some(extension => filename.slice(-extension.length) === extension);

if (isAllowedExtension) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-first-prop-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
(configuration === 'multiline-multiprop' && isMultilineJSX(node) && node.attributes.length > 1) ||
(configuration === 'always')
) {
node.attributes.some(function(decl) {
node.attributes.some(decl => {
if (decl.loc.start.line === node.loc.start.line) {
context.report({
node: decl,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = {
* @param {Boolean} excludeCommas skip comma on start of line
*/
function checkNodesIndent(nodes, indent, excludeCommas) {
nodes.forEach(function(node) {
nodes.forEach(node => {
const nodeIndent = getNodeIndent(node, false, excludeCommas);
if (
node.type !== 'ArrayExpression' && node.type !== 'ObjectExpression' &&
Expand Down

0 comments on commit 64e837b

Please sign in to comment.