Skip to content

unurgunite/rubocop_sorted_methods_by_call

RubocopSortedMethodsByCall

Alt

! WARNING !

This project is not updated yet and needs some improvements in code semantics. If you able to help this project, fork it and make pull requests.

Welcome to the rubocop_sorted_methods_by_call gem! This repo contains main sources of project.

Documentation content

  1. Overview
  2. Installation
    1. Build from source
      1. Manual installation
      2. Automatic installation
    2. Build via bundler
  3. Usage
    1. Code examples
  4. Todo
  5. Development
  6. Requirements
    1. Common usage
    2. Development purposes
  7. Project style guide
  8. Contributing
  9. License
  10. Code of Conduct

Overview

This gem analyze Ruby AST and check if code was written according to the "waterfall" feature which give flexibility to sources by declaring methods after they are called.

Installation

rubocop_sorted_methods_by_call gem is quite simple to use and install. There are two options to install it — for those who is going to contribute into the project and for those who is going to embed gem to theirs project. See below for each step.

Build from source

Manual installation

The manual installation includes installation via command line interface. it is practically no different from what happens during the automatic build of the project:

git clone https://github.com/unurgunite/rubocop_sorted_methods_by_call.git && \
cd rubocop_sorted_methods_by_call && \
bundle install && \
gem build rubocop_sorted_methods_by_call.gemspec && \
gem install rubocop_sorted_methods_by_call-0.1.0.gem

Now everything should work fine. Just type irb and require "rubocop_sorted_methods_by_call/rubocop_sorted_methods_by_call" to start working with the library

Automatic installation

The automatic installation is simpler but it has at least same steps as manual installation:

git clone https://github.com/unurgunite/rubocop_sorted_methods_by_call.git && \
cd rubocop_sorted_methods_by_call && \
bin/setup

If you see irb interface, then everything works fine. The main goal of automatic installation is that you do not need to create your own script to simplify project build and clean up the shell history. Note: you do not need to require projects file after the automatic installation. See bin/setup file for clarity of the statement

Build via bundler

This documentation point is close to those who need to embed the library in their project. Just place this gem to your Gemfile or create it manually via bundle init:

# Your Gemfile
gem 'rubocop_sorted_methods_by_call'

And then execute:

bundle install

Or install it yourself for non bundled projects as:

gem install rubocop_sorted_methods_by_call

Usage

All docs are available at the separate page: https://unurgunite.github.io/rubocop_sorted_methods_by_call_docs/

Code examples

Positive case:

# file.rb
def foo
  bar
end

def bar
  123
end

# main.rb
require "parser/current"

code = Parser::CurrentRuby.parse(File.read("file.rb"))
ast = RubocopSortedMethodsByCall::Processor.new
ast.process(code)
ast.ordered? #=> true

Negative case:

# file.rb
def bar
  123
end

def foo
  bar
end

# main.rb
require "parser/current"

code = Parser::CurrentRuby.parse(File.read("file.rb"))
ast = RubocopSortedMethodsByCall::Processor.new
ast.process(code)
ast.ordered? #=> false

TODO

  • Add recursion support
  • Add classes support
  • Add struct support
  • Add modules support
  • Add nested structures support
  • Add standalone method support (without invoking another methods inside)
  • Add detection for method overriding (namespace pollutions)
  • Support for method calling inside of params
  • Refactor code base
  • Make more examples for specs

Development

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.

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 the created tag, and push the .gem file to rubygems.org.

Requirements

This section will show dependencies which are used in the project. This section splits in two other sections — requirements for common use and requirements for the development purposes.

Common use

The rubocop_sorted_methods_by_call gem is built on top of another gem:

Dependencies Description
Parser Parser is used to build AST for future structure identifying.

Development purposes

For the development purposes rubocop_sorted_methods_by_call gem uses:

Dependencies Description
RSpec The RSpec gem is used for test which are located in a separate folder under spec name.
RuboCop The RuboCop gem is used for code formatting.
Rake The Rake gem is used for building tasks as generating documentation.
YARD The YARD gem is used for the documentation.
Parser The Parser gem is used for building AST.

Project style guide

To make the code base much cleaner gem has its own style guides. They are defined in a root folder of the gem in a CONTRIBUTING.md file. Check it for more details.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/unurgunite/rubocop_sorted_methods_by_call. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct. To contribute you should fork this project and create there new branch:

git clone https://github.com/your-beautiful-username/rubocop_sorted_methods_by_call.git && \
git checkout -b refactor && \
git commit -m "Affected new changes" && \
git push origin refactor

And then make new pull request with additional notes of what you have done. The better the changes are scheduled, the faster the PR will be checked.

Code of Conduct

Everyone interacting in the RubocopSortedMethodsByCall project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

License

The gem is available as open source under the terms of the New BSD License. The copy of the license is stored in project under the LICENSE.txt file name: copy of the License

The documentation is available as open source under the terms of the CC BY-SA 4.0 License

The other libs are available as open source under the terms of the New BSD License

CC BY-SA 4.0 BSD license logo

About

RuboCop extension for method sorting in AST by stack trace.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published