Skip to content

Commit

Permalink
[New] add support for @typescript-eslint/parser v5
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 25, 2021
1 parent 734b455 commit 5448e2e
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-4+.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
after_install: |
npm install --no-save "eslint@${{ matrix.eslint }}" "@typescript-eslint/parser@${{ matrix.node-version >= 14 && '4' || (matrix.node-version >= 12 && '4' || (matrix.node-version >= 10 && '4.0' || (matrix.node-version >= 8 && '3' || '2'))) }}" "babel-eslint@${{ matrix.babel-eslint }}"
npm install --no-save "eslint@${{ matrix.eslint }}" "@typescript-eslint/parser@${{ matrix.node-version >= 14 && '5' || (matrix.node-version >= 12 && '4' || (matrix.node-version >= 10 && '4.0' || (matrix.node-version >= 8 && '3' || '2'))) }}" "babel-eslint@${{ matrix.babel-eslint }}"
skip-ls-check: true
env:
NPM_CONFIG_LEGACY_PEER_DEPS: true
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Added
* [`no-unused-class-component-methods`]: Handle unused class component methods ([#2166][] @jakeleventhal @pawelnvk)
* add [`no-arrow-function-lifecycle`] ([#1980][] @ngtan)
* add support for `@typescript-eslint/parser` v5 (@ljharb)

### Fixed
* `propTypes`: add `VoidFunctionComponent` to react generic list ([#3092][] @vedadeepta)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!rule || !propsUtil.isPropTypesDeclaration(node)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ module.exports = {
function isInClassProperty(node) {
let curNode = node.parent;
while (curNode) {
if (curNode.type === 'ClassProperty') {
if (curNode.type === 'ClassProperty' || curNode.type === 'PropertyDefinition') {
return true;
}
curNode = curNode.parent;
Expand Down Expand Up @@ -221,7 +221,7 @@ module.exports = {

if (
classComponent && destructuringClass && configuration === 'never'
&& !(ignoreClassFields && node.parent.type === 'ClassProperty')
&& !(ignoreClassFields && (node.parent.type === 'ClassProperty' || node.parent.type === 'PropertyDefinition'))
) {
report(context, messages.noDestructAssignment, 'noDestructAssignment', {
node,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!propsUtil.isDisplayNameDeclaration(node)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-foreign-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
let parent = node.parent;

while (parent && parent.type !== 'Program') {
if (parent.type === 'ClassProperty') {
if (parent.type === 'ClassProperty' || parent.type === 'PropertyDefinition') {
return parent;
}
parent = parent.parent;
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 @@ -156,7 +156,7 @@ module.exports = {
}

return {
ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (
!propsUtil.isPropTypesDeclaration(node)
&& !shouldCheckContextTypes(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-sort-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
// --------------------------------------------------------------------------

return {
ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!isDefaultPropsDeclaration(node)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-arrow-function-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
return `: function(${params.join(', ')}) `;
}

if (node.type === 'ClassProperty') {
if (node.type === 'ClassProperty' || node.type === 'PropertyDefinition') {
return `(${params.join(', ')}) `;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ module.exports = {
}
},

ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!node.static || !utils.isES6Component(node.parent.parent)) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-unused-class-component-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module.exports = {
}
},

'ClassProperty, MethodDefinition'(node) {
'ClassProperty, MethodDefinition, PropertyDefinition'(node) {
if (!classInfo) {
return;
}
Expand All @@ -208,6 +208,7 @@ module.exports = {

'ClassProperty:exit': exitMethod,
'MethodDefinition:exit': exitMethod,
'PropertyDefinition:exit': exitMethod,

MemberExpression(node) {
if (!classInfo || classInfo.inStatic) {
Expand Down
14 changes: 13 additions & 1 deletion lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ module.exports = {
}
},

ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!classInfo) {
return;
}
Expand Down Expand Up @@ -345,6 +345,18 @@ module.exports = {
}
},

'PropertyDefinition:exit'(node) {
if (
classInfo
&& !node.static
&& node.value
&& node.value.type === 'ArrowFunctionExpression'
) {
// Forget our set of local aliases.
classInfo.aliases = null;
}
},

MethodDefinition() {
if (!classInfo) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-exact-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = {
typeAliases[node.id.name] = node;
},

ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!propsUtil.isPropTypesDeclaration(node)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-render-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
depth++;
}
if (
/(MethodDefinition|(Class)?Property)$/.test(ancestor.type)
/(MethodDefinition|Property|ClassProperty|PropertyDefinition)$/.test(ancestor.type)
&& astUtil.getPropertyName(ancestor) === 'render'
&& depth <= 1
) {
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,17 @@ module.exports = {
getter: node.kind === 'get',
setter: node.kind === 'set',
staticVariable: node.static
&& node.type === 'ClassProperty'
&& (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')
&& (!node.value || !astUtil.isFunctionLikeExpression(node.value)),
staticMethod: node.static
&& (node.type === 'ClassProperty' || node.type === 'MethodDefinition')
&& (node.type === 'ClassProperty' || node.type === 'PropertyDefinition' || node.type === 'MethodDefinition')
&& node.value
&& (astUtil.isFunctionLikeExpression(node.value)),
instanceVariable: !node.static
&& node.type === 'ClassProperty'
&& (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')
&& (!node.value || !astUtil.isFunctionLikeExpression(node.value)),
instanceMethod: !node.static
&& node.type === 'ClassProperty'
&& (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')
&& node.value
&& (astUtil.isFunctionLikeExpression(node.value)),
typeAnnotation: !!node.typeAnnotation && node.value === null,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/sort-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module.exports = {
}
},

ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!propsUtil.isPropTypesDeclaration(node)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/state-in-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
create: Components.detect((context, components, utils) => {
const option = context.options[0] || 'always';
return {
ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (
option === 'always'
&& !node.static
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/static-property-placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ module.exports = {
// Public
// ----------------------------------------------------------------------
return {
ClassProperty: (node) => {
'ClassProperty, PropertyDefinition'(node) {
if (!utils.getParentES6Component()) {
return;
}

reportNodeIncorrectlyPositioned(node, STATIC_PUBLIC_FIELD);
},

MemberExpression: (node) => {
MemberExpression(node) {
// If definition type is undefined then it must not be a defining expression or if the definition is inside a
// class body then skip this node.
const right = node.parent.right;
Expand All @@ -168,7 +168,7 @@ module.exports = {
reportNodeIncorrectlyPositioned(node, PROPERTY_ASSIGNMENT);
},

MethodDefinition: (node) => {
MethodDefinition(node) {
// If the function is inside a class and is static getter then check if correctly positioned
if (utils.getParentES6Component() && node.static && node.kind === 'get') {
// Report error if needed
Expand Down
2 changes: 1 addition & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ function componentRule(rule, context) {
components.add(node, 2);
},

ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
node = utils.getParentComponent();
if (!node) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/defaultProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ module.exports = function defaultPropsInstructions(context, components, utils) {
// bar: 'baz'
// };
// }
ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (!(node.static && node.value)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/makeNoMethodSetStateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
depth++;
}
if (
(ancestor.type !== 'Property' && ancestor.type !== 'MethodDefinition' && ancestor.type !== 'ClassProperty')
(ancestor.type !== 'Property' && ancestor.type !== 'MethodDefinition' && ancestor.type !== 'ClassProperty' && ancestor.type !== 'PropertyDefinition')
|| !nameMatches(ancestor.key.name)
|| (mode !== 'disallow-in-func' && depth > 1)
) {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
let n = propTypes;
while (n) {
if (((n.type === 'AssignmentExpression') && propsUtil.isPropTypesDeclaration(n.left))
|| ((n.type === 'ClassProperty' || n.type === 'Property') && propsUtil.isPropTypesDeclaration(n))) {
|| ((n.type === 'ClassProperty' || n.type === 'PropertyDefinition' || n.type === 'Property') && propsUtil.isPropTypesDeclaration(n))) {
// Found a propType used inside of another propType. This is not considered usage, we'll still validate
// this component.
isUsedInPropTypes = true;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
* @returns {Boolean} True if the node is a type annotated props declaration, false if not.
*/
function isAnnotatedClassPropsDeclaration(node) {
if (node && node.type === 'ClassProperty') {
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
const tokens = context.getFirstTokens(node, 2);
if (
node.typeAnnotation && (
Expand Down Expand Up @@ -1099,7 +1099,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
}
},

ClassProperty(node) {
'ClassProperty, PropertyDefinition'(node) {
if (isAnnotatedClassPropsDeclaration(node)) {
markPropTypesAsDeclared(node, resolveTypeAnnotation(node));
} else if (propsUtil.isPropTypesDeclaration(node)) {
Expand Down
5 changes: 3 additions & 2 deletions lib/util/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const astUtil = require('./ast');
* @returns {Boolean} `true` if the node is a propTypes declaration, `false` if not
*/
function isPropTypesDeclaration(node) {
if (node && node.type === 'ClassProperty') {
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
// Flow support
if (node.typeAnnotation && node.key.name === 'props') {
return true;
Expand All @@ -27,7 +27,7 @@ function isPropTypesDeclaration(node) {
* @returns {Boolean} `true` if the node is a contextTypes declaration, `false` if not
*/
function isContextTypesDeclaration(node) {
if (node && node.type === 'ClassProperty') {
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
// Flow support
if (node.typeAnnotation && node.key.name === 'context') {
return true;
Expand Down Expand Up @@ -72,6 +72,7 @@ function isDefaultPropsDeclaration(node) {
function isDisplayNameDeclaration(node) {
switch (node.type) {
case 'ClassProperty':
case 'PropertyDefinition':
return node.key && node.key.name === 'displayName';
case 'Identifier':
return node.name === 'displayName';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/eslint": "=7.2.10",
"@types/estree": "^0.0.50",
"@types/node": "^14.17.27",
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4.0.0",
"@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4.0.0 || ^5.0.0",
"aud": "^1.1.5",
"babel-eslint": "^8 || ^9 || ^10.1.0",
"eslint": "^3 || ^4 || ^5 || ^6 || ^7",
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/require-render-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ ruleTester.run('require-render-return', rule, {
errors: [
{
messageId: 'noRenderReturn',
type: 'ClassProperty',
line: 3,
},
],
},
Expand Down

0 comments on commit 5448e2e

Please sign in to comment.