Skip to content

Commit

Permalink
Merge pull request #147 from iljapostnovs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
iljapostnovs committed Jan 27, 2024
2 parents 8a5e4e9 + a1d0e44 commit 3c7c552
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.15.0 (27-01-2024)

- `WrongOverrideLinter` now checks if member is deprecated
- Fix: `UnusedClassLinter` doesn't show error if any member is used outside the class

## 1.14.5 (25-01-2024)

- [UI5 Parser](https://github.com/iljapostnovs/ui5plugin-parser) updated to v1.7.7
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Checks if imported module exists and is not deprecated

### WrongOverrideLinter

Checks if overriden member is not private
Checks if overriden member is not private and if parent member is not deprecated

![Alt text](images/WrongOverrideLinter1.png)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui5plugin-linter",
"version": "1.14.5",
"version": "1.15.0",
"description": "UI5 Class linter",
"main": "dist/index.js",
"scripts": {
Expand Down
38 changes: 36 additions & 2 deletions src/classes/js/parts/UnusedClassLinter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { AbstractUI5Parser, ParserPool, TextDocument } from "ui5plugin-parser";
import { AbstractCustomClass } from "ui5plugin-parser/dist/classes/parsing/ui5class/AbstractCustomClass";
import {
AbstractUI5Parser,
ParserPool,
ReferenceFinder,
TSReferenceFinder,
TextDocument,
UI5JSParser,
UI5TSParser
} from "ui5plugin-parser";
import {
AbstractCustomClass,
ICustomClassField,
ICustomClassMethod
} from "ui5plugin-parser/dist/classes/parsing/ui5class/AbstractCustomClass";
import { IXMLFile } from "ui5plugin-parser/dist/classes/parsing/util/filereader/IFileReader";
import { RangeAdapter } from "ui5plugin-parser/dist/classes/parsing/util/range/adapters/RangeAdapter";
import { IError, JSLinters } from "../../Linter";
Expand Down Expand Up @@ -48,12 +60,34 @@ export class UnusedClassLinter<
this._checkIfClassIsUsedAsInterface(CustomJSClass, UIClass)
);
}) ||
this._checkIfClassMembersHasAnyReferencesOutside(UIClass) ||
this._checkIfClassMentionedInManifest(UIClass) ||
this._checkIfClassIsViewsController(UIClass) ||
this._checkIfClassIsUsedInView(UIClass)
);
}

private _checkIfClassMembersHasAnyReferencesOutside(UIClass: AbstractCustomClass): boolean {
const members: (ICustomClassMethod | ICustomClassField)[] = [...UIClass.methods, ...UIClass.fields];
return members.some(
member =>
this._getReferenceLocations(member).filter(location => location.filePath !== UIClass.fsPath).length > 0
);
}

private _getReferenceLocations(member: ICustomClassMethod | ICustomClassField) {
if (this._parser instanceof UI5JSParser) {
const referenceFinder = new ReferenceFinder(this._parser);
return referenceFinder.getReferenceLocations(member);
}
if (this._parser instanceof UI5TSParser) {
const referenceFinder = new TSReferenceFinder(this._parser);
return referenceFinder.getReferenceLocations(member);
} else {
return [];
}
}

private _checkClassForLintingExceptions(UIClass: AbstractCustomClass) {
return (
UIClass.fsPath?.toLowerCase().endsWith("component.js") ||
Expand Down
16 changes: 15 additions & 1 deletion src/classes/js/parts/WrongOverrideLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class WrongOverrideLinter extends JSLinter<UI5JSParser, CustomJSClass> {
) {
let error: IError | undefined;
const parentMember = this._getMemberFromParent(UIClass, UIMember);
if (parentMember && parentMember.visibility === "private" && UIMember.loc) {
if (parentMember?.visibility === "private" && UIMember.loc) {
const range = RangeAdapter.acornLocationToRange(UIMember.loc);
error = {
message: `You can't override "${UIMember.name}" because it is a private member of class "${parentMember.owner}"`,
Expand All @@ -54,6 +54,20 @@ export class WrongOverrideLinter extends JSLinter<UI5JSParser, CustomJSClass> {
severity: this._configHandler.getSeverity(this.className),
fsPath: UIClass.fsPath || ""
};
} else if (parentMember?.deprecated && UIMember.loc) {
const range = RangeAdapter.acornLocationToRange(UIMember.loc);
error = {
message: `Member "${UIMember.name}" is deprecated`,
code: "UI5Plugin",
source: this.className,
range: range,
className: UIClass.className,
acornNode: UIMember.node,
methodName: UIMember.name,
sourceClassName: UIClass.className,
severity: this._configHandler.getSeverity(this.className),
fsPath: UIClass.fsPath || ""
};
}

return error;
Expand Down

0 comments on commit 3c7c552

Please sign in to comment.