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 b646485 commit b62a1c2
Show file tree
Hide file tree
Showing 44 changed files with 118 additions and 156 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
6 changes: 3 additions & 3 deletions docs/rules/forbid-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ This rule checks all JSX elements and `React.createElement` calls and verifies t

### `forbid`

An array of strings and/or objects. An object in this array may have the following properties:
An array of strings and/or objects. An object in this array may have the following properties:

* `element` (required): the name of the forbidden element (e.g. `'button'`, `'Modal'`)
* `message`: additional message that gets reported

A string item in the array is a shorthand for `{ element: string }`.
A string item in the array is a shorthand for `{ element: string }`.

The following patterns are not considered warnings:

Expand Down Expand Up @@ -50,7 +50,7 @@ React.createElement(Namespaced.Element);

// [1, { "forbid": [{ "element": "button", "message": "use <Button> instead" }, "input"] }]
<div><button /><input /></div>
React.createElement('div', {}, React.createElemet('button', {}, React.createElement('input')));
React.createElement('div', {}, React.createElement('button', {}, React.createElement('input')));
```

## When not to use
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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
4 changes: 2 additions & 2 deletions lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ module.exports = {
});

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

if (additionalMessage) {
message = message + ', ' + additionalMessage;
return `${message}, ${additionalMessage}`;
}

return message;
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 @@ -4,8 +4,6 @@
*/
'use strict';

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

// ------------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -47,7 +45,7 @@ module.exports = {
},

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

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 @@ -146,9 +146,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 @@ -73,7 +73,7 @@ module.exports = {
var name = getPropName(propsInLine[maximum]);
context.report({
node: propsInLine[maximum],
message: 'Prop `' + name + '` must be placed on a new line'
message: `Prop \`${name}\` must be placed on a new line`
});
}
});
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
Loading

0 comments on commit b62a1c2

Please sign in to comment.