Skip to content

Commit 442d20b

Browse files
committed
Remove usage of context deprecated methods
1 parent efa2630 commit 442d20b

35 files changed

+236
-87
lines changed

lib/rules/display-name.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Components = require('../util/Components');
1212

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

15+
var sourceCode = context.getSourceCode();
1516
var config = context.options[0] || {};
1617
var acceptTranspilerName = config.acceptTranspilerName || false;
1718

@@ -26,7 +27,7 @@ module.exports = Components.detect(function(context, components, utils) {
2627
// Special case for class properties
2728
// (babel-eslint does not expose property name so we have to rely on tokens)
2829
if (node.type === 'ClassProperty') {
29-
var tokens = context.getFirstTokens(node, 2);
30+
var tokens = sourceCode.getFirstTokens(node, 2);
3031
if (
3132
tokens[0].value === 'displayName' ||
3233
(tokens[1] && tokens[1].value === 'displayName')
@@ -57,12 +58,13 @@ module.exports = Components.detect(function(context, components, utils) {
5758
* @param {Object} component The component to process
5859
*/
5960
function reportMissingDisplayName(component) {
60-
context.report(
61-
component.node,
62-
MISSING_MESSAGE, {
61+
context.report({
62+
node: component.node,
63+
message: MISSING_MESSAGE,
64+
data: {
6365
component: component.name
6466
}
65-
);
67+
});
6668
}
6769

6870
/**

lib/rules/forbid-prop-types.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ module.exports = function(context) {
7575
target = value.name;
7676
}
7777
if (isForbidden(target)) {
78-
context.report(declaration, 'Prop type `' + target + '` is forbidden');
78+
context.report({
79+
node: declaration,
80+
message: 'Prop type `' + target + '` is forbidden'
81+
});
7982
}
8083
});
8184
}

lib/rules/jsx-closing-bracket-location.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = function(context) {
1919
};
2020
var DEFAULT_LOCATION = 'tag-aligned';
2121

22+
var sourceCode = context.getSourceCode();
2223
var config = context.options[0];
2324
var options = {
2425
nonEmpty: DEFAULT_LOCATION,
@@ -115,18 +116,18 @@ module.exports = function(context) {
115116
* prop and start of opening line.
116117
*/
117118
function getTokensLocations(node) {
118-
var opening = context.getFirstToken(node).loc.start;
119-
var closing = context.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
120-
var tag = context.getFirstToken(node.name).loc.start;
119+
var opening = sourceCode.getFirstToken(node).loc.start;
120+
var closing = sourceCode.getLastTokens(node, node.selfClosing ? 2 : 1)[0].loc.start;
121+
var tag = sourceCode.getFirstToken(node.name).loc.start;
121122
var lastProp;
122123
if (node.attributes.length) {
123124
lastProp = node.attributes[node.attributes.length - 1];
124125
lastProp = {
125-
column: context.getFirstToken(lastProp).loc.start.column,
126-
line: context.getLastToken(lastProp).loc.end.line
126+
column: sourceCode.getFirstToken(lastProp).loc.start.column,
127+
line: sourceCode.getLastToken(lastProp).loc.end.line
127128
};
128129
}
129-
var openingLine = context.getSourceCode().lines[opening.line - 1];
130+
var openingLine = sourceCode.lines[opening.line - 1];
130131
var openingStartOfLine = {
131132
column: /^\s*/.exec(openingLine)[0].length,
132133
line: opening.line

lib/rules/jsx-curly-spacing.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// ------------------------------------------------------------------------------
1616

1717
module.exports = function(context) {
18+
19+
var sourceCode = context.getSourceCode();
1820
var spaced = context.options[0] === 'always';
1921
var multiline = context.options[1] ? context.options[1].allowMultiline : true;
2022

@@ -192,8 +194,8 @@ module.exports = function(context) {
192194
JSXExpressionContainer: function(node) {
193195
var first = context.getFirstToken(node);
194196
var second = context.getFirstToken(node, 1);
195-
var penultimate = context.getLastToken(node, 1);
196-
var last = context.getLastToken(node);
197+
var penultimate = sourceCode.getLastToken(node, 1);
198+
var last = sourceCode.getLastToken(node);
197199

198200
if (first === penultimate && second === last) {
199201
return;

lib/rules/jsx-equals-spacing.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,34 @@ module.exports = function(context) {
4040
default:
4141
case 'never':
4242
if (spacedBefore) {
43-
context.report(attrNode, equalToken.loc.start,
44-
'There should be no space before \'=\'');
43+
context.report({
44+
node: attrNode,
45+
loc: equalToken.loc.start,
46+
message: 'There should be no space before \'=\''
47+
});
4548
}
4649
if (spacedAfter) {
47-
context.report(attrNode, equalToken.loc.start,
48-
'There should be no space after \'=\'');
50+
context.report({
51+
node: attrNode,
52+
loc: equalToken.loc.start,
53+
message: 'There should be no space after \'=\''
54+
});
4955
}
5056
break;
5157
case 'always':
5258
if (!spacedBefore) {
53-
context.report(attrNode, equalToken.loc.start,
54-
'A space is required before \'=\'');
59+
context.report({
60+
node: attrNode,
61+
loc: equalToken.loc.start,
62+
message: 'A space is required before \'=\''
63+
});
5564
}
5665
if (!spacedAfter) {
57-
context.report(attrNode, equalToken.loc.start,
58-
'A space is required after \'=\'');
66+
context.report({
67+
node: attrNode,
68+
loc: equalToken.loc.start,
69+
message: 'A space is required after \'=\''
70+
});
5971
}
6072
break;
6173
}

lib/rules/jsx-handler-names.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
module.exports = function(context) {
1212

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

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

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

3738
if (propIsEventHandler && !propFnIsNamedCorrectly) {
38-
context.report(
39-
node,
40-
'Handler function for ' + propKey + ' prop key must begin with \'' + eventHandlerPrefix + '\''
41-
);
39+
context.report({
40+
node: node,
41+
message: 'Handler function for ' + propKey + ' prop key must begin with \'' + eventHandlerPrefix + '\''
42+
});
4243
} else if (propFnIsNamedCorrectly && !propIsEventHandler) {
43-
context.report(
44-
node,
45-
'Prop key for ' + propValue + ' must begin with \'' + eventHandlerPropPrefix + '\''
46-
);
44+
context.report({
45+
node: node,
46+
message: 'Prop key for ' + propValue + ' must begin with \'' + eventHandlerPropPrefix + '\''
47+
});
4748
}
4849
}
4950
};

lib/rules/jsx-indent-props.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module.exports = function(context) {
4040
var indentType = 'space';
4141
var indentSize = 4;
4242

43+
var sourceCode = context.getSourceCode();
44+
4345
if (context.options.length) {
4446
if (context.options[0] === 'tab') {
4547
indentSize = 1;
@@ -66,9 +68,18 @@ module.exports = function(context) {
6668
};
6769

6870
if (loc) {
69-
context.report(node, loc, MESSAGE, msgContext);
71+
context.report({
72+
node: node,
73+
loc: loc,
74+
message: MESSAGE,
75+
data: msgContext
76+
});
7077
} else {
71-
context.report(node, MESSAGE, msgContext);
78+
context.report({
79+
node: node,
80+
message: MESSAGE,
81+
data: msgContext
82+
});
7283
}
7384
}
7485

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

86-
var src = context.getSource(node, node.loc.start.column + extraColumnStart);
97+
var src = sourceCode.getText(node, node.loc.start.column + extraColumnStart);
8798
var lines = src.split('\n');
8899
if (byLastLine) {
89100
src = lines[lines.length - 1];
@@ -111,7 +122,7 @@ module.exports = function(context) {
111122
* @return {Boolean} true if its the first in the its start line
112123
*/
113124
function isNodeFirstInLine(node, byEndLocation) {
114-
var firstToken = byEndLocation === true ? context.getLastToken(node, 1) : context.getTokenBefore(node);
125+
var firstToken = byEndLocation === true ? sourceCode.getLastToken(node, 1) : sourceCode.getTokenBefore(node);
115126
var startLine = byEndLocation === true ? node.loc.end.line : node.loc.start.line;
116127
var endLine = firstToken ? firstToken.loc.end.line : -1;
117128

lib/rules/jsx-indent.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module.exports = function(context) {
4040
var indentType = 'space';
4141
var indentSize = 4;
4242

43+
var sourceCode = context.getSourceCode();
44+
4345
if (context.options.length) {
4446
if (context.options[0] === 'tab') {
4547
indentSize = 1;
@@ -66,9 +68,18 @@ module.exports = function(context) {
6668
};
6769

6870
if (loc) {
69-
context.report(node, loc, MESSAGE, msgContext);
71+
context.report({
72+
node: node,
73+
loc: loc,
74+
message: MESSAGE,
75+
data: msgContext
76+
});
7077
} else {
71-
context.report(node, MESSAGE, msgContext);
78+
context.report({
79+
node: node,
80+
message: MESSAGE,
81+
data: msgContext
82+
});
7283
}
7384
}
7485

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

86-
var src = context.getSource(node, node.loc.start.column + extraColumnStart);
97+
var src = sourceCode.getText(node, node.loc.start.column + extraColumnStart);
8798
var lines = src.split('\n');
8899
if (byLastLine) {
89100
src = lines[lines.length - 1];
@@ -112,7 +123,7 @@ module.exports = function(context) {
112123
function isNodeFirstInLine(node) {
113124
var token = node;
114125
do {
115-
token = context.getTokenBefore(token);
126+
token = sourceCode.getTokenBefore(token);
116127
} while (token.type === 'JSXText');
117128
var startLine = node.loc.start.line;
118129
var endLine = token ? token.loc.end.line : -1;

lib/rules/jsx-key.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ module.exports = function(context) {
2323

2424
function checkIteratorElement(node) {
2525
if (node.type === 'JSXElement' && !hasKeyProp(node)) {
26-
context.report(node, 'Missing "key" prop for element in iterator');
26+
context.report({
27+
node: node,
28+
message: 'Missing "key" prop for element in iterator'
29+
});
2730
}
2831
}
2932

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

4245
if (node.parent.type === 'ArrayExpression') {
43-
context.report(node, 'Missing "key" prop for element in array');
46+
context.report({
47+
node: node,
48+
message: 'Missing "key" prop for element in array'
49+
});
4450
}
4551
},
4652

lib/rules/jsx-max-props-per-line.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
module.exports = function (context) {
1313

14+
var sourceCode = context.getSourceCode();
1415
var configuration = context.options[0] || {};
1516
var maximum = configuration.maximum || 1;
1617

1718
function getPropName(propNode) {
1819
if (propNode.type === 'JSXSpreadAttribute') {
19-
return context.getSource(propNode.argument);
20+
return sourceCode.getText(propNode.argument);
2021
}
2122
return propNode.name.name;
2223
}
@@ -40,7 +41,10 @@ module.exports = function (context) {
4041
}
4142
if (props[line].length > maximum) {
4243
var name = getPropName(props[line][maximum]);
43-
context.report(props[line][maximum], 'Prop `' + name + '` must be placed on a new line');
44+
context.report({
45+
node: props[line][maximum],
46+
message: 'Prop `' + name + '` must be placed on a new line'
47+
});
4448
break;
4549
}
4650
}

lib/rules/jsx-no-bind.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ module.exports = function(context) {
2525
valueNode.callee.type === 'MemberExpression' &&
2626
valueNode.callee.property.name === 'bind'
2727
) {
28-
context.report(node, 'JSX props should not use .bind()');
28+
context.report({
29+
node: node,
30+
message: 'JSX props should not use .bind()'
31+
});
2932
} else if (
3033
!configuration.allowArrowFunctions &&
3134
valueNode.type === 'ArrowFunctionExpression'
3235
) {
33-
context.report(node, 'JSX props should not use arrow functions');
36+
context.report({
37+
node: node,
38+
message: 'JSX props should not use arrow functions'
39+
});
3440
}
3541
}
3642
};

lib/rules/jsx-no-duplicate-props.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ module.exports = function (context) {
3030
}
3131

3232
if (props.hasOwnProperty(name)) {
33-
context.report(decl, 'No duplicate props allowed');
33+
context.report({
34+
node: decl,
35+
message: 'No duplicate props allowed'
36+
});
3437
} else {
3538
props[name] = 1;
3639
}

lib/rules/jsx-no-literals.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
module.exports = function(context) {
1212

1313
function reportLiteralNode(node) {
14-
context.report(node, 'Missing JSX expression container around literal string');
14+
context.report({
15+
node: node,
16+
message: 'Missing JSX expression container around literal string'
17+
});
1518
}
1619

1720
// --------------------------------------------------------------------------

lib/rules/jsx-no-undef.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ module.exports = function(context) {
5050
}
5151
}
5252

53-
context.report(node, '\'' + node.name + '\' is not defined.');
53+
context.report({
54+
node: node,
55+
message: '\'' + node.name + '\' is not defined.'
56+
});
5457
}
5558

5659
return {

lib/rules/jsx-pascal-case.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ module.exports = function(context) {
3838
var isCompatTag = COMPAT_TAG_REGEX.test(node.name);
3939

4040
if (!isPascalCase && !isCompatTag) {
41-
context.report(node, 'Imported JSX component ' + node.name + ' must be in PascalCase');
41+
context.report({
42+
node: node,
43+
message: 'Imported JSX component ' + node.name + ' must be in PascalCase'
44+
});
4245
}
4346
}
4447
};

0 commit comments

Comments
 (0)