diff --git a/Rakefile b/Rakefile index 813bdd7..70a218e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,29 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' require 'open3' + +require 'bundler' +require 'bundler/gem_tasks' + +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + warn e.message + warn 'Run `bundle install` to install missing gems' + exit e.status_code +end + require 'rspec/core/rake_task' +require 'rubocop/rake_task' Dir['tasks/**/*.rake'].each { |t| load t } -RSpec::Core::RakeTask.new(:spec) +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] +end + +desc 'Run RuboCop over this gem' +RuboCop::RakeTask.new(:internal_investigation) desc 'Confirm documentation is up to date' task confirm_documentation: :generate_cops_documentation do @@ -14,9 +31,31 @@ task confirm_documentation: :generate_cops_documentation do Open3.popen3('git diff --exit-code docs/') unless process.value.success? - abort 'Please run `rake generate_cops_documentation` ' \ + raise 'Please run `rake generate_cops_documentation` ' \ 'and add docs/ to the commit.' end end -task default: :spec +task default: %i[spec + internal_investigation + documentation_syntax_check + confirm_documentation] + +desc 'Generate a new cop template' +task :new_cop, [:cop] do |_task, args| + require 'rubocop' + + cop_name = args.fetch(:cop) do + warn "usage: bundle exec rake 'new_cop[ThreadSafety/Name]'" + exit! + end + + generator = RuboCop::Cop::Generator.new(cop_name) + + generator.write_source + generator.write_spec + generator.inject_require(root_file_path: 'lib/rubocop-thread_safety.rb') + generator.inject_config(config_file_path: 'config/default.yml') + + puts generator.todo +end diff --git a/docs/antora.yml b/docs/antora.yml new file mode 100644 index 0000000..c710316 --- /dev/null +++ b/docs/antora.yml @@ -0,0 +1,5 @@ +name: rubocop-thread_safety +title: RuboCop Thread Safety +version: ~ +nav: + - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc new file mode 100644 index 0000000..be86578 --- /dev/null +++ b/docs/modules/ROOT/nav.adoc @@ -0,0 +1,6 @@ +* xref:index.adoc[Home] +* xref:installation.adoc[Installation] +* xref:usage.adoc[Usage] +* xref:cops.adoc[Cops] +* Cops Documentation +** xref:cops_threadsafety.adoc[thread_safety] diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc new file mode 100644 index 0000000..42bf586 --- /dev/null +++ b/docs/modules/ROOT/pages/index.adoc @@ -0,0 +1,4 @@ += RuboCop Thread Safety + +Thread safety analysis for your projects, as an extension to +https://github.com/rubocop/rubocop[RuboCop]. diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc new file mode 100644 index 0000000..b0b410e --- /dev/null +++ b/docs/modules/ROOT/pages/installation.adoc @@ -0,0 +1,15 @@ += Installation + +Just install the `rubocop-thread_safety` gem + +[source,bash] +---- +gem install rubocop-thread_safety +---- + +or if you use bundler put this in your `Gemfile` + +[source,ruby] +---- +gem 'rubocop-thread_safety' +---- diff --git a/docs/modules/ROOT/pages/usage.adoc b/docs/modules/ROOT/pages/usage.adoc new file mode 100644 index 0000000..224b9f9 --- /dev/null +++ b/docs/modules/ROOT/pages/usage.adoc @@ -0,0 +1,32 @@ += Usage + +You need to tell RuboCop to load the Thread Safety extension. There are three +ways to do this: + +== RuboCop configuration file + +Put this into your `.rubocop.yml`. + +[source,yaml] +---- +require: rubocop-thread_safety +---- + +Now you can run `rubocop` and it will automatically load the RuboCop Thread Safety +cops together with the standard cops. + +== Command line + +[source,sh] +---- +$ rubocop --require rubocop-thread_safety +---- + +== Rake task + +[source,ruby] +---- +RuboCop::RakeTask.new do |task| + task.requires << 'rubocop-thread_safety' +end +----