voxpupuli / metadata-json-lint

Tool to check the validity of Puppet metadata.json files
Apache License 2.0
29 stars 27 forks source link

metadata-json-lint should be easier to consume as a gem, not always via CLI #85

Open glennsarti opened 7 years ago

glennsarti commented 7 years ago

I am one of the developers of the Visual Studio Code Puppet Extension (https://github.com/jpogran/puppet-vscode) and I started to add metadata lint support to the extension using this gem. Currently the metadata-json-lint is somewhat impossible to consume in a programmatic form, and assumes it will always be invoked from a command line:

  1. The parse method assumes that the metadata string is a file on disk whereas I already have the string content, and it may not actually be on disk. This method seems to conflate loading a file and parsing a file into the same method

  2. The output from parse is always via puts and the instance variables for warnings and errors are not exposed on the public API. This means even if I could parse a text string (from point 1) I wouldn't have access to any lint failures

  3. The linting options are only settable in the run method however this again means I need a file on disk. It seems the run method is conflating setting lint options and linting text content

  4. Minor nit, but the failures just say the file failed linting but doesn't give a line/char offset, but granted this is difficult to do with the current JSON parser

I will probably end up forking the gem source and adding the ability to consume the gem in a programmatic way. Would you be interesting in accepting PRs for this assume I'm not breaking any public APIs?

rnelson0 commented 7 years ago

Absolutely, we would love to accept PRs that provide this functionality! If they cause a semver major bump then we can deal with that when the time comes. -- Rob Nelson