Major Project Presentation
Utkarsh Gupta
Samyak Jain
(8CSE - 8Y)
Presented By:
(A2305217557)
(A2305217638)
ASET (B.Tech. CSE)
Faculty Guide:
Dr. Pooja Singh
Assistant Professor
(Deptartment of CSE)
ASET, AUUP
The main goal of this project is to provide a tool to automatically detect those issues and report them upstream.
During the maintenance of the Ruby packages in Debian, several issues in upstream codebases have been identified that make it difficult to build a Debian package out of Ruby gems.
Debian is a free operating system (OS) for your computer. An operating system is the set of basic programs and utilities that make your computer run.
Debian provides more than a pure OS: it comes with over 65000 packages, precompiled software bundled up in a nice format for easy installation on your machine.
class GemspecGit < Cop
def_node_search :xstr, <<~PATTERN
(block
(send
(const
(const {cbase nil?} :Gem) :Specification) :new)
(args
(arg _)) `$(xstr (str start_with('git'))))
PATTERN
The usage of `git ls-files` in the `gemspec` file can be determined by the following AST:
STEP 1:
def investigate(processed_source)
xstr(processed_source.ast).each do |node|
add_offense(
processed_source.ast,
location: node.loc.expression,
message: MSG
)
end
end
The next thing is to process the AST formed against the source code to match problematic lines:
STEP 2:
RSpec.describe RuboCop::Cop::Packaging::GemspecGit do
subject(:cop) { described_class.new(config) }
let(:config) { RuboCop::Config.new }
let(:message) { RuboCop::Cop::Packaging::GemspecGit::MSG }
it 'registers an offense when using `git` for :files=' do
expect_offense(<<~RUBY)
Gem::Specification.new do |spec|
spec.files = `git ls-files`.split("\\n")
^^^^^^^^^^^^^^ #{message}
end
RUBY
end
end
Write tests \o/
STEP 3:
class RequireRelativeHardcodingLib < Base
include RuboCop::Packaging::LibHelperModule
extend AutoCorrector
def_node_matcher :require_relative, <<~PATTERN
(send nil? :require_relative
(str #falls_in_lib?))
PATTERN
The usage of `require_relative` in the spec/ dir can be determined by the following AST:
STEP 1:
def on_new_investigation
@file_path = processed_source.file_path
@file_directory = File.dirname(@file_path)
end
def on_send(node)
return unless require_relative(node)
add_offense(node) do |corrector|
corrector.replace(node, good_require_call)
end
end
The next thing is to process the AST formed against the source code to match problematic lines:
STEP 2:
RSpec.describe RuboCop::Cop::Packaging::RequireRelativeHardcodingLib, :config do
let(:message) { RuboCop::Cop::Packaging::RequireRelativeHardcodingLib::MSG }
let(:project_root) { RuboCop::ConfigLoader.project_root }
context "when `require_relative` call lies outside spec/" do
let(:filename) { "#{project_root}/spec/foo_spec.rb" }
let(:source) { "require_relative '../lib/foo.rb'" }
it "registers an offense" do
expect_offense(<<~RUBY, filename)
#{source}
#{"^" * source.length} #{message}
RUBY
end
end
end
Write tests \o/
STEP 3:
Now, the tool is ready to be deployed, let's use this in other projects:
(this correctly determies the usage of `git ls-files` in the `gemspec` file)
I expect the following outcome from this entire project:
Selected for Google Summer of Code - 2020
(https://wiki.debian.org/SummerOfCode2020/Projects)
(https://wiki.debian.org/SummerOfCode2020/Projects)
Being used by hundreds of people, already.
(https://github.com/utkarsh2102/rubocop-packaging)