alefragnani / vscode-jenkins-status

Jenkins Status Extension for Visual Studio Code
MIT License
27 stars 20 forks source link

Enable comments in .jenkins file #26

Open szalapski opened 5 years ago

szalapski commented 5 years ago

Could you somehow enable us to add comments in the .jenkins file? Currently, it seems like any invalid characters cause Jenkins Status to fail silently.

alefragnani commented 5 years ago

Hi @szalapski ,

To read the .jenkins file, and easily convert it to an Object, I use JSON.parse(), which does not support comments. If you know a stable library that support that, I'll be glad to use it.

Thanks for your help

szalapski commented 5 years ago

An easy way would be to allow a comment anywhere with:

comment: "Any comment we want",

...that would then be ignored by the plugin.

On Sun, Sep 16, 2018 at 5:26 PM Alessandro Fragnani < notifications@github.com> wrote:

Hi @szalapski https://github.com/szalapski ,

To read the .jenkins file, and easily convert it to an Object, I use JSON.parse(), which does not support comments. If you know a stable library that support that, I'll be glad to use it.

Thanks for your help

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alefragnani/vscode-jenkins-status/issues/26#issuecomment-421844237, or mute the thread https://github.com/notifications/unsubscribe-auth/ACmOsYWRuptebqOkBl0D0VrsCIM4_0qGks5ubs_7gaJpZM4WORjH .

alefragnani commented 5 years ago

Do you mean as a "new attribute", like:

{
    "url": "http://127.0.0.1:8080/job/myproject",
    "username": "jenkins_user",
    "password": "jenkins_password_or_token",
    "comment": "Any comment we want"
}

That would be easy to do, but I don't think this would be effective.

I'm thinking that move from JSON to YAML files would be a better approach. YAML allows comments, and is better suited for configuration files, like below. Maybe #11 and #16 would also benefit from this.

# Any comment we want
url: http://127.0.0.1:8080/job/myproject
username: jenkins_user
password: jenkins_password_or_token

I don't remember why I decided to use JSON in the first place. Probably because the simplicity of JSON.parse 🤔 .

What do you think?

pmartindev commented 5 years ago

One reason to use JSON would be that the settings file in VSCode uses JSON. I don't see the files conflicting in any way, but I do think it's a benefit to have the same markup language used across the board.

alefragnani commented 5 years ago

Yep, probably that, but once JSON does not support comments, we are out of luck.

I'll do that, I just have to decide if I support a file named .jenkins as JSON or YAML, or add support to another file named .jenkins.yml for the YAML format. I'll see 😄

Thank you

szalapski commented 5 years ago

At the very least, unrecognized keys/values shouldn't break things. This would enable unofficial comments to be added as additional keys/values.

On Wed, Oct 31, 2018 at 11:45 AM Alessandro Fragnani < notifications@github.com> wrote:

Yep, probably that, but once JSON does not support comments, we are out of luck.

I'll do that, I just have to decide if I support a file named .jenkins as JSON or YAML, or add support to another file named .jenkins.yml for the YAML format. I'll see 😄

Thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alefragnani/vscode-jenkins-status/issues/26#issuecomment-434758213, or mute the thread https://github.com/notifications/unsubscribe-auth/ACmOscMc_awPtfAd43tEtvXX_rNcdbzEks5uqdOfgaJpZM4WORjH .

redrails commented 4 years ago

You can also use comment-json library. It is able to parse commented JSON files. It also has a fairly small dependency tree.