Skip to content

Commit

Permalink
[Breaking] drop node < 4 support.
Browse files Browse the repository at this point in the history
Also, require template literals instead of concatenation, and auto fix.
  • Loading branch information
ljharb committed Jan 21, 2017
1 parent e332b08 commit 720aabe
Show file tree
Hide file tree
Showing 39 changed files with 108 additions and 143 deletions.
17 changes: 11 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"env": {
"node": true
},
parserOptions: {
ecmaVersion: 2015
},
ecmaFeatures: {
jsx: true
},
"globals": {
},
"plugins": [
],
"rules": {
// Possible Errors
"comma-dangle": [2, "never"],
Expand Down Expand Up @@ -149,10 +148,16 @@
"wrap-regex": 0,
// Legacy
"max-depth": 0,
"max-len": [2, 120],
"max-len": [2, 120, {
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreComments": true,
}],
"max-params": 0,
"max-statements": 0,
"no-plusplus": 0,
"no-prototype-builtins": 2
"no-prototype-builtins": 2,
"prefer-template": 2,
"template-curly-spacing": [2, "never"]
}
}
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ node_js:
- '6'
- '5'
- '4'
- 'iojs'
- '0.12'
- '0.10'
before_script:
- 'if [ "${TRAVIS_NODE_VERSION}" = "iojs" ] || [ "${TRAVIS_NODE_VERSION}" = "0.12" ] || [ "${TRAVIS_NODE_VERSION}" = "0.10" ]; then npm install eslint@2 babel-eslint@6; fi'
after_success:
- npm run coveralls
matrix:
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function configureAsError(rules) {
if (!has(rules, key)) {
continue;
}
result['react/' + key] = 2;
result[`react/${key}`] = 2;
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-component-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {

context.report({
node: node,
message: 'Prop `' + prop + '` is forbidden on Components'
message: `Prop \`${prop}\` is forbidden on Components`
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module.exports = {
if (isForbidden(target)) {
context.report({
node: declaration,
message: 'Prop type `' + target + '` is forbidden'
message: `Prop type \`${target}\` is forbidden`
});
}
});
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ module.exports = {
if (correctColumn !== null) {
expectedNextLine = tokens.lastProp &&
(tokens.lastProp.lastLine === tokens.closing.line);
data.details = ' (expected column ' + (correctColumn + 1) +
(expectedNextLine ? ' on the next line)' : ')');
data.details = ` (expected column ${correctColumn + 1}${expectedNextLine ? ' on the next line)' : ')'}`;
}

context.report({
Expand All @@ -274,7 +273,7 @@ module.exports = {
case 'tag-aligned':
case 'line-aligned':
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
'\n' + getIndentation(tokens, expectedLocation, correctColumn) + closingTag);
`\n${getIndentation(tokens, expectedLocation, correctColumn)}${closingTag}`);
default:
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/rules/jsx-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = {
context.report({
node: node,
loc: token.loc.start,
message: 'There should be no newline after \'' + token.value + '\'',
message: `There should be no newline after '${token.value}'`,
fix: function(fixer) {
var nextToken = sourceCode.getTokenAfter(token);
return fixer.replaceTextRange([token.range[1], nextToken.range[0]], spaced ? ' ' : '');
Expand All @@ -101,7 +101,7 @@ module.exports = {
context.report({
node: node,
loc: token.loc.start,
message: 'There should be no newline before \'' + token.value + '\'',
message: `There should be no newline before '${token.value}'`,
fix: function(fixer) {
var previousToken = sourceCode.getTokenBefore(token);
return fixer.replaceTextRange([previousToken.range[1], token.range[0]], spaced ? ' ' : '');
Expand All @@ -119,7 +119,7 @@ module.exports = {
context.report({
node: node,
loc: token.loc.start,
message: 'There should be no space after \'' + token.value + '\'',
message: `There should be no space after '${token.value}'`,
fix: function(fixer) {
var nextToken = sourceCode.getTokenAfter(token);
var leadingComments = sourceCode.getNodeByRangeIndex(nextToken.range[0]).leadingComments;
Expand All @@ -139,7 +139,7 @@ module.exports = {
context.report({
node: node,
loc: token.loc.start,
message: 'There should be no space before \'' + token.value + '\'',
message: `There should be no space before '${token.value}'`,
fix: function(fixer) {
var previousToken = sourceCode.getTokenBefore(token);
var trailingComments = sourceCode.getNodeByRangeIndex(previousToken.range[0]).trailingComments;
Expand All @@ -159,7 +159,7 @@ module.exports = {
context.report({
node: node,
loc: token.loc.start,
message: 'A space is required after \'' + token.value + '\'',
message: `A space is required after '${token.value}'`,
fix: function(fixer) {
return fixer.insertTextAfter(token, ' ');
}
Expand All @@ -176,7 +176,7 @@ module.exports = {
context.report({
node: node,
loc: token.loc.start,
message: 'A space is required before \'' + token.value + '\'',
message: `A space is required before '${token.value}'`,
fix: function(fixer) {
return fixer.insertTextBefore(token, ' ');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-filename-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = {

context.report({
node: invalidNode,
message: 'JSX not allowed in files with extension \'' + invalidExtension + '\''
message: `JSX not allowed in files with extension '${invalidExtension}'`
});
}
};
Expand Down
9 changes: 4 additions & 5 deletions lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ module.exports = {
var eventHandlerPrefix = configuration.eventHandlerPrefix || 'handle';
var eventHandlerPropPrefix = configuration.eventHandlerPropPrefix || 'on';

var EVENT_HANDLER_REGEX = new RegExp('^((props\\.' + eventHandlerPropPrefix + ')'
+ '|((.*\\.)?' + eventHandlerPrefix + '))[A-Z].*$');
var PROP_EVENT_HANDLER_REGEX = new RegExp('^(' + eventHandlerPropPrefix + '[A-Z].*|ref)$');
var EVENT_HANDLER_REGEX = new RegExp(`^((props\\.${eventHandlerPropPrefix})|((.*\\.)?${eventHandlerPrefix}))[A-Z].*$`);
var PROP_EVENT_HANDLER_REGEX = new RegExp(`^(${eventHandlerPropPrefix}[A-Z].*|ref)$`);

return {
JSXAttribute: function(node) {
Expand All @@ -60,12 +59,12 @@ module.exports = {
if (propIsEventHandler && !propFnIsNamedCorrectly) {
context.report({
node: node,
message: 'Handler function for ' + propKey + ' prop key must begin with \'' + eventHandlerPrefix + '\''
message: `Handler function for ${propKey} prop key must begin with '${eventHandlerPrefix}'`
});
} else if (propFnIsNamedCorrectly && !propIsEventHandler) {
context.report({
node: node,
message: 'Prop key for ' + propValue + ' must begin with \'' + eventHandlerPropPrefix + '\''
message: `Prop key for ${propValue} must begin with '${eventHandlerPropPrefix}'`
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/jsx-indent-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ module.exports = {

var regExp;
if (indentType === 'space') {
regExp = new RegExp('^[ ' + skip + ']+');
regExp = new RegExp(`^[ ${skip}]+`);
} else {
regExp = new RegExp('^[\t' + skip + ']+');
regExp = new RegExp(`^[\t${skip}]+`);
}

var indent = regExp.exec(src);
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ module.exports = {

var regExp;
if (indentType === 'space') {
regExp = new RegExp('^[ ' + skip + ']+');
regExp = new RegExp(`^[ ${skip}]+`);
} else {
regExp = new RegExp('^[\t' + skip + ']+');
regExp = new RegExp(`^[\t${skip}]+`);
}

var indent = regExp.exec(src);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-max-props-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
var name = getPropName(props[line][maximum]);
context.report({
node: props[line][maximum],
message: 'Prop `' + name + '` must be placed on a new line'
message: `Prop \`${name}\` must be placed on a new line`
});
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-no-undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {

context.report({
node: node,
message: '\'' + node.name + '\' is not defined.'
message: `'${node.name}' is not defined.`
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-pascal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = {
if (!isPascalCase && !isCompatTag && !isAllowedAllCaps && !isIgnored) {
context.report({
node: node,
message: 'Imported JSX component ' + name + ' must be in PascalCase'
message: `Imported JSX component ${name} must be in PascalCase`
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-wrap-multilines.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
node: node,
message: 'Missing parentheses around multilines JSX',
fix: function(fixer) {
return fixer.replaceText(node, '(' + sourceCode.getText(node) + ')');
return fixer.replaceText(node, `(${sourceCode.getText(node)})`);
}
});
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/no-children-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
'use strict';

var find = require('array.prototype.find');

// ------------------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -55,7 +53,7 @@ module.exports = {
}

var props = node.arguments[1].properties;
var childrenProp = find(props, function(prop) {
var childrenProp = props.find(function(prop) {
return prop.key && prop.key.name === 'children';
});

Expand Down
9 changes: 4 additions & 5 deletions lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

var find = require('array.prototype.find');
var variableUtil = require('../util/variable');

// ------------------------------------------------------------------------------
Expand All @@ -21,7 +20,7 @@ module.exports = {
},
create: function(context) {
function findSpreadVariable(name) {
return find(variableUtil.variablesInScope(context), function (item) {
return variableUtil.variablesInScope(context).find(function (item) {
return item.name === name;
});
}
Expand All @@ -34,7 +33,7 @@ module.exports = {
if (!node.properties) {
return false;
}
return find(node.properties, function(prop) {
return node.properties.find(function(prop) {
if (prop.type === 'Property') {
return prop.key.name === propName;
} else if (prop.type === 'ExperimentalSpreadProperty') {
Expand All @@ -54,7 +53,7 @@ module.exports = {
*/
function findJsxProp(node, propName) {
var attributes = node.openingElement.attributes;
return find(attributes, function (attribute) {
return attributes.find(function (attribute) {
if (attribute.type === 'JSXSpreadAttribute') {
var variable = findSpreadVariable(attribute.argument.name);
if (variable && variable.defs.length && variable.defs[0].node.init) {
Expand Down Expand Up @@ -95,7 +94,7 @@ module.exports = {
var props = node.arguments[1];

if (props.type === 'Identifier') {
var variable = find(variableUtil.variablesInScope(context), function (item) {
var variable = variableUtil.variablesInScope(context).find(function (item) {
return item.name === props.name;
});
if (variable && variable.defs[0].node.init) {
Expand Down
34 changes: 17 additions & 17 deletions lib/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ module.exports = {
MemberExpression: {}
};
// 0.12.0
deprecated.MemberExpression[pragma + '.renderComponent'] = ['0.12.0', pragma + '.render'];
deprecated.MemberExpression[pragma + '.renderComponentToString'] = ['0.12.0', pragma + '.renderToString'];
deprecated.MemberExpression[pragma + '.renderComponentToStaticMarkup'] = [
deprecated.MemberExpression[`${pragma}.renderComponent`] = ['0.12.0', `${pragma}.render`];
deprecated.MemberExpression[`${pragma}.renderComponentToString`] = ['0.12.0', `${pragma}.renderToString`];
deprecated.MemberExpression[`${pragma}.renderComponentToStaticMarkup`] = [
'0.12.0',
pragma + '.renderToStaticMarkup'
`${pragma}.renderToStaticMarkup`
];
deprecated.MemberExpression[pragma + '.isValidComponent'] = ['0.12.0', pragma + '.isValidElement'];
deprecated.MemberExpression[pragma + '.PropTypes.component'] = ['0.12.0', pragma + '.PropTypes.element'];
deprecated.MemberExpression[pragma + '.PropTypes.renderable'] = ['0.12.0', pragma + '.PropTypes.node'];
deprecated.MemberExpression[pragma + '.isValidClass'] = ['0.12.0'];
deprecated.MemberExpression[`${pragma}.isValidComponent`] = ['0.12.0', `${pragma}.isValidElement`];
deprecated.MemberExpression[`${pragma}.PropTypes.component`] = ['0.12.0', `${pragma}.PropTypes.element`];
deprecated.MemberExpression[`${pragma}.PropTypes.renderable`] = ['0.12.0', `${pragma}.PropTypes.node`];
deprecated.MemberExpression[`${pragma}.isValidClass`] = ['0.12.0'];
deprecated.MemberExpression['this.transferPropsTo'] = ['0.12.0', 'spread operator ({...})'];
// 0.13.0
deprecated.MemberExpression[pragma + '.addons.classSet'] = ['0.13.0', 'the npm module classnames'];
deprecated.MemberExpression[pragma + '.addons.cloneWithProps'] = ['0.13.0', pragma + '.cloneElement'];
deprecated.MemberExpression[`${pragma}.addons.classSet`] = ['0.13.0', 'the npm module classnames'];
deprecated.MemberExpression[`${pragma}.addons.cloneWithProps`] = ['0.13.0', `${pragma}.cloneElement`];
// 0.14.0
deprecated.MemberExpression[pragma + '.render'] = ['0.14.0', 'ReactDOM.render'];
deprecated.MemberExpression[pragma + '.unmountComponentAtNode'] = ['0.14.0', 'ReactDOM.unmountComponentAtNode'];
deprecated.MemberExpression[pragma + '.findDOMNode'] = ['0.14.0', 'ReactDOM.findDOMNode'];
deprecated.MemberExpression[pragma + '.renderToString'] = ['0.14.0', 'ReactDOMServer.renderToString'];
deprecated.MemberExpression[pragma + '.renderToStaticMarkup'] = ['0.14.0', 'ReactDOMServer.renderToStaticMarkup'];
deprecated.MemberExpression[`${pragma}.render`] = ['0.14.0', 'ReactDOM.render'];
deprecated.MemberExpression[`${pragma}.unmountComponentAtNode`] = ['0.14.0', 'ReactDOM.unmountComponentAtNode'];
deprecated.MemberExpression[`${pragma}.findDOMNode`] = ['0.14.0', 'ReactDOM.findDOMNode'];
deprecated.MemberExpression[`${pragma}.renderToString`] = ['0.14.0', 'ReactDOMServer.renderToString'];
deprecated.MemberExpression[`${pragma}.renderToStaticMarkup`] = ['0.14.0', 'ReactDOMServer.renderToStaticMarkup'];
// 15.0.0
deprecated.MemberExpression[pragma + '.addons.LinkedStateMixin'] = ['15.0.0'];
deprecated.MemberExpression[`${pragma}.addons.LinkedStateMixin`] = ['15.0.0'];
deprecated.MemberExpression['ReactPerf.printDOM'] = ['15.0.0', 'ReactPerf.printOperations'];
deprecated.MemberExpression['Perf.printDOM'] = ['15.0.0', 'Perf.printOperations'];
deprecated.MemberExpression['ReactPerf.getMeasurementsSummaryMap'] = ['15.0.0', 'ReactPerf.getWasted'];
Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = {
data: {
oldMethod: method,
version: deprecated[node.type][method][0],
newMethod: deprecated[node.type][method][1] ? ', use ' + deprecated[node.type][method][1] + ' instead' : ''
newMethod: deprecated[node.type][method][1] ? `, use ${deprecated[node.type][method][1]} instead` : ''
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-render-return-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
) {
context.report({
node: callee,
message: 'Do not depend on the return value from ' + callee.object.name + '.render'
message: `Do not depend on the return value from ${callee.object.name}.render`
});
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// https://github.com/yannickcr/eslint-plugin-react/issues/7

var has = require('has');
var assign = require('object.assign');
var Components = require('../util/Components');
var variable = require('../util/variable');
var annotations = require('../util/annotations');
Expand Down Expand Up @@ -52,7 +51,7 @@ module.exports = {

var defaults = {skipShapeProps: true};
var sourceCode = context.getSourceCode();
var configuration = assign({}, defaults, context.options[0] || {});
var configuration = Object.assign({}, defaults, context.options[0] || {});
var skipShapeProps = configuration.skipShapeProps;
var customValidators = configuration.customValidators || [];
// Used to track the type annotations in scope.
Expand Down Expand Up @@ -588,7 +587,7 @@ module.exports = {
}
break;
default:
throw new Error(node.type + ' ASTNodes are not handled by markPropTypesAsUsed');
throw new Error(`${node.type} ASTNodes are not handled by markPropTypesAsUsed`);
}

var component = components.get(utils.getParentComponent());
Expand Down
Loading

0 comments on commit 720aabe

Please sign in to comment.