Skip to content

Commit

Permalink
feat(eslint-plugin): removed value from abstract property nodes (#3765)
Browse files Browse the repository at this point in the history
* chore: bump @types/jest from 26.0.24 to 27.0.1 (#3748)

Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.24 to 27.0.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

---
updated-dependencies:
- dependency-name: "@types/jest"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: address comments

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
3 people committed Oct 11, 2021
1 parent 71c9370 commit 5823524
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 138 deletions.
2 changes: 2 additions & 0 deletions packages/ast-spec/src/element/TSAbstractClassProperty/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import type {
export interface TSAbstractClassPropertyComputedName
extends ClassPropertyComputedNameBase {
type: AST_NODE_TYPES.TSAbstractClassProperty;
value: null;
}

export interface TSAbstractClassPropertyNonComputedName
extends ClassPropertyNonComputedNameBase {
type: AST_NODE_TYPES.TSAbstractClassProperty;
value: null;
}

export type TSAbstractClassProperty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ export default util.createRule<Options, MessageIds>({
return;

case AST_NODE_TYPES.ClassProperty:
case AST_NODE_TYPES.TSAbstractClassProperty:
if (node.accessibility === 'private') {
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function getNodeType(node: Member): string | null {
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'constructor';
case AST_NODE_TYPES.TSAbstractClassProperty:
return 'field';
case AST_NODE_TYPES.ClassProperty:
return node.value && functionExpressions.includes(node.value.type)
? 'method'
Expand Down
18 changes: 8 additions & 10 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ abstract class Foo {
private D: string;
protected static F(): {};
public E(): {};
public abstract A = () => {};
public abstract A(): void;
protected abstract G(): void;
}
`,
Expand Down Expand Up @@ -3618,7 +3618,7 @@ type Foo = {
{
code: `
abstract class Foo {
abstract A = () => {};
abstract A(): void;
B: string;
}
`,
Expand All @@ -3639,9 +3639,6 @@ abstract class Foo {
abstract class Foo {
abstract A: () => {};
B: string;
public C() {};
private D() {};
abstract E() {};
}
`,
errors: [
Expand All @@ -3659,18 +3656,19 @@ abstract class Foo {
{
code: `
abstract class Foo {
B: string;
abstract C = () => {};
abstract A: () => {};
B: string;
public C() {};
private D() {};
abstract E() {};
}
`,
options: [{ default: ['method', 'constructor', 'field'] }],
errors: [
{
messageId: 'incorrectGroupOrder',
data: {
name: 'C',
rank: 'field',
name: 'B',
rank: 'public abstract field',
},
line: 4,
column: 5,
Expand Down
63 changes: 18 additions & 45 deletions packages/eslint-plugin/tests/rules/quotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,25 +455,25 @@ class Foo {
{
code: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
public abstract a: "";
public abstract "a-b": "";
}
`,
},
{
code: `
abstract class Foo {
public abstract a = '';
public abstract 'a-b' = '';
public abstract a: '';
public abstract 'a-b': '';
}
`,
options: ['single'],
},
{
code: `
abstract class Foo {
public abstract a = \`\`;
public abstract 'a-b' = \`\`;
public abstract a: \`\`;
public abstract 'a-b': \`\`;
}
`,
options: ['backtick'],
Expand Down Expand Up @@ -1047,21 +1047,21 @@ class Foo {
{
code: `
abstract class Foo {
public abstract a = '';
public abstract 'a-b' = '';
public abstract a: '';
public abstract 'a-b': '';
}
`,
output: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
public abstract a: "";
public abstract "a-b": "";
}
`,
errors: [
{
...useDoubleQuote,
line: 3,
column: 23,
column: 22,
},
{
...useDoubleQuote,
Expand All @@ -1071,28 +1071,28 @@ abstract class Foo {
{
...useDoubleQuote,
line: 4,
column: 27,
column: 26,
},
],
},
{
code: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
public abstract a: "";
public abstract "a-b": "";
}
`,
output: `
abstract class Foo {
public abstract a = '';
public abstract 'a-b' = '';
public abstract a: '';
public abstract 'a-b': '';
}
`,
errors: [
{
...useSingleQuote,
line: 3,
column: 23,
column: 22,
},
{
...useSingleQuote,
Expand All @@ -1102,38 +1102,11 @@ abstract class Foo {
{
...useSingleQuote,
line: 4,
column: 27,
column: 26,
},
],
options: ['single'],
},
{
code: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
}
`,
output: `
abstract class Foo {
public abstract a = \`\`;
public abstract "a-b" = \`\`;
}
`,
errors: [
{
...useBacktick,
line: 3,
column: 23,
},
{
...useBacktick,
line: 4,
column: 27,
},
],
options: ['backtick'],
},

// TSAbstractMethodDefinition
{
Expand Down
4 changes: 3 additions & 1 deletion packages/scope-manager/src/referencer/ClassVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ class ClassVisitor extends Visitor {
this.#referencer.visit(node.key);
}

this.#referencer.visit(node.value);
if (node.type !== AST_NODE_TYPES.TSAbstractClassProperty) {
this.#referencer.visit(node.value);
}

if ('decorators' in node) {
node.decorators?.forEach(d => this.#referencer.visit(d));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract class Foo {
abstract bar;
abstract baz = 3;
abstract baz: number;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
abstract class Foo {
public abstract readonly foo = 'string';
public abstract readonly foo: string;
}
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ export class Converter {
? AST_NODE_TYPES.TSAbstractClassProperty
: AST_NODE_TYPES.ClassProperty,
key: this.convertChild(node.name),
value: this.convertChild(node.initializer),
value: isAbstract ? null : this.convertChild(node.initializer),
computed: isComputedProperty(node.name),
static: hasModifier(SyntaxKind.StaticKeyword, node),
readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
if (node.abstract) {
node.type = AST_NODE_TYPES.TSAbstractClassProperty;
delete node.abstract;
node.value = null;
}
/**
* TS 3.7: declare class properties
Expand Down
Loading

0 comments on commit 5823524

Please sign in to comment.