Skip to content
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
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
// Strict Mode
"strict": [2, "global"],
// Variables
"prefer-const": 2,
"no-catch-shadow": 2,
"no-const-assign": 2,
"no-delete-var": 2,
"no-label-var": 2,
"no-shadow": 2,
Expand All @@ -98,6 +100,7 @@
"no-undefined": 2,
"no-unused-vars": 2,
"no-use-before-define": 2,
"no-var": 2,
// Stylistic Issues
"indent": [2, 2, {
"SwitchCase": 1
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

var has = require('has');
const has = require('has');

var allRules = {
const allRules = {
'jsx-uses-react': require('./lib/rules/jsx-uses-react'),
'no-multi-comp': require('./lib/rules/no-multi-comp'),
'prop-types': require('./lib/rules/prop-types'),
Expand Down Expand Up @@ -68,8 +68,8 @@ var allRules = {
};

function filterRules(rules, predicate) {
var result = {};
for (var key in rules) {
const result = {};
for (const key in rules) {
if (has(rules, key) && predicate(rules[key])) {
result[key] = rules[key];
}
Expand All @@ -78,8 +78,8 @@ function filterRules(rules, predicate) {
}

function configureAsError(rules) {
var result = {};
for (var key in rules) {
const result = {};
for (const key in rules) {
if (!has(rules, key)) {
continue;
}
Expand All @@ -88,12 +88,12 @@ function configureAsError(rules) {
return result;
}

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

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

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/default-props-match-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
create: Components.detect(function(context, components, utils) {
const configuration = context.options[0] || {};
const allowRequiredDefaults = configuration.allowRequiredDefaults || false;
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);

/**
* Get properties name
Expand Down Expand Up @@ -603,7 +603,7 @@ module.exports = {
'Program:exit': function() {
const list = components.list();

for (let component in list) {
for (const component in list) {
if (!has(list, component)) {
continue;
}
Expand Down
30 changes: 15 additions & 15 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
'use strict';

var has = require('has');
var Components = require('../util/Components');
const has = require('has');
const Components = require('../util/Components');

// ------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -31,11 +31,11 @@ module.exports = {
},

create: Components.detect(function(context, components, utils) {
var sourceCode = context.getSourceCode();
var config = context.options[0] || {};
var ignoreTranspilerName = config.ignoreTranspilerName || false;
const sourceCode = context.getSourceCode();
const config = context.options[0] || {};
const ignoreTranspilerName = config.ignoreTranspilerName || false;

var MISSING_MESSAGE = 'Component definition is missing display name';
const MISSING_MESSAGE = 'Component definition is missing display name';

/**
* Checks if we are declaring a display name
Expand All @@ -47,7 +47,7 @@ module.exports = {
// Special case for class properties
// (babel-eslint does not expose property name so we have to rely on tokens)
case 'ClassProperty':
var tokens = sourceCode.getFirstTokens(node, 2);
const tokens = sourceCode.getFirstTokens(node, 2);
if (
tokens[0].value === 'displayName' ||
(tokens[1] && tokens[1].value === 'displayName')
Expand Down Expand Up @@ -94,7 +94,7 @@ module.exports = {
* @returns {Boolean} True if component has a name, false if not.
*/
function hasTranspilerName(node) {
var namedObjectAssignment = (
const namedObjectAssignment = (
node.type === 'ObjectExpression' &&
node.parent &&
node.parent.parent &&
Expand All @@ -105,25 +105,25 @@ module.exports = {
node.parent.parent.left.property.name !== 'exports'
)
);
var namedObjectDeclaration = (
const namedObjectDeclaration = (
node.type === 'ObjectExpression' &&
node.parent &&
node.parent.parent &&
node.parent.parent.type === 'VariableDeclarator'
);
var namedClass = (
const namedClass = (
(node.type === 'ClassDeclaration' || node.type === 'ClassExpression') &&
node.id &&
node.id.name
);

var namedFunctionDeclaration = (
const namedFunctionDeclaration = (
(node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') &&
node.id &&
node.id.name
);

var namedFunctionExpression = (
const namedFunctionExpression = (
(node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') &&
node.parent &&
(node.parent.type === 'VariableDeclarator' || node.parent.method === true) &&
Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = {
if (!isDisplayNameDeclaration(node.property)) {
return;
}
var component = utils.getRelatedComponent(node);
const component = utils.getRelatedComponent(node);
if (!component) {
return;
}
Expand Down Expand Up @@ -221,9 +221,9 @@ module.exports = {
},

'Program:exit': function() {
var list = components.list();
const list = components.list();
// Report missing display name for all components
for (var component in list) {
for (const component in list) {
if (!has(list, component) || list[component].hasDisplayName) {
continue;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/forbid-component-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Constants
// ------------------------------------------------------------------------------

var DEFAULTS = ['className', 'style'];
const DEFAULTS = ['className', 'style'];

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -38,21 +38,21 @@ module.exports = {

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

var forbid = configuration.forbid || DEFAULTS;
const forbid = configuration.forbid || DEFAULTS;
return forbid.indexOf(prop) >= 0;
}

return {
JSXAttribute: function(node) {
var tag = node.parent.name.name;
const tag = node.parent.name.name;
if (tag && tag[0] !== tag[0].toUpperCase()) {
// This is a DOM node, not a Component, so exit.
return;
}

var prop = node.name.name;
const prop = node.name.name;

if (!isForbidden(prop)) {
return;
Expand Down
18 changes: 9 additions & 9 deletions lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
'use strict';

var has = require('has');
const has = require('has');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -44,11 +44,11 @@ module.exports = {
},

create: function(context) {
var sourceCode = context.getSourceCode();
var configuration = context.options[0] || {};
var forbidConfiguration = configuration.forbid || [];
const sourceCode = context.getSourceCode();
const configuration = context.options[0] || {};
const forbidConfiguration = configuration.forbid || [];

var indexedForbidConfigs = {};
const indexedForbidConfigs = {};

forbidConfiguration.forEach(function(item) {
if (typeof item === 'string') {
Expand All @@ -59,8 +59,8 @@ module.exports = {
});

function errorMessageForElement(name) {
var message = `<${name}> is forbidden`;
var additionalMessage = indexedForbidConfigs[name].message;
const message = `<${name}> is forbidden`;
const additionalMessage = indexedForbidConfigs[name].message;

if (additionalMessage) {
return `${message}, ${additionalMessage}`;
Expand Down Expand Up @@ -96,8 +96,8 @@ module.exports = {
return;
}

var argument = node.arguments[0];
var argType = argument.type;
const argument = node.arguments[0];
const argType = argument.type;

if (argType === 'Identifier' && /^[A-Z_]/.test(argument.name)) {
reportIfForbidden(argument.name, argument);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-foreign-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
},

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

Expand Down
16 changes: 8 additions & 8 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Constants
// ------------------------------------------------------------------------------

var DEFAULTS = ['any', 'array', 'object'];
const DEFAULTS = ['any', 'array', 'object'];

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -36,12 +36,12 @@ module.exports = {
},

create: function(context) {
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);

function isForbidden(type) {
var configuration = context.options[0] || {};
const configuration = context.options[0] || {};

var forbid = configuration.forbid || DEFAULTS;
const forbid = configuration.forbid || DEFAULTS;
return forbid.indexOf(type) >= 0;
}

Expand All @@ -54,7 +54,7 @@ module.exports = {
// Special case for class properties
// (babel-eslint does not expose property name so we have to rely on tokens)
if (node.type === 'ClassProperty') {
var tokens = context.getFirstTokens(node, 2);
const tokens = context.getFirstTokens(node, 2);
if (tokens[0].value === 'propTypes' || (tokens[1] && tokens[1].value === 'propTypes')) {
return true;
}
Expand All @@ -78,8 +78,8 @@ module.exports = {
if (declaration.type !== 'Property') {
return;
}
var target;
var value = declaration.value;
let target;
let value = declaration.value;
if (
value.type === 'MemberExpression' &&
value.property &&
Expand Down Expand Up @@ -135,7 +135,7 @@ module.exports = {
return;
}

var right = node.parent.right;
const right = node.parent.right;
switch (right && right.type) {
case 'ObjectExpression':
checkForbidden(right.properties);
Expand Down
Loading