Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daci committed Feb 15, 2024
1 parent 5c059a5 commit 4cc1cf6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4169,7 +4169,7 @@ describe('MaestroPlugin', () => {
`);
expect(
getContents('source/comp.brs')
).to.eql(undent`
).to.eql(undent`
function __Comp_builder()
instance = {}
instance.new = sub()
Expand Down Expand Up @@ -4260,7 +4260,7 @@ describe('MaestroPlugin', () => {
`);
expect(
getContents('source/comp.brs')
).to.eql(undent`
).to.eql(undent`
function __Comp_builder()
instance = {}
instance.new = sub()
Expand Down Expand Up @@ -4299,7 +4299,7 @@ describe('MaestroPlugin', () => {
//ignore diagnostics - need to import core
expect(
getContents('source/comp.brs')
).to.eql(undent`
).to.eql(undent`
function __Comp_builder()
instance = {}
instance.new = sub()
Expand Down
65 changes: 33 additions & 32 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import ReflectionUtil from './lib/reflection/ReflectionUtil';
import { FileFactory } from './lib/utils/FileFactory';
import NodeClassUtil from './lib/node-classes/NodeClassUtil';
import { RawCodeStatement, RawCodeExpression } from './lib/utils/RawCodeStatement';
import { addClassFieldsNotFoundOnSetOrGet, addIOCNoTypeSupplied, addIOCWrongArgs, noCallsInAsXXXAllowed, functionNotImported, IOCClassNotInScope, namespaceNotImported, noPathForInject, noPathForIOCSync, unknownClassMethod, unknownConstructorMethod, unknownSuperClass, unknownType, wrongConstructorArgs, wrongMethodArgs, observeRequiresFirstArgumentIsField, observeRequiresFirstArgumentIsNotM, observeFunctionNameNotFound, observeFunctionNameWrongArgs, addWrongAnnotation, noNameForNotification, onNotificationFieldError, notificationAnnotationDisabled,onNotificationWrongParameter, onNotificationConstructorError, onNotificationNotSupported } from './lib/utils/Diagnostics';
import { addClassFieldsNotFoundOnSetOrGet, addIOCNoTypeSupplied, addIOCWrongArgs, noCallsInAsXXXAllowed, functionNotImported, IOCClassNotInScope, namespaceNotImported, noPathForInject, noPathForIOCSync, unknownClassMethod, unknownConstructorMethod, unknownSuperClass, unknownType, wrongConstructorArgs, wrongMethodArgs, observeRequiresFirstArgumentIsField, observeRequiresFirstArgumentIsNotM, observeFunctionNameNotFound, observeFunctionNameWrongArgs, addWrongAnnotation, noNameForNotification, onNotificationFieldError, notificationAnnotationDisabled, onNotificationWrongParameter, onNotificationConstructorError, onNotificationNotSupported } from './lib/utils/Diagnostics';
import { getAllAnnotations, getAllFields, defaultAnnotations } from './lib/utils/Utils';
import { getSGMembersLookup } from './SGApi';
import { DynamicType } from 'brighterscript/dist/types/DynamicType';
Expand Down Expand Up @@ -284,36 +284,36 @@ export class MaestroPlugin implements CompilerPlugin {
let classes = file.parser.references.classStatements;
for (let cs of classes) {
for (let method of cs.methods) {
let annotation = (method.annotations|| []).find((a) => a.name.toLowerCase() === 'onnotification');
if (!annotation) {
continue;
}
let classAnnotations = this.findAnnotations(method.parent) || [];
if (!classAnnotations.find((a) => a.name.toLowerCase() === 'node' || a.name.toLowerCase() === 'task')) {
file.addDiagnostics([{
...onNotificationNotSupported(),
range: cs.range,
file: file
}]);
continue
}
if (method.name.text.toLowerCase() == "new") {
let annotation = (method.annotations || []).find((a) => a.name.toLowerCase() === 'onnotification');
if (!annotation) {
continue;
}
let classAnnotations = this.findAnnotations(method.parent) || [];
if (!classAnnotations.find((a) => a.name.toLowerCase() === 'node' || a.name.toLowerCase() === 'task')) {
file.addDiagnostics([{
...onNotificationNotSupported(),
range: cs.range,
file: file
}]);
continue;
}
if (method.name.text.toLowerCase() === 'new') {
file.addDiagnostics([{
...onNotificationConstructorError(),
range: method.range,
file: file
}]);
continue;
}
if (method.func.parameters.length !== 1 ) {
if (method.func.parameters.length !== 1) {
file.addDiagnostics([{
...onNotificationWrongParameter(),
range: method.range,
file: file
}]);
continue;
} else if (method.func.parameters.length == 1) {
if (method.func.parameters[0].type.toString() !== "mc.notification") {
} else if (method.func.parameters.length === 1) {
if (method.func.parameters[0].type.toString() !== 'mc.notification') {
file.addDiagnostics([{
...onNotificationWrongParameter(),
range: method.range,
Expand Down Expand Up @@ -719,24 +719,25 @@ export class MaestroPlugin implements CompilerPlugin {
}

private updateNotificationAnnotation(cs: ClassStatement, event: BeforeFileTranspileEvent) {
for (let method of cs.methods) {
let annotation = (method.annotations|| []).find((a) => a.name.toLowerCase() === 'onnotification');
if (annotation && method.name.text.toLowerCase() !== "new") {
let args = annotation.getArguments();
if (args.length == 1) {
let initializeMethod = cs.memberMap["initialize"];
let observeStatement = new RawCodeStatement(`m.observeNotification("${args[0].toString()}", m.${method?.func.functionStatement?.name?.text})`, event.file, cs.range);
if (isMethodStatement(initializeMethod)) {
initializeMethod.func.body.statements.push(observeStatement);
} else {
let constructor = cs.memberMap.new as MethodStatement;
if (constructor) {
constructor.func.body.statements.push(observeStatement);
}
for (let method of cs.methods) {
let annotation = (method.annotations || []).find((a) => a.name.toLowerCase() === 'onnotification');
if (annotation && method.name.text.toLowerCase() !== 'new') {
let args = annotation.getArguments();
if (args.length === 1) {
let initializeMethod = cs.memberMap.initialize;
// eslint-disable-next-line
let observeStatement = new RawCodeStatement(`m.observeNotification("${args[0].toString()}", m.${method?.func.functionStatement?.name?.text})`, event.file, cs.range);
if (isMethodStatement(initializeMethod)) {
initializeMethod.func.body.statements.push(observeStatement);
} else {
let constructor = cs.memberMap.new as MethodStatement;
if (constructor) {
constructor.func.body.statements.push(observeStatement);
}
}
}
}
}
}

private getRootValue(value: DottedGetExpression) {
Expand Down

0 comments on commit 4cc1cf6

Please sign in to comment.