├── .rubocop_todo.yml ├── .rspec ├── .yardopts ├── Gemfile ├── .gitignore ├── .codeclimate.yml ├── examples ├── input │ ├── unparseable.rb │ ├── circular_ref.rb │ └── lot_of_errors.rb ├── bare_log.rb └── formatted_log.rb ├── lib ├── yard-junk │ ├── version.rb │ ├── rake.rb │ ├── command_line.rb │ ├── janitor │ │ ├── text_reporter.rb │ │ ├── yard_options.rb │ │ ├── base_reporter.rb │ │ ├── html_reporter.rb │ │ └── resolver.rb │ ├── logger │ │ ├── spellcheck.rb │ │ └── message.rb │ ├── logger.rb │ └── janitor.rb └── yard-junk.rb ├── Rakefile ├── spec ├── spec_helper.rb ├── .rubocop.yml └── yard-junk │ ├── janitor │ ├── html_reporter_spec.rb │ ├── resolver_spec.rb │ └── text_reporter_spec.rb │ ├── logger │ └── message_spec.rb │ ├── logger_spec.rb │ ├── janitor_spec.rb │ └── integration │ └── inject_in_parsing_spec.rb ├── .github └── workflows │ └── ci.yml ├── .rubocop.yml ├── Changelog.md ├── yard-junk.gemspec ├── exe └── yard-junk ├── Gemfile.lock └── README.md /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | -r ./spec/spec_helper 2 | --color 3 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --markup markdown 2 | -e ./lib/yard-junk.rb 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | .yardoc 3 | examples/doc 4 | tmp 5 | pkg 6 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | engines: 2 | rubocop: 3 | enabled: true 4 | channel: rubocop-0-49 5 | -------------------------------------------------------------------------------- /examples/input/unparseable.rb: -------------------------------------------------------------------------------- 1 | class 2 | def m1 3 | end 4 | end 5 | 6 | class B 7 | end 8 | -------------------------------------------------------------------------------- /examples/bare_log.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | exec('cd examples; yard doc -o doc/ --no-stats input/*.rb') 4 | -------------------------------------------------------------------------------- /examples/input/circular_ref.rb: -------------------------------------------------------------------------------- 1 | class Foo 2 | # @param (see #b) 3 | def a; end 4 | # @param (see #a) 5 | def b; end 6 | end 7 | -------------------------------------------------------------------------------- /examples/formatted_log.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | exec('cd examples; yard doc -o doc/ --no-stats -e ../lib/junk_yard.rb input/*.rb') 4 | 5 | 6 | -------------------------------------------------------------------------------- /lib/yard-junk/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module YardJunk 4 | # @private 5 | MAJOR = 0 6 | # @private 7 | MINOR = 0 8 | # @private 9 | PATCH = 10 10 | 11 | # @private 12 | VERSION = [MINOR, MAJOR, PATCH].join('.') 13 | end 14 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | require 'rubygems/tasks' 3 | Gem::Tasks.new 4 | 5 | require_relative 'lib/yard-junk/rake' 6 | YardJunk::Rake.define_task 7 | 8 | require 'rspec/core/rake_task' 9 | RSpec::Core::RakeTask.new 10 | 11 | require 'rubocop/rake_task' 12 | RuboCop::RakeTask.new 13 | 14 | task default: %w[spec rubocop yard:junk] 15 | -------------------------------------------------------------------------------- /lib/yard-junk.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'yard' 4 | require_relative 'yard-junk/version' 5 | require_relative 'yard-junk/logger' 6 | require_relative 'yard-junk/command_line' 7 | require_relative 'yard-junk/janitor' 8 | 9 | YARD::Logger.prepend YardJunk::Logger::Mixin 10 | YARD::CLI::Command.prepend YardJunk::CommandLineOptions 11 | -------------------------------------------------------------------------------- /lib/yard-junk/rake.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module YardJunk 4 | module Rake 5 | extend ::Rake::DSL 6 | 7 | def self.define_task(*args) 8 | desc 'Check the junk in your YARD Documentation' 9 | task('yard:junk') do 10 | require 'yard' 11 | require_relative '../yard-junk' 12 | args = :text if args.empty? 13 | exit Janitor.new.run.report(*args) 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rspec/its' 4 | require 'fakefs/spec_helpers' 5 | require 'saharspec' 6 | 7 | # Imitating YARD's core_ext/file.rb 8 | module FakeFS 9 | class File 10 | def self.cleanpath(path) 11 | path 12 | end 13 | 14 | def self.read_binary(file) 15 | File.binread(file) 16 | end 17 | end 18 | end 19 | 20 | $LOAD_PATH.unshift 'lib' 21 | 22 | require 'yard' 23 | require 'yard-junk/version' 24 | require 'yard-junk/logger' 25 | require 'yard-junk/janitor' 26 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | main: 11 | name: >- 12 | ${{ matrix.ruby }} 13 | runs-on: ubuntu-latest 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | ruby: [ 2.7, "3.0", "3.1", "3.2", "3.3", head ] 18 | 19 | steps: 20 | - name: checkout 21 | uses: actions/checkout@v2 22 | - name: set up Ruby 23 | uses: ruby/setup-ruby@v1 24 | with: 25 | ruby-version: ${{ matrix.ruby }} 26 | 27 | - name: install dependencies 28 | run: bundle install --jobs 3 --retry 3 29 | - name: spec 30 | run: bundle exec rake spec 31 | - name: rubocop 32 | run: bundle exec rake rubocop 33 | -------------------------------------------------------------------------------- /examples/input/lot_of_errors.rb: -------------------------------------------------------------------------------- 1 | # This file tries to show as much errors in documentation as possible 2 | 3 | # Macros attached to class 4 | # @!macro [attach] attached4 5 | # $1 $2 $3 6 | class A 7 | # Wrong macro directive format: 8 | # 9 | # @!macro 10 | # 11 | # Unknown directive: 12 | # @!wtf 13 | 14 | 15 | # @wrong Free hanging unknown tag 16 | 17 | # Unknown macro name: 18 | # @!macro wtf 19 | # Points to unknown class: {B} 20 | # 21 | # @wrong This is unknown tag 22 | # 23 | # @param arg1 [C] Link to unknown class. 24 | # @param arg3 This is unknown argument. 25 | # 26 | def foo(arg1, arg2) 27 | end 28 | 29 | # @param para 30 | # @param para 31 | # @example 32 | # @see {invalid} 33 | def bar(para) 34 | end 35 | 36 | OPTIONS = %i[foo bar baz] 37 | # undocumentable attr_reader 38 | attr_reader *OPTIONS 39 | end 40 | 41 | # not recognize namespace 42 | Bar::BOOKS = 5 43 | -------------------------------------------------------------------------------- /lib/yard-junk/command_line.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module YardJunk 4 | module CommandLineOptions 5 | def common_options(opts) # rubocop:disable Metrics/MethodLength 6 | super 7 | 8 | opts.separator '' 9 | opts.separator 'YardJunk plugin options' 10 | 11 | opts.on('--junk-log-format [FMT]', 12 | 'YardJunk::Logger format string, by default ' \ 13 | "#{Logger::Message::DEFAULT_FORMAT.inspect}") do |format| 14 | Logger.instance.format = format 15 | end 16 | 17 | opts.on('--junk-log-ignore [TYPE1,TYPE2,...]', 18 | 'YardJunk::Logger message types to ignore, by default ' \ 19 | "#{Logger::DEFAULT_IGNORE.map(&:inspect).join(', ')}") do |ignore| 20 | Logger.instance.ignore = ignore.to_s.split(',') 21 | end 22 | 23 | opts.separator '' 24 | opts.separator 'Generic options' 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: "../.rubocop.yml" 2 | 3 | Style/BlockDelimiters: 4 | Enabled: false 5 | 6 | Metrics/BlockLength: 7 | Enabled: false 8 | 9 | Layout/MultilineBlockLayout: 10 | Enabled: false 11 | 12 | Layout/ParameterAlignment: 13 | EnforcedStyle: with_fixed_indentation 14 | 15 | Layout/ArgumentAlignment: 16 | EnforcedStyle: with_fixed_indentation 17 | 18 | RSpec: 19 | Language: 20 | Includes: 21 | Examples: 22 | - its_block 23 | - its_call 24 | 25 | RSpec/DescribeClass: 26 | Enabled: false 27 | 28 | RSpec/NestedGroups: 29 | Enabled: false 30 | 31 | RSpec/BeforeAfterAll: 32 | Enabled: false 33 | 34 | # RSpec/EmptyExampleGroup: 35 | # CustomIncludeMethods: [its_call, its_block] 36 | 37 | RSpec/SpecFilePathFormat: 38 | Enabled: false 39 | 40 | RSpec/ImplicitSubject: 41 | Enabled: false 42 | 43 | RSpec/ContextWording: 44 | Enabled: false 45 | 46 | RSpec/MultipleMemoizedHelpers: 47 | Enabled: false 48 | 49 | Layout/BlockEndNewline: 50 | Enabled: false 51 | 52 | # Because 53 | # expect { ... } 54 | # .to send_message.with(...) 55 | # .and send_message.with(...) 56 | Layout/MultilineMethodCallIndentation: 57 | Enabled: false 58 | 59 | Layout/LineLength: 60 | Enabled: false 61 | -------------------------------------------------------------------------------- /lib/yard-junk/janitor/text_reporter.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rainbow' 4 | 5 | module YardJunk 6 | class Janitor 7 | # Reporter that just outputs everything in plaintext format. Useful 8 | # for commandline usage. See {BaseReporter} for details about reporters. 9 | # 10 | class TextReporter < BaseReporter 11 | private 12 | 13 | def _stats(**stat) 14 | @io.puts "\n#{colorized_stats(**stat)}" 15 | end 16 | 17 | def colorized_stats(errors:, problems:, duration:) 18 | colorize( 19 | format('%i failures, %i problems', errors, problems), status_color(errors, problems) 20 | ) + format(' (%s to run)', duration) 21 | end 22 | 23 | def colorize(text, color) 24 | Rainbow(text).color(color) 25 | end 26 | 27 | def status_color(errors, problems) 28 | case 29 | when errors.positive? then :red 30 | when problems.positive? then :yellow 31 | else :green 32 | end 33 | end 34 | 35 | def header(title, explanation) 36 | @io.puts 37 | @io.puts title 38 | @io.puts '-' * title.length 39 | @io.puts "#{explanation}\n\n" 40 | end 41 | 42 | def row(msg) 43 | @io.puts msg.to_s # default Message#to_s is good enough 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml 2 | require: rubocop-rspec 3 | 4 | AllCops: 5 | Include: 6 | - 'lib/**/*.rb' 7 | - 'spec/**/*.rb' 8 | Exclude: 9 | - 'vendor/**/*' 10 | - 'examples/**/*' 11 | - 'tmp/**/*' 12 | - Gemfile 13 | - Rakefile 14 | - '*.gemspec' 15 | DisplayCopNames: true 16 | TargetRubyVersion: 2.7 17 | NewCops: enable 18 | 19 | Style/PercentLiteralDelimiters: 20 | PreferredDelimiters: 21 | default: '{}' 22 | 23 | Style/SignalException: 24 | EnforcedStyle: semantic 25 | 26 | Style/RegexpLiteral: 27 | Enabled: false 28 | 29 | Style/FormatStringToken: 30 | Enabled: false 31 | 32 | Style/AndOr: 33 | EnforcedStyle: conditionals 34 | 35 | Layout/SpaceInsideHashLiteralBraces: 36 | EnforcedStyle: no_space 37 | 38 | Layout/LineLength: 39 | Max: 100 40 | AllowedPatterns: ['(^| )\# .*'] # ignore long comments 41 | 42 | Metrics/ParameterLists: 43 | CountKeywordArgs: false 44 | 45 | Style/FormatString: 46 | Enabled: false 47 | 48 | Style/EmptyCaseCondition: 49 | Enabled: false 50 | 51 | Lint/AmbiguousOperatorPrecedence: 52 | Enabled: false 53 | 54 | Lint/EmptyWhen: 55 | Enabled: false 56 | 57 | Naming/FileName: 58 | Exclude: 59 | - 'lib/yard-junk.rb' 60 | 61 | Lint/MixedRegexpCaptureTypes: 62 | Enabled: false 63 | 64 | Style/MultilineBlockChain: 65 | Enabled: false 66 | 67 | Style/BlockDelimiters: 68 | Enabled: false 69 | 70 | Style/OpenStructUse: 71 | Enabled: false 72 | 73 | # TODO 74 | Style/Documentation: 75 | Enabled: false 76 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | # Yard-Junk changelog 2 | 3 | ## 0.0.10 -- 2024-09-08 4 | 5 | * Update to support newer Rubies (by [@pboling](https://github.com/pboling) at [#42](https://github.com/zverok/yard-junk/pull/42)) 6 | * Drop support for Ruby < 2.7 7 | 8 | ## 0.0.9 -- 2020-12-05 9 | 10 | * Avoid deprecation warnings ([640bc355d](https://github.com/zverok/yard-junk/commit/640bc355d156e892348b80210fc034af25e196cf)) 11 | 12 | ## 0.0.8 -- 2020-11-12 13 | 14 | * Support Ruby 2.7 (and hopefully 3.0) 15 | * Drop support for Rubies below 2.5 :shrug: 16 | 17 | ## 0.0.7 -- 2017-09-21 18 | 19 | * Fix problems with links resolution for RDoc. 20 | 21 | ## 0.0.6 -- 2017-09-20 22 | 23 | * More robust (and more logical) colorization on text output (#25); 24 | * Fast "sanity check" for using in pre-commit hook on large codebases (#24). 25 | 26 | ## 0.0.5 -- 2017-09-11 27 | 28 | * Fix gem conflict with `did_you_mean`. 29 | 30 | ## 0.0.4 -- 2017-09-09 31 | 32 | * Support for partial reports `yard-junk --path path/to/folder` (#13) 33 | 34 | ## 0.0.3 -- 2017-09-07 35 | 36 | * Wiser dependency on `did_you_mean`, should not break CIs now. 37 | * Support for Ruby 2.1 and 2.2. 38 | 39 | ## 0.0.2 -- 2017-09-03 40 | 41 | * Lots of small cleanups and enchancement of README, Gemfile and directory structure ([@olleolleolle]); 42 | * Colorized text output ([@olleolleolle]); 43 | * HTML reporter; 44 | * Options for command line and Rake task. 45 | 46 | ## 0.0.1 -- 2017-08-27 47 | 48 | Yard-Junk was born (Even RubyWeekly [#364](http://rubyweekly.com/issues/364) noticed!) 49 | -------------------------------------------------------------------------------- /spec/yard-junk/janitor/html_reporter_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe YardJunk::Janitor::HtmlReporter do 4 | subject(:reporter) { described_class.new(out) } 5 | 6 | let(:out) { StringIO.new } 7 | 8 | describe 'initial' do 9 | its(:html) { is_expected.to eq described_class::HEADER } 10 | end 11 | 12 | describe '#section' do 13 | before do 14 | reporter.section( 15 | 'Section', 16 | 'Explanation', 17 | [ 18 | YardJunk::Logger::Message.new(message: 'Something bad', file: 'file.rb', line: 10), 19 | YardJunk::Logger::Message.new(message: 'Something bad', file: 'file.rb', line: 12) 20 | ] 21 | ) 22 | end 23 | 24 | its(:html) do 25 | # NB: this is not very strict test, but... enough 26 | is_expected.to include('Section') 27 | .and include('Explanation') 28 | .and include('