rubocop-raylib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fa60ba490d320df555d0867856ab1113922f19fe0169e77010548d538fa6aa4f
4
+ data.tar.gz: '01557792f11c4331e96206472ee4a99bde683c793f25d4a7702062e01a5e10cb'
5
+ SHA512:
6
+ metadata.gz: d9063d3d285a69560869661fe854f970c4a40c24e81334a49e6826f4094ce88e2b14122548d89986f22be54fd2e57f85a2e9829b2959b464039803fc61d0f4b0
7
+ data.tar.gz: 947bbc8565b677335f8b9d96053f9a07a538be4382796f72fbd3e9f5338826a636c41ea3275f77d7d365d0ada283037fe7a9ada2e650c8341d59b48f6fec3b2d
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2
3
+ NewCops: enable
4
+
5
+ Gemspec/DevelopmentDependencies:
6
+ Enabled: false
7
+
8
+ Naming/FileName:
9
+ Exclude:
10
+ - lib/rubocop-raylib.rb
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - rubocop-raylib.gemspec
15
+ - spec/rubocop/cop/memory_management/unpaired_resource_spec.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-20
4
+
5
+ - Initial release with the cop `MemoryManagement/UnpairedResource`
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at wilson.dsigns@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Wilson Silva
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,85 @@
1
+ # RuboCop::Raylib
2
+
3
+ Linter to ensure the correct and optimal usage of the [Raylib gem's](https://github.com/wilsonsilva/raylib-ruby) API.
4
+ By leveraging RuboCop, it provides insights and prompts for best practices when using Raylib gem.
5
+
6
+ ## Installation
7
+
8
+ Install the gem and add to the application's Gemfile by executing:
9
+
10
+ $ bundle add rubocop-raylib --require=false
11
+
12
+ If bundler is not being used to manage dependencies, install the gem by executing:
13
+
14
+ $ gem install rubocop-raylib
15
+
16
+ Then add the following to the application's `.rubocop.yml` file:
17
+
18
+ ```yaml
19
+ require:
20
+ - rubocop-raylib
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Run RuboCop as usual and it will automatically load the RuboCop Raylib cops together with the standard cops.
26
+
27
+ For example, given the following Raylib app where `Raylib.end_drawing` and `Raylib.close_window` are missing:
28
+
29
+ ```ruby
30
+ require 'raylib'
31
+
32
+ SCREEN_WIDTH = 640
33
+ SCREEN_HEIGHT = 480
34
+
35
+ Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'My window')
36
+ Raylib.set_target_fps(60)
37
+
38
+ until Raylib.window_should_close # Detect window close button or ESC key
39
+ Raylib.begin_drawing
40
+ Raylib.clear_background(Raylib::WHITE)
41
+ Raylib.draw_text('Hello, Raylib!', 10, 10, 20, Raylib::BLACK)
42
+ end
43
+ ```
44
+
45
+ Running `rubocop` will produce the following output:
46
+
47
+ ```
48
+ Inspecting 1 file
49
+ I
50
+
51
+ Offenses:
52
+
53
+ app.rb:6:1: I: MemoryManagement/UnpairedResource: Found init_window without a corresponding close_window.
54
+ Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'My window')
55
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56
+ app.rb:10:3: I: MemoryManagement/UnpairedResource: Found begin_drawing without a corresponding end_drawing.
57
+ Raylib.begin_drawing
58
+ ^^^^^^^^^^^^^^^^^^^^
59
+
60
+ 1 file inspected, 2 offenses detected
61
+ ```
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
66
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
69
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
70
+ push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/rubocop-raylib. This project is
75
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
76
+ [code of conduct](https://github.com/wilsonsilva/rubocop-raylib/blob/main/CODE_OF_CONDUCT.md).
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the Rubocop::Raylib project's codebases, issue trackers, chat rooms and mailing lists is
85
+ expected to follow the [code of conduct](https://github.com/wilsonsilva/rubocop-raylib/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
11
+
12
+ desc 'Generate a new cop with a template'
13
+ task :new_cop, [:cop] do |_task, args|
14
+ require 'rubocop'
15
+
16
+ cop_name = args.fetch(:cop) do
17
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
18
+ exit!
19
+ end
20
+
21
+ generator = RuboCop::Cop::Generator.new(cop_name)
22
+
23
+ generator.write_source
24
+ generator.write_spec
25
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/raylib_cops.rb')
26
+ generator.inject_config(config_file_path: 'config/default.yml')
27
+
28
+ puts generator.todo
29
+ end
@@ -0,0 +1,47 @@
1
+ MemoryManagement/UnpairedResource:
2
+ Description: >-
3
+ Checks for instances where resource initialization methods are called without
4
+ their corresponding closing methods. Prevents potential memory leaks or
5
+ undesired behaviors.
6
+ Enabled: true
7
+ VersionAdded: 0.1
8
+ Severity: info
9
+ Pairs:
10
+ # rcore
11
+ begin_drawing: end_drawing
12
+ begin_mode_2d: end_mode_2d
13
+ begin_mode_3d: end_mode_3d
14
+ begin_texture_mode: end_texture_mode
15
+ begin_shader_mode: end_shader_mode
16
+ begin_blend_mode: end_blend_mode
17
+ begin_scissor_mode: end_scissor_mode
18
+ begin_vr_stereo_mode: end_vr_stereo_mode
19
+ init_window: close_window
20
+ load_directory_files: unload_directory_files
21
+ load_dropped_files: unload_dropped_files
22
+ load_file_data: unload_file_data
23
+ load_file_text: unload_file_text
24
+ load_shader: unload_shader
25
+ load_shader_from_memory: unload_shader
26
+ load_vr_stereo_config: unload_vr_stereo_config
27
+ # rtextures
28
+ load_image: unload_image
29
+ load_texture: unload_texture
30
+ load_render_texture: unload_render_texture
31
+ # rtext
32
+ load_font: unload_font
33
+ load_font_ex: unload_font
34
+ load_font_from_image: unload_font
35
+ load_font_from_memory: unload_font
36
+ load_font_data: unload_font_data
37
+ gen_image_font_atlas: unload_font_data
38
+ # rmodels
39
+ load_model: unload_model
40
+ load_model_animations: unload_model_animation
41
+ load_materials: unload_material
42
+ # raudio
43
+ init_audio_device: close_audio_device
44
+ load_wave: unload_wave
45
+ load_sound: unload_sound
46
+ load_music_stream: unload_music_stream
47
+ load_audio_stream: unload_audio_stream
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module MemoryManagement
6
+ # Checks for instances of unpaired resource initialization and closing.
7
+ #
8
+ # Configuration example:
9
+ #
10
+ # MemoryManagement/UnpairedResource:
11
+ # Raylib:
12
+ # init_audio_device: close_audio_device
13
+ # begin_drawing: end_drawing
14
+ # ...
15
+ #
16
+ class UnpairedResource < Base
17
+ def on_send(node)
18
+ pairs.each do |init_method, close_method|
19
+ if node.method?(init_method) && !paired?(node, close_method)
20
+ msg = "Found `#{node.method_name}` without a corresponding `#{close_method}`."
21
+ add_offense(node, message: msg)
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def pairs
29
+ cop_config['Pairs'] || {}
30
+ end
31
+
32
+ def paired?(init_node, close_method)
33
+ processed_source.ast.each_node(:send).find do |node|
34
+ node.method?(close_method) && node.source_range.begin_pos > init_node.source_range.begin_pos
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'memory_management/unpaired_resource'
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Raylib
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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Raylib
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'raylib/version'
4
+
5
+ module RuboCop
6
+ # Raylib cops for the RuboCop static code analyzer.
7
+ module Raylib
8
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
9
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
10
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
11
+
12
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/raylib'
6
+ require_relative 'rubocop/raylib/version'
7
+ require_relative 'rubocop/raylib/inject'
8
+
9
+ RuboCop::Raylib::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/raylib_cops'
@@ -0,0 +1,6 @@
1
+ module Rubocop
2
+ module Raylib
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-raylib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wilson Silva
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-20 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: '1.57'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.57'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ description: Leverages RuboCop to ensure the correct and optimal usage of the raylib
56
+ gem's API
57
+ email:
58
+ - wilson.dsigns@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - CHANGELOG.md
66
+ - CODE_OF_CONDUCT.md
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - config/default.yml
71
+ - lib/rubocop-raylib.rb
72
+ - lib/rubocop/cop/memory_management/unpaired_resource.rb
73
+ - lib/rubocop/cop/raylib_cops.rb
74
+ - lib/rubocop/raylib.rb
75
+ - lib/rubocop/raylib/inject.rb
76
+ - lib/rubocop/raylib/version.rb
77
+ - sig/rubocop/raylib.rbs
78
+ homepage: https://raylib-ruby.com/learn/linter
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ rubygems_mfa_required: 'true'
84
+ homepage_uri: https://raylib-ruby.com/learn/linter
85
+ source_code_uri: https://github.com/wilsonsilva/rubocop-raylib
86
+ changelog_uri: https://github.com/wilsonsilva/rubocop-raylib/blob/main/CHANGELOG.md
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 3.2.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.4.20
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A linter for the raylib gem to ensure proper usage of its API.
106
+ test_files: []