inspecstyle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +54 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +38 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/default.yml +9 -0
- data/inspecstyle.gemspec +29 -0
- data/lib/inspecstyle.rb +11 -0
- data/lib/rubocop/cop/inspecstyle/deprecated_attributes.rb +50 -0
- data/lib/rubocop/cop/inspecstyle/first_cop.rb +69 -0
- data/lib/rubocop/cop/inspecstyle_cops.rb +3 -0
- data/lib/rubocop/inspecstyle.rb +14 -0
- data/lib/rubocop/inspecstyle/inject.rb +20 -0
- data/lib/rubocop/inspecstyle/version.rb +5 -0
- data/notes-for-development.md +45 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e638a82024fe7f9482ea0f85766d10864e215739b29e46dd90cdde9977c9b7ee
|
4
|
+
data.tar.gz: 2e07ab7f1a98d5e7820eb3a6b7af04814e4cc1ccd8ddd9d0b9b5207f167373c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba17616f81d48ed11ecc84a740973fced42aa2ef5c5833e6f407014337083179c4e597f71079d6afe635484e268ed8f5205d156a606245c413d79ed599e581df
|
7
|
+
data.tar.gz: d2ff5b5d9da6786f15acb5afaa41a87e266a22551d627be464ae02fbe395324d1596a65f253da21cfb068f0a0afe33237f095910e487c313d3a03b8f8937e16b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Changelog
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nschwaderer@chef.io. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
inspecstyle (0.1.0)
|
5
|
+
rubocop
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
jaro_winkler (1.5.4)
|
13
|
+
minitest (5.14.1)
|
14
|
+
parallel (1.19.1)
|
15
|
+
parser (2.7.1.2)
|
16
|
+
ast (~> 2.4.0)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
rexml (3.2.4)
|
20
|
+
rspec (3.9.0)
|
21
|
+
rspec-core (~> 3.9.0)
|
22
|
+
rspec-expectations (~> 3.9.0)
|
23
|
+
rspec-mocks (~> 3.9.0)
|
24
|
+
rspec-core (3.9.2)
|
25
|
+
rspec-support (~> 3.9.3)
|
26
|
+
rspec-expectations (3.9.2)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-mocks (3.9.1)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-support (3.9.3)
|
33
|
+
rubocop (0.81.0)
|
34
|
+
jaro_winkler (~> 1.5.1)
|
35
|
+
parallel (~> 1.10)
|
36
|
+
parser (>= 2.7.0.1)
|
37
|
+
rainbow (>= 2.2.2, < 4.0)
|
38
|
+
rexml
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
41
|
+
ruby-progressbar (1.10.1)
|
42
|
+
unicode-display_width (1.7.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
minitest (~> 5.0)
|
49
|
+
rake (~> 12.0)
|
50
|
+
rspec
|
51
|
+
inspecstyle!
|
52
|
+
|
53
|
+
BUNDLED WITH
|
54
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Nick Schwaderer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Rubocop::InSpecStyle
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/inspecstyle`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'inspecstyle', require: false
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install inspecstyle
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/inspecstyle. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/inspecstyle/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the Rubocop::InSpecStyle project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/inspecstyle/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
15
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Generate a new cop with a template'
|
19
|
+
task :new_cop, [:cop] do |_task, args|
|
20
|
+
require 'rubocop'
|
21
|
+
|
22
|
+
cop_name = args.fetch(:cop) do
|
23
|
+
warn 'usage: bundle exec rake new_cop[Department/Name]'
|
24
|
+
exit!
|
25
|
+
end
|
26
|
+
|
27
|
+
github_user = `git config github.user`.chop
|
28
|
+
github_user = 'your_id' if github_user.empty?
|
29
|
+
|
30
|
+
generator = RuboCop::Cop::Generator.new(cop_name, github_user)
|
31
|
+
|
32
|
+
generator.write_source
|
33
|
+
generator.write_spec
|
34
|
+
generator.inject_require(root_file_path: 'lib/rubocop/cop/inspecstyle_cops.rb')
|
35
|
+
generator.inject_config(config_file_path: 'config/default.yml')
|
36
|
+
|
37
|
+
puts generator.todo
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rubocop/inspecstyle"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config/default.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
InSpecStyle/DeprecatedAttributes:
|
2
|
+
Description: 'Attributes are deprecated in favor of inputs'
|
3
|
+
Enabled: true
|
4
|
+
VersionAdded: '0.82'
|
5
|
+
|
6
|
+
InspecStyle/FirstCop:
|
7
|
+
Description: 'This first cop is a sandbox for exploring new InspecStyle cops.'
|
8
|
+
Enabled: true
|
9
|
+
VersionAdded: '0.82'
|
data/inspecstyle.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/rubocop/inspecstyle/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "inspecstyle"
|
5
|
+
spec.version = RuboCop::InSpecStyle::VERSION
|
6
|
+
spec.authors = ["Nick Schwaderer"]
|
7
|
+
spec.email = ["nschwaderer@chef.io"]
|
8
|
+
|
9
|
+
spec.summary = %q{Preferred styling and performant InSpec code.}
|
10
|
+
spec.description = %q{InSpecStyle allows InSpec developers to write code with predictable styling and in a secure/performant manner.}
|
11
|
+
spec.homepage = "https://github.com/schwad/inspecstyle"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/schwad/inspecstyle"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/schwad/inspecstyle"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'rubocop'
|
29
|
+
end
|
data/lib/inspecstyle.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
require_relative 'rubocop/inspecstyle'
|
6
|
+
require_relative 'rubocop/inspecstyle/version'
|
7
|
+
require_relative 'rubocop/inspecstyle/inject'
|
8
|
+
|
9
|
+
RuboCop::InSpecStyle::Inject.defaults!
|
10
|
+
|
11
|
+
require_relative 'rubocop/cop/inspecstyle_cops'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# TODO: when finished, run `rake generate_cops_documentation` to update the docs
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module InSpecStyle
|
7
|
+
#
|
8
|
+
# @example DeprecatedAttributes: Do not use attributes
|
9
|
+
# # Attributes have been deprecated for inputs
|
10
|
+
# # https://github.com/inspec/inspec/issues/3802
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# attribute('my_element', value: 10)
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# input('my_element', value: 10)
|
17
|
+
#
|
18
|
+
class DeprecatedAttributes < Cop
|
19
|
+
include RangeHelp
|
20
|
+
|
21
|
+
MSG = 'Use `#input` instead of `#attribute`.'
|
22
|
+
|
23
|
+
def_node_matcher :attribute?, <<~PATTERN
|
24
|
+
(send nil? :attribute ...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def on_send(node)
|
28
|
+
return unless attribute?(node)
|
29
|
+
add_offense(node, location: range(node))
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def range(node)
|
35
|
+
# Only highlights the method 'attribute'
|
36
|
+
range_between(node.source_range.begin_pos,
|
37
|
+
node.source_range.begin_pos+9
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
# def autocorrect
|
42
|
+
# ->(corrector) do
|
43
|
+
# corrector.insert_before(node.source_range, 'input')
|
44
|
+
# corrector.remove(node.source_range, 'attribute')
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# TODO: when finished, run `rake generate_cops_documentation` to update the docs
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module InSpecStyle
|
7
|
+
# TODO: Write cop description and example of bad / good code. For every
|
8
|
+
# `SupportedStyle` and unique configuration, there needs to be examples.
|
9
|
+
# Examples must have valid Ruby syntax. Do not use upticks.
|
10
|
+
#
|
11
|
+
# @example EnforcedStyle: bar (default)
|
12
|
+
# # Description of the `bar` style.
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# bad_bar_method
|
16
|
+
#
|
17
|
+
# # bad
|
18
|
+
# bad_bar_method(args)
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# good_bar_method
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# good_bar_method(args)
|
25
|
+
#
|
26
|
+
# @example EnforcedStyle: foo
|
27
|
+
# # Description of the `foo` style.
|
28
|
+
#
|
29
|
+
# # bad
|
30
|
+
# bad_foo_method
|
31
|
+
#
|
32
|
+
# # bad
|
33
|
+
# bad_foo_method(args)
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
# good_foo_method
|
37
|
+
#
|
38
|
+
# # good
|
39
|
+
# good_foo_method(args)
|
40
|
+
#
|
41
|
+
class FirstCop < Cop
|
42
|
+
# TODO: Implement the cop in here.
|
43
|
+
#
|
44
|
+
# In many cases, you can use a node matcher for matching node pattern.
|
45
|
+
# See https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/node_pattern.rb
|
46
|
+
#
|
47
|
+
# For example
|
48
|
+
MSG = 'Use `#good_method` instead of `#bad_method`. %<example_insertion>'
|
49
|
+
|
50
|
+
def_node_matcher :bad_method?, <<~PATTERN
|
51
|
+
(send nil? :bad_method ...)
|
52
|
+
PATTERN
|
53
|
+
|
54
|
+
def on_send(node)
|
55
|
+
return unless bad_method?(node)
|
56
|
+
message = format(MSG, example_insertion: node.first.source)
|
57
|
+
add_offense(node, message: message)
|
58
|
+
end
|
59
|
+
|
60
|
+
def autocorrect(node)
|
61
|
+
->(corrector) do
|
62
|
+
corrector.insert_before(node.source_range, 'good_method')
|
63
|
+
corrector.remove(node.source_range)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rubocop/inspecstyle/version"
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module InSpecStyle
|
5
|
+
class Error < StandardError; end
|
6
|
+
# Your code goes here...
|
7
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
8
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
9
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
10
|
+
|
11
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
+
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
|
+
module RuboCop
|
6
|
+
module InSpecStyle
|
7
|
+
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
+
# bit of our configuration.
|
9
|
+
module Inject
|
10
|
+
def self.defaults!
|
11
|
+
path = CONFIG_DEFAULT.to_s
|
12
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
13
|
+
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
15
|
+
config = ConfigLoader.merge_with_default(config, path)
|
16
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Notes for Dev
|
2
|
+
|
3
|
+
These are generic personal notes for useful documentation, approaches, and development strategies around constructing InSpecStyle. It's a bit hacked together like I will do for personal notes, but keeping together before this goes live to help others who might want to hack on InSpecStyle for the first time
|
4
|
+
|
5
|
+
- Toolsets for cop development: https://github.com/rubocop-hq/rubocop-ast/blob/master/docs/modules/ROOT/pages/node_pattern.adoc
|
6
|
+
|
7
|
+
- https://docs.rubocop.org/rubocop/development.html
|
8
|
+
|
9
|
+
- Advanced example custom cop: https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/cop/rspec/not_to_not.rb
|
10
|
+
|
11
|
+
- https://www.rubyguides.com/2015/08/static-analysis-in-ruby/
|
12
|
+
|
13
|
+
- https://blog.arkency.com/using-ruby-parser-and-ast-tree-to-find-deprecated-syntax/
|
14
|
+
|
15
|
+
- attribute autocorrect (audit-cookbook)
|
16
|
+
|
17
|
+
- https://www.rubydoc.info/gems/rubocop-ast/RuboCop/AST/NodePattern
|
18
|
+
|
19
|
+
- hack on these specs locally and docs to learn https://github.com/rubocop-hq/rubocop-ast
|
20
|
+
|
21
|
+
<!-- (cookstyle)
|
22
|
+
|
23
|
+
- part of inspec (& check)
|
24
|
+
- part of cookstyle
|
25
|
+
- atom -->
|
26
|
+
|
27
|
+
```
|
28
|
+
ruby-parse -e '1'
|
29
|
+
(int 1)
|
30
|
+
```
|
31
|
+
|
32
|
+
Example usage for testing against example code:
|
33
|
+
|
34
|
+
`bundle exec rubocop violations.rb --only InSpecStyle/DeprecatedAttributes`
|
35
|
+
|
36
|
+
Processing via IRB for AST parsing:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
code = '!something.empty?'
|
40
|
+
source = RuboCop::ProcessedSource.new(code, RUBY_VERSION.to_f)
|
41
|
+
node = source.ast
|
42
|
+
node.type
|
43
|
+
node.children
|
44
|
+
node.source
|
45
|
+
```
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inspecstyle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Schwaderer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: InSpecStyle allows InSpec developers to write code with predictable styling
|
28
|
+
and in a secure/performant manner.
|
29
|
+
email:
|
30
|
+
- nschwaderer@chef.io
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- ".travis.yml"
|
39
|
+
- CHANGELOG.md
|
40
|
+
- CODE_OF_CONDUCT.md
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- LICENSE.txt
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- bin/console
|
47
|
+
- bin/setup
|
48
|
+
- config/default.yml
|
49
|
+
- inspecstyle.gemspec
|
50
|
+
- lib/inspecstyle.rb
|
51
|
+
- lib/rubocop/cop/inspecstyle/deprecated_attributes.rb
|
52
|
+
- lib/rubocop/cop/inspecstyle/first_cop.rb
|
53
|
+
- lib/rubocop/cop/inspecstyle_cops.rb
|
54
|
+
- lib/rubocop/inspecstyle.rb
|
55
|
+
- lib/rubocop/inspecstyle/inject.rb
|
56
|
+
- lib/rubocop/inspecstyle/version.rb
|
57
|
+
- notes-for-development.md
|
58
|
+
homepage: https://github.com/schwad/inspecstyle
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata:
|
62
|
+
homepage_uri: https://github.com/schwad/inspecstyle
|
63
|
+
source_code_uri: https://github.com/schwad/inspecstyle
|
64
|
+
changelog_uri: https://github.com/schwad/inspecstyle
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.4.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Preferred styling and performant InSpec code.
|
84
|
+
test_files: []
|