Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

New Rule 61 - valid cookbook version #405

Merged
merged 3 commits into from
Nov 10, 2015
Merged

Conversation

lamont-granquist
Copy link
Contributor

closes #351

else
pass = true
parts = ver.to_s.gsub(/\s|'|"/, '').split('.')
if parts.length > 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to check <= 3 too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is just a rebase of the existing code, I want to add tests and fix that. CBVs actually have to be exactly 3 dotted decimals and this code can most likely be simplified considerably.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably okay to accept one or two parts and let it extend them, or at least that is pretty common and doesn't seem like a bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I didn't realize 'x.y' was acceptable:

ERROR: Chef::Exceptions::InvalidCookbookVersion: '1' does not match 'x.y.z' or 'x.y'

We should just do that.

@lamont-granquist lamont-granquist changed the title New Rule 55 - valid cookbook version New Rule 61 - valid cookbook version Nov 6, 2015
@lamont-granquist
Copy link
Contributor Author

@coderanger @tas50 @acrmp hows this look now?

@coderanger
Copy link
Contributor

I would make throw in one test using double quotes because I'm paranoid, but 👍 :shipit:

@acrmp
Copy link
Member

acrmp commented Nov 6, 2015

A metadata.rb with this would also match incorrectly - don't know how common it would be in practice:

expr = '1.0.0'
version expr

@lamont-granquist
Copy link
Contributor Author

Uhm, yeah, that's actually terrible and blocker for this.

We need to only select string or double string literals here and check them. Peeps with CI/CD style cookbook delivery systems may be calling out to random ruby libraries to set their versions.

(probably single quoted or double quoted string literals that have no interpolation in them)

@lamont-granquist
Copy link
Contributor Author

Also we should probably not file_match but match with a line number...

- one checks for version presence
- one checks for valid version syntax
- version syntax requires a fixed string with no interpolation to
  trigger
@lamont-granquist
Copy link
Contributor Author

@coderanger @acrmp @tas50 think this one is ready.

@@ -826,3 +826,21 @@ def invalid_name(ast)
end
end
end

rule 'FC061', 'Valid cookbook versions are of the form x.y or x.y.z' do
tags %w{metadata}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also include the tag correctness here

lamont-granquist added a commit that referenced this pull request Nov 10, 2015
New Rule 61 - valid cookbook version
@lamont-granquist lamont-granquist merged commit 36852dc into master Nov 10, 2015
@lamont-granquist lamont-granquist deleted the chazzly-newrule branch November 10, 2015 17:49
@acrmp acrmp added the Feature label Nov 12, 2015
@acrmp
Copy link
Member

acrmp commented Nov 12, 2015

Thanks. I think FC061 would still match this case:

version generated('like this')

In some rules I believe we count ancestors to avoid this kind of issue.

We could also return the matching node so that we get the correct line number rather than using file_match.

@lamont-granquist
Copy link
Contributor Author

working on a fix...

@tas50 tas50 added Enhancements and removed Feature labels Jan 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants