Skip to content

Commit

Permalink
Remove usage of context deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Feb 12, 2016
1 parent efa2630 commit 442d20b
Show file tree
Hide file tree
Showing 35 changed files with 236 additions and 87 deletions.
12 changes: 7 additions & 5 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Components = require('../util/Components');

module.exports = Components.detect(function(context, components, utils) {

var sourceCode = context.getSourceCode();
var config = context.options[0] || {};
var acceptTranspilerName = config.acceptTranspilerName || false;

Expand All @@ -26,7 +27,7 @@ module.exports = Components.detect(function(context, components, utils) {
// 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);
var tokens = sourceCode.getFirstTokens(node, 2);
if (
tokens[0].value === 'displayName' ||
(tokens[1] && tokens[1].value === 'displayName')
Expand Down Expand Up @@ -57,12 +58,13 @@ module.exports = Components.detect(function(context, components, utils) {
* @param {Object} component The component to process
*/
function reportMissingDisplayName(component) {
context.report(
component.node,
MISSING_MESSAGE, {
context.report({
node: component.node,
message: MISSING_MESSAGE,
data: {
component: component.name
}
);
});
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ module.exports = function(context) {
target = value.name;
}
if (isForbidden(target)) {
context.report(declaration, 'Prop type `' + target + '` is forbidden');
context.report({
node: declaration,
message: 'Prop type `' + target + '` is forbidden'
});
}
});
}
Expand Down
13 changes: 7 additions & 6 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function(context) {
};
var DEFAULT_LOCATION = 'tag-aligned';

var sourceCode = context.getSourceCode();
var config = context.options[0];
var options = {
nonEmpty: DEFAULT_LOCATION,
Expand Down Expand Up @@ -115,18 +116,18 @@ module.exports = function(context) {
* prop and start of opening line.
*/
function getTokensLocations(node) {
var opening = context.getFirstToken(node).loc.start;
var closing = context.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
var tag = context.getFirstToken(node.name).loc.start;
var opening = sourceCode.getFirstToken(node).loc.start;
var closing = sourceCode.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
var tag = sourceCode.getFirstToken(node.name).loc.start;
var lastProp;
if (node.attributes.length) {
lastProp = node.attributes[node.attributes.length - 1];
lastProp = {
column: context.getFirstToken(lastProp).loc.start.column,
line: context.getLastToken(lastProp).loc.end.line
column: sourceCode.getFirstToken(lastProp).loc.start.column,
line: sourceCode.getLastToken(lastProp).loc.end.line
};
}
var openingLine = context.getSourceCode().lines[opening.line - 1];
var openingLine = sourceCode.lines[opening.line - 1];
var openingStartOfLine = {
column: /^\s*/.exec(openingLine)[0].length,
line: opening.line
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/jsx-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ------------------------------------------------------------------------------

module.exports = function(context) {

var sourceCode = context.getSourceCode();
var spaced = context.options[0] === 'always';
var multiline = context.options[1] ? context.options[1].allowMultiline : true;

Expand Down Expand Up @@ -192,8 +194,8 @@ module.exports = function(context) {
JSXExpressionContainer: function(node) {
var first = context.getFirstToken(node);
var second = context.getFirstToken(node, 1);
var penultimate = context.getLastToken(node, 1);
var last = context.getLastToken(node);
var penultimate = sourceCode.getLastToken(node, 1);
var last = sourceCode.getLastToken(node);

if (first === penultimate && second === last) {
return;
Expand Down
28 changes: 20 additions & 8 deletions lib/rules/jsx-equals-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,34 @@ module.exports = function(context) {
default:
case 'never':
if (spacedBefore) {
context.report(attrNode, equalToken.loc.start,
'There should be no space before \'=\'');
context.report({
node: attrNode,
loc: equalToken.loc.start,
message: 'There should be no space before \'=\''
});
}
if (spacedAfter) {
context.report(attrNode, equalToken.loc.start,
'There should be no space after \'=\'');
context.report({
node: attrNode,
loc: equalToken.loc.start,
message: 'There should be no space after \'=\''
});
}
break;
case 'always':
if (!spacedBefore) {
context.report(attrNode, equalToken.loc.start,
'A space is required before \'=\'');
context.report({
node: attrNode,
loc: equalToken.loc.start,
message: 'A space is required before \'=\''
});
}
if (!spacedAfter) {
context.report(attrNode, equalToken.loc.start,
'A space is required after \'=\'');
context.report({
node: attrNode,
loc: equalToken.loc.start,
message: 'A space is required after \'=\''
});
}
break;
}
Expand Down
19 changes: 10 additions & 9 deletions lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

module.exports = function(context) {

var sourceCode = context.getSourceCode();
var configuration = context.options[0] || {};
var eventHandlerPrefix = configuration.eventHandlerPrefix || 'handle';
var eventHandlerPropPrefix = configuration.eventHandlerPropPrefix || 'on';
Expand All @@ -25,7 +26,7 @@ module.exports = function(context) {
}

var propKey = typeof node.name === 'object' ? node.name.name : node.name;
var propValue = context.getSource(node.value.expression).replace(/^this\./, '');
var propValue = sourceCode.getText(node.value.expression).replace(/^this\./, '');

if (propKey === 'ref') {
return;
Expand All @@ -35,15 +36,15 @@ module.exports = function(context) {
var propFnIsNamedCorrectly = EVENT_HANDLER_REGEX.test(propValue);

if (propIsEventHandler && !propFnIsNamedCorrectly) {
context.report(
node,
'Handler function for ' + propKey + ' prop key must begin with \'' + eventHandlerPrefix + '\''
);
context.report({
node: node,
message: 'Handler function for ' + propKey + ' prop key must begin with \'' + eventHandlerPrefix + '\''
});
} else if (propFnIsNamedCorrectly && !propIsEventHandler) {
context.report(
node,
'Prop key for ' + propValue + ' must begin with \'' + eventHandlerPropPrefix + '\''
);
context.report({
node: node,
message: 'Prop key for ' + propValue + ' must begin with \'' + eventHandlerPropPrefix + '\''
});
}
}
};
Expand Down
19 changes: 15 additions & 4 deletions lib/rules/jsx-indent-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module.exports = function(context) {
var indentType = 'space';
var indentSize = 4;

var sourceCode = context.getSourceCode();

if (context.options.length) {
if (context.options[0] === 'tab') {
indentSize = 1;
Expand All @@ -66,9 +68,18 @@ module.exports = function(context) {
};

if (loc) {
context.report(node, loc, MESSAGE, msgContext);
context.report({
node: node,
loc: loc,
message: MESSAGE,
data: msgContext
});
} else {
context.report(node, MESSAGE, msgContext);
context.report({
node: node,
message: MESSAGE,
data: msgContext
});
}
}

Expand All @@ -83,7 +94,7 @@ module.exports = function(context) {
byLastLine = byLastLine || false;
excludeCommas = excludeCommas || false;

var src = context.getSource(node, node.loc.start.column + extraColumnStart);
var src = sourceCode.getText(node, node.loc.start.column + extraColumnStart);
var lines = src.split('\n');
if (byLastLine) {
src = lines[lines.length - 1];
Expand Down Expand Up @@ -111,7 +122,7 @@ module.exports = function(context) {
* @return {Boolean} true if its the first in the its start line
*/
function isNodeFirstInLine(node, byEndLocation) {
var firstToken = byEndLocation === true ? context.getLastToken(node, 1) : context.getTokenBefore(node);
var firstToken = byEndLocation === true ? sourceCode.getLastToken(node, 1) : sourceCode.getTokenBefore(node);
var startLine = byEndLocation === true ? node.loc.end.line : node.loc.start.line;
var endLine = firstToken ? firstToken.loc.end.line : -1;

Expand Down
19 changes: 15 additions & 4 deletions lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module.exports = function(context) {
var indentType = 'space';
var indentSize = 4;

var sourceCode = context.getSourceCode();

if (context.options.length) {
if (context.options[0] === 'tab') {
indentSize = 1;
Expand All @@ -66,9 +68,18 @@ module.exports = function(context) {
};

if (loc) {
context.report(node, loc, MESSAGE, msgContext);
context.report({
node: node,
loc: loc,
message: MESSAGE,
data: msgContext
});
} else {
context.report(node, MESSAGE, msgContext);
context.report({
node: node,
message: MESSAGE,
data: msgContext
});
}
}

Expand All @@ -83,7 +94,7 @@ module.exports = function(context) {
byLastLine = byLastLine || false;
excludeCommas = excludeCommas || false;

var src = context.getSource(node, node.loc.start.column + extraColumnStart);
var src = sourceCode.getText(node, node.loc.start.column + extraColumnStart);
var lines = src.split('\n');
if (byLastLine) {
src = lines[lines.length - 1];
Expand Down Expand Up @@ -112,7 +123,7 @@ module.exports = function(context) {
function isNodeFirstInLine(node) {
var token = node;
do {
token = context.getTokenBefore(token);
token = sourceCode.getTokenBefore(token);
} while (token.type === 'JSXText');
var startLine = node.loc.start.line;
var endLine = token ? token.loc.end.line : -1;
Expand Down
10 changes: 8 additions & 2 deletions lib/rules/jsx-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ module.exports = function(context) {

function checkIteratorElement(node) {
if (node.type === 'JSXElement' && !hasKeyProp(node)) {
context.report(node, 'Missing "key" prop for element in iterator');
context.report({
node: node,
message: 'Missing "key" prop for element in iterator'
});
}
}

Expand All @@ -40,7 +43,10 @@ module.exports = function(context) {
}

if (node.parent.type === 'ArrayExpression') {
context.report(node, 'Missing "key" prop for element in array');
context.report({
node: node,
message: 'Missing "key" prop for element in array'
});
}
},

Expand Down
8 changes: 6 additions & 2 deletions lib/rules/jsx-max-props-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

module.exports = function (context) {

var sourceCode = context.getSourceCode();
var configuration = context.options[0] || {};
var maximum = configuration.maximum || 1;

function getPropName(propNode) {
if (propNode.type === 'JSXSpreadAttribute') {
return context.getSource(propNode.argument);
return sourceCode.getText(propNode.argument);
}
return propNode.name.name;
}
Expand All @@ -40,7 +41,10 @@ module.exports = function (context) {
}
if (props[line].length > maximum) {
var name = getPropName(props[line][maximum]);
context.report(props[line][maximum], 'Prop `' + name + '` must be placed on a new line');
context.report({
node: props[line][maximum],
message: 'Prop `' + name + '` must be placed on a new line'
});
break;
}
}
Expand Down
10 changes: 8 additions & 2 deletions lib/rules/jsx-no-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ module.exports = function(context) {
valueNode.callee.type === 'MemberExpression' &&
valueNode.callee.property.name === 'bind'
) {
context.report(node, 'JSX props should not use .bind()');
context.report({
node: node,
message: 'JSX props should not use .bind()'
});
} else if (
!configuration.allowArrowFunctions &&
valueNode.type === 'ArrowFunctionExpression'
) {
context.report(node, 'JSX props should not use arrow functions');
context.report({
node: node,
message: 'JSX props should not use arrow functions'
});
}
}
};
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-no-duplicate-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ module.exports = function (context) {
}

if (props.hasOwnProperty(name)) {
context.report(decl, 'No duplicate props allowed');
context.report({
node: decl,
message: 'No duplicate props allowed'
});
} else {
props[name] = 1;
}
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
module.exports = function(context) {

function reportLiteralNode(node) {
context.report(node, 'Missing JSX expression container around literal string');
context.report({
node: node,
message: 'Missing JSX expression container around literal string'
});
}

// --------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-no-undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ module.exports = function(context) {
}
}

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

return {
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-pascal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ module.exports = function(context) {
var isCompatTag = COMPAT_TAG_REGEX.test(node.name);

if (!isPascalCase && !isCompatTag) {
context.report(node, 'Imported JSX component ' + node.name + ' must be in PascalCase');
context.report({
node: node,
message: 'Imported JSX component ' + node.name + ' must be in PascalCase'
});
}
}
};
Expand Down

0 comments on commit 442d20b

Please sign in to comment.