Skip to content

Commit d672588

Browse files
authored
Merge pull request jsx-eslint#1277 from dfilipidisz/transform-variables
Transform variables
2 parents 9f3b740 + 68b9b06 commit d672588

File tree

128 files changed

+1180
-1178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1180
-1178
lines changed

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888
// Strict Mode
8989
"strict": [2, "global"],
9090
// Variables
91+
"prefer-const": 2,
9192
"no-catch-shadow": 2,
93+
"no-const-assign": 2,
9294
"no-delete-var": 2,
9395
"no-label-var": 2,
9496
"no-shadow": 2,
@@ -98,6 +100,7 @@
98100
"no-undefined": 2,
99101
"no-unused-vars": 2,
100102
"no-use-before-define": 2,
103+
"no-var": 2,
101104
// Stylistic Issues
102105
"indent": [2, 2, {
103106
"SwitchCase": 1

index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
var has = require('has');
3+
const has = require('has');
44

5-
var allRules = {
5+
const allRules = {
66
'jsx-uses-react': require('./lib/rules/jsx-uses-react'),
77
'no-multi-comp': require('./lib/rules/no-multi-comp'),
88
'prop-types': require('./lib/rules/prop-types'),
@@ -69,8 +69,8 @@ var allRules = {
6969
};
7070

7171
function filterRules(rules, predicate) {
72-
var result = {};
73-
for (var key in rules) {
72+
const result = {};
73+
for (const key in rules) {
7474
if (has(rules, key) && predicate(rules[key])) {
7575
result[key] = rules[key];
7676
}
@@ -79,8 +79,8 @@ function filterRules(rules, predicate) {
7979
}
8080

8181
function configureAsError(rules) {
82-
var result = {};
83-
for (var key in rules) {
82+
const result = {};
83+
for (const key in rules) {
8484
if (!has(rules, key)) {
8585
continue;
8686
}
@@ -89,12 +89,12 @@ function configureAsError(rules) {
8989
return result;
9090
}
9191

92-
var activeRules = filterRules(allRules, function(rule) {
92+
const activeRules = filterRules(allRules, function(rule) {
9393
return !rule.meta.deprecated;
9494
});
95-
var activeRulesConfig = configureAsError(activeRules);
95+
const activeRulesConfig = configureAsError(activeRules);
9696

97-
var deprecatedRules = filterRules(allRules, function(rule) {
97+
const deprecatedRules = filterRules(allRules, function(rule) {
9898
return rule.meta.deprecated;
9999
});
100100

lib/rules/default-props-match-prop-types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
create: Components.detect(function(context, components, utils) {
3737
const configuration = context.options[0] || {};
3838
const allowRequiredDefaults = configuration.allowRequiredDefaults || false;
39-
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
39+
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
4040

4141
/**
4242
* Get properties name
@@ -603,7 +603,7 @@ module.exports = {
603603
'Program:exit': function() {
604604
const list = components.list();
605605

606-
for (let component in list) {
606+
for (const component in list) {
607607
if (!has(list, component)) {
608608
continue;
609609
}

lib/rules/display-name.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
'use strict';
66

7-
var has = require('has');
8-
var Components = require('../util/Components');
7+
const has = require('has');
8+
const Components = require('../util/Components');
99

1010
// ------------------------------------------------------------------------------
1111
// Rule Definition
@@ -31,11 +31,11 @@ module.exports = {
3131
},
3232

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

38-
var MISSING_MESSAGE = 'Component definition is missing display name';
38+
const MISSING_MESSAGE = 'Component definition is missing display name';
3939

4040
/**
4141
* Checks if we are declaring a display name
@@ -47,7 +47,7 @@ module.exports = {
4747
// Special case for class properties
4848
// (babel-eslint does not expose property name so we have to rely on tokens)
4949
case 'ClassProperty':
50-
var tokens = sourceCode.getFirstTokens(node, 2);
50+
const tokens = sourceCode.getFirstTokens(node, 2);
5151
if (
5252
tokens[0].value === 'displayName' ||
5353
(tokens[1] && tokens[1].value === 'displayName')
@@ -94,7 +94,7 @@ module.exports = {
9494
* @returns {Boolean} True if component has a name, false if not.
9595
*/
9696
function hasTranspilerName(node) {
97-
var namedObjectAssignment = (
97+
const namedObjectAssignment = (
9898
node.type === 'ObjectExpression' &&
9999
node.parent &&
100100
node.parent.parent &&
@@ -105,25 +105,25 @@ module.exports = {
105105
node.parent.parent.left.property.name !== 'exports'
106106
)
107107
);
108-
var namedObjectDeclaration = (
108+
const namedObjectDeclaration = (
109109
node.type === 'ObjectExpression' &&
110110
node.parent &&
111111
node.parent.parent &&
112112
node.parent.parent.type === 'VariableDeclarator'
113113
);
114-
var namedClass = (
114+
const namedClass = (
115115
(node.type === 'ClassDeclaration' || node.type === 'ClassExpression') &&
116116
node.id &&
117117
node.id.name
118118
);
119119

120-
var namedFunctionDeclaration = (
120+
const namedFunctionDeclaration = (
121121
(node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') &&
122122
node.id &&
123123
node.id.name
124124
);
125125

126-
var namedFunctionExpression = (
126+
const namedFunctionExpression = (
127127
(node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') &&
128128
node.parent &&
129129
(node.parent.type === 'VariableDeclarator' || node.parent.method === true) &&
@@ -157,7 +157,7 @@ module.exports = {
157157
if (!isDisplayNameDeclaration(node.property)) {
158158
return;
159159
}
160-
var component = utils.getRelatedComponent(node);
160+
const component = utils.getRelatedComponent(node);
161161
if (!component) {
162162
return;
163163
}
@@ -221,9 +221,9 @@ module.exports = {
221221
},
222222

223223
'Program:exit': function() {
224-
var list = components.list();
224+
const list = components.list();
225225
// Report missing display name for all components
226-
for (var component in list) {
226+
for (const component in list) {
227227
if (!has(list, component) || list[component].hasDisplayName) {
228228
continue;
229229
}

lib/rules/forbid-component-props.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Constants
99
// ------------------------------------------------------------------------------
1010

11-
var DEFAULTS = ['className', 'style'];
11+
const DEFAULTS = ['className', 'style'];
1212

1313
// ------------------------------------------------------------------------------
1414
// Rule Definition
@@ -38,21 +38,21 @@ module.exports = {
3838

3939
create: function(context) {
4040
function isForbidden(prop) {
41-
var configuration = context.options[0] || {};
41+
const configuration = context.options[0] || {};
4242

43-
var forbid = configuration.forbid || DEFAULTS;
43+
const forbid = configuration.forbid || DEFAULTS;
4444
return forbid.indexOf(prop) >= 0;
4545
}
4646

4747
return {
4848
JSXAttribute: function(node) {
49-
var tag = node.parent.name.name;
49+
const tag = node.parent.name.name;
5050
if (tag && tag[0] !== tag[0].toUpperCase()) {
5151
// This is a DOM node, not a Component, so exit.
5252
return;
5353
}
5454

55-
var prop = node.name.name;
55+
const prop = node.name.name;
5656

5757
if (!isForbidden(prop)) {
5858
return;

lib/rules/forbid-elements.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict';
66

7-
var has = require('has');
7+
const has = require('has');
88

99
// ------------------------------------------------------------------------------
1010
// Rule Definition
@@ -44,11 +44,11 @@ module.exports = {
4444
},
4545

4646
create: function(context) {
47-
var sourceCode = context.getSourceCode();
48-
var configuration = context.options[0] || {};
49-
var forbidConfiguration = configuration.forbid || [];
47+
const sourceCode = context.getSourceCode();
48+
const configuration = context.options[0] || {};
49+
const forbidConfiguration = configuration.forbid || [];
5050

51-
var indexedForbidConfigs = {};
51+
const indexedForbidConfigs = {};
5252

5353
forbidConfiguration.forEach(function(item) {
5454
if (typeof item === 'string') {
@@ -59,8 +59,8 @@ module.exports = {
5959
});
6060

6161
function errorMessageForElement(name) {
62-
var message = `<${name}> is forbidden`;
63-
var additionalMessage = indexedForbidConfigs[name].message;
62+
const message = `<${name}> is forbidden`;
63+
const additionalMessage = indexedForbidConfigs[name].message;
6464

6565
if (additionalMessage) {
6666
return `${message}, ${additionalMessage}`;
@@ -96,8 +96,8 @@ module.exports = {
9696
return;
9797
}
9898

99-
var argument = node.arguments[0];
100-
var argType = argument.type;
99+
const argument = node.arguments[0];
100+
const argType = argument.type;
101101

102102
if (argType === 'Identifier' && /^[A-Z_]/.test(argument.name)) {
103103
reportIfForbidden(argument.name, argument);

lib/rules/forbid-foreign-prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
},
4646

4747
ObjectPattern: function(node) {
48-
var propTypesNode = node.properties.find(function(property) {
48+
const propTypesNode = node.properties.find(function(property) {
4949
return property.type === 'Property' && property.key.name === 'propTypes';
5050
});
5151

lib/rules/forbid-prop-types.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Constants
88
// ------------------------------------------------------------------------------
99

10-
var DEFAULTS = ['any', 'array', 'object'];
10+
const DEFAULTS = ['any', 'array', 'object'];
1111

1212
// ------------------------------------------------------------------------------
1313
// Rule Definition
@@ -36,12 +36,12 @@ module.exports = {
3636
},
3737

3838
create: function(context) {
39-
var propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
39+
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
4040

4141
function isForbidden(type) {
42-
var configuration = context.options[0] || {};
42+
const configuration = context.options[0] || {};
4343

44-
var forbid = configuration.forbid || DEFAULTS;
44+
const forbid = configuration.forbid || DEFAULTS;
4545
return forbid.indexOf(type) >= 0;
4646
}
4747

@@ -54,7 +54,7 @@ module.exports = {
5454
// Special case for class properties
5555
// (babel-eslint does not expose property name so we have to rely on tokens)
5656
if (node.type === 'ClassProperty') {
57-
var tokens = context.getFirstTokens(node, 2);
57+
const tokens = context.getFirstTokens(node, 2);
5858
if (tokens[0].value === 'propTypes' || (tokens[1] && tokens[1].value === 'propTypes')) {
5959
return true;
6060
}
@@ -78,8 +78,8 @@ module.exports = {
7878
if (declaration.type !== 'Property') {
7979
return;
8080
}
81-
var target;
82-
var value = declaration.value;
81+
let target;
82+
let value = declaration.value;
8383
if (
8484
value.type === 'MemberExpression' &&
8585
value.property &&
@@ -135,7 +135,7 @@ module.exports = {
135135
return;
136136
}
137137

138-
var right = node.parent.right;
138+
const right = node.parent.right;
139139
switch (right && right.type) {
140140
case 'ObjectExpression':
141141
checkForbidden(right.properties);

0 commit comments

Comments
 (0)