Skip to content

Commit

Permalink
fix(lint/noStaticOnlyClass): prevent error on static classes that ext…
Browse files Browse the repository at this point in the history
…end other classes (#3626)
  • Loading branch information
errmayank authored Aug 16, 2024
1 parent 8b4f3ff commit ffb66d9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ impl Rule for NoStaticOnlyClass {
return None;
}

if class_declaration.extends_clause().is_some() {
return None;
}

let all_members_static = class_declaration
.members()
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ class StaticConstants1 {
}

class Empty {}

class Environment {
type: string;

constructor(type: string) {
this.type = type;
}

getType(): string {
return this.type;
}
}

class Application extends Environment {
private static environment: Environment;

static initialize(type: string): void {
if (!this.environment) {
this.environment = new Environment(type);
}
}

static getEnvironment(): string {
if (!this.environment) {
throw new Error("Application not initialized.");
}
return this.environment.getType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@ class StaticConstants1 {

class Empty {}

```
class Environment {
type: string;

constructor(type: string) {
this.type = type;
}

getType(): string {
return this.type;
}
}

class Application extends Environment {
private static environment: Environment;

static initialize(type: string): void {
if (!this.environment) {
this.environment = new Environment(type);
}
}

static getEnvironment(): string {
if (!this.environment) {
throw new Error("Application not initialized.");
}
return this.environment.getType();
}
}

```

0 comments on commit ffb66d9

Please sign in to comment.