diff --git a/bin/bookworm b/bin/bookworm index 68bde10..a22b98e 100755 --- a/bin/bookworm +++ b/bin/bookworm @@ -295,7 +295,8 @@ module Bookworm end end -if __FILE__ == $PROGRAM_NAME || $PROGRAM_NAME == './bin/bookworm' +# TODO refactor this file so the below PROGRAM_NAME hack isn't necessary +if __FILE__ == $PROGRAM_NAME || $PROGRAM_NAME == './bin/bookworm' || $PROGRAM_NAME == './bookworm.rb' run = Bookworm::Run.new(options, parser.help) run.do_action end diff --git a/lib/bookworm/reports/CookbookNameAndMaintainerEmail.rb b/lib/bookworm/reports/CookbookNameAndMaintainerEmail.rb index f2ff58c..4438039 100644 --- a/lib/bookworm/reports/CookbookNameAndMaintainerEmail.rb +++ b/lib/bookworm/reports/CookbookNameAndMaintainerEmail.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2022-present, Meta, Inc. +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/bookworm/reports/RecipeOnlyCookbooks.rb b/lib/bookworm/reports/RecipeOnlyCookbooks.rb new file mode 100644 index 0000000..48747cd --- /dev/null +++ b/lib/bookworm/reports/RecipeOnlyCookbooks.rb @@ -0,0 +1,35 @@ +# Copyright (c) 2023-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Determines all cookbooks that do not evaluate Ruby code on load' +needs_rules %w{ + MetadatarbExists + AttributeExists + LibraryExists + ResourceExists + ProviderExists +} + +def to_a + cookbooks = Set.new(@kb.cookbooks.keys) + cookbooks.subtract(Set.new(@kb.attributes.map { |_, c| c['cookbook'] })) + cookbooks.subtract(Set.new(@kb.libraries.map { |_, c| c['cookbook'] })) + cookbooks.subtract(Set.new(@kb.resources.map { |_, c| c['cookbook'] })) + cookbooks.subtract(Set.new(@kb.providers.map { |_, c| c['cookbook'] })) + cookbooks.to_a.sort +end + +def output + to_a +end diff --git a/lib/bookworm/rules/AttributeExists.rb b/lib/bookworm/rules/AttributeExists.rb new file mode 100644 index 0000000..4d3f6c6 --- /dev/null +++ b/lib/bookworm/rules/AttributeExists.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Helper rule to show existence of an attributes file' +keys %w{ + attribute +} + +def output + true +end diff --git a/lib/bookworm/rules/LibraryExists.rb b/lib/bookworm/rules/LibraryExists.rb new file mode 100644 index 0000000..9c325e7 --- /dev/null +++ b/lib/bookworm/rules/LibraryExists.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Helper rule to show existence of a library file' +keys %w{ + library +} + +def output + true +end diff --git a/lib/bookworm/rules/MetadatarbAttributeLiterals.rb b/lib/bookworm/rules/MetadatarbAttributeLiterals.rb index f8b6840..6ee9336 100644 --- a/lib/bookworm/rules/MetadatarbAttributeLiterals.rb +++ b/lib/bookworm/rules/MetadatarbAttributeLiterals.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2022-present, Meta, Inc. +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/bookworm/rules/MetadatarbExists.rb b/lib/bookworm/rules/MetadatarbExists.rb new file mode 100644 index 0000000..922a4be --- /dev/null +++ b/lib/bookworm/rules/MetadatarbExists.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Helper rule to show existence of a metadata.rb file' +keys %w{ + metadatarb +} + +def output + true +end diff --git a/lib/bookworm/rules/ProviderExists.rb b/lib/bookworm/rules/ProviderExists.rb new file mode 100644 index 0000000..c579130 --- /dev/null +++ b/lib/bookworm/rules/ProviderExists.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Helper rule to show existence of a provider file' +keys %w{ + provider +} + +def output + true +end diff --git a/lib/bookworm/rules/RecipeExists.rb b/lib/bookworm/rules/RecipeExists.rb new file mode 100644 index 0000000..b40e824 --- /dev/null +++ b/lib/bookworm/rules/RecipeExists.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Helper rule to show existence of a recipe' +keys %w{ + recipe +} + +def output + true +end diff --git a/lib/bookworm/rules/ResourceExists.rb b/lib/bookworm/rules/ResourceExists.rb new file mode 100644 index 0000000..6c554d8 --- /dev/null +++ b/lib/bookworm/rules/ResourceExists.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +description 'Helper rule to show existence of a resource file' +keys %w{ + resource +} + +def output + true +end diff --git a/spec/knowledge_base_spec.rb b/spec/knowledge_base_spec.rb index e4773ae..9cbec31 100644 --- a/spec/knowledge_base_spec.rb +++ b/spec/knowledge_base_spec.rb @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. require_relative 'spec_helper' -require_relative '../lib/bookworm/keys' -require_relative '../lib/bookworm/knowledge_base' +require 'bookworm/keys' +require 'bookworm/knowledge_base' describe Bookworm::KnowledgeBase do it 'holds all yer roles' do diff --git a/lib/bookworm/spec/rules/CookbookPropertyLiterals_spec.rb b/spec/rules/CookbookPropertyLiterals_spec.rb similarity index 100% rename from lib/bookworm/spec/rules/CookbookPropertyLiterals_spec.rb rename to spec/rules/CookbookPropertyLiterals_spec.rb diff --git a/lib/bookworm/spec/rules/MetadatarbAttributeLiterals_spec.rb b/spec/rules/MetadatarbAttributeLiterals_spec.rb similarity index 94% rename from lib/bookworm/spec/rules/MetadatarbAttributeLiterals_spec.rb rename to spec/rules/MetadatarbAttributeLiterals_spec.rb index a03faf3..fcfe650 100644 --- a/lib/bookworm/spec/rules/MetadatarbAttributeLiterals_spec.rb +++ b/spec/rules/MetadatarbAttributeLiterals_spec.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2022-present, Meta, Inc. +# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/rules/helper.rb b/spec/rules/helper.rb index d292de2..bf79a25 100644 --- a/spec/rules/helper.rb +++ b/spec/rules/helper.rb @@ -1,3 +1,4 @@ +# rubocop:disable Chef/Meta/SpecFilename # Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates # All rights reserved. # @@ -13,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. require 'pathname' -require_relative '../../lib/bookworm/crawler' -require_relative '../../lib/bookworm/exceptions' -require_relative '../../lib/bookworm/infer_engine' +require 'bookworm/crawler' +require 'bookworm/exceptions' +require 'bookworm/infer_engine' # Load all rule files files = Dir.glob("#{__dir__}/../../lib/bookworm/rules/*.rb") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3719c64..c70c087 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,3 +21,5 @@ config.filter_run(:focus) config.order = :random end + +$LOAD_PATH.unshift("#{__dir__}/../lib")