Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agregar validation para checkear que las consts dentro de un program esten inicializadas #175

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ export const shouldInitializeGlobalReference = error<Variable>(node =>
!(node.isAtPackageLevel && node.value.isSynthetic && node.value.is(Literal) && node.value.isNull())
)

export const shouldInitializeConst = error<Variable>(node => {
const isInProgram = getContainer(node)?.kind == 'Program'
juanbono marked this conversation as resolved.
Show resolved Hide resolved
return !(
isInProgram &&
!node.isAtPackageLevel &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto hace falta? Si isInProgram entonces no está al nivel package.

node.isConstant &&
node.value.isSynthetic &&
node.value.is(Literal) &&
node.value.isNull())
Comment on lines +448 to +450
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tal vez podamos abstraer esto en una función isNotInitialized, se repite en la otra validación.

})

export const shouldNotDefineUnusedVariables = warning<Field>(node => !unusedVariable(node))

export const shouldNotDuplicatePackageName = error<Package>(node =>
Expand Down Expand Up @@ -774,7 +785,7 @@ const validationsByKind = (node: Node): Record<string, Validation<any>> => match
when(Mixin)(() => ({ nameShouldBeginWithUppercase, shouldNotHaveLoopInHierarchy, shouldOnlyInheritFromMixin, shouldNotDuplicateGlobalDefinitions, shouldNotDuplicateVariablesInLinearization, shouldNotDuplicateEntities })),
when(Field)(() => ({ nameShouldBeginWithLowercase, shouldNotAssignToItselfInDeclaration, nameShouldNotBeKeyword, shouldNotDuplicateFields, shouldNotUseReservedWords, shouldNotDefineUnusedVariables, shouldDefineConstInsteadOfVar, shouldInitializeSingletonAttribute })),
when(Method)(() => ({ onlyLastParameterCanBeVarArg, nameShouldNotBeKeyword, methodShouldHaveDifferentSignature, shouldNotOnlyCallToSuper, shouldUseOverrideKeyword, possiblyReturningBlock, shouldNotUseOverride, shouldMatchSuperclassReturnValue, shouldNotDefineNativeMethodsOnUnnamedSingleton, overridingMethodShouldHaveABody, getterMethodShouldReturnAValue, shouldHaveBody })),
when(Variable)(() => ({ nameShouldBeginWithLowercase, nameShouldNotBeKeyword, shouldNotAssignToItselfInDeclaration, shouldNotDuplicateLocalVariables, shouldNotDuplicateGlobalDefinitions, shouldNotDefineGlobalMutableVariables, shouldNotUseReservedWords, shouldInitializeGlobalReference, shouldDefineConstInsteadOfVar, shouldNotDuplicateEntities })),
when(Variable)(() => ({ nameShouldBeginWithLowercase, nameShouldNotBeKeyword, shouldNotAssignToItselfInDeclaration, shouldNotDuplicateLocalVariables, shouldNotDuplicateGlobalDefinitions, shouldNotDefineGlobalMutableVariables, shouldNotUseReservedWords, shouldInitializeGlobalReference, shouldInitializeConst, shouldDefineConstInsteadOfVar, shouldNotDuplicateEntities })),
when(Assignment)(() => ({ shouldNotAssignToItself, shouldNotReassignConst })),
when(Reference)(() => ({ missingReference, shouldUseSelfAndNotSingletonReference })),
when(Self)(() => ({ shouldNotUseSelf })),
Expand All @@ -795,4 +806,4 @@ export default (target: Node): List<Problem> => target.reduce<Problem[]>((found,
.map(([code, validation]) => validation(node, code)!)
.filter(result => result !== null),
]
}, [])
}, [])
Loading