Skip to content

checked const value for the Boolean type#1066

Merged
datho7561 merged 5 commits into
redhat-developer:mainfrom
msivasubramaniaan:fix-boolean-validation-with-cont-value
May 8, 2025
Merged

checked const value for the Boolean type#1066
datho7561 merged 5 commits into
redhat-developer:mainfrom
msivasubramaniaan:fix-boolean-validation-with-cont-value

Conversation

@msivasubramaniaan
Copy link
Copy Markdown
Contributor

What does this PR do?

This PR do the validation for the const value of Boolean type

What issues does this PR fix or reference?

redhat-developer/vscode-yaml#1116

Is it tested? How?

Yes with existing test case

@msivasubramaniaan msivasubramaniaan self-assigned this May 6, 2025

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function equals(one: any, other: any): boolean {
export function equals(one: any, other: any, type?: any): boolean {

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function equals(one: any, other: any): boolean {
export function equals(one: any, other: any, type?: any): boolean {

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function equals(one: any, other: any): boolean {
export function equals(one: any, other: any, type?: any): boolean {

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 84.18% (-0.02%) from 84.201%
when pulling 18a8f35 on msivasubramaniaan:fix-boolean-validation-with-cont-value
into 4a5c6ca on redhat-developer:main.

Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

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

The quickfix is still broken ( there is a quickfix entry with no label that does nothing when the value is wrong ).

eg. if you have

prop: false

with the existing schema it will not suggest changing it to true

I couldn't find an existing test case that has a schema with "const": true, "type": "boolean". It would be nice to have one so that we can detect any regressions.

@datho7561
Copy link
Copy Markdown
Contributor

For the quickfix, something like this could solve it. We should add a test case too, though.

diff --git a/src/languageservice/services/yamlCodeActions.ts b/src/languageservice/services/yamlCodeActions.ts
index da0c7ee..85eba90 100644
--- a/src/languageservice/services/yamlCodeActions.ts
+++ b/src/languageservice/services/yamlCodeActions.ts
@@ -348,10 +348,11 @@ export class YamlCodeActions {
         continue;
       }
       for (const value of values) {
+        const cleanedValue = typeof value === 'boolean' ? `${value}` : value;
         results.push(
           CodeAction.create(
-            value,
-            createWorkspaceEdit(document.uri, [TextEdit.replace(diagnostic.range, value)]),
+            cleanedValue,
+            createWorkspaceEdit(document.uri, [TextEdit.replace(diagnostic.range, cleanedValue)]),
             CodeActionKind.QuickFix
           )
         );

@coveralls
Copy link
Copy Markdown

coveralls commented May 8, 2025

Coverage Status

coverage: 83.864% (+0.04%) from 83.824%
when pulling a4cacf0 on msivasubramaniaan:fix-boolean-validation-with-cont-value
into 1be76fb on redhat-developer:main.

@msivasubramaniaan
Copy link
Copy Markdown
Contributor Author

The quickfix is still broken ( there is a quickfix entry with no label that does nothing when the value is wrong ).

eg. if you have

prop: false

with the existing schema it will not suggest changing it to true

I couldn't find an existing test case that has a schema with "const": true, "type": "boolean". It would be nice to have one so that we can detect any regressions.

With the recent fix it will ask to change it to false when the schema expects true. Please find the attachment and I will add a sperate test case
image

Comment thread test/schemaValidation.test.ts Outdated
Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

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

This fixes the validation issue. The quickfix can be fixed later. Thanks, Muthu!

@datho7561 datho7561 merged commit 4e25b52 into redhat-developer:main May 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants