Skip to content

Commit

Permalink
Drop support for legacy node type ClassProperty (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 1, 2021
1 parent 3ef389d commit d4ce499
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"devDependencies": {
"@babel/code-frame": "^7.14.5",
"@babel/core": "^7.15.5",
"@babel/eslint-parser": "^7.15.8",
"@babel/eslint-parser": "^7.16.0",
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
"@typescript-eslint/parser": "^5.2.0",
"ava": "^3.15.0",
Expand Down
21 changes: 5 additions & 16 deletions rules/custom-error-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,11 @@ const isAssignmentExpression = (node, name) => {
return lhs.property.name === name;
};

const isPropertyDefinition = (node, name) => {
const {type, computed, key} = node;
if (type !== 'PropertyDefinition' && type !== 'ClassProperty') {
return false;
}

if (computed) {
return false;
}

if (key.type !== 'Identifier') {
return false;
}

return key.name === name;
};
const isPropertyDefinition = (node, name) =>
node.type === 'PropertyDefinition'
&& !node.computed
&& node.key.type === 'Identifier'
&& node.key.name === name;

function * customErrorDefinition(context, node) {
if (!hasValidSuperClass(node)) {
Expand Down
5 changes: 1 addition & 4 deletions rules/no-static-only-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ const isDeclarationOfExportDefaultDeclaration = node =>
&& node.parent.type === 'ExportDefaultDeclaration'
&& node.parent.declaration === node;

// https://github.com/estree/estree/blob/master/stage3/class-features.md#propertydefinition
const isPropertyDefinition = node => node.type === 'PropertyDefinition'
// Legacy node type
|| node.type === 'ClassProperty';
const isPropertyDefinition = node => node.type === 'PropertyDefinition';
const isMethodDefinition = node => node.type === 'MethodDefinition';

function isStaticMember(node) {
Expand Down
13 changes: 4 additions & 9 deletions rules/prevent-abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,10 @@ const shouldReportIdentifierAsProperty = identifier => {
}

if (
identifier.parent.type === 'MethodDefinition'
&& identifier.parent.key === identifier
&& !identifier.parent.computed
) {
return true;
}

if (
(identifier.parent.type === 'ClassProperty' || identifier.parent.type === 'PropertyDefinition')
(
identifier.parent.type === 'MethodDefinition'
|| identifier.parent.type === 'PropertyDefinition'
)
&& identifier.parent.key === identifier
&& !identifier.parent.computed
) {
Expand Down
2 changes: 0 additions & 2 deletions rules/selectors/reference-identifier-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const nonReferenceSelectors = [
'ClassDeclaration > .id',
// `const foo = class Identifier() {}`
'ClassExpression > .id',
// TODO: remove `ClassProperty` when `babel` and `typescript` support `PropertyDefinition`
'ClassProperty[computed!=true] > .key',
// `class Foo {Identifier = 1}`
'PropertyDefinition[computed!=true] > .key',
// `class Foo {Identifier() {}}`
Expand Down

0 comments on commit d4ce499

Please sign in to comment.